pytorch_sparse icon indicating copy to clipboard operation
pytorch_sparse copied to clipboard

AttributeError: 'NoneType' object has no attribute 'origin'

Open devskroy1 opened this issue 4 years ago • 18 comments

I am using torch-sparse version 0.6.8 as a dependency for a project I am working on.

However, I get the following error inside the torch_sparse/__init__.py file: torch.ops.load_library(importlib.machinery.PathFinder().find_spec( AttributeError: 'NoneType' object has no attribute 'origin'

It seems that the find_spec() call returns None.

I am running on CUDA on Ubuntu and using torch version 1.7.1 and torch-scatter version 2.0.5 Do you know how I can resolve this error?

Thanks

devskroy1 avatar Apr 02 '21 14:04 devskroy1

Have you seen https://github.com/rusty1s/pytorch_geometric/issues/2304? Can you check if the *.so files in the torch_sparse folder exist?

You also may have multiple torch-sparse versions? Can you try to repeatedly uninstall them and install again?

rusty1s avatar Apr 04 '21 06:04 rusty1s

Thanks for your reply. I have now resolved the issue. The *.so files were getting created in the torch_sparse folder. The problem was that the cuda .so files weren't getting created. I had to change the torch_sparse and torch_cluster versions. I don't believe I had multiple torch_sparse versions.

devskroy1 avatar Apr 04 '21 19:04 devskroy1

@devskroy1 I am getting the same error. Which version of torch_sparse and torch_cluster did you end up installing?

Andrea-V avatar Apr 13 '21 08:04 Andrea-V

I will leave my 50 cents here, I tried other methods to solve this problem but then but just got other issues 😅 I solved them by updating to PyTorch 1.8.1 and CUDA to 11.1 (using Ubuntu 20.04). Here are the steps:

  1. Update CUDA to the latest version. NOTE: if you encounter problems with the CUDA installation, follow this solution (basically purge the Nvidia drivers and reinstall them so to avoid problems with dependencies)
  2. Install latest version of torch with cuda by running this (from PyTorch webpage)
pip3 install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
  1. Install torch-geometric and its dependencies this in your terminal (from the PyTorch Geometric installation guide):
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-geometric

fedebotu avatar Apr 21 '21 07:04 fedebotu

Thanks for your reply. I have now resolved the issue. The *.so files were getting created in the torch_sparse folder. The problem was that the cuda .so files weren't getting created. I had to change the torch_sparse and torch_cluster versions. I don't believe I had multiple torch_sparse versions.

actually i met with the same issue with you. In my case, *cpu.so file were getting created but no cuda .so files found. How did you. resolve. this problem?

JiayuanDing100 avatar Apr 22 '21 21:04 JiayuanDing100

Did you install the CUDA package, e.g. via https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html? Otherwise, you may try to install with the --no-index option, i.e.

pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+{CUDA}.html

rusty1s avatar Apr 23 '21 11:04 rusty1s

I am also facing the same issue. My environment is

  • python = 3.9.4
  • pytorch = 1.8.1
  • CUDA = 11.1
  • torch_scatter = 2.0.6
  • torch_sparse = 0.6.9
  • torch_cluster = 1.5.9
  • torch_geometric = 1.7.0

I installed the packages from pypi and I checked that I was installing using the pytorch 1.8.0 and CUDA 111 link. I tried to do --no-index install but I got the following error

ERROR: Could not find a version that satisfies the requirement torch-sparse
ERROR: No matching distribution found for torch-sparse

I checked that torch.cuda.is_available() returns True. The issue is torch_sparse is not compiling the cuda.so files. I checked by installing the packages from source (except pytorch) and the same error persists. I installed pytorch using the conda command and the version of cuda is 11.1.74.

During the compilation process of torch_sparse it is building cpu packages but not building cuda packages. I can confirm that this error was not occurring with python 3.8 and pytorch 1.7 and cuda 10.

KushajveerSingh avatar Apr 30 '21 20:04 KushajveerSingh

@rusty1s I think there is some inconsistency for wheels of pytorch=1.8.0 and cuda=11.1.

Note: python = 3.9.4 did not work. So I am using python = 3.8.8

I installed pytorch=1.8.1 and torch-sparse using below commands

conda install pytorch cudatoolkit=11.1 -c pytorch -c nvidia
pip install --no-cache-dir torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html

But the *_cuda.so files were not copied. When I tried pytorch=1.8.1, cuda=10.2 using the below commands

conda install pytorch cudatoolkit=10.2 -c pytorch
pip install --no-cache-dir torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html

the *_cuda.so files were copied. Also, compiling torch-sparse from source would not work as when pytorch is installed from conda the environment variable torch.utils.cpp_extension.CUDA_HOME is set to None, so CUDA extensions will never be built.

KushajveerSingh avatar Apr 30 '21 21:04 KushajveerSingh

Yes, we currently do not provide Python 3.9 binaries. I will work on that.

I'm not sure if there is a difference between packages with different CUDA versions. You can check by downloading https://pytorch-geometric.com/whl/torch-1.8.0+cu111/torch_sparse-0.6.9-cp38-cp38-linux_x86_64.whl that it also contains the required *_cuda.so files.

I installed PyTorch from conda and CUDA_HOME is set for me. Nonetheless, you can still force CUDA installation by running:

FORCE_CUDA=1 python setup.py install

rusty1s avatar May 01 '21 07:05 rusty1s

This is interesting. I checked with a clean miniconda installation also that CUDA_HOME was not set after installing pytorch (1.8.1) from conda. Maybe the driver on my machine is not working properly with cudatoolkit that is installed with conda or I am using a maxwell mobile GPU, that is pretty old for cuda 11.

But I got the pytorch_geometric working with cuda 10.2 so I am ok. There are not many features of cuda 11 that my gpu can use, so I am not missing on anything.

KushajveerSingh avatar May 01 '21 20:05 KushajveerSingh

Thanks for your reply. I have now resolved the issue. The *.so files were getting created in the torch_sparse folder. The problem was that the cuda .so files weren't getting created. I had to change the torch_sparse and torch_cluster versions. I don't believe I had multiple torch_sparse versions.

I met the same problem and fixed it by installing cuda package. Check if '/usr/local/cuda-11.x' is existing. If you only install 'cuda toolkit' in conda virtual env, you can't find it. (refer to below explanation)

image

My solution is:

  1. install 'cuda' (not in conda virtual env)
  2. install torch_geometric in conda virtual env using below commands conda create -n XXX python=3.8 conda activate XXX conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge conda install pytorch-geometric -c rusty1s -c conda-forge

kimsu55 avatar Aug 05 '21 02:08 kimsu55

I installed pytorch with conda: conda install pytorch=1.9.0 torchvision torchaudio cpuonly -c pytorch and pytorch-geometric with: conda install pytorch-geometric -c rusty1s -c conda-forge

These are the pytorch packages that got installed:

pytorch=1.9.0=cuda112py38h3d13190_1 pytorch-cluster=1.5.9=py38_torch_1.9.0_cpu pytorch-geometric=1.7.2=py38_torch_1.9.0_cpu pytorch-gpu=1.9.0=cuda112py38h0bbbad9_1 pytorch-scatter=2.0.8=py38_torch_1.9.0_cpu pytorch-sparse=0.6.11=py38_torch_1.9.0_cpu pytorch-spline-conv=1.2.1=py38_torch_1.9.0_cpu

When importing: from torch_geometric.data import Data I get the above error as well

KukumavMozolo avatar Aug 27 '21 08:08 KukumavMozolo

Note sure why you have a PyTorch version installed with CUDA support although you have specified thecpuonly flag, but I'm fairly sure that this explains the error.

rusty1s avatar Aug 27 '21 08:08 rusty1s

As a side note: I tried to install the packages with an environment.yml `channels:

  • conda-forge
  • anaconda
  • pytorch
  • rusty1s dependencies:
  • pip==21.0.1
  • python==3.8.11
  • gql==2.0.0
  • graphql-core==2.3.2
  • flask==1.1.2
  • pytorch
  • torchvision
  • torchaudio
  • cpuonly
  • pytorch-geometric`

this led to the inconsistent packages. I fixed it by explicitly stating packages e.g: ` - pytorch=1.9.0=py3.8_cpu_0

  • pytorch-cluster=1.5.9=py38_torch_1.9.0_cpu
  • pytorch-geometric=1.7.2=py38_torch_1.9.0_cpu
  • pytorch-scatter=2.0.8=py38_torch_1.9.0_cpu
  • pytorch-sparse=0.6.11=py38_torch_1.9.0_cpu
  • pytorch-spline-conv=1.2.1=py38_torch_1.9.0_cpu`

KukumavMozolo avatar Aug 27 '21 09:08 KukumavMozolo

There is also a PyTorch conda package in conda-forge which is picked up (rather than the one from the -c pytorch channel). Swapping the order of channels, i.e., putting pytorch before conda-forge, should fix this.

rusty1s avatar Aug 27 '21 09:08 rusty1s

Thanks for your reply. I have now resolved the issue. The *.so files were getting created in the torch_sparse folder. The problem was that the cuda .so files weren't getting created. I had to change the torch_sparse and torch_cluster versions. I don't believe I had multiple torch_sparse versions.

I met the same problem and fixed it by installing cuda package. Check if '/usr/local/cuda-11.x' is existing. If you only install 'cuda toolkit' in conda virtual env, you can't find it. (refer to below explanation)

image

My solution is:

  1. install 'cuda' (not in conda virtual env)
  2. install torch_geometric in conda virtual env using below commands conda create -n XXX python=3.8 conda activate XXX conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge conda install pytorch-geometric -c rusty1s -c conda-forge

this is work for me. thanks :)

daeunni avatar Feb 01 '22 03:02 daeunni

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?

github-actions[bot] avatar Aug 01 '22 02:08 github-actions[bot]

This issue has not been solved.

omoju avatar Aug 02 '22 21:08 omoju

Hi all, currently experiencing this issue only when I run torch on GPU, but everything works fine. I usually use torch==1.12.1+cu116, but had to downgrade to torch==1.8.1+cu111 to be able to import torch_geometric on just CPU. This is the error I get when I try and import torch_geometric on GPU:

Python 3.8.2 (default, Jun 2 2020, 16:34:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information.

import torch torch.version '1.8.1+cu111' import torch_geometric Traceback (most recent call last): File "", line 1, in File "/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/init.py", line 5, in import torch_geometric.data File "/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/data/init.py", line 1, in from .data import Data File "/home/widatall/cuda111/lib/python3.8/site-packages/torch_geometric/data/data.py", line 8, in from torch_sparse import coalesce, SparseTensor File "/home/widatall/cuda111/lib/python3.8/site-packages/torch_sparse/init.py", line 14, in torch.ops.load_library(importlib.machinery.PathFinder().find_spec( AttributeError: 'NoneType' object has no attribute 'origin'

I installed all packages as per PyTorch guidelines:

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html pip install torch-geometric

In regard to the .so files, I am having the issue of only having *_cpu.so files and no *_cuda.so files in my torch_sparse, torch_scatter etc. directories in the site-packages/ directory of my venv. Any help on this would be greatly appreciated as I am currently trying to train a transformer+GCNN on just cpu...... which will be done when I'm 90 years old.

twidatalla avatar Oct 17 '22 23:10 twidatalla

Please install via --no-index option for later PyTorch versions:

pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install --no-index torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html

rusty1s avatar Oct 29 '22 18:10 rusty1s

I had the same issue, after spending day and days, finally the above solution works so far for me!

na396 avatar Nov 30 '22 18:11 na396

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?

github-actions[bot] avatar May 30 '23 01:05 github-actions[bot]