fix: fix YAML conversion#4565
Conversation
Fix deepmodeling#4564. Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
📝 WalkthroughWalkthroughThe changes modify the Changes
Assessment against linked issues
The change directly addresses the serialization error reported in the linked issue by adding a more robust type-checking mechanism when saving model data to YAML format. The modification prevents the ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
deepmd/dpmodel/utils/serialization.py (1)
116-118: LGTM! Consider adding version validation and array size warning.The implementation correctly preserves numpy array metadata during YAML serialization. The changes align well with the existing loading logic in
load_dp_model.Consider these improvements:
- Add a size check and warning for large arrays that might be inefficient in YAML format.
- Add version validation in
load_dp_modelto handle future format changes.Example improvement:
if isinstance(x, np.ndarray) + and ( + # Warn if array is too large (e.g., > 1MB) + np.prod(x.shape) * x.dtype.itemsize > 1024 * 1024 + and warnings.warn( + f"Large array of size {x.nbytes / 1024 / 1024:.1f}MB " + "might be inefficient in YAML format", + UserWarning, + ) + )
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
deepmd/dpmodel/utils/serialization.py(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: Test Python (6, 3.12)
- GitHub Check: Test Python (6, 3.9)
- GitHub Check: Test Python (5, 3.12)
- GitHub Check: Build wheels for cp311-win_amd64
- GitHub Check: Test Python (5, 3.9)
- GitHub Check: Test Python (4, 3.12)
- GitHub Check: Test Python (4, 3.9)
- GitHub Check: Test Python (3, 3.12)
- GitHub Check: Test Python (3, 3.9)
- GitHub Check: Test Python (2, 3.12)
- GitHub Check: Analyze (python)
- GitHub Check: Test Python (2, 3.9)
- GitHub Check: Build C library (2.14, >=2.5.0rc0,<2.15, libdeepmd_c_cu11.tar.gz)
- GitHub Check: Analyze (c-cpp)
- GitHub Check: Test Python (1, 3.12)
- GitHub Check: Test C++ (false)
- GitHub Check: Build C library (2.18, libdeepmd_c.tar.gz)
- GitHub Check: Test Python (1, 3.9)
- GitHub Check: Test C++ (true)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## devel #4565 +/- ##
==========================================
- Coverage 84.60% 84.60% -0.01%
==========================================
Files 680 680
Lines 64468 64469 +1
Branches 3538 3539 +1
==========================================
- Hits 54546 54545 -1
- Misses 8781 8782 +1
- Partials 1141 1142 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fix deepmodeling#4564. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved serialization of NumPy arrays when saving model data to YAML files. - Enhanced metadata handling for array representations during model export. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu> (cherry picked from commit ec19ab3)
Fix #4564.
Summary by CodeRabbit