fix: restore weights_only=False when reloading best checkpoint#15867
Open
nileshpatil6 wants to merge 1 commit into
Open
fix: restore weights_only=False when reloading best checkpoint#15867nileshpatil6 wants to merge 1 commit into
nileshpatil6 wants to merge 1 commit into
Conversation
PR NVIDIA-NeMo#15314 dropped the explicit weights_only=False from the torch.load call in NeMoModelCheckpoint.on_save_checkpoint (used when save_best_model=True). Since torch 2.6 defaults weights_only to True, this call now fails whenever the checkpoint's hparams contain an OmegaConf DictConfig, which is the normal case for any Hydra-configured model. The checkpoint being loaded here was just written to disk by this same training run a few lines above, so it is a trusted file and loading it with weights_only=False is safe. Fixes NVIDIA-NeMo#15709 Signed-off-by: nileshpatil6 <technil6436@gmail.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.
What does this PR do?
Fixes #15709.
PR #15314 removed the explicit
weights_only=Falsefrom thetorch.loadcall inNeMoModelCheckpoint.on_save_checkpoint, the code path used whensave_best_model=True. Since torch 2.6 changed the default ofweights_onlytoTrue, this call now fails as soon as the checkpoint's hparams contain an OmegaConfDictConfig, which is the normal case for any Hydra-configured NeMo model. The reporter hit this directly with a real training run and pasted the traceback in the issue.The checkpoint being loaded here was written to disk by this same training run a few lines above (it is the last/best checkpoint the callback itself just saved), so it is not an untrusted external file, and loading it with
weights_only=Falseis safe. This restores that behavior.Changelog
nemo/utils/callbacks/nemo_model_checkpoint.py: passweights_only=Falseback to thetorch.loadcall inon_save_checkpoint, with a comment explaining why.Testing
Ran
pytest tests/core/test_exp_manager.py -k test_nemo_checkpoint_save_best_model_1locally (CPU), it passes with this change. That particular test uses a minimalExampleModelwhose hparams do not include aDictConfig, so it passes both before and after this change and does not by itself catch the regression, the regression only shows up once hparams contain an OmegaConf object, as in the issue's traceback.I was not able to fully set up NeMo's heavier ASR/TTS dependency stack in this environment to add a new end to end regression test in reasonable time. I verified the fix by reading the exact code path (this is the only
torch.loadcall in this method, loading a file this same callback just wrote), comparing against the pre-#15314 behavior, and confirming the diff is syntactically valid and mirrors the exact change #15314 made in reverse for this one call site.Usage
No API change, this only affects the internal reload of the best checkpoint when
save_best_model=TrueinModelCheckpointparams.