Repository navigation
Freeze parameters of models loaded by the ASE and TorchSim integrations in eager mode - #617
Merged
Merged
Conversation
Contributor
Author
|
(Pre-existing test failure: https://github.com/mir-group/nequip/actions/runs/39305994111/job/118243278242) |
cw-tan
force-pushed
the
freeze-integration-params
branch
from
November 12, 2026 02:41
5f7b52c to
1c8411f
Compare
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.
_from_saved_model, used byNequIPCalculatorandNequIPTorchSimCalcto load checkpoints and packages ineagermode, puts the model in eval mode but leaves its parameters withrequires_grad=True. Other inference paths (TorchScript, AOTInductor and LAMMPS ML-IAP) already freeze them withprepare_model_for_compile. With trainable parameters, autograd keeps the tensors needed for parameter gradients while computing forces, although inference never computes those gradients. This PR addsmodel.requires_grad_(False)aftermodel.eval()to instead freeze the parameters, which significantly reduces memory demand.Peak RSS in eager CPU inference on a rattled 216-atom NaCl cell; Apple M5 Pro, 6 threads, torch 2.10:
'einsum allegro' is the
Contractereinsum change in mir-group/allegro#148. For Allegro, the saving is one[edges, channels, i, j]tensor per layer, kept for theContracterweight gradient: 256 KiB per edge for Allegro-OAM-L, about 4 GiB here.NequIP models save less, since their large per-edge tensors are needed for the forces anyway, and only the radial MLP's hidden activations and some node-level tensors are dropped: peak mem is 3% (NequIP-OAM-M) and 5% (NequIP-OAM-L) lower on 216 atoms, and 5.5% and 6.5% lower on a 1,000-atom cell:
Tested:
Types of changes
Checklist:
black.CHANGELOG.md.