Commit a3195b0
feat: SFPG cross-rank completion — capabilities, ZBL bridging and spin+ZBL multi-rank (#5939)
Closes #5906.
The DPA4/SeZM Source Freeze Propagation Gate computes each node's `eta_j
= prod over outgoing edges of w(r_e)`; under MPI domain decomposition a
rank only holds edges with owned destinations, so the src-keyed per-node
partials are rank-incomplete and bridged models were single-rank only.
This PR completes the gate across ranks and, as a prerequisite, promotes
the export-time questions to atomic-model capabilities so compositions
answer by aggregation.
## Phase 1 — capability aggregation (issue Task 4)
- Split the conflated descriptor capability:
`has_message_passing_across_ranks` (needs the per-block exchange;
unconditionally true for SeZM) vs the new `supports_edge_parallel` (can
run under domain decomposition).
- Six capabilities on `BaseAtomicModel` with concrete defaults,
descriptor delegation on `DPAtomicModel`, and any/all aggregation on
`LinearEnergyAtomicModel`: `has_message_passing_across_ranks` (any),
`supports_edge_parallel` (all), `dense_lower_supports_comm` (all),
`uses_compact_edge_pairs` (any), `graph_edge_dtype` (float32 iff all
children), `supports_graph_export` (all).
- `forward_lower_graph_exportable_with_comm` hoisted from `EnergyModel`
into `make_model` (one owner, next to the non-comm twin) so
`LinearEnergyModel` compositions can export it.
- The four `serialization.py` helpers now consult the atomic model — no
`isinstance`-on-concrete-model checks, no `.descriptor` walks.
Regression fixed: a linear composition of two DPA2 children now gets its
with-comm artifact (previously denied by wrapper type).
- Composition-safe reach-ins outside serialization: `.pt`-checkpoint
eval no longer crashes on compositions (`ntypes` via the model API),
`enable_compile` degrades gracefully, and pt_expt `get_standard_model`
honors `bridging_method` like its dpmodel twin (`_compose_bridging` is
the single composition owner).
## Phase 2 — SFPG cross-rank completion (issue Tasks 2 and 3)
No new communication machinery: the fix is one extra invocation of the
existing `deepmd_export::border_op_backward` + `border_op` pair (they
are exact transposes, `R = B^T`) on an `(N, 2)` `[log_eta, zero_count]`
tensor before the gate is applied — reverse-accumulate ghost partials
into owners, then broadcast the completed values back. Zero C++ changes.
- `border_op_backward` gains autograd (its gradient is `border_op`'s
forward), so gate gradients cross ranks.
- dpmodel: `compute_edge_src_gate` packs the partials through an
optional `node_partial_exchange` hook; the dpmodel
`_gate_partial_exchange` raises (single-process reference), the pt_expt
subclass implements it on the border-op pair.
- pt backend wired the same way. The red run of the new pt parity test
demonstrated the issue's claim and more: pt's bridged parallel path did
not just compute a silently wrong gate — it crashed outright (the ZBL
injection indexed per-local types with extended ghost `src` indices);
fixed by reading extended types.
- Gates flipped: `supports_edge_parallel` is now `True` for bridged SeZM
in both backends; bridged (and spin+ZBL) graph freezes embed the nested
`forward_lower_with_comm.pt2`.
## Verification
Anti-vacuous discipline throughout: every parity test places a
sub-`r_outer` pair ACROSS the periodic/rank boundary (without it every
cross-rank gate contribution is `log w = 0`), covers both bridging
channels (hard-freeze `zero_count` at 0.4 Å, transition-zone `log_eta`
at ~1 Å), and carries an identity-exchange ablation that must diverge.
- Eager self-comm parity vs the folded reference at rtol/atol 1e-12
(energy, force, and force_mag for the spin variant), pt and pt_expt.
- make_fx traces both border ops symbolically (21-input with-comm ABI
unchanged); freeze embeds the nested artifact for ZBL and spin+ZBL
compositions.
- LAMMPS end-to-end on a Tesla T4: 2-rank vs 1-rank close-pair parity
for ZBL (`pair_style deepmd`) and spin+ZBL (`pair_style deepspin`, incl.
magnetic forces) — the spin+ZBL variant gets its first LAMMPS file. All
24 `*Dpa4Zbl*` C++ gtests pass (CPU + T4).
- Variant-alignment coverage: ZBL empty-rank fail-fast twin, the first
test of the DeepSpin owned-empty phantom path, charge-spin through
`pair_style deepspin`, and default-CLI `dp freeze` resolution
(nlist→graph auto-override + with-comm artifact) for both compositions.
## Known limitations
1. pt eager multi-rank bridging has no true-MPI pt test (no pt `.pth`
LAMMPS ZBL fixtures exist); its parity rung is self-comm.
2. `graph_edge_dtype` composition rule (float32 iff ALL children) is
conservative; fp64 is the universal ABI.
3. `supports_graph_export` keeps the hardcoded `"cuda"` probe inside
pt_expt DPA1 (capability promoted; probe internals unchanged).
4. The `NativeSpinModelKind` marker-base check in
`_needs_with_comm_artifact` remains (a cross-backend family test, not a
concrete-type reach-through).
5. Model-deviation coverage stays absent for all dpa4 variants
(pre-existing; Python `model_devi` has no spin support at all).
6. DeepPot vs DeepSpin empty-rank designs deliberately differ (fail-fast
vs phantom-pad, PR #5485); both are now pinned per variant, not unified.
7. Found while testing, left for a separate fix:
`source/api_c/include/deepmd.hpp` uses `&vec[0]` on possibly-empty
vectors (~33 sites) — undefined behavior that SIGABRTs under
`_GLIBCXX_ASSERTIONS` before the empty-rank guard's message can fire
(benign on non-hardened builds).
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added multi-rank inference for bridged DPA4/SeZM models, including
native-spin and ZBL configurations.
* Improved graph export detection, metadata, edge precision, and
communication-aware export.
* Added atomic-output-only inference for statistics workflows.
* Standard model loading now preserves bridging configurations.
* **Bug Fixes**
* Improved handling of atom types, ghost atoms, empty MPI ranks,
charge-spin inputs, and cross-rank calculations.
* **Documentation**
* Updated DPA4 and native-spin documentation for expanded multi-rank and
graph export support.
* **Tests**
* Added regression coverage for MPI parity, graph exports, bridging,
charge-spin behavior, and capability reporting.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent c0c1f0c commit a3195b0
46 files changed
Lines changed: 3653 additions & 772 deletions
File tree
- deepmd
- dpmodel
- atomic_model
- descriptor
- dpa4_nn
- model
- pt_expt
- descriptor
- infer
- model
- train
- utils
- pt
- entrypoints
- model
- descriptor
- sezm_nn
- model
- doc/model
- source
- lmp/tests
- tests
- common/dpmodel
- infer
- pt_expt
- model
- utils
- pt/model
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 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 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
193 | 241 | | |
194 | 242 | | |
195 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
170 | 194 | | |
171 | 195 | | |
172 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 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 | + | |
185 | 210 | | |
186 | 211 | | |
187 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
545 | 560 | | |
546 | 561 | | |
547 | 562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
604 | 604 | | |
605 | 605 | | |
606 | 606 | | |
| 607 | + | |
607 | 608 | | |
608 | 609 | | |
609 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
1541 | 1542 | | |
1542 | 1543 | | |
1543 | 1544 | | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
1544 | 1553 | | |
1545 | 1554 | | |
1546 | 1555 | | |
| |||
1562 | 1571 | | |
1563 | 1572 | | |
1564 | 1573 | | |
| 1574 | + | |
1565 | 1575 | | |
1566 | 1576 | | |
1567 | 1577 | | |
| |||
2196 | 2206 | | |
2197 | 2207 | | |
2198 | 2208 | | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
2199 | 2243 | | |
2200 | 2244 | | |
2201 | 2245 | | |
| |||
2278 | 2322 | | |
2279 | 2323 | | |
2280 | 2324 | | |
2281 | | - | |
| 2325 | + | |
2282 | 2326 | | |
2283 | | - | |
2284 | | - | |
2285 | | - | |
2286 | | - | |
2287 | | - | |
2288 | | - | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
2289 | 2331 | | |
2290 | 2332 | | |
2291 | 2333 | | |
2292 | 2334 | | |
2293 | 2335 | | |
2294 | | - | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2295 | 2346 | | |
2296 | 2347 | | |
2297 | 2348 | | |
| |||
2316 | 2367 | | |
2317 | 2368 | | |
2318 | 2369 | | |
2319 | | - | |
2320 | | - | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
2321 | 2374 | | |
2322 | 2375 | | |
2323 | 2376 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
| |||
209 | 218 | | |
210 | 219 | | |
211 | 220 | | |
212 | | - | |
213 | 221 | | |
214 | 222 | | |
215 | | - | |
216 | | - | |
217 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
218 | 228 | | |
219 | | - | |
| 229 | + | |
220 | 230 | | |
221 | | - | |
| 231 | + | |
222 | 232 | | |
223 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
224 | 248 | | |
225 | 249 | | |
226 | 250 | | |
| |||
244 | 268 | | |
245 | 269 | | |
246 | 270 | | |
| 271 | + | |
247 | 272 | | |
248 | 273 | | |
249 | 274 | | |
| |||
295 | 320 | | |
296 | 321 | | |
297 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
298 | 327 | | |
299 | 328 | | |
300 | 329 | | |
| |||
358 | 387 | | |
359 | 388 | | |
360 | 389 | | |
| 390 | + | |
361 | 391 | | |
362 | 392 | | |
363 | 393 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
215 | 233 | | |
216 | 234 | | |
217 | 235 | | |
| |||
0 commit comments