Uwe.Schneider
Uwe.Schneider

Reputation: 1415

PyTorch: module 'torch' has no attribute 'gradient'

PyTorch seems to have a serious bug leading to the error message

AttributeError: module 'torch' has no attribute [some torch function]

In my case, I try to use torch.gradient link. I am using Python version 3.8.5 and tried the PyTorch Versions 1.6.0, 1.7.0, 1.7.1 , 1.8, 1.9.0 for CPU. (The newest version has another bug for gradient torch.gradient edge order).

There are several answers suggesting that I should install torch via pip, I should install torchvision, nothing worked. There is also the suggestion, that the wrong torch folder is used as a namespace which does not seem to be the case, since there is an initfile when I run print(torch.__path__)

So my question is: How to finally solve this problem?


I tried to install it with the recommended pytorch.org version for conda, with anaconda.org/pytorch/pytorch and with pypi.org/project/torch – nothing worked.


The conda list torch element gives

pytorch                   1.7.1               py3.8_cpu_0  [cpuonly]  pytorch
pytorch-mutex             1.0                         cpu    pytorch
torchaudio                0.7.2                      py38    pytorch
torchvision               0.8.2                  py38_cpu  [cpuonly]  pytorch

Upvotes: 0

Views: 4190

Answers (1)

joaquin
joaquin

Reputation: 11

The same happened to me. What I did was to create a new conda environment and reinstall PyTorch according to https://pytorch.org/

Upvotes: 1

Related Questions