feat(pt): support shared_dict in linear energy model#5550
Conversation
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
📝 WalkthroughWalkthroughAdds Changesshared_dict for linear_ener model
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/model/dp_linear_model.py`:
- Around line 86-88: The assertion checking shared_level ordering only compares
each shared_level_link against the shared_level_base, which allows unsorted
sequences like [0, 2, 1] to pass validation. To enforce true monotonic ordering,
you need to track and compare each shared_level_link against the previously
processed shared_level value (not just the base level). Update the assertion
logic in both locations (around line 86-88 and line 103-105) to maintain a
running reference to the last processed shared_level and compare each new link
against that previous value to ensure strictly increasing order.
🪄 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: 0dcd25b7-05b3-49ce-bf5c-3d1192e63e67
📒 Files selected for processing (7)
deepmd/pt/entrypoints/main.pydeepmd/pt/model/model/__init__.pydeepmd/pt/model/model/dp_linear_model.pydeepmd/pt/train/training.pydeepmd/pt/utils/multi_task.pydeepmd/utils/argcheck.pysource/tests/pt/model/test_shared_dict_linear.py
| assert shared_level_link >= shared_level_base, ( | ||
| "The shared_links must be sorted by shared_level!" | ||
| ) |
There was a problem hiding this comment.
Enforce true monotonic shared_level ordering.
Line 86 and Line 103 only compare each link against the base level, so an unsorted sequence like 0, 2, 1 still passes. That can apply sharing in the wrong order.
Suggested fix
for shared_item in shared_links:
shared_base = shared_links[shared_item]["links"][0]
class_type_base = shared_base["shared_type"]
model_idx_base = get_model_index(shared_base["model_key"])
shared_level_base = int(shared_base["shared_level"])
if "descriptor" in class_type_base:
base_class = get_descriptor(model_idx_base, class_type_base)
+ prev_shared_level = shared_level_base
for link_item in shared_links[shared_item]["links"][1:]:
class_type_link = link_item["shared_type"]
shared_level_link = int(link_item["shared_level"])
- assert shared_level_link >= shared_level_base, (
+ assert shared_level_link >= prev_shared_level, (
"The shared_links must be sorted by shared_level!"
)
+ prev_shared_level = shared_level_link
assert "descriptor" in class_type_link, (
f"Class type mismatched: {class_type_base} vs {class_type_link}!"
)
link_class = get_descriptor(
get_model_index(link_item["model_key"]), class_type_link
@@
else:
base_class = get_fitting_net(model_idx_base, class_type_base)
+ prev_shared_level = shared_level_base
for link_item in shared_links[shared_item]["links"][1:]:
class_type_link = link_item["shared_type"]
shared_level_link = int(link_item["shared_level"])
- assert shared_level_link >= shared_level_base, (
+ assert shared_level_link >= prev_shared_level, (
"The shared_links must be sorted by shared_level!"
)
+ prev_shared_level = shared_level_link
assert class_type_base == class_type_link, (
f"Class type mismatched: {class_type_base} vs {class_type_link}!"
)Also applies to: 103-105
🤖 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 `@deepmd/pt/model/model/dp_linear_model.py` around lines 86 - 88, The assertion
checking shared_level ordering only compares each shared_level_link against the
shared_level_base, which allows unsorted sequences like [0, 2, 1] to pass
validation. To enforce true monotonic ordering, you need to track and compare
each shared_level_link against the previously processed shared_level value (not
just the base level). Update the assertion logic in both locations (around line
86-88 and line 103-105) to maintain a running reference to the last processed
shared_level and compare each new link against that previous value to ensure
strictly increasing order.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5550 +/- ##
===========================================
- Coverage 82.23% 70.32% -11.91%
===========================================
Files 894 870 -24
Lines 102002 96536 -5466
Branches 4276 3545 -731
===========================================
- Hits 83877 67887 -15990
- Misses 16823 27949 +11126
+ Partials 1302 700 -602 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Closing this duplicate in favor of #5548, which is farther along (newer updates, an extra follow-up fix commit, and the latest CI run). Authored by OpenClaw (version: 2026.5.28 e932160, model: custom-chat-jinzhezeng-group/gpt-5.5) |
Summary
linear_enermodel.shared_dictreferences by adapting the existing multi-task shared-parameter preprocessor to the linear model'smodelslist.shared_dict.Verification
python3 -m py_compile deepmd/pt/utils/multi_task.py deepmd/pt/entrypoints/main.py deepmd/pt/model/model/__init__.py deepmd/pt/model/model/dp_linear_model.py deepmd/pt/train/training.py deepmd/utils/argcheck.py source/tests/pt/model/test_shared_dict_linear.pytorchandpytest.Fixes #4412
Authored by OpenClaw (model: custom-chat-jinzhezeng-group/gpt-5.5)
Summary by CodeRabbit
New Features
shared_dictconfiguration option, allowing efficient reuse of descriptors and other model components.Tests