Skip to content

feat(pt_expt): O(N) on-device NeighborGraph builders — vesin & nvalchemiops (PR-C)#5714

Open
wanghan-iapcm wants to merge 7 commits into
deepmodeling:masterfrom
wanghan-iapcm:feat-graph-builders-prC
Open

feat(pt_expt): O(N) on-device NeighborGraph builders — vesin & nvalchemiops (PR-C)#5714
wanghan-iapcm wants to merge 7 commits into
deepmodeling:masterfrom
wanghan-iapcm:feat-graph-builders-prC

Conversation

@wanghan-iapcm

Copy link
Copy Markdown
Collaborator

NeighborGraph PR-C — O(N) on-device graph builders (vesin / nv)

Third PR of the NeighborGraph series (after #5581 foundation, #5583 PR-A dpa1 graph forward, #5604 PR-B .pt2/C++). Adds two O(N) carry-all NeighborGraph builders behind the World-2 neighbor_graph_method dispatcher, replacing PR-A's O(N²) dense search / per-frame ASE stopgap with on-device cell lists.

What

  • build_neighbor_graph_vesin (deepmd/pt_expt/utils/vesin_graph_builder.py) — vesin.torch cell list. Device-following: runs the search on the input tensor's device (CUDA kernel on CUDA input, CPU cell list otherwise).
  • build_neighbor_graph_nv (deepmd/pt_expt/utils/nv_graph_builder.py) — nvalchemiops GPU cell list, frame-batched (batch_idx/batch_ptr, one kernel for all frames — no Python loop). CUDA-only.
  • Both structurally clone build_neighbor_graph_ase: search → per-frame local (i, j, S)neighbor_graph_from_ijs(...), which recomputes edge_vec differentiably from the original grad-carrying coords.
  • Wired into the pt_expt make_model graph dispatch (neighbor_graph_method ∈ {"legacy","dense","ase","vesin","nv"}) and DeepEval .pt2 graph inference (new neighbor_graph_method kwarg, default "dense" → existing inference byte-identical). dpmodel/jax fail-fast on vesin/nv (torch/CUDA-only).

Perf-only: all builders emit the SAME neighbor set as dense (carry-all, sel=normalization-only), proven by exact set-equality; energy/force/virial are unchanged (parity 1e-12 CPU / 1e-10 CUDA).

Layering

  • dpmodel stays torch-free: vesin/nv builders live in pt_expt; the dpmodel dispatch only carries a fail-fast message.
  • vesin/nv are optional deps, NOT in pyproject — lazy-imported, guarded by is_vesin_torch_available() / is_nv_available(), ImportError with an install hint on absence.
  • nv decode is a faithful transcription of the tested deepmd/pt/utils/nv_nlist.py:_matrix_to_extended_inputs Step-1 extraction.

Testing

  • Local (CPU): 13 passed (vesin builder 5, vesin/reject dispatch 2, DeepEval graph 6), nv self-skips.
  • Remote GPU (Tesla T4), commit 78f6c24:
    • test_nv_graph_builder.py: 4 passed (set-equality vs dense periodic+non-periodic, frame-batch, differentiable edge_vec).
    • test_graph_builder_dispatch.py: 3 passed on CUDA (vesin parity 1e-10, dpmodel reject vesin+nv, nv parity 1e-10).
    • test_graph_deepeval.py: 6 passed on CUDA (.pt2 graph dense parity + vesin, AOTI compile + torch.as_tensor extraction).

Known limitations

  • vesin per-frame Python loopvesin.torch.compute is single-system (no batch dim), so multi-frame vesin loops over frames (each an O(N) search; nf=1 inference has zero loop cost). nv batches natively — the loop-free path for batched training.
  • vesin/nv not in pyproject; no "auto" selector (explicit strings only).
  • nv search_capacity = max(64, nloc) initial heuristic + 1.25× grow loop (.item() host-sync per grow).
  • nv passes the normalized coord to from_ijs (differentiable lattice translation, identity gradient; edge_vec is lattice-invariant) — consistent with the pt nv-nlist path.
  • jax O(N) graph builders (matscipy/jax-md) = PR-F; attention/angles/MP = PR-D/E/G.

Implements plan_neighbor_graph_prC_implementation; design spec: discussion wanghan-iapcm#4.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5f659661-fb43-4e4b-b30b-954f2680bf5e

📥 Commits

Reviewing files that changed from the base of the PR and between 55d7e79 and 78f6c24.

📒 Files selected for processing (9)
  • deepmd/dpmodel/model/make_model.py
  • deepmd/pt_expt/infer/deep_eval.py
  • deepmd/pt_expt/model/make_model.py
  • deepmd/pt_expt/utils/nv_graph_builder.py
  • deepmd/pt_expt/utils/vesin_graph_builder.py
  • source/tests/pt_expt/infer/test_graph_deepeval.py
  • source/tests/pt_expt/model/test_graph_builder_dispatch.py
  • source/tests/pt_expt/utils/test_nv_graph_builder.py
  • source/tests/pt_expt/utils/test_vesin_graph_builder.py
👮 Files not reviewed due to content moderation or server errors (9)
  • source/tests/pt_expt/infer/test_graph_deepeval.py
  • source/tests/pt_expt/utils/test_vesin_graph_builder.py
  • deepmd/pt_expt/infer/deep_eval.py
  • deepmd/pt_expt/utils/vesin_graph_builder.py
  • source/tests/pt_expt/utils/test_nv_graph_builder.py
  • deepmd/dpmodel/model/make_model.py
  • source/tests/pt_expt/model/test_graph_builder_dispatch.py
  • deepmd/pt_expt/utils/nv_graph_builder.py
  • deepmd/pt_expt/model/make_model.py

📝 Walkthrough

[!WARNING]

Walkthrough skipped

File diffs could not be summarized.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.26357% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.11%. Comparing base (9bd1f16) to head (6048490).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
deepmd/pt_expt/utils/nv_graph_builder.py 13.79% 50 Missing ⚠️
deepmd/pt_expt/infer/deep_eval.py 79.16% 5 Missing ⚠️
deepmd/pt_expt/model/make_model.py 50.00% 3 Missing ⚠️
deepmd/pt_expt/utils/vesin_graph_builder.py 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5714      +/-   ##
==========================================
- Coverage   81.24%   81.11%   -0.14%     
==========================================
  Files         981      990       +9     
  Lines      109860   111000    +1140     
  Branches     4234     4236       +2     
==========================================
+ Hits        89257    90033     +776     
- Misses      19080    19442     +362     
- Partials     1523     1525       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wanghan-iapcm wanghan-iapcm requested review from OutisLi and iProzd July 2, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant