Skip to content

docs+tests(bias): pin set/change-by-statistic semantics for bridged models - #5966

Merged
njzjz merged 3 commits into
deepmodeling:masterfrom
wanghan-iapcm:fix-set-bias-analytical
Aug 12, 2026
Merged

docs+tests(bias): pin set/change-by-statistic semantics for bridged models#5966
njzjz merged 3 commits into
deepmodeling:masterfrom
wanghan-iapcm:fix-set-bias-analytical

Conversation

@wanghan-iapcm

@wanghan-iapcm wanghan-iapcm commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Close #5927 — resolved as designed, with documentation and semantic pin tests instead of a behavior change.

The definitions (verified against the code)

The model energy decomposes as E = E_model + E_bias, where E_model is everything the model computes (learned network, analytical ZBL term, or a linear_ener combination) and E_bias is the per-type output bias.

  • set-by-statistic assigns E_bias directly: user values, or the per-type least-squares statistic of the raw labels. It never calls a model forward (compute_output_stats with model_forward=None, stored with add=False) — it is independent of E_model by definition, ignoring a trained network and the analytical ZBL term alike.
  • change-by-statistic fits the residual of the labels against the complete model prediction (the bridged predictor since fix(pt): calibrate DPA4 bias and support PyTorch 2.13 compile #5910) and adds the delta to the existing bias.

Under these definitions the "double count" described in the issue is not a bridging bug: set uniformly ignores all of E_model for every model kind. A bridged model after set carries no compensation for the mean ZBL contribution — exactly as a trained plain model after set carries no compensation for its network output. The two modes "disagree" because they are defined to answer different questions; a self-consistent calibration is change's job.

Verified conformance of the linear_ener composition path in both backends: children compute no output statistics (compute_or_load_out_stat=False); the composition level performs one set fit on the raw labels. Also verified: the ZBL term contributes exactly zero for isolated atoms, so its own statistics are trivially bias = 0.

Changes

  • doc/model/change-bias.md: precise definitions of the two modes, and the guidance that calibrating a bridged (or any nonzero-E_model) model self-consistently requires change-by-statistic.
  • doc/model/dpa4.md: note in the ZBL section.
  • Semantic pin tests (pt SeZMModel + dpmodel LinearEnergyAtomicModel composition): set-by-statistic equals the raw-label least-squares fit exactly — guarding against a future "fix" that would subtract the analytical term and silently create a third, model-dependent mode.

Known limitations

  • No behavior change anywhere; the pin tests cover model.change_out_bias (the dp change-bias --mode set and finetune routes) and the dpmodel composition out-stat; the pt training-init chain was verified in-session and funnels into the same pinned branch.
  • The spin variants share the machinery but have no dedicated pin.
  • Fact worth knowing when reading the docs: InnerPotential adds the full ZBL over the whole cutoff (not only below bridging_r_outer), so the label-side ZBL at equilibrium geometries is small but not strictly zero; the docs state the offset plainly.

Summary by CodeRabbit

  • Documentation

    • Clarified how set and change statistic modes handle model energy, analytical contributions, labels, residuals, and existing bias.
    • Documented the interaction between output-bias calibration and ZBL bridging, including guidance for self-consistent calibration.
  • Tests

    • Added regression coverage confirming that set-by-statistic calibration uses raw energy labels independently of learned and ZBL model contributions.
    • Verified calibration correctly replaces seeded bias and remains consistent when repeated.

Han Wang added 2 commits August 11, 2026 16:43
Close deepmodeling#5927 as designed. The model energy decomposes as
E = E_model + E_bias; set-by-statistic DEFINES E_bias as the per-type
statistic of the raw labels (or user values), independent of E_model --
it ignores a trained network and it equally ignores the analytical ZBL
term of a bridged model. change-by-statistic fits the residual against
the complete model prediction (bridged predictor since deepmodeling#5910). The
'double count' described in the issue is therefore not a bridging bug
but the uniform, defined behavior of the set mode for any model with
nonzero E_model; no code change is made.

- doc/model/change-bias.md: precise definitions of the two modes and
  the guidance that a self-consistent calibration of a bridged model
  needs change-by-statistic.
- doc/model/dpa4.md: note in the ZBL section.
- Semantic pin tests in pt (SeZMModel) and dpmodel
  (LinearEnergyAtomicModel composition): set-by-statistic equals the
  raw-label least-squares fit exactly -- guarding against a future
  'fix' that would subtract the analytical term and silently create a
  third, model-dependent mode. Verified conformance of the linear_ener
  composition path in both backends: children compute no output
  statistics; the composition-level set fits raw labels.
@coderabbitai

coderabbitai Bot commented Aug 11, 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: ed21ef98-2774-4c0d-92fd-4a7080b13246

📥 Commits

Reviewing files that changed from the base of the PR and between edde584 and a6a2bf6.

📒 Files selected for processing (3)
  • doc/model/change-bias.md
  • source/tests/common/dpmodel/test_zbl_bridging.py
  • source/tests/pt/model/test_sezm_model.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • doc/model/change-bias.md
  • source/tests/common/dpmodel/test_zbl_bridging.py
  • source/tests/pt/model/test_sezm_model.py

📝 Walkthrough

Walkthrough

The changes document set and change statistic semantics, including ZBL contributions. Two regression tests verify that set-by-statistic fits output bias from raw energy labels for bridged models.

Changes

Output-bias calibration

Layer / File(s) Summary
Calibration semantics and regression coverage
doc/model/change-bias.md, doc/model/dpa4.md, source/tests/common/dpmodel/test_zbl_bridging.py, source/tests/pt/model/test_sezm_model.py
The documentation distinguishes raw-label fitting from residual fitting and describes ZBL contribution handling. The regression tests verify raw-label bias fitting for bridged models.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The tests and documentation preserve the behavior but do not resolve the double-counting bug described in issue #5927. Implement a correction for set-by-statistic or explicitly reject it for models with model-level analytical contributions, then add regression coverage.
✅ 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 identifies the documentation and test changes for set/change-by-statistic semantics in bridged models.
Out of Scope Changes check ✅ Passed The documentation and regression tests directly address bias-statistic semantics and bridged-model behavior described in issue #5927.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
✨ 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: 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 `@doc/model/change-bias.md`:
- Around line 24-26: Update the prediction-offset description in the
set-by-statistic discussion to state that set leaves the configuration-dependent
E_model uncompensated, along with any residual from the raw-label least-squares
fit; remove the claim that each calibration prediction is offset by the data
mean of E_model.
🪄 Autofix

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: d255cd38-cff2-45c8-9b21-b47dd30d7b25

📥 Commits

Reviewing files that changed from the base of the PR and between bc902da and edde584.

📒 Files selected for processing (4)
  • doc/model/change-bias.md
  • doc/model/dpa4.md
  • source/tests/common/dpmodel/test_zbl_bridging.py
  • source/tests/pt/model/test_sezm_model.py

Comment thread doc/model/change-bias.md Outdated
@wanghan-iapcm
wanghan-iapcm requested a review from njzjz August 11, 2026 08:48
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.36%. Comparing base (bc902da) to head (a6a2bf6).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5966      +/-   ##
==========================================
- Coverage   79.60%   79.36%   -0.25%     
==========================================
  Files        1085     1085              
  Lines      126405   126405              
  Branches     4598     4598              
==========================================
- Hits       100631   100319     -312     
- Misses      24120    24434     +314     
+ Partials     1654     1652       -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.

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

Three independent review passes converged on the two inline findings below. I also verified the existing CodeRabbit comment on change-bias.md lines 24–26 and did not duplicate it.

Validation:

  • Both newly added targeted tests pass locally.
  • A SeZM+ZBL self-label reproduction shows set-by-statistic changes the predictions to exactly 2× their original values with a full-rank type-count matrix (maximum error 2.84e-14).
  • All reported PR checks currently pass.

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

Comment thread doc/model/change-bias.md Outdated
Comment thread source/tests/pt/model/test_sezm_model.py

@njzjz njzjz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@njzjz-bot has commented above.

- change-bias.md: drop the incorrect 'offset by the data mean of
  E_model' claim (the remaining error is the configuration-dependent
  E_model plus the raw-label least-squares residual) and the
  'double-counts nothing' claim (the raw-label fit can absorb the
  composition-correlated component of E_model into E_bias, which the
  forward pass then adds again).
- pt + dpmodel set-by-statistic tests: seed a nonzero out_bias before
  the call (an accidental additive implementation would shift the
  result) and repeat the call to pin idempotence; mirrored in dpmodel
  because its bias storage is separate.
@wanghan-iapcm
wanghan-iapcm requested a review from njzjz August 12, 2026 11:32

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

Three independent review passes covered functional correctness, test/regression behavior, and API/compatibility/maintainability on the current head a6a2bf690e693144ea6f478f3037d4ef4b574e29.

No new actionable findings remain on the current diff, so there are no new inline comments to attach. The earlier line-specific findings about the set semantics and the missing nonzero-bias/idempotence coverage are addressed by the latest commit.

Validation:

  • source/tests/common/dpmodel/test_zbl_bridging.py::test_set_by_statistic_fits_raw_labels_by_definition: passed.
  • source/tests/pt/model/test_sezm_model.py::TestSeZMModelBridging::test_set_by_statistic_fits_raw_labels_by_definition: passed.
  • Documentation and Python CI checks pass.
  • The remaining failed C++ job stopped while downloading the Paddle inference archive with Transferred a partial file; it did not reach code compilation and is unrelated to this PR.

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

@njzjz
njzjz enabled auto-merge August 12, 2026 16:09
@njzjz
njzjz added this pull request to the merge queue Aug 12, 2026
Merged via the queue into deepmodeling:master with commit fec4497 Aug 12, 2026
62 of 63 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.

set-by-statistic double-counts the model-level analytical contribution for bridged models

3 participants