-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Add utility to get all unsafe globals in checkpoint (no pickletools dependency) #139221
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 utility to get all unsafe globals in checkpoint (no pickletools dependency) #139221
Conversation
…ependency) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/139221
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit e788465 with merge base 73fde0d ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…ckletools dependency)" #139106 without pickletools [ghstack-poisoned]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, imo it's much more explicit what are we doing here, and what are the guarantees...
…ckletools dependency)" #139106 without pickletools [ghstack-poisoned]
…ckletools dependency)" #139106 without pickletools [ghstack-poisoned]
|
@pytorchbot merge |
Merge startedYour 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 |
Pull Request resolved: #139433 Approved by: https://github.com/malfet ghstack dependencies: #138936, #139221
…139541) This is tested in PR stacked above in ```python python test/distributed/fsdp/test_fsdp_state_dict.py TestFSDPStateDict.test_torch_save_load ``` We cannot depend on whether `hasattr(..., __slots__)` to know whether a BUILD instruction has slotstate. For example, if a class subclasses ABC `hasattr(__slots__)` will be `True` but there might be no slots (and hence `state` will not be a tuple). So revert #138936 to following the pickle library's code ```python >>> from abc import ABC >>> hasattr(ABC, "__slots__") True ``` So ```python import torch from abc import ABC from dataclasses import dataclass class Foo(ABC): pass class FooWrapper(Foo): def __init__(self, x, y): self.x = x self.y = y f = FooWrapper(1, 2) torch.save(f, "temp.pt") with torch.serialization.safe_globals([FooWrapper]): torch.load("temp.pt") ``` Would fail on the previous code with ``` File "/data/users/mg1998/pytorch/torch/serialization.py", line 1934, in _load result = unpickler.load() File "/data/users/mg1998/pytorch/torch/_weights_only_unpickler.py", line 366, in load for k, v in slotstate.items(): ``` As there is actually no slotstate Pull Request resolved: #139541 Approved by: https://github.com/malfet ghstack dependencies: #138936, #139221, #139433
Pull Request resolved: #137602 Approved by: https://github.com/malfet, https://github.com/albanD ghstack dependencies: #138936, #139221, #139433, #139541
…ependency) (pytorch#139221) Fixes pytorch#129698 pytorch#139106 without pickletools Pull Request resolved: pytorch#139221 Approved by: https://github.com/malfet ghstack dependencies: pytorch#138936
Pull Request resolved: pytorch#139433 Approved by: https://github.com/malfet ghstack dependencies: pytorch#138936, pytorch#139221
Prevent same global from being added multiple times Pull Request resolved: pytorch#139303 Approved by: https://github.com/janeyx99 ghstack dependencies: pytorch#138936, pytorch#139221, pytorch#139433, pytorch#139541, pytorch#137602
Prevent same global from being added multiple times Pull Request resolved: pytorch#139303 Approved by: https://github.com/janeyx99 ghstack dependencies: pytorch#138936, pytorch#139221, pytorch#139433, pytorch#139541, pytorch#137602
Fixes #129698
#139106 without pickletools
Stack from ghstack (oldest at bottom):