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
{{ message }}
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
TorchTensor deepcopy raises error when dtype is not float32 #1831
I have read and followed the docs and still think this is a bug
Description
when calling copy.deepcopy() over TorchTensor, it fails when tensor.dtype != torch.float32.
The problem is that TorchTensor.new_empty() will create a float32 tensor no matter what, regardless of self.dtype
Example Code
importtorchfromdocarray.typing.tensor.torch_tensorimportTorchTensorimportcopyx=TorchTensor(torch.randn(2,3))
y=copy.deepcopy(x) # this worksxx=TorchTensor(torch.randint(0,100,(2,3)))
yy=copy.deepcopy(xx) # RuntimeError: Expected a Storage of type float or an UntypedStorage, but got type Long for argument 1 'storage'
Activity
JoanFM commentedon Nov 14, 2023
Hey @igamenovoer,
Thanms for reporting the issue. Since you spotted the problem, would you like to contribute the fix?
ai-naymul commentedon Nov 30, 2023
I think we need to add a custom implementation of
deepcopyfor TorchTensor to avoid storage-sharing issues.@JoanFM could you please help me to contribute in this?
Here is my approach:
JoanFM commentedon Nov 30, 2023
what do u mean by a deepcopy class for that?
ai-naymul commentedon Nov 30, 2023
Oh, I am sorry I was mentioning the method, It's was a typing mistake.
JoanFM commentedon Nov 30, 2023
the approach seems to make sense indeed
ai-naymul commentedon Nov 30, 2023
So should I try the approach?
JoanFM commentedon Nov 30, 2023
yws
ai-naymul commentedon Dec 2, 2023
@JoanFM would you mind having a look at the PR, please?