Skip to content

Conversation

@wanghan-iapcm
Copy link
Collaborator

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

Huber energy loss uses raw model energy instead of energy_pred that includes atom_ener_coeff weighting, so coefficients are silently dropped when use_huber=True

Summary by CodeRabbit

  • Bug Fixes

    • Fixed energy Huber loss to use the same precomputed energy values as other loss paths for consistent energy loss computation.
    • Improved energy aggregation handling to be more robust and correctly shaped during computation.
  • Tests

    • Expanded loss tests to cover configurations with and without atom energy coefficients and updated test inputs to validate the revised behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

…hat includes atom_ener_coeff weighting, so coefficients are silently dropped when use_huber=True
@wanghan-iapcm wanghan-iapcm requested a review from iProzd January 20, 2026 12:20
@wanghan-iapcm wanghan-iapcm changed the title fix: Huber energy loss uses raw model energy fix(pt): Huber energy loss uses raw model energy Jan 20, 2026
@dosubot dosubot bot added the bug label Jan 20, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Huber branch in energy loss now calls custom_huber_loss with precomputed energy_pred and energy_label tensors instead of model_pred["energy"]/label["energy"]. Tests updated to add enable_atom_ener_coeff flag and related test data fields; minor array-shape/axis clarifications applied in dpmodel loss code.

Changes

Cohort / File(s) Summary
Energy loss (PyTorch & Paddle)
deepmd/pt/loss/ener.py, deepmd/pd/loss/ener.py
Huber-loss branch now passes energy_pred and energy_label to custom_huber_loss instead of using model_pred["energy"] / label["energy"]. Delta, inference conditioning, and aggregation unchanged.
DPModel energy computation
deepmd/dpmodel/loss/ener.py
Reshape uses atom_ener.shape and sum uses explicit axis=1 (clarified indexing for robustness).
Tests: consistent energy loss
source/tests/consistent/loss/test_ener.py
Test parameterization expanded to (use_huber, enable_atom_ener_coeff); test fixtures now include atom_ener_coeff and find_atom_ener_coeff in predict/label data and propagate enable_atom_ener_coeff into test inputs.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • njzjz
  • iProzd
🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title states 'Huber energy loss uses raw model energy', but the actual fix changes it to use precomputed energy_pred instead of raw model energy. Update title to reflect the actual fix: 'fix(pt): Huber energy loss uses energy_pred with atom_ener_coeff weighting' or similar to accurately describe the correction.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@codecov
Copy link

codecov bot commented Jan 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.94%. Comparing base (6c91e99) to head (0fea766).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5168   +/-   ##
=======================================
  Coverage   81.93%   81.94%           
=======================================
  Files         714      714           
  Lines       73397    73412   +15     
  Branches     3616     3616           
=======================================
+ Hits        60140    60155   +15     
+ Misses      12094    12092    -2     
- Partials     1163     1165    +2     

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

Copy link
Collaborator

@iProzd iProzd left a comment

Choose a reason for hiding this comment

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

Huber energy in pd loss also needs to be fixed.

@wanghan-iapcm wanghan-iapcm requested a review from iProzd January 20, 2026 16:02
Copy link
Collaborator

@iProzd iProzd left a comment

Choose a reason for hiding this comment

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

xp.shape(atom_ener) should be atom_ener.shape in https://github.com/deepmodeling/deepmd-kit/blob/master/deepmd/dpmodel/loss/ener.py#L134 .

It seems that ut never reached here. @njzjz

@njzjz
Copy link
Member

njzjz commented Jan 20, 2026

xp.shape(atom_ener) should be atom_ener.shape in

You are correct.

@wanghan-iapcm wanghan-iapcm requested a review from iProzd January 21, 2026 00:27
@iProzd iProzd added this pull request to the merge queue Jan 21, 2026
Merged via the queue into deepmodeling:master with commit c0cce5d Jan 21, 2026
70 checks passed
@wanghan-iapcm wanghan-iapcm deleted the fix-huber-atom-ener-coeff branch January 22, 2026 01:51
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.

3 participants