Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

TorchTensor cannot be deep copied. #1719

Closed

Description

@gusseppe

Describe the bug
TorchTensor cannot be deep copied.

docarray.version
'0.36.0'

Related:
#1143

To Reproduce
script.py

import torch
from docarray import BaseDoc
from docarray.typing import TorchTensor
class Meow(BaseDoc):
    embedding : TorchTensor

a = Meow(embedding=torch.randn(42))
print(id(a.embedding), id(a.copy(deep=True).embedding))

Originally posted by @gusseppe in #1131 (comment)

Activity

  1. JoanFM commented on Jul 20, 2023

    @JoanFM
    Member

    Hey @gusseppe,

    What is the exact error u see?

  2. moved this to Todo/Bug in DocArray backlogon Jul 20, 2023
  3. linked a pull request that will close this issuefix: fix deepcopy torchtensor #1720on Jul 21, 2023
  4. moved this from Todo/Bug to In Progress in DocArray backlogon Jul 21, 2023
  5. moved this from In Progress to Done in DocArray backlogon Jul 21, 2023
  6. gusseppe commented on Jul 21, 2023

    @gusseppe
    Author

    Apologize for the late response, but the error is similar to the related bug #1131:

    RuntimeError: The default implementation of __deepcopy__() for non-wrapper subclasses only works for subclass types that implement new_empty() and for which that function returns another instance of the same subclass. You should either properly implement new_empty() for your subclass or override __deepcopy__() if it is intended behavior for new_empty() to return an instance of a different type.

  7. JoanFM commented on Jul 21, 2023

    @JoanFM
    Member

    We have seen it, the fix has been merged and will be released soon

  8. gusseppe commented on Jul 21, 2023

    @gusseppe
    Author

    Super great! thanks!

  9. JoanFM commented on Jul 21, 2023

    @JoanFM
    Member

    You can enjoy thr fix by installing the prerelease pip install docarray --pre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions