GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TorchTensor deepcopy raises error when dtype is not float32 · Issue #1831 · docarray/docarray

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 deepcopy raises error when dtype is not float32 #1831

Copy link
Copy link
Closed
#1833
Closed
TorchTensor deepcopy raises error when dtype is not float32#1831
#1833
Copy link

Description

@igamenovoer
igamenovoer
opened on Nov 14, 2023
Issue body actions

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

  • Vector Database / Index
  • Representing
  • Sending
  • storing
  • multi modal data type

Activity

  1. JoanFM commented on Nov 14, 2023

    @JoanFM
    JoanFM
    on Nov 14, 2023
    Member
    More actions

    Hey @igamenovoer,

    Thanms for reporting the issue. Since you spotted the problem, would you like to contribute the fix?

  2. ai-naymul commented on Nov 30, 2023

    @ai-naymul
    ai-naymul
    on Nov 30, 2023
    Contributor
    More actions

    I think we need to add a custom implementation of deepcopy for TorchTensor to avoid storage-sharing issues.

    @JoanFM could you please help me to contribute in this?

    Here is my approach:

    1. Create a deepcopy methods for that
    2. create a new tensor with the same data and properties
    3. Set the class to the custom Torchtensor class
    4. return the new tensor
  3. JoanFM commented on Nov 30, 2023

    @JoanFM
    JoanFM
    on Nov 30, 2023
    Member
    More actions

    what do u mean by a deepcopy class for that?

  4. ai-naymul commented on Nov 30, 2023

    @ai-naymul
    ai-naymul
    on Nov 30, 2023
    Contributor
    More actions

    what do u mean by a deepcopy class for that?

    Oh, I am sorry I was mentioning the method, It's was a typing mistake.

  5. JoanFM commented on Nov 30, 2023

    @JoanFM
    JoanFM
    on Nov 30, 2023
    Member
    More actions

    the approach seems to make sense indeed

  6. ai-naymul commented on Nov 30, 2023

    @ai-naymul
    ai-naymul
    on Nov 30, 2023
    Contributor
    More actions

    the approach seems to make sense indeed

    So should I try the approach?

  7. JoanFM commented on Nov 30, 2023

    @JoanFM
    JoanFM
    on Nov 30, 2023
    Member
    More actions

    yws

    Reacted by Naymul Islam
  8. ai-naymul commented on Dec 2, 2023

    @ai-naymul
    ai-naymul
    on Dec 2, 2023
    Contributor
    More actions

    yws

    @JoanFM would you mind having a look at the PR, please?

  9. JoanFM
    linked a pull request that will close this issuefix: fix storage issue in torchtensor class #1833on Dec 9, 2023
  10. JoanFM
    closed this as completedin #1833on Dec 9, 2023
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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.