KEMBAR78
Have __sizeof__ on tensors account for size of data · Issue #3655 · pytorch/pytorch · GitHub
Skip to content

Have __sizeof__ on tensors account for size of data #3655

@lantiga

Description

@lantiga

From https://discuss.pytorch.org/t/data-type-when-change-tensor-array-to-numpy-array/9786

getsizeof internally calls the __sizeof__ method on the object, then it adds the garbage collection overhead to it and returns. Apparently __sizeof__ on PyTorch tensors doesn’t take the size of the underlying buffer into account:

torch.ones(10,10).__sizeof__()  # 40
torch.ones(100,100).__sizeof__()  # 40
np.ones((10,10)).__sizeof__() # 912
np.ones((100,100)).__sizeof__() # 80112

I can take care of this a few days from now.

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