Skip to content

docs(argcheck): document backend support matrices - #5915

Merged
njzjz merged 4 commits into
deepmodeling:masterfrom
njzjz-bot:docs/argcheck-backend-support
Jul 30, 2026
Merged

docs(argcheck): document backend support matrices#5915
njzjz merged 4 commits into
deepmodeling:masterfrom
njzjz-bot:docs/argcheck-backend-support

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Verification

  • ruff format .
  • ruff check .
  • venv/bin/python -m pytest source/tests/common/test_argcheck_backend_docs.py source/tests/common/test_doc_train_input.py -q (10 passed)
  • venv/bin/python -m py_compile deepmd/utils/argcheck.py source/tests/common/test_argcheck_backend_docs.py
  • git diff --check
  • generated dp doc-train-input and confirmed the six-backend label
  • ran dp --version and imported deepmd, deepmd.tf, and deepmd.pt

Refs #5755
Refs #5756
Refs #5757

Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh

Summary by CodeRabbit

  • Documentation

    • Updated argument/option doc strings to generate “Supported Backend” labels from a centralized registry, with stable ordering and duplicate removal.
    • Hidden backends are omitted automatically; “stat_file_mode” now reflects a broader backend set.
    • Unknown backend identifiers are rejected with a clear error message, and embedded documentation spacing is kept consistent.
  • Tests

    • Added backend-doc label validation covering ordering/deduplication, hidden/all-hidden filtering, unknown-backend errors, and representative doc-string prefix behavior.

Add explicit cached backend support labels for argument documentation and cover the verified backend matrices with focused tests.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@dosubot dosubot Bot added the Docs label Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 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 Plus

Run ID: 22892105-6c6e-422d-b50e-9b90835e605a

📥 Commits

Reviewing files that changed from the base of the PR and between af05ca3 and afcdfa3.

📒 Files selected for processing (2)
  • deepmd/utils/argcheck.py
  • source/tests/common/test_argcheck_backend_docs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/utils/argcheck.py

📝 Walkthrough

Walkthrough

Backend documentation is centralized in a registry, formatted through a validated helper, and applied across argument definitions. New tests validate ordering, visibility, unknown keys, representative documentation prefixes, and spacing.

Changes

Backend documentation generation

Layer / File(s) Summary
Backend registry and formatter
deepmd/utils/argcheck.py
Adds BackendDocumentation, the backend registry, and visibility-aware formatting of supported backend labels.
Descriptor, fitting, and model documentation
deepmd/utils/argcheck.py
Applies supported_backends(...) prefixes across descriptor, fitting, and model registrations and argument documentation.
Optimizer, loss, and training documentation
deepmd/utils/argcheck.py
Updates optimizer, loss, data, mixed-precision, training, and validation documentation, including stat_file_mode backend labels.
Backend documentation test coverage
source/tests/common/test_argcheck_backend_docs.py
Tests deterministic labels, duplicate handling, hidden backends, unknown backends, representative documentation prefixes, and spacing.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: wanghan-iapcm, iprozd, outisli

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: centralized backend support matrix documentation in argcheck.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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.

@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: 2

🤖 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/utils/argcheck.py`:
- Line 1372: Normalize the embedded supported_backends() text in the affected
documentation strings: update doc_smooth_type_embedding and the corresponding
strings near the other listed sites so mid-sentence text has exactly one
separating space, while the list-of-bools descriptions have one space before the
backend label and none before the following colon. Account for
supported_backends()’s trailing space by trimming it where needed and adding
literal spacing only where required.
- Around line 3449-3454: Update the DPA4/SeZM fitting configuration around
doc_fitting and fitting_args_plugin.register("property", ...) so generated
documentation does not imply TensorFlow 2 support for DPA4 property fitting. Use
DPA4-specific backend labels or registration while preserving the existing
PyTorch and PyTorch Exportable support descriptions.
🪄 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 Plus

Run ID: 12f096e6-c7aa-4c97-a45c-4abd067497b3

📥 Commits

Reviewing files that changed from the base of the PR and between dd0e511 and 53861c7.

📒 Files selected for processing (2)
  • deepmd/utils/argcheck.py
  • source/tests/common/test_argcheck_backend_docs.py

Comment thread deepmd/utils/argcheck.py Outdated
Comment thread deepmd/utils/argcheck.py
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.96%. Comparing base (4f827cc) to head (afcdfa3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5915      +/-   ##
==========================================
- Coverage   79.21%   78.96%   -0.25%     
==========================================
  Files        1069     1069              
  Lines      124070   124084      +14     
  Branches     4522     4522              
==========================================
- Hits        98278    97982     -296     
- Misses      24171    24482     +311     
+ Partials     1621     1620       -1     

☔ 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 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I went through the changed support sets mechanically rather than by eye -- extracting every rendered (Supported Backend: ...) label from the base and the head by walking the full argument tree, then diffing the two mappings and checking each changed entry against the actual registration decorators.

Most of it holds up well. All ten descriptor variants match their BaseDescriptor.register decorators exactly, including the non-obvious exclusions; all seven loss variants match the trainer dispatchers; the model variants, the spin arguments, finetune_head, atom_exclude_types / pair_exclude_types, gradient_max_norm, stat_file and rglob_patterns all check out. The mechanism itself is sound, and every key in the registry does correspond to a real package directory, tf2 included.

Three claims are wrong, though, and I have left them inline. Two are false negatives that would actively mislead a user, and one is an argument that lost its label entirely when the old constant was deleted.

The thing I would most like your view on is structural rather than any individual entry. This PR takes the file from six labels to 216, which turns a convention of "mark what is restricted" into "declare the full matrix for everything". That declared matrix duplicates information the code already carries in its registration decorators, and it now has to be maintained by hand against six backends -- while, as noted in the test comment below, nothing in CI can tell us when it drifts. The errors here are the predictable consequence of that: the mechanism is fine, but hand-declaring two hundred facts about other people's modules is difficult to keep true. Deriving the labels from the plugin registries, at least for descriptors and fittings where registration is the criterion, would make most of the matrix self-maintaining and reduce the hand-written part to the genuinely judgement-based cases like the training options.

That is a design question rather than a defect, and if you would rather land the corrections and keep the declarative form, that is a reasonable call -- but it is worth making deliberately, because the maintenance burden lands on whoever adds the next backend.

One note on the criterion itself. Excluding jax from the non-energy fittings is correct on a trainability reading, since the JAX trainer raises on any loss but ener -- I checked this because it looked like an inconsistency at first, and it is not one. But descriptors are labelled on a registration reading. Both are defensible; stating which one applies, in the registry comment, would make the matrix auditable by the next person instead of requiring them to re-derive your reasoning.

Not repeating the two points coderabbit already raised on spacing and on the property/DPA4 label; both look valid to me.

Comment thread deepmd/utils/argcheck.py
Comment thread deepmd/utils/argcheck.py Outdated
Comment thread deepmd/utils/argcheck.py Outdated
Comment thread deepmd/utils/argcheck.py Outdated
Comment thread source/tests/common/test_argcheck_backend_docs.py Outdated
Correct the reviewed backend labels and make support-label regression tests independent of the formatter implementation.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

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

🧹 Nitpick comments (1)
source/tests/common/test_argcheck_backend_docs.py (1)

13-21: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Add a cache-reuse regression test.

The PR promises cached labels, but this suite would remain green if memoization were removed. Exercise the intended cache behavior (including cache isolation around registry patching) so the performance contract is protected.

🤖 Prompt for 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.

In `@source/tests/common/test_argcheck_backend_docs.py` around lines 13 - 21, Add
a regression test alongside test_registry_order_and_duplicate_keys that verifies
supported_backends reuses cached labels on repeated calls, then confirms
registry patching uses an isolated cache and does not leak modified labels into
the original cached result. Use the existing supported_backends API and
registry-patching mechanisms, preserving the current ordering and duplicate-key
assertions.
🤖 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.

Nitpick comments:
In `@source/tests/common/test_argcheck_backend_docs.py`:
- Around line 13-21: Add a regression test alongside
test_registry_order_and_duplicate_keys that verifies supported_backends reuses
cached labels on repeated calls, then confirms registry patching uses an
isolated cache and does not leak modified labels into the original cached
result. Use the existing supported_backends API and registry-patching
mechanisms, preserving the current ordering and duplicate-key assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c6946270-8953-404d-a16e-9bd4d9cb42ce

📥 Commits

Reviewing files that changed from the base of the PR and between 53861c7 and c00fab7.

📒 Files selected for processing (2)
  • deepmd/utils/argcheck.py
  • source/tests/common/test_argcheck_backend_docs.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepmd/utils/argcheck.py

Normalize embedded label spacing and narrow DPA4 property fitting documentation to its PyTorch-only support.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
@njzjz-bot

Copy link
Copy Markdown
Contributor Author

Thanks for the mechanical audit and the design discussion. I kept the support declarations explicit in this PR rather than deriving them from backend registries. The criterion is user-configurable behavior, which is not uniform: descriptor variants generally follow registration, while fitting, loss, and training entries can be narrower when a registered component is inference-only or the trainer cannot consume an option. I documented that criterion next to the registry.

The common tests now treat the declarations as change-detecting regression guards, not proof of backend correctness, and use literal expected labels. Importing every backend registry into this common documentation path would also make it dependency-heavy, so automated derivation is better considered as a separate follow-up with a deliberately scoped criterion.

I also fixed the two CodeRabbit points endorsed in the review summary in af05ca3: embedded labels now render with exactly one separator, and DPA4 gets a fresh property fitting argument narrowed to PyTorch without changing the generic property fitting label.

Validation: pytest source/tests/common/test_argcheck_backend_docs.py source/tests/common/test_doc_train_input.py -v (13 passed); changed-file Ruff checks pass. Repository-wide ruff check . still reports five unrelated pre-existing violations in deepmd/jax/jax_md/__init__.py and deepmd/tf/entrypoints/__init__.py.

Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz
njzjz requested a review from wanghan-iapcm July 29, 2026 16:45
Resolve the stat_file_mode documentation conflict by retaining the expanded backend support from master through the centralized support-label helper. Add a regression assertion for the merged backend matrix.

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning-Effort: xhigh

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

All five points check out against af05ca3d8, verified against the files rather than the replies.

I paid particular attention to the sub-argument labels, since those were asserted rather than shown. They are exactly right: on this branch pt_expt's Adam path is torch.optim.Adam(params, lr=initial_lr) with no betas and no weight decay, AdamW takes weight_decay but not the betas, and LKF/AdaMuon/HybridMuon raise. All six corresponding labels match. Likewise the dpa4_property_fitting.doc mutation in the follow-up commit is safe for the reason the comment gives -- fitting_property() returns a list, so get_argument builds a fresh wrapper each call and get_all_argument constructs its own independently, so nothing leaks into the generic property fitting.

Removing the cache and rewriting the registry comment to describe the actual import-time lifecycle is the right resolution, and the literal-string assertions plus the out-of-order, duplicate, all-hidden and unknown-key cases make the test file a real regression guard instead of a restatement of the source.

One forward-looking note, not a change request. #5913 rewrites this same pt_expt optimizer block so that both Adam and AdamW receive betas and weight_decay, and adds HybridMuon support. When that lands, Adam.weight_decay, both optimizers' adam_beta1/adam_beta2, and the HybridMuon type label all need pt_expt added. The literal tests here pin argcheck's own strings, so a change confined to the pt_expt side would leave them green while the labels go stale -- whichever of the two merges second will need to reconcile them by hand.

@njzjz
njzjz enabled auto-merge July 30, 2026 05:27
@njzjz
njzjz added this pull request to the merge queue Jul 30, 2026
Merged via the queue into deepmodeling:master with commit 4c3763e Jul 30, 2026
58 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.

5 participants