Skip to content

[BUG] - FutureWarning in "Introduction to PyTorch - Save and Load the Model" tutorial #3007

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

Closed
tgilbert09 opened this issue Aug 25, 2024 · 3 comments · Fixed by #3012
Closed
Assignees
Labels
bug core Tutorials of any level of difficulty related to the core pytorch functionality intro

Comments

@tgilbert09
Copy link

tgilbert09 commented Aug 25, 2024

Add Link

https://pytorch.org/tutorials/beginner/basics/saveloadrun_tutorial.html

Describe the bug

Getting 2x FutureWarnings from lines model.load_state_dict(torch.load('model_weights.pth')) and model = torch.load('model.pth') in the Save and Load Model tutorial. I think this is what it wants changing:

We recommend you start setting weights_only=True

The full warning I am seeing is:

/var/lib/workspace/beginner_source/basics/saveloadrun_tutorial.py:37: FutureWarning:
You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.

Describe your environment

Shows for me in the tutorial on my web browser. Also on MacOS, torch version 2.4.0.

cc @subramen @albanD

@tgilbert09 tgilbert09 added the bug label Aug 25, 2024
@svekars svekars added intro core Tutorials of any level of difficulty related to the core pytorch functionality labels Aug 26, 2024
@albanD
Copy link
Contributor

albanD commented Aug 26, 2024

cc @mikaylagawarecki to add to our list to update all tutorials with best practices!

@svekars
Copy link
Contributor

svekars commented Aug 26, 2024

I just chatted with @mikaylagawarecki and she gave me a great explanation about the differences. I guess I can send a fix for this one.

@tgilbert09
Copy link
Author

Amazing thanks for looking into it so quickly!

If it's useful to know - I spotted another FutureWarning in the TorchVision Object Detection Finetuning Tutorial.

/var/lib/workspace/intermediate_source/engine.py:30: FutureWarning:

torch.cuda.amp.autocast(args...) is deprecated. Please use torch.amp.autocast('cuda', args...) instead.

Coming from https://raw.githubusercontent.com/pytorch/vision/main/references/detection/engine.py. I think others are aware of this one though - pytorch/pytorch#130659 - I will add a comment on that issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core Tutorials of any level of difficulty related to the core pytorch functionality intro
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants