Skip to content

Commit 480cd61

Browse files
author
Han Wang
committed
test: binding-sel audit for graph-default attention models
- linear-model weight tests: pin smooth_type_embedding=False — the standard (graph-routed, carry-all) and linear (graph-ineligible, dense) submodels otherwise differ by the accepted smooth-attention denominator divergence (~1e-6), which is a route artifact, not a weight-combination bug. - new binding-sel sanity: carry-all graph attention diverges from the sel-truncated dense path when sel binds (spec decision #17).
1 parent e069d2d commit 480cd61

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

source/tests/common/dpmodel/test_dpa1_graph_attention_parity.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,45 @@ def test_strip_mode_stays_dense(self) -> None:
225225

226226
dd = DescrptSeAttenV2(rcut=4.0, rcut_smth=0.5, sel=[20], ntypes=2, attn_layer=2)
227227
assert not dd.uses_graph_lower()
228+
229+
230+
class TestBindingSelDivergence:
231+
"""At BINDING sel the carry-all graph attends over MORE neighbors than the
232+
sel-truncated dense path — outputs must differ (sanity, not parity;
233+
spec decision #17).
234+
"""
235+
236+
def test_carry_all_attention_differs_at_binding_sel(self) -> None:
237+
from deepmd.dpmodel.utils.neighbor_graph import (
238+
build_neighbor_graph,
239+
)
240+
241+
rng = np.random.default_rng(GLOBAL_SEED)
242+
nloc = 6
243+
coord = rng.random((1, nloc, 3)) * 2.0 # dense blob => binding sel=2
244+
atype = np.array([[0, 1, 0, 1, 1, 0]], dtype=np.int64)
245+
dd = _make(2, dotr=True, sel=(2,))
246+
ext_coord, ext_atype, mapping, nlist = extend_input_and_build_neighbor_list(
247+
coord, atype, dd.get_rcut(), dd.get_sel(), mixed_types=True, box=None
248+
)
249+
assert (nlist >= 0).all(), "fixture must be sel-binding (all slots full)"
250+
tebd = dd.type_embedding.call()
251+
atype_embd_ext = np.reshape(
252+
np.take(tebd, np.reshape(ext_atype, (-1,)), axis=0),
253+
(1, ext_atype.shape[1], dd.tebd_dim),
254+
)
255+
dense_g, *_ = dd.se_atten.call(
256+
nlist,
257+
ext_coord,
258+
ext_atype,
259+
atype_embd_ext=atype_embd_ext,
260+
mapping=None,
261+
type_embedding=tebd,
262+
)
263+
graph = build_neighbor_graph(coord, atype, None, dd.get_rcut())
264+
graph_g, _ = dd.se_atten.call_graph(
265+
graph, atype.reshape(-1), type_embedding=tebd
266+
)
267+
assert np.max(np.abs(graph_g.reshape(dense_g.shape) - dense_g)) > 1e-6, (
268+
"carry-all attention must diverge from sel-truncated dense"
269+
)

source/tests/pt_expt/model/test_linear_model.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ def test_forward_lower_exportable(self) -> None:
343343
"temperature": 1.0,
344344
"set_davg_zero": True,
345345
"type_one_side": True,
346+
# smooth attention diverges between the graph default (standard model,
347+
# carry-all: no phantom sel-padding softmax terms) and the dense route
348+
# (linear models are graph-ineligible) by design (NeighborGraph PR-D);
349+
# pin smooth off so both routes are exact and the weight-combination
350+
# comparison stays at 1e-10.
351+
"smooth_type_embedding": False,
346352
"seed": 1,
347353
},
348354
"fitting_net": {

0 commit comments

Comments
 (0)