Commit 5082854
feat(pt_expt): dpa1(attn_layer=0) graph-native NeighborGraph forward (#5583)
## Summary
Adds the graph-native forward path for `dpa1(attn_layer=0)` (the
factorizable, mixed-types case), built on the `NeighborGraph` foundation
from #5581. Geometry enters the descriptor only through per-edge
`edge_vec`; the neighbor-axis reduction becomes a `segment_sum` over
edge centers. For `pt_expt` this becomes the **default** forward
(force/virial via a single autograd backward through `edge_vec`).
## What it adds
- **dpmodel**: `edge_env_mat` (per-edge env-mat 4-vector),
`DescrptBlockSeAtten._call_graph` + `DescrptDPA1.call_graph`, model
`call_lower_graph` (energy), `neighbor_graph_from_ijs` + an optional
**ASE** O(N) carry-all builder.
- **pt_expt**: `edge_energy_deriv` (autograd `grad(E, edge_vec)` →
`edge_force_virial`) + `forward_common_lower_graph` (energy + force +
virial + atom_virial).
- The dense `DescrptDPA1.call` becomes a thin adapter
(`from_dense_quartet → call_graph`) preserving the 5-tuple ABI; a
**shape-static** converter keeps it `jax.jit` /
`torch.export`-traceable.
## Default behavior
- **pt_expt** defaults graph-eligible `dpa1(attn_layer=0, concat tebd,
no exclude_types)` models to the carry-all graph (it has the autograd
force/virial path).
- **dpmodel/jax** keep the dense default (they compute force/virial
analytically; the graph lower is energy-only), and **agree with pt_expt
at non-binding `sel`**.
- Ineligible configs (attention, strip tebd, `exclude_types`,
linear/ZBL) fall back to the dense path unchanged.
`neighbor_graph_method="legacy"` forces dense; `"dense"`/`"ase"` force
the graph.
## Parity (graph vs legacy dense lower, fp64 CPU)
| | energy | force | virial | atom_virial |
|---|---|---|---|---|
| max abs diff | 0 | ~1e-19 | ~1e-18 | **~1e-18** |
atom_virial matches the canonical TF==pt-legacy full-to-src convention.
dpa1 descriptor + model consistency suites green across dp/jax/pt_expt.
## Known limitations
- Default-flip is **pt_expt-only**; full carry-all default for dp/jax
needs analytical/jax graph force (follow-up).
- `make_fx` (forward + grad) traces; **full `.pt2` AOTI export is a
follow-up** (PR-B). The carry-all builders
(`build_neighbor_graph`/`from_ijs`) still use `nonzero` (eager-only);
their static variants land with the export PR.
- Single-rank only; CUDA unvalidated (CPU box); ASE is opt-in O(N)
(vesin O(N) is a follow-up); no jax graph force / dpa2-3 message-passing
yet.
Also folds in three follow-up fixes to the #5581 foundation from
@OutisLi's review (dangling spec refs → design discussion,
`edge_force_virial` jax int-sum short-circuit, `Array` typing).
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Added graph-native “lowering” for DPA1 when compatible, including
graph-native descriptor/forward execution and graph-native
descriptor→model output conversion.
* Introduced opt-in `neighbor_graph_method` routing for
energy/force/virial, with carry-all neighbor graphs and graph-output
fitting/post-processing.
* Added new neighbor-graph utilities (including ASE-based carry-all
building, `(i,j,S)` conversion, and per-edge environment-matrix
computation), exported as part of the public API.
* **Bug Fixes**
* Improved stability for masked/padded edges, virtual atom handling, and
parameter protection consistency; refined traced virial assembly when
node-capacity is used.
* **Tests**
* Expanded parity/regression suites for graph lowering,
energy/force/virial, conversion correctness, ragged graphs, and FX
tracing.
<!-- 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 ac8e430 commit 5082854
37 files changed
Lines changed: 4388 additions & 98 deletions
File tree
- deepmd
- dpmodel
- atomic_model
- descriptor
- fitting
- model
- utils
- neighbor_graph
- pt_expt/model
- source/tests
- common
- dpmodel
- pd/model
- pt_expt
- descriptor
- model
- universal/common/cases
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | 19 | | |
13 | 20 | | |
| |||
303 | 310 | | |
304 | 311 | | |
305 | 312 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
310 | 403 | | |
311 | 404 | | |
312 | 405 | | |
313 | 406 | | |
314 | | - | |
| 407 | + | |
315 | 408 | | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
321 | 416 | | |
322 | | - | |
323 | 417 | | |
324 | 418 | | |
325 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
9 | 15 | | |
10 | 16 | | |
11 | 17 | | |
| |||
248 | 254 | | |
249 | 255 | | |
250 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
251 | 311 | | |
252 | 312 | | |
253 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
57 | 56 | | |
58 | 57 | | |
59 | 58 | | |
60 | | - | |
| 59 | + | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | | - | |
67 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
0 commit comments