fix(lammps): free model deviation buffers#5803
Open
njzjz wants to merge 1 commit into
Open
Conversation
Centralize allocation, growth, reuse, and destruction of atomic model-deviation communication buffers for DeepMD and DeepSpin pair styles. Coding-Agent: Codex Codex-Version: codex-cli 0.144.1 Model: gpt-5.6-sol Reasoning-Effort: xhigh
Contributor
|
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 (5)
📝 WalkthroughWalkthroughThe change centralizes model-deviation communication buffer allocation, resizing, and destruction, initializes buffer pointers safely, updates DeepMD and DeepSpin call paths, and adds a repeated-run cleanup smoke test. ChangesModel-deviation buffer lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5644.
Summary
nullptr;ensure_model_deviation_buffers()helper;init_style()calls instead of overwriting live allocations;Memory::grow()when the global atom count increases;run(0)/clear()smoke test for reinitialization and pair destruction.Root cause
init_style()created the communication arrays whenever atomic model-deviation output was enabled, but repeated LAMMPS runs can callinit_style()again on the same pair object. Those creates overwrote the stored pointers. The compute paths separately destroyed and recreated four arrays on atom-count growth, while the pair destructor released none of the six arrays.The pair object is the sole owner of these buffers. Allocation, reuse, growth, and destruction are now handled in one base-class implementation, with
nullptrinitialization making every cleanup path safe.Why existing tests missed this
The existing model-deviation tests validate numerical output. Leaking a LAMMPS-managed buffer does not change those values or necessarily crash, so the old implementation passes ordinary functional tests.
The new repeated-init/clear test is intentionally only a lifecycle smoke: it exercises repeated
init_style()and pair destruction and can catch obvious double-free or use-after-free regressions. It is not presented as a leak detector, and the old implementation also passes it while leaking.A direct stable old-fail/new-pass demonstration requires a dedicated LeakSanitizer build with appropriate handling of unrelated TensorFlow/Python/LAMMPS allocations. No RSS or process-memory threshold was added because it would be allocator- and timing-dependent.
Validation
stable_22Jul2025_update2;test_pair_deepmd_model_devi: passed;test_pair_deepmd_model_devi_atomic_reinit_clear_smoke: passed;ruff format .;ruff check .;git diff --check;Coding agent: Codex
Codex version: codex-cli 0.144.1
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
Bug Fixes
Tests