8000 torch.save does not save python attributes attached to Tensors or Parameters · Issue #72129 · pytorch/pytorch · GitHub 8000
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
torch.save does not save python attributes attached to Tensors or Parameters #72129
Closed
@thegregyang

Description

@thegregyang

🐛 Describe the bug

If one attaches python attributes to a Tensor or Parameter, these attributes are not saved by torch.save. This is not expected based on torch's documentation that "torch.save() and torch.load() use Python’s pickle by default".

import torch
xx = torch.zeros(3, 4)
xx.foo = 'bar'
torch.save(xx, '_xx.pt')
torch.load('_xx.pt').foo

yields an error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_19139/1249207437.py in <module>
----> 1 torch.load('_xx.pt').foo

AttributeError: 'Tensor' object has no attribute 'foo'

whereas one would expect this returns 'bar'.

Versions

Collecting environment information...
PyTorch version: 1.10.2
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.3 LTS (x86_64)
GCC version: (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.27

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-1067-azure-x86_64-with-glibc2.27
Is CUDA available: True
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: Tesla P100-PCIE-16GB
Nvidia driver version: 495.46
cuDNN version: /usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.2
[pip3] torch==1.10.2
[pip3] torchaudio==0.10.2
[pip3] torchvision==0.11.3
[conda] blas 1.0 mkl
[conda] cudatoolkit 11.3.1 h2bc3f7f_2
[conda] ffmpeg 4.3 hf484d3e_0 pytorch
[conda] mkl 2021.3.0 h06a4308_520
[conda] mkl-service 2.4.0 py39h7f8727e_0
[conda] mkl_fft 1.3.1 py39hd3c417c_0
[conda] mkl_random 1.2.2 py39h51133e4_0
[conda] numpy 1.21.2 py39h20f2e39_0
[conda] numpy-base 1.21.2 py39h79a1101_0
[conda] pytorch 1.10.2 py3.9_cuda11.3_cudnn8.2.0_0 pytorch
[conda] pytorch-mutex 1.0 cuda pytorch
[conda] torchaudio 0.10.2 py39_cu113 pytorch
[conda] torchvision 0.11.3 py39_cu113 pytorch

cc @ezyang @gchanan @zou3519 @mruberry

Metadata

Metadata

Assignees

Labels

high prioritymodule: serializationIssues related to serialization (e.g., via pickle, or otherwise) of PyTorch objectsrelease notes: python_frontendpython frontend release notes categorytriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0