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

added 'weights_only' param in torch.load examples #112860

Closed
wants to merge 1 commit into from

Conversation

Viditagarwal7479
Copy link
Contributor

@Viditagarwal7479 Viditagarwal7479 commented Nov 3, 2023

Fixes #111876

torch.load without setting weights_only=True is unsafe. So updating examples of torch.load to use weights_only=True where possible and weights_only=False elsewhere with a warning of being unsafety.

cc @svekars @carljparker

Copy link

pytorch-bot bot commented Nov 3, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112860

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 809c2f4 with merge base b10fa8a (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copy link

linux-foundation-easycla bot commented Nov 3, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Viditagarwal7479 / name: Vidit Agarwal (809c2f4)

@Viditagarwal7479
Copy link
Contributor Author

@pytorchbot label "docathon-h2-2023"

@pytorch-bot pytorch-bot bot added the docathon-h2-2023 Issues for the docathon in H2 2023 label Nov 3, 2023
@svekars svekars requested a review from kit1980 November 3, 2023 16:20
@svekars svekars added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module medium Label for medium docathon tasks module: docs Related to our documentation, both in docs/ and docblocks labels Nov 3, 2023
@vadimkantorov
Copy link
Contributor

vadimkantorov commented Nov 3, 2023

Also, very recently on a nightly torch.load(, weights_only=True) threw as strange deprecation warning, repro in #52181 (comment)

Maybe would be nice to assert in test that it produces no warnings

@Viditagarwal7479
Copy link
Contributor Author

Do you mean to add context manager, with warnings.catch_warnings(action="error") in test/test_serialization.py. So the depreciation warning doesn't comes into the stable PyTorch?

@vadimkantorov
Copy link
Contributor

I think, this UserWarning needs to be fixed by not using the deprecated UntypedStorage... It's just strange that hopefully-soon-to-be-default-safe-method raises deprecation warnings :) which sort of deceiptfully signals that the user's not doing the right thing by using weights_only=True

@vadimkantorov
Copy link
Contributor

Deprecation UserWarning was on 2.1.0.dev20230802+cpu, not sure how it is on more recent nightlies, hope it is fixed now :)

@Viditagarwal7479
Copy link
Contributor Author

That depreciation warning is also coming in 2.1.0 stable with cuda 11.8

@Viditagarwal7479
Copy link
Contributor Author

weights_only=True let's us only load torch.tensors specifically speaking torch.TypedStorage and python default datatypes (int, float, list, tuples,...). Loading python default datatypes with this argument doesn't raise any warning but loading tensors raises warning.
Internally also when using Storage class a depreciation warning is set which can be seen at:
https://pytorch.org/docs/stable/storage.html

"All storage classes except for torch.UntypedStorage will be removed in the future, and torch.UntypedStorage will be used in all cases."

@Viditagarwal7479
Copy link
Contributor Author

@kit1980 a gentle reminder to review the PR.

@kit1980
Copy link
Member

kit1980 commented Nov 6, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 6, 2023
@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@svekars svekars added the topic: not user facing topic category label Nov 6, 2023
@svekars
Copy link
Contributor

svekars commented Nov 6, 2023

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Nov 7, 2023
Fixes pytorch#111876

`torch.load` without setting `weights_only=True` is unsafe. So updating examples of `torch.load` to use `weights_only=True` where possible and `weights_only=False` elsewhere with a warning of being unsafety.

Pull Request resolved: pytorch#112860
Approved by: https://github.com/kit1980
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
Fixes pytorch#111876

`torch.load` without setting `weights_only=True` is unsafe. So updating examples of `torch.load` to use `weights_only=True` where possible and `weights_only=False` elsewhere with a warning of being unsafety.

Pull Request resolved: pytorch#112860
Approved by: https://github.com/kit1980
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request docathon-h2-2023 Issues for the docathon in H2 2023 medium Label for medium docathon tasks Merged module: docs Related to our documentation, both in docs/ and docblocks open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update torch.load examples to encourage best security practices
6 participants