Skip to content

feat(dpa4): so3_readout across pt + dpmodel/pt_expt backends#5561

Merged
OutisLi merged 3 commits into
deepmodeling:masterfrom
wanghan-iapcm:feat-dpa4-so3-readout
Jun 20, 2026
Merged

feat(dpa4): so3_readout across pt + dpmodel/pt_expt backends#5561
OutisLi merged 3 commits into
deepmodeling:masterfrom
wanghan-iapcm:feat-dpa4-so3-readout

Conversation

@wanghan-iapcm

@wanghan-iapcm wanghan-iapcm commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

What

Adds the DPA4/SeZM so3_readout option ("none" / "glu" / "mlp") across all backends (pt + dpmodel + pt_expt), making it cross-backend consistent.

Builds on #5556 (@OutisLi): its pt so3_readout commit (refactor(dpa4): output ffn) is included here with original authorship preserved; this PR adds the missing dpmodel counterpart so the shared DPA4 serialize format round-trips across backends. (The unrelated nv_nlist/compiler-check fixes from #5556 are intentionally left to #5556.)

Why

so3_readout is implemented by configuring the final output FFN — "glu"/"mlp" turn on the SO(3)-grid FFN (ffn_so3_grid, grid_mlp). On its own (pt-only, as in #5556) it breaks DPA4 cross-backend consistency: pt serialize() emits so3_readout but dpmodel DescrptDPA4 couldn't round-trip it → source/tests/consistent/descriptor/test_dpa4.py::...::test_pt_consistent_with_ref failed on every Test Python shard.

This is now feasible and small because #5555 already ported ffn_so3_grid + the SO(3)-grid machinery (SO3GridNet/GridMLP/GridProduct) into the dpmodel EquivariantFFN. So the dpmodel so3_readout is just: accept the param, configure output_ffn exactly like pt, wire the readout (l=0 slice for "none"; full (N,D,1,C) fold for "glu"/"mlp" then slice l=0), and serialize the key. pt_expt auto-wraps.

Changes

  • pt (from feat(pt/dpa4): add SO3 readout and small bug fix #5556): so3_readout in DescrptSeZM + argcheck + examples/water/dpa4/input.json.
  • dpmodel descriptor/dpa4.py: so3_readout param + validation; output_ffn configured (lmax=node_l_schedule[-1], kmax=min(kmax, readout_lmax), ffn_so3_grid, grid_mlp, grid_branch=0); readout forward mirrors pt; serialize the key.
  • pt_expt: auto-wrapped (no explicit change).

Validation

  • test_dpa4.py cross-backend consistency rows for so3_readout ∈ {none, glu, mlp} (pt vs dpmodel vs pt_expt, mixed_types) — green; test_pt_consistent_with_ref now passes.
  • Full-descriptor pt→dpmodel parity (weight-copied, glu+mlp) — ~7e-15 abs (gate 1e-10), proving serialize interop.
  • dpa4 suite: 611 passed; ruff clean.

Notes

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a configurable so3_readout option to the DPA4 and SeZM descriptors (modes: "none", "glu", "mlp"), controlling how the final SO(3) readout is computed.
    • The setting is included in descriptor configuration serialization/deserialization to support round-tripping.
    • Updated the water DPA4 example to use so3_readout: "mlp".
  • Tests

    • Added tests covering multiple readout modes, backend parity between implementations, and correct behavior for edge-free scenarios.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bdefabe7a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread deepmd/pt/model/descriptor/sezm.py Outdated
@wanghan-iapcm wanghan-iapcm requested a review from OutisLi June 20, 2026 01:16
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: ca7199e0-01a3-4c4b-8e35-4adc1d92d4a1

📥 Commits

Reviewing files that changed from the base of the PR and between bdefabe and 01ba376.

📒 Files selected for processing (3)
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/pt/model/descriptor/sezm.py
  • source/tests/pt/model/test_descriptor_sezm.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • deepmd/pt/model/descriptor/sezm.py
  • deepmd/dpmodel/descriptor/dpa4.py

📝 Walkthrough

Walkthrough

Adds a so3_readout parameter (values: "none", "glu", "mlp") to DescrptDPA4 and DescrptSeZM. The parameter controls whether the final output_ffn operates only on the l=0 scalar slice or on the full SO(3) coefficient tensor; all three modes apply a residual before extracting l=0. Serialization, argcheck validation, tests, and the example config are updated accordingly.

Changes

so3_readout feature for DPA4/SeZM

Layer / File(s) Summary
Constructor signatures, validation, and argcheck
deepmd/pt/model/descriptor/sezm.py, deepmd/dpmodel/descriptor/dpa4.py, deepmd/utils/argcheck.py
Both DescrptSeZM and DescrptDPA4 add so3_readout: str = "none" with lowercase normalization and ValueError on invalid values. SeZM docstring documents the three modes. descrpt_se_zm_args() adds a matching Argument entry with doc string and validation.
Conditional output_ffn construction
deepmd/pt/model/descriptor/sezm.py, deepmd/dpmodel/descriptor/dpa4.py
output_ffn init is replaced with a conditional block: "none" keeps a degree-0 scalar FFN; "glu"/"mlp" configure a wider equivariant FFN using the last block's node degree, clamped kmax, ffn_so3_grid=True, and grid_mlp=True for "mlp".
Forward pass mixing and serialization
deepmd/pt/model/descriptor/sezm.py, deepmd/dpmodel/descriptor/dpa4.py
call(), forward(), and forward_with_edges() now conditionally build ffn_in from the l=0 slice or full SO(3) tensor, apply the residual, then extract l=0. Both backends serialize so3_readout in their config dicts.
Tests and example config
source/tests/consistent/descriptor/test_dpa4.py, source/tests/pt/model/test_dpa4_dpmodel_parity.py, source/tests/pt/model/test_descriptor_sezm.py, examples/water/dpa4/input.json
Consistent test case fields and curated cases are extended for "glu" and "mlp". A new parametrized PT/DP parity test constructs both backends with each readout mode, perturbs weights, and asserts strict fp64 parity. A regression test validates readout behavior with empty edge lists. Example config adds "so3_readout": "mlp".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • njzjz
  • iProzd
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding the so3_readout feature across multiple backends (PyTorch, dpmodel, and pt_expt).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@deepmd/pt/model/descriptor/sezm.py`:
- Around line 1236-1243: When `so3_readout != "none"`, the `ffn_in` variable is
set to the full `x` tensor without truncation, but `x` may retain its initial
dimension (`self.node_ebed_dims[0]`) instead of the final expected dimension
(`self.node_ebed_dims[-1]`) when `_forward_blocks` is skipped. This causes a
shape mismatch when feeding to `output_ffn`. In the else branch of the
conditional that sets `ffn_in`, truncate `x` to match the final node embedding
dimension before casting to the compute dtype, similar to the slicing applied in
the `if self.so3_readout == "none"` branch, to ensure the tensor shape matches
what `output_ffn` expects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dd93cd81-2191-41e0-a1ea-4c93376cdf20

📥 Commits

Reviewing files that changed from the base of the PR and between 5a0d505 and bdefabe.

📒 Files selected for processing (6)
  • deepmd/dpmodel/descriptor/dpa4.py
  • deepmd/pt/model/descriptor/sezm.py
  • deepmd/utils/argcheck.py
  • examples/water/dpa4/input.json
  • source/tests/consistent/descriptor/test_dpa4.py
  • source/tests/pt/model/test_dpa4_dpmodel_parity.py

Comment thread deepmd/pt/model/descriptor/sezm.py
@wanghan-iapcm wanghan-iapcm added the Test CUDA Trigger test CUDA workflow label Jun 20, 2026
@github-actions github-actions Bot removed the Test CUDA Trigger test CUDA workflow label Jun 20, 2026
…e path)

AI-review (CodeRabbit/codex) finding on deepmodeling#5561: with so3_readout=glu/mlp and a
shrinking l_schedule, the empty-edge path skips _forward_blocks, leaving x at
the initial node degree (node_ebed_dims[0]); the full x was fed to output_ffn
built for node_ebed_dims[-1] -> SO3Linear einsum shape mismatch on isolated
atoms. Truncate the readout input to node_ebed_dims[-1] (no-op once blocks ran).

- pt sezm.py: slice x to node_ebed_dims[-1] in both readout sites (forward,
  forward_with_edges).
- dpmodel dpa4.py: same truncation for symmetry/robustness (no-op there since
  padded-edge blocks always shrink x).
- regression test: so3_readout glu/mlp + shrinking schedule + all-isolated
  nlist (proven to fail pre-fix with the einsum size 4 vs 9 mismatch).
@wanghan-iapcm wanghan-iapcm added the Test CUDA Trigger test CUDA workflow label Jun 20, 2026
@github-actions github-actions Bot removed the Test CUDA Trigger test CUDA workflow label Jun 20, 2026
@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.15%. Comparing base (5a0d505) to head (01ba376).

Files with missing lines Patch % Lines
deepmd/dpmodel/descriptor/dpa4.py 88.88% 1 Missing ⚠️
deepmd/pt/model/descriptor/sezm.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5561   +/-   ##
=======================================
  Coverage   82.15%   82.15%           
=======================================
  Files         898      898           
  Lines      103306   103317   +11     
  Branches     4410     4412    +2     
=======================================
+ Hits        84867    84885   +18     
+ Misses      17065    17058    -7     
  Partials     1374     1374           

☔ 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.

@OutisLi OutisLi enabled auto-merge June 20, 2026 05:49
@OutisLi OutisLi added this pull request to the merge queue Jun 20, 2026
Merged via the queue into deepmodeling:master with commit 4b6506d Jun 20, 2026
73 checks passed
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.

2 participants