Make training checkpoints loadable under torch.load(weights_only=True)#802
Merged
kenko911 merged 4 commits intoJun 10, 2026
Conversation
ModelLightningModule / PotentialLightningModule called save_hyperparameters(ignore=["model"]), so the optimizer and scheduler *objects* (and, for the Potential module, the numpy element_refs array) were pickled into the checkpoint's hyper_parameters. Since torch 2.6 flipped torch.load's default to weights_only=True, resuming training via Trainer.fit(ckpt_path=...) then fails with an UnpicklingError on those globals. Exclude optimizer/scheduler from save_hyperparameters (their state is already persisted in the checkpoint's optimizer_states / lr_schedulers, so this loses nothing) and store element_refs as a plain list instead of a numpy array (AtomRef already accepts a list). configure_optimizers is unaffected because it reads the self.optimizer / self.scheduler instance attributes, not hparams. Adds a regression test asserting the objects are absent from hparams, element_refs is a list, and a checkpoint built from these hparams loads under weights_only=True. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
ModelLightningModule / PotentialLightningModule called save_hyperparameters(ignore=["model"]), so the optimizer and scheduler objects (and, for the Potential module, the numpy element_refs array) were pickled into the checkpoint's hyper_parameters. Since torch 2.6 flipped torch.load's default to weights_only=True, resuming training via Trainer.fit(ckpt_path=...) then fails with an UnpicklingError on those globals.
Exclude optimizer/scheduler from save_hyperparameters (their state is already persisted in the checkpoint's optimizer_states / lr_schedulers, so this loses nothing) and store element_refs as a plain list instead of a numpy array (AtomRef already accepts a list). configure_optimizers is unaffected because it reads the self.optimizer / self.scheduler instance attributes, not hparams.
This PR fixes the issue reported by Chao Yang @Y-Chao.