You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtorchclassA:
passtorch.save(A(), 'a.pth')
# File ".../python2.7/site-packages/torch/serialization.py", line 120, in save# return _save(obj, f, pickle_module, pickle_protocol)# File ".../python2.7/site-packages/torch/serialization.py", line 186, in _save# pickler.dump(obj)# File ".../python2.7/site-packages/torch/serialization.py", line 150, in persistent_id# elif torch.is_storage(obj):# File ".../python2.7/site-packages/torch/__init__.py", line 100, in is_storage# return obj.__class__ in _storage_classes# AttributeError: class A has no attribute '__class__'
Is it expected behavior?
Root cause seems to be te that torch.is_tensor(obj) and torch.is_storage(obj) expect an object to have the attribute __class__. And somehow serializer calls torch.is_storage(A) which blows (torch.is_storage(A()) does not).
Activity
soumith commentedon Mar 15, 2017
Classes have to be derived from
objectin py2 afaik.Once you do that, it should serialize fine.
vadimkantorov commentedon Mar 15, 2017
I think the ones derived from object are called new-style classes or something like that.
I have patched
is_storageandis_tensorto have:getattr(obj, "__class__", None) in _storage_classes. It has solved the issue.It may still be good to make is_tensor and is_storage to be robust to objects of old-style classes.
soumith commentedon Mar 15, 2017
can you send a PR with that patch. Yes, if it's an easy fix, probs worth supporting old-style classes.
soumith commentedon Apr 11, 2017
fixed in master. will be in next release.
Improvements in expression sorting and compute at. (pytorch#1003)
Merge pull request pytorch#1003 from ROCmSoftwarePlatform/IFU-master-…
Build libtorch and manywheel for 11.6 (pytorch#1003)
pytorch#1010 1.7a': delete the F.1 add bypass, name the alpha path's …