KEMBAR78
Add utility to get all unsafe globals in checkpoint (no pickletools dependency) by mikaylagawarecki · Pull Request #139221 · pytorch/pytorch · GitHub
Skip to content

Conversation

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 29, 2024

🔗 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 Failures

As of commit e788465 with merge base 73fde0d (image):
💚 Looks good so far! There are no failures yet. 💚

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

…ckletools dependency)"

#139106 without pickletools




[ghstack-poisoned]
…ckletools dependency)"

#139106 without pickletools




[ghstack-poisoned]
…ckletools dependency)"

#139106 without pickletools




[ghstack-poisoned]
Copy link
Contributor

@malfet malfet left a 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]
@mikaylagawarecki mikaylagawarecki added release notes: python_frontend python frontend release notes category topic: improvements topic category labels Oct 31, 2024
@mikaylagawarecki mikaylagawarecki marked this pull request as ready for review October 31, 2024 19:20
…ckletools dependency)"

#139106 without pickletools




[ghstack-poisoned]
…ckletools dependency)"

#139106 without pickletools




[ghstack-poisoned]
@mikaylagawarecki
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 1, 2024
@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

pytorchmergebot pushed a commit that referenced this pull request Nov 1, 2024
pytorchmergebot pushed a commit that referenced this pull request Nov 4, 2024
…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
pytorchmergebot pushed a commit that referenced this pull request Nov 4, 2024
pytorchmergebot pushed a commit that referenced this pull request Nov 4, 2024
Prevent same global from being added multiple times

Pull Request resolved: #139303
Approved by: https://github.com/janeyx99
ghstack dependencies: #138936, #139221, #139433, #139541, #137602
rahulsingh-intel pushed a commit to rahulsingh-intel/pytorch that referenced this pull request Nov 5, 2024
rahulsingh-intel pushed a commit to rahulsingh-intel/pytorch that referenced this pull request Nov 5, 2024
atalman pushed a commit to atalman/pytorch that referenced this pull request Nov 11, 2024
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
@github-actions github-actions bot deleted the gh/mikaylagawarecki/280/head branch December 2, 2024 02:13
Ryo-not-rio pushed a commit to Ryo-not-rio/pytorch that referenced this pull request Dec 2, 2024
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
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 Merged release notes: python_frontend python frontend release notes category topic: improvements topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants