Skip to content

TorchTensor deepcopy raises error when dtype is not float32 #1831

@igamenovoer

Description

@igamenovoer

Initial Checks

  • 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
image

Example Code

import torch
from docarray.typing.tensor.torch_tensor import TorchTensor
import copy

x = TorchTensor(torch.randn(2,3))
y = copy.deepcopy(x)    # this works

xx = 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'

Python, DocArray & OS Version

0.39.1

Affected Components

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions