Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: explicitly set weights_only to False during checkpoint loading to support PyTorch 2.6 #56

Open
wants to merge 5 commits into
base: rocm_dev
Choose a base branch
from

Conversation

mpashkovskii
Copy link

Starting version 2.4 PyTorch warns developers that default value of weights_only will be flipped from False to True. Version 2.6 introduced that change. We have to set weights_only=False to maintain the old behaviour and avoid checkpoint loading crashes with PyTorch >=2.6 like following:

could not load the checkpoint

Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint. 
(1) In PyTorch 2.6, we changed the default value of the `weights_only` argument in `torch.load` from `False` to `True`. Re-running `torch.load` with `weights_only` set to `False` will likely succeed, but it can result in arbitrary code execution. Do it only if you got the file from a trusted source.
(2) Alternatively, to load with `weights_only=True` please check the recommended steps in the following error message.

WeightsUnpickler error: Unsupported global: GLOBAL argparse.Namespace was not an allowed global by default. Please use `torch.serialization.add_safe_globals([Namespace])` or the `torch.serialization.safe_globals([Namespace])` context manager to allowlist this global if you trust this class/function.

Check the documentation of torch.load to learn more about types accepted by default with weights_only https://pytorch.org/docs/stable/generated/torch.load.html.

Additionally see this note on torch.load with weights_only=True for a summary what weights_only=True does and all utilities related to weights_only.

@wenchenvincent
Copy link
Collaborator

@mpashkovskii There are some unit test failures in CI, could you address them?

@mpashkovskii
Copy link
Author

@wenchenvincent fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants