fix(spatial): 已移除的边不再进入实体的入射求和

和 remove_entity 是同一类 bug:跳数已经按干预后的图算,但价值流里还在把被切断的
边加进端点。于是"删除 k0(tx 轴)"之后 P 的表示仍然报告 tx 被锁住,模型得先学会
把它减掉才能答对——自由度域的三种子抖动可能就来自这里。
This commit is contained in:
x committed 2026-12-03 20:25:34 +08:00
1 parent 898e691fbf
commit 830bbac4f3
1 file changed
+8 -2
+8 -2
View File
@@ -303,7 +303,10 @@ class RelationBackbone(nn.Module):
# backward pass simple and it makes "an entity receiving three edges sums
# three vectors" obvious. Dangling edges are excluded: their far end is
# not an entity, and pretending otherwise would credit an arbitrary node
# with a relation it does not have.
# with a relation it does not have. Removed edges are excluded too, for
# the same reason the hop distance excludes them: the question is about
# the graph after the cut, and an entity whose value still sums a cut
# constraint has to un-learn it before it can answer.
inc = torch.zeros(B, n_ent, E, device=device)
cols = torch.arange(E, device=device).view(1, E).expand(B, E)
ones = torch.ones_like(cols, dtype=inc.dtype)
@@ -311,7 +314,10 @@ class RelationBackbone(nn.Module):
edge_index[..., 0].clamp(min=0, max=n_ent - 1), cols), ones)
inc.index_put_((ar.unsqueeze(1).expand(B, E),
edge_index[..., 1].clamp(min=0, max=n_ent - 1), cols), ones)
inc = inc * (edge_mask & ~has_unk).unsqueeze(1).to(inc.dtype)
live = edge_mask & ~has_unk
if edge_removed is not None:
live = live & ~(edge_removed > 0)
inc = inc * live.unsqueeze(1).to(inc.dtype)
msg = torch.bmm(inc, ef)
# query token is read out of the two entities it names