fix(pt): pass device and dtype in SeZMDeNSFittingNet.deserialize - #6006
fix(pt): pass device and dtype in SeZMDeNSFittingNet.deserialize#6006Anai-Guo wants to merge 1 commit into
Conversation
safe_numpy_to_tensor takes `device` and `dtype` as required keyword-only arguments, so SeZMDeNSFittingNet.deserialize raised TypeError. Rebuild the state dict from the instantiated module's own state_dict, matching the other sezm_nn deserialize implementations. Signed-off-by: Anai-Guo <antai12232931@outlook.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughChangesThe deserialization path now converts serialized tensors to each reconstructed parameter’s device and dtype before loading the state dictionary. Device-aware state loading
Merge Risk: ⚪ Minimal · up to This change makes deserialization load serialized tensors using reconstructed parameter devices and dtypes. No current merge-blocking risk is identified. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6006 +/- ##
==========================================
- Coverage 77.20% 76.96% -0.25%
==========================================
Files 1152 1152
Lines 138792 138793 +1
Branches 5062 5056 -6
==========================================
- Hits 107156 106818 -338
- Misses 29754 30093 +339
Partials 1882 1882 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
SeZMDeNSFittingNet.deserializecannot run — it raisessafe_numpy_to_tensoris declared indeepmd/pt/model/descriptor/sezm_nn/utils.pyasBoth are keyword-only and required, but
dens.py:749called it with the array alone:Why this is the right fix
This is the only one of the 17
safe_numpy_to_tensorcall sites in the tree that omits them. The othersezm_nndeserializeimplementations —ffn.py,norm.py,embedding.py,block.py,attn_res.py,activation.py,radial.py,so2.py,so3.py— all share one identical block, so I simply matched it:Taking
device/dtypefrom the freshly-built module's ownstate_dict()is what makes the round trip self-consistent:serializebuilds@variablesfromstate = self.state_dict(), so every key invariablesis present intemplateandtemplate[key]cannotKeyError.I deliberately did not copy the siblings'
precision = config.pop("precision"); config["dtype"] = PRECISION_DICT[precision]lines —SeZMDeNSFittingNet.__init__takesprecisiondirectly and derivesself.dtypeitself, socls(**config)is already correct here.Verification
I don't have a runtime for this path, so I verified by replaying the real signature (AST-extracted from
utils.py, not hand-copied) against the real call site:ruff checkandruff format --check(v0.16.0, the pinned pre-commit version) pass on the changed file.🤖 Generated with Claude Code
Summary by CodeRabbit