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

Loading a checkpoint needs weights_only=False #1837

Open
ghsanti opened this issue Dec 10, 2024 · 1 comment
Open

Loading a checkpoint needs weights_only=False #1837

ghsanti opened this issue Dec 10, 2024 · 1 comment

Comments

@ghsanti
Copy link

ghsanti commented Dec 10, 2024

📚 Documentation

Here in loading a checkpoint

model = TheModelClass(*args, **kwargs)
optimizer = TheOptimizerClass(*args, **kwargs)

checkpoint = torch.load(PATH, weights_only=True)
model.load_state_dict(checkpoint['model_state_dict'])
optimizer.load_state_dict(checkpoint['optimizer_state
#...

One should load all the model not weights only:

checkpoint = torch.load(PATH, weights_only=True)

to

checkpoint = torch.load(PATH, weights_only=False)
@Tony-Y
Copy link

Tony-Y commented Dec 11, 2024

You should carefully read https://pytorch.org/docs/stable/generated/torch.load.html. It is insecure to set weights_only to False.

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

No branches or pull requests

2 participants