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

Add support for using AffineQuantizedTensor with weights_only=True #630

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

jerryzh168
Copy link
Contributor

Summary:
torch.load(file, weights_only=True) is safer so ideally we can use that, by default it does not work with tensor subclasses, since now we have https://pytorch.org/docs/main/notes/serialization.html#torch.serialization.add_safe_globals we can add all tensor subclass classes and special types to globals so that these can work with weights_only=True

Test Plan:
python test/dtypes/test_affine_quantized.py

Reviewers:

Subscribers:

Tasks:

Tags:

Copy link

pytorch-bot bot commented Aug 7, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 009d28e with merge base 8bba8ed (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 7, 2024
@jerryzh168 jerryzh168 force-pushed the add-aqt-to-safe-global branch 3 times, most recently from a8b7ee6 to 42ccee6 Compare August 8, 2024 00:07
Summary:
`torch.load(file, weights_only=True)` is safer so ideally we can use that, by default it does not work
with tensor subclasses, since now we have https://pytorch.org/docs/main/notes/serialization.html#torch.serialization.add_safe_globals
we can add all tensor subclass classes and special types to globals so that these can work with `weights_only=True`

Test Plan:
python test/dtypes/test_affine_quantized.py

Reviewers:

Subscribers:

Tasks:

Tags:
Copy link

@mikaylagawarecki mikaylagawarecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -466,3 +481,7 @@ def int8_dynamic_activation_int8_semi_sparse_weight():
"""
from torchao.dtypes import SemiSparseLayoutType
return int8_dynamic_activation_int8_weight(layout_type=SemiSparseLayoutType())


if TORCH_VERSION_AFTER_2_5:
Copy link

@mikaylagawarecki mikaylagawarecki Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A n00b qn: it wasn't super clear to me why these functions are used during unpickling?

but I trust that you added them because they appeared in the error message :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's correct, these functions are serialized as well when we do dynamic quantization

@msaroufim msaroufim merged commit 433cd14 into pytorch:main Aug 8, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants