-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensor subclasses lose type when pickling #47051
Comments
I guess |
I originally wrote this for, IIRC, pytorch 1.4, since we added our own subclassing support back then when PyTorch didn't support it. At the time, I largely copied, pasted, and refactored code from PyTorch to do so. So it shouldn't be any slower than PyTorch, unless things have changed since then. |
Yes, |
Being worked on in #47115 |
Thank you @hameerabbasi ! :) |
Hi, should pickling of
Is there anything different I would need to do in Line 104 in 666dff3
__torch_function__ to handle also pickling, that would be great. I also think a section could be added to PyTorch documentation at https://pytorch.org/docs/stable/notes/extending.html#extending-torch, which was very helpful in creating a custom torch.Tensor subclass except for pickling support.
I see that the regression test for this issue uses a tensor subclass type which does not define I get the impression I run into this issue because of my
i.e., converts all Similarly, changing this to:
leads to an infinite recursion. It is also puzzling that both Any suggestion on how to properly implement a subclass that supports pickling appreciated. Thanks! |
Reopening this issue until we have a chance to review your question, @aschuh-hf. |
馃悰 Bug
Pickling and then unpickling a subclass of
Tensor
should result in an object of the same class as what was pickled. However, it doesn't - instead it always creates something of classTensor
.To Reproduce
The following prints
torch.Tensor
, however it should print_T
.Expected behavior
It should print
_T
.Environment
torch.__version__
== 1.7.0, running on Ubuntu.Additional context
Placing the following method in the base class resolves the problem:
Perhaps something like this could be used to fix this issue.
cc @hameerabbasi @rgommers @mruberry
The text was updated successfully, but these errors were encountered: