fix(pt-expt): detach tensors before numpy serialization#5566
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesPyTorch grad-tensor detachment in
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 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.
🧹 Nitpick comments (1)
source/tests/consistent/test_array_api.py (1)
41-43: ⚡ Quick winAdd an explicit dtype assertion in the regression test.
This test currently checks values and
requires_grad, but it doesn’t strictly fail on dtype regression. Add a direct dtype check to match the stated regression scope.Proposed test update
- np.testing.assert_allclose( - to_numpy_array(param), np.array([1.0, 2.0], dtype=np.float64) - ) + converted = to_numpy_array(param) + np.testing.assert_allclose( + converted, np.array([1.0, 2.0], dtype=np.float64) + ) + self.assertEqual(converted.dtype, np.float64)🤖 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 `@source/tests/consistent/test_array_api.py` around lines 41 - 43, The regression test in the assert_allclose block validates values but does not explicitly check dtype to prevent regressions on data type changes. Add a direct dtype assertion after the assert_allclose call that explicitly verifies the dtype of the param matches the expected np.float64 dtype to ensure the dtype regression scope is properly tested.
🤖 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.
Nitpick comments:
In `@source/tests/consistent/test_array_api.py`:
- Around line 41-43: The regression test in the assert_allclose block validates
values but does not explicitly check dtype to prevent regressions on data type
changes. Add a direct dtype assertion after the assert_allclose call that
explicitly verifies the dtype of the param matches the expected np.float64 dtype
to ensure the dtype regression scope is properly tested.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fbd5d63c-dac0-4f15-a2f4-4db12a02a9de
📒 Files selected for processing (2)
deepmd/dpmodel/common.pysource/tests/consistent/test_array_api.py
41e8af8 to
731326c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5566 +/- ##
=======================================
Coverage 82.17% 82.17%
=======================================
Files 898 898
Lines 103576 103578 +2
Branches 4432 4436 +4
=======================================
+ Hits 85117 85120 +3
- Misses 17063 17066 +3
+ Partials 1396 1392 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
to_numpy_arraytorch.asarraybehavior change from pytorch/pytorch@a97dcf9torch.nn.ParameterTests
ruff check deepmd/dpmodel/common.py source/tests/consistent/test_array_api.pyruff format --check deepmd/dpmodel/common.py source/tests/consistent/test_array_api.pypytest source/tests/consistent/test_array_api.py::TestArrayConversion::test_torch_parameter_requires_grad -qpytest source/tests/consistent/test_array_api.py -qsrun --gres=gpu:1 dp --pt-expt train input.json --skip-neighbor-statsrun --gres=gpu:1 dp --pt-expt train input.jsonSummary by CodeRabbit
Bug Fixes
Tests