Commit 34d1fdb
fix(dpmodel): dpa1 dense call must not route through divergent graph adapter (#5785)
## Problem
`DescrptDPA1.call` routes graph-eligible configs through
`_call_graph_adapter` (decision #14: dense call = thin adapter). That
adapter is bit-exact vs `_call_dense` **only in the trivial-statistics
regime** (`davg == 0`): the dense se_atten body leaks a phantom
padding-neighbor `-davg/dstd` residual (`EnvMat.call` subtracts `davg`
after the padding rows' geometry is weight-zeroed; with empty
`exclude_types` nothing re-masks it, at **any** `attn_layer`) that the
graph path deliberately omits. Measured on the consistency fixture:
dense vs adapter agree at 0.0 for `davg=0`, diverge by ~20 (abs) for
nonzero `davg`, at both `attn_layer=0` and `2`.
The gate also made `mapping` — an argument that only enables ghost
folding on graph routes — silently change the numerics of a dense call:
`call(..., mapping)` and `call(...)` returned different descriptors for
the same physical system.
## Why it never surfaced
The pt/pd consistency tests invoke `dd2.call()` **without** `mapping`,
so the routing gate (`mapping is not None or nall == nloc`) is off and
the tests exercise the dense body — a code path production never takes:
`DPAtomicModel.forward_atomic` always forwards `mapping`. Consequence:
dpmodel/jax/tf2 inference of a **trained** dpa1 with
`set_davg_zero=False` (the constructor default) silently used the
adapter and differed from the pt/tf dense backends. Cross-backend suites
stayed green only because fresh models sit in the trivial-stat regime.
This is the dpa1 twin of the dpa2 routing fix in #5779
(wanghan-iapcm/deepmd-kit@bc0d70ade, where the same class of divergence
was caught by CI because the dpa2 consistency test does pass `mapping`).
## Fix
- `DescrptDPA1.call` always runs `_call_dense` — it is the cross-backend
consistency reference. The graph-native route is reached exclusively
through `call_graph` (pt_expt `forward_atomic_graph` and the graph
`.pt2`); nothing in shipping code consumed the `call` flip.
- `_call_graph_adapter` is retained as the bit-exact-regime reference;
its docstring now states the actual regime (including the slot-0
statistics simplification, exact for real slot-uniform stat tables).
## Tests
- pt/pd `test_dpa1.py::test_consistency` now pass `mapping` (the
production invocation). Red on the old routing (71%-scale mismatch),
green with the fix.
- New regression: `call(mapping) == call(None) == _call_dense` at zero
tolerance with nonzero injected `davg` and ghosts present.
- Adapter parity tests (`test_dpa1_call_graph_descriptor.py`,
`test_dpa1_graph_attention_parity.py`) exercise `_call_graph_adapter`
directly instead of relying on the removed `call` routing — adapter
coverage is unchanged.
- Local sweep: dpa1/se_atten_v2 graph+consistency+universal battery — 94
+ 304 + 852 passed.
## Notes
- No conflict expected with #5779 (different files); the two PRs are
independent.
- pt_expt training/export graph routes are untouched (`uses_graph_lower`
still gates them; it no longer influences the dense `call`).
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Ensured descriptor calculations consistently use the dense path,
regardless of mapping or graph-related conditions.
* Preserved graph-based processing through its dedicated pathway.
* Prevented mapping settings from changing dense numerical results.
* **Tests**
* Expanded parity and consistency coverage across dense and graph-based
calculations.
* Added regression checks for mapping, ghost atoms, exclusions, and
single-rank scenarios.
* Improved validation of bit-exact results and production-path behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>1 parent d798a8a commit 34d1fdb
5 files changed
Lines changed: 121 additions & 47 deletions
File tree
- deepmd/dpmodel/descriptor
- source/tests
- common/dpmodel
- pd/model
- pt/model
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
611 | 618 | | |
612 | 619 | | |
613 | 620 | | |
| |||
616 | 623 | | |
617 | 624 | | |
618 | 625 | | |
619 | | - | |
| 626 | + | |
620 | 627 | | |
621 | 628 | | |
622 | 629 | | |
623 | 630 | | |
624 | | - | |
625 | | - | |
626 | | - | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
627 | 647 | | |
628 | 648 | | |
629 | 649 | | |
| |||
Lines changed: 66 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
6 | 5 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
69 | | - | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | | - | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
| 141 | + | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
180 | 181 | | |
181 | 182 | | |
182 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
183 | 222 | | |
184 | 223 | | |
185 | 224 | | |
| |||
188 | 227 | | |
189 | 228 | | |
190 | 229 | | |
191 | | - | |
| 230 | + | |
192 | 231 | | |
193 | 232 | | |
194 | 233 | | |
| |||
208 | 247 | | |
209 | 248 | | |
210 | 249 | | |
211 | | - | |
| 250 | + | |
212 | 251 | | |
213 | 252 | | |
214 | 253 | | |
| |||
299 | 338 | | |
300 | 339 | | |
301 | 340 | | |
302 | | - | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
303 | 345 | | |
304 | | - | |
| 346 | + | |
305 | 347 | | |
306 | 348 | | |
307 | 349 | | |
| |||
315 | 357 | | |
316 | 358 | | |
317 | 359 | | |
318 | | - | |
| 360 | + | |
319 | 361 | | |
320 | | - | |
321 | | - | |
| 362 | + | |
| 363 | + | |
322 | 364 | | |
323 | 365 | | |
324 | 366 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
232 | 234 | | |
233 | 235 | | |
234 | 236 | | |
| |||
243 | 245 | | |
244 | 246 | | |
245 | 247 | | |
246 | | - | |
| 248 | + | |
247 | 249 | | |
248 | | - | |
249 | | - | |
| 250 | + | |
| 251 | + | |
250 | 252 | | |
251 | 253 | | |
252 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
105 | 109 | | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
111 | 115 | | |
112 | 116 | | |
| 117 | + | |
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
| |||
0 commit comments