0

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
Uwe.Schneider
  • 1,112
  • 1
  • 15
  • 28
  • How did you install PyTorch? With `conda`? – Ivan Nov 10 '21 at 21:02
  • I tried to install it with the recommended https://pytorch.org/ version for conda, with https://anaconda.org/pytorch/pytorch and with https://pypi.org/project/torch/ – Uwe.Schneider Nov 10 '21 at 21:15
  • *"I tried"*, in the end what did you use to install PyTorch on your machine: pip or conda? – Ivan Nov 10 '21 at 22:41
  • I used several environments for each versions. In one environment I used pip, in another one conda. – Uwe.Schneider Nov 11 '21 at 11:49
  • In your conda environment, can you do `conda list torch`? – Ivan Nov 11 '21 at 14:21
  • Yes, I wrote it into the description now. Do you think the packages are overlapping? – Uwe.Schneider Nov 12 '21 at 10:04
  • Thank you, how are you loading your environment, i.e. executing your python script? – Ivan Nov 12 '21 at 10:12
  • Thank you for trying to help. I let it run via a jupyter kernel in Visual Studio Code. Is that, what you ask? – Uwe.Schneider Nov 12 '21 at 11:54
  • Ok, can you check the version the kernel is running (`torch.__version__`). There might be a version mismatch between the version you see listed and the one you are actually running in your environment. – Ivan Nov 12 '21 at 12:34

1 Answers1

1

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
joaquin
  • 11
  • 1