Skip to content

Fix: Square atom_norm in non-Huber energy and virial loss calculations.#5332

Open
anyangml wants to merge 21 commits intodeepmodeling:masterfrom
anyangml:fix/rmse-loss-normalization
Open

Fix: Square atom_norm in non-Huber energy and virial loss calculations.#5332
anyangml wants to merge 21 commits intodeepmodeling:masterfrom
anyangml:fix/rmse-loss-normalization

Conversation

@anyangml
Copy link
Copy Markdown
Collaborator

@anyangml anyangml commented Mar 23, 2026

This is to normalize all L2 loss so that in multitask training, the scale of gradients becomes independent of system size. Do we want to update pref in examples? @iProzd @njzjz

Summary by CodeRabbit

  • New Features

    • Added an "intensive" option to energy/virial loss configs to toggle alternative size normalization (legacy 1/N vs intensive 1/N²) for non-Huber MSE loss across energy and spin loss implementations and config helpers.
  • Bug Fixes

    • Serialization updated to persist the new option and remain backward-compatible when loading older configs.
  • Documentation

    • Training docs and examples updated; fixed "magnetic" typo and added math and guidance for the intensive option.
  • Tests

    • New and extended tests validate intensive vs legacy scaling across scenarios and backends.

Copilot AI review requested due to automatic review settings March 23, 2026 04:27
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds an intensive: bool option that, when true, changes non‑Huber MSE energy and virial normalization from atom_norm (1/N) to atom_norm**2 (1/N^2). Propagates option across backends, updates serialization versions with backward compatibility, extends arg parsing, and adds tests validating scaling.

Changes

Cohort / File(s) Summary
Core energy loss implementations
deepmd/dpmodel/loss/ener.py, deepmd/pd/loss/ener.py, deepmd/pt/loss/ener.py, deepmd/tf/loss/ener.py
Add intensive: bool parameter; non‑Huber MSE energy/virial terms scaled by atom_norm**norm_exp where norm_exp = 2 if intensive else 1. Huber/MAE paths unchanged. Bump serialize @version and include intensive; deserialize backfills intensive=False for older versions.
Spin-energy loss implementations
deepmd/dpmodel/loss/ener_spin.py, deepmd/pt/loss/ener_spin.py, deepmd/tf/loss/ener.py (EnerSpinLoss)
Add intensive ctor arg and instance field; change MSE energy/virial scaling to use atom_norm**norm_exp. Serialization version bumped and intensive added; TF adds serialize/deserialize for spin loss with backward defaulting.
Argument validation / config docs
deepmd/utils/argcheck.py
Expose intensive: bool = False in loss_ener() and loss_ener_spin() argument lists and docs; document effect on MSE normalization.
Tests (consistency / scaling)
source/tests/consistent/loss/test_ener.py, source/tests/consistent/loss/test_ener_spin.py
Extend parameterizations to include intensive; update setup/unpacking; add PyTorch‑gated tests asserting intensive vs legacy natoms scaling and expected loss ratios.
Documentation
doc/model/train-energy.md, doc/model/train-energy-spin.md
Add intensive option to examples and docs, correct minor typos, and include formulas showing 1/N → 1/N^2 behavior for MSE energy/virial when enabled.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.04% 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 'Fix: Square atom_norm in non-Huber energy and virial loss calculations' directly describes the core technical change across the PR: squaring atom_norm normalization in non-Huber MSE loss paths. This is evident from all modified loss files implementing norm_exp=2 for intensive mode.
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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes normalization in energy/virial MSE loss terms so that per-atom scaling is consistent with the Huber-loss code paths and the reported per-atom RMSE metrics.

Changes:

  • Square atom_norm / atom_norm_ener in non-Huber (MSE) energy loss accumulation.
  • Square atom_norm in non-Huber (MSE) virial loss accumulation.
  • Apply the same normalization fix across TF, PyTorch, Paddle, and dpmodel backends for the updated loss implementations.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
deepmd/tf/loss/ener.py Squares atom normalization in non-Huber MSE energy/virial loss accumulation (EnerStdLoss path).
deepmd/pt/loss/ener.py Squares atom_norm in non-Huber MSE energy and virial loss accumulation.
deepmd/pd/loss/ener.py Squares atom_norm in non-Huber MSE energy and virial loss accumulation.
deepmd/dpmodel/loss/ener.py Squares atom normalization in non-Huber MSE energy and virial loss accumulation in the array-API backend.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deepmd/pt/loss/ener.py
Comment thread deepmd/tf/loss/ener.py
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
deepmd/dpmodel/loss/ener.py (1)

248-248: Add a regression test for the new normalization rule.

Because the displayed RMSE stays unchanged, this 1/N vs 1/N^2 mistake is easy to reintroduce. A tiny EnergyLoss.call() case with natoms > 1 and fixed energy/virial deltas would lock it down.

Also applies to: 315-315

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deepmd/dpmodel/loss/ener.py` at line 248, The energy normalization is
currently prone to a 1/N vs 1/N^2 regression; add a unit/regression test
targeting EnergyLoss.call() in deepmd/dpmodel/loss/ener.py that constructs a
small batch with natoms > 1, fixed per-atom energy deltas and virials, and
asserts the computed energy loss scales with 1/N (not 1/N^2) by comparing
expected loss values for different natom counts; reference EnergyLoss.call() and
the atom_norm_ener accumulation (the expression involving atom_norm_ener**2 *
(pref_e * l2_ener_loss)) to ensure the test fails if the normalization is
squared incorrectly and include an explicit check for both energy-only and
energy+virial modes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@deepmd/tf/loss/ener.py`:
- Line 349: EnerSpinLoss.build and EnerDipoleLoss.build still use the old
single-factor 1/N normalization; update both to use the same squared per-atom
normalization pattern used in EnerStdLoss (i.e., multiply the loss term by
atom_norm_ener**2 * (pref_e * l2_ener_loss) instead of a single atom_norm_ener
factor) so all energy loss variants apply the corrected normalization
consistently; locate the energy-loss accumulation in EnerSpinLoss.build and
EnerDipoleLoss.build and replace the old single-factor scaling with the squared
atom_norm_ener**2 * (pref_e * l2_ener_loss) pattern used in EnerStdLoss.

---

Nitpick comments:
In `@deepmd/dpmodel/loss/ener.py`:
- Line 248: The energy normalization is currently prone to a 1/N vs 1/N^2
regression; add a unit/regression test targeting EnergyLoss.call() in
deepmd/dpmodel/loss/ener.py that constructs a small batch with natoms > 1, fixed
per-atom energy deltas and virials, and asserts the computed energy loss scales
with 1/N (not 1/N^2) by comparing expected loss values for different natom
counts; reference EnergyLoss.call() and the atom_norm_ener accumulation (the
expression involving atom_norm_ener**2 * (pref_e * l2_ener_loss)) to ensure the
test fails if the normalization is squared incorrectly and include an explicit
check for both energy-only and energy+virial modes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a73a40cd-4fda-4353-8c33-d0685030359b

📥 Commits

Reviewing files that changed from the base of the PR and between b97ad98 and 247f053.

📒 Files selected for processing (4)
  • deepmd/dpmodel/loss/ener.py
  • deepmd/pd/loss/ener.py
  • deepmd/pt/loss/ener.py
  • deepmd/tf/loss/ener.py

Comment thread deepmd/tf/loss/ener.py Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 78.46154% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.46%. Comparing base (3f91293) to head (a22767f).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
deepmd/tf/loss/ener.py 60.86% 9 Missing ⚠️
deepmd/dpmodel/loss/ener.py 87.50% 1 Missing ⚠️
deepmd/dpmodel/loss/ener_spin.py 87.50% 1 Missing ⚠️
deepmd/pd/loss/ener.py 87.50% 1 Missing ⚠️
deepmd/pt/loss/ener.py 87.50% 1 Missing ⚠️
deepmd/pt/loss/ener_spin.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5332      +/-   ##
==========================================
- Coverage   80.46%   80.46%   -0.01%     
==========================================
  Files         820      820              
  Lines       86005    86050      +45     
  Branches     4139     4140       +1     
==========================================
+ Hits        69207    69239      +32     
- Misses      15521    15535      +14     
+ Partials     1277     1276       -1     

☔ View full report in Codecov by Sentry.
📢 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.

@deepmodeling deepmodeling deleted a comment from JacobMazelin Mar 23, 2026
@anyangml anyangml requested a review from iProzd March 23, 2026 07:29
@anyangml anyangml marked this pull request as draft March 23, 2026 09:54
iProzd and others added 7 commits April 13, 2026 17:09
…tion-fix

feat(loss): add intensive parameter for backward-compatible RMSE normalization
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 11 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deepmd/utils/argcheck.py Outdated
Comment thread deepmd/utils/argcheck.py Outdated
Comment thread deepmd/tf/loss/ener.py Outdated
Comment thread deepmd/pd/loss/ener.py Outdated
Comment thread deepmd/dpmodel/loss/ener.py Outdated
Comment thread deepmd/tf/loss/ener.py Outdated
Comment thread deepmd/dpmodel/loss/ener.py
Comment thread deepmd/pt/loss/ener.py Outdated
Comment thread deepmd/dpmodel/loss/ener_spin.py Outdated
Comment thread deepmd/dpmodel/loss/ener_spin.py
@iProzd
Copy link
Copy Markdown
Member

iProzd commented Apr 17, 2026

Some AI suggestions are needed to be resovled. Others LGTM.

Copilot AI and others added 2 commits April 19, 2026 10:52
…ew-comments

fix(loss): clarify intensive normalization docs and add test coverage
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deepmd/tf/loss/ener.py Outdated
Comment thread source/tests/consistent/loss/test_ener.py Outdated
…d-5332

fix: complete EnerSpinLoss serialization and improve intensive normalization tests
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deepmd/utils/argcheck.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Anyang Peng <137014849+anyangml@users.noreply.github.com>
@anyangml anyangml marked this pull request as ready for review April 20, 2026 06:37
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
deepmd/pd/loss/ener.py (1)

420-430: ⚠️ Potential issue | 🟠 Major

Keep intensive scoped to MSE virial loss.

Line 430 applies norm_exp even when loss_func="mae" because the Paddle virial block is outside the loss_func switch. With virial prefactors enabled, intensive=True changes MAE-configured training from legacy 1/N to 1/N², contradicting the MSE-only behavior described by the new option.

🐛 Proposed minimal fix
-            if not self.use_huber:
-                loss += atom_norm**norm_exp * (pref_v * l2_virial_loss)
+            if not self.use_huber:
+                virial_norm_exp = norm_exp if self.loss_func == "mse" else 1
+                loss += atom_norm**virial_norm_exp * (pref_v * l2_virial_loss)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deepmd/pd/loss/ener.py` around lines 420 - 430, The virial term currently
applies intensity scaling atom_norm**norm_exp regardless of configured loss
type, causing MAE runs to get 1/N² scaling; restrict the intensive scaling to
MSE-only: inside the virial block (where find_virial, pref_v, diff_v,
l2_virial_loss are computed) keep computing l2_virial_loss and adding more_loss
as-is, but only multiply by atom_norm**norm_exp when adding to loss if the
configured loss is MSE (e.g. check self.loss_func == "mse" or equivalent) —
otherwise add the virial contribution using pref_v * l2_virial_loss without the
atom_norm**norm_exp factor; keep the existing self.use_huber and self.inference
checks intact.
♻️ Duplicate comments (1)
deepmd/tf/loss/ener.py (1)

1135-1138: ⚠️ Potential issue | 🟡 Minor

EnerDipoleLoss.build() still uses single-factor 1/N normalization.

EnerStdLoss and EnerSpinLoss were updated to apply atom_norm**norm_exp, but EnerDipoleLoss.build() at line 1137 still does atom_norm_ener * (pref_e * l2_ener_loss). If the intent is to normalize "all L2 loss" consistently (per the PR description), this branch should be updated too — either by threading an intensive flag through EnerDipoleLoss.__init__ or by squaring atom_norm_ener unconditionally if the dipole loss is meant to always be intensive.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deepmd/tf/loss/ener.py` around lines 1135 - 1138, EnerDipoleLoss.build()
currently multiplies L2 terms by atom_norm_ener (single-factor 1/N) while
EnerStdLoss/EnerSpinLoss apply atom_norm**norm_exp; update EnerDipoleLoss to
match: add/propagate the same normalization parameter (e.g., norm_exp or an
intensive flag) in EnerDipoleLoss.__init__ and replace the line using
atom_norm_ener * (pref_e * l2_ener_loss) with atom_norm_ener**norm_exp * (pref_e
* l2_ener_loss) (and similarly adjust any other uses like pref_ed *
l2_ener_dipole_loss) so dipole L2 losses are normalized consistently with the
other energy loss classes.
🧹 Nitpick comments (1)
deepmd/tf/loss/ener.py (1)

1047-1054: EnerSpinLoss.deserialize accepts @version=1 that was never emitted.

serialize is new and always writes @version=2; there is no on-disk v1 payload for this class. check_version_compatibility(version, 2, 1) plus the if version < 2 backfill is therefore dead code. Consider tightening to check_version_compatibility(version, 2, 2) and removing the backfill, unless you want to stay lenient for hand-authored configs (in which case, fine to keep as-is).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deepmd/tf/loss/ener.py` around lines 1047 - 1054, EnerSpinLoss.deserialize
currently accepts a never-emitted v1 payload and contains dead backfill; update
the compatibility check to require exactly v2 and remove the obsolete backfill:
change the call check_version_compatibility(version, 2, 1) to
check_version_compatibility(version, 2, 2) in EnerSpinLoss.deserialize and
delete the conditional block that backfills "intensive" when version < 2 (the
versioned serialize always writes `@version`=2 so the backfill is unnecessary).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@deepmd/pd/loss/ener.py`:
- Around line 420-430: The virial term currently applies intensity scaling
atom_norm**norm_exp regardless of configured loss type, causing MAE runs to get
1/N² scaling; restrict the intensive scaling to MSE-only: inside the virial
block (where find_virial, pref_v, diff_v, l2_virial_loss are computed) keep
computing l2_virial_loss and adding more_loss as-is, but only multiply by
atom_norm**norm_exp when adding to loss if the configured loss is MSE (e.g.
check self.loss_func == "mse" or equivalent) — otherwise add the virial
contribution using pref_v * l2_virial_loss without the atom_norm**norm_exp
factor; keep the existing self.use_huber and self.inference checks intact.

---

Duplicate comments:
In `@deepmd/tf/loss/ener.py`:
- Around line 1135-1138: EnerDipoleLoss.build() currently multiplies L2 terms by
atom_norm_ener (single-factor 1/N) while EnerStdLoss/EnerSpinLoss apply
atom_norm**norm_exp; update EnerDipoleLoss to match: add/propagate the same
normalization parameter (e.g., norm_exp or an intensive flag) in
EnerDipoleLoss.__init__ and replace the line using atom_norm_ener * (pref_e *
l2_ener_loss) with atom_norm_ener**norm_exp * (pref_e * l2_ener_loss) (and
similarly adjust any other uses like pref_ed * l2_ener_dipole_loss) so dipole L2
losses are normalized consistently with the other energy loss classes.

---

Nitpick comments:
In `@deepmd/tf/loss/ener.py`:
- Around line 1047-1054: EnerSpinLoss.deserialize currently accepts a
never-emitted v1 payload and contains dead backfill; update the compatibility
check to require exactly v2 and remove the obsolete backfill: change the call
check_version_compatibility(version, 2, 1) to
check_version_compatibility(version, 2, 2) in EnerSpinLoss.deserialize and
delete the conditional block that backfills "intensive" when version < 2 (the
versioned serialize always writes `@version`=2 so the backfill is unnecessary).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 977b2962-fd77-4fe5-bea8-4beb3c792f8a

📥 Commits

Reviewing files that changed from the base of the PR and between 247f053 and 2ce4029.

📒 Files selected for processing (9)
  • deepmd/dpmodel/loss/ener.py
  • deepmd/dpmodel/loss/ener_spin.py
  • deepmd/pd/loss/ener.py
  • deepmd/pt/loss/ener.py
  • deepmd/pt/loss/ener_spin.py
  • deepmd/tf/loss/ener.py
  • deepmd/utils/argcheck.py
  • source/tests/consistent/loss/test_ener.py
  • source/tests/consistent/loss/test_ener_spin.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • deepmd/pt/loss/ener.py
  • deepmd/dpmodel/loss/ener.py

@github-actions github-actions Bot added the Docs label Apr 20, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
doc/model/train-energy.md (2)

149-150: Add a short migration note about prefactor retuning.

When users switch intensive from false to true, the effective scale of energy/virial loss terms changes; documenting that start_pref_e/v and limit_pref_e/v may need retuning would make adoption safer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@doc/model/train-energy.md` around lines 149 - 150, Add a short migration note
to the intensive option documentation explaining that toggling intensive from
false to true changes the effective scale of energy and virial loss terms (when
loss_func="mse"), and that users should consider retuning the prefactors
start_pref_e, start_pref_v, limit_pref_e, and limit_pref_v accordingly; update
the paragraph describing intensive to include a sentence recommending checking
and possibly adjusting those prefactor settings when migrating to
intensive=true.

134-137: Consider clarifying why the example keeps intensive: false.

Since Line 149 describes intensive mode as recommended for multitask use, a short note here (e.g., “false shown for backward-compatible reproduction of legacy behavior”) would reduce ambiguity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@doc/model/train-energy.md` around lines 134 - 137, Update the example JSON
block that sets "intensive": false to include a brief clarifying note explaining
why false is used (e.g., for backward-compatible reproduction of legacy behavior
or to show default non-intensive mode), so readers aren't confused by the later
recommendation of intensive mode for multitask use; add the note immediately
adjacent to the example or as an inline comment/short sentence in the
surrounding text referencing the "intensive" field to make the rationale
explicit.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@doc/model/train-energy.md`:
- Around line 149-150: Add a short migration note to the intensive option
documentation explaining that toggling intensive from false to true changes the
effective scale of energy and virial loss terms (when loss_func="mse"), and that
users should consider retuning the prefactors start_pref_e, start_pref_v,
limit_pref_e, and limit_pref_v accordingly; update the paragraph describing
intensive to include a sentence recommending checking and possibly adjusting
those prefactor settings when migrating to intensive=true.
- Around line 134-137: Update the example JSON block that sets "intensive":
false to include a brief clarifying note explaining why false is used (e.g., for
backward-compatible reproduction of legacy behavior or to show default
non-intensive mode), so readers aren't confused by the later recommendation of
intensive mode for multitask use; add the note immediately adjacent to the
example or as an inline comment/short sentence in the surrounding text
referencing the "intensive" field to make the rationale explicit.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 041f290d-4c28-47d4-8f1c-3c358c084621

📥 Commits

Reviewing files that changed from the base of the PR and between 2ce4029 and c856d72.

📒 Files selected for processing (2)
  • doc/model/train-energy-spin.md
  • doc/model/train-energy.md

@anyangml anyangml requested a review from wanghan-iapcm April 20, 2026 09:02
Comment thread deepmd/dpmodel/loss/ener.py Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
deepmd/pt/loss/ener.py (1)

653-660: Minor: the setdefault is redundant with the __init__ default.

Since EnergyStdLoss.__init__ already defaults intensive=False, the explicit setdefault("intensive", False) for version < 3 doesn't change behavior. It's harmless as a self-documenting guard, but can be simplified if you prefer. Not blocking.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deepmd/pt/loss/ener.py` around lines 653 - 660, Remove the redundant
backward-compatibility setdefault call: delete the line
data.setdefault("intensive", False) in the classmethod that builds the instance
(the block ending with return cls(**data)) because EnergyStdLoss.__init__
already defaults intensive=False; keep the version check if you want to retain
the semantic note but avoid mutating data unnecessarily.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@deepmd/pt/loss/ener.py`:
- Around line 653-660: Remove the redundant backward-compatibility setdefault
call: delete the line data.setdefault("intensive", False) in the classmethod
that builds the instance (the block ending with return cls(**data)) because
EnergyStdLoss.__init__ already defaults intensive=False; keep the version check
if you want to retain the semantic note but avoid mutating data unnecessarily.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dcbf6d99-6149-4952-9fc1-feee972ecd2c

📥 Commits

Reviewing files that changed from the base of the PR and between c856d72 and 29a7833.

📒 Files selected for processing (6)
  • deepmd/dpmodel/loss/ener_spin.py
  • deepmd/pd/loss/ener.py
  • deepmd/pt/loss/ener.py
  • deepmd/pt/loss/ener_spin.py
  • deepmd/tf/loss/ener.py
  • deepmd/utils/argcheck.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • deepmd/utils/argcheck.py
  • deepmd/pd/loss/ener.py
  • deepmd/pt/loss/ener_spin.py

@anyangml anyangml requested a review from njzjz April 21, 2026 04:26
@njzjz
Copy link
Copy Markdown
Member

njzjz commented Apr 22, 2026

@anyangml The code where I commented was not changed?

image

Signed-off-by: Anyang Peng <137014849+anyangml@users.noreply.github.com>
Comment thread deepmd/dpmodel/loss/ener_spin.py Outdated
Comment on lines +53 to +60
intensive : bool
If true, the MSE energy and virial terms use intensive normalization,
i.e. an additional normalization by the square of the number of atoms
(1/N^2) instead of the legacy (1/N) behavior. This keeps those MSE loss
terms consistent with per-atom RMSE reporting and less dependent on
system size. This option does not change the MAE formulation, which is
handled separately. The default is false for backward compatibility with
models trained using deepmd-kit <= 3.1.3.
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.

intensive -> intensive_ener_virial
to be more self explanatory.

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.

6 participants