-
Hello community, I'm encountering an issue when running the LinkNeighborLoader in the context of the torch_geometric library. My code works seamlessly with torch-sparse, but when I transition to using pyg-lib, I am presented with the following error: File python3.10/site-packages/torch_geometric/sampler/neighbor_sampler.py:276, in NeighborSampler._sample(self, seed, seed_time, **kwargs)
273 num_sampled_nodes = num_sampled_edges = None
275 else:
--> 276 raise ImportError(f"'{self.__class__.__name__}' requires "
277 f"either 'pyg-lib' or 'torch-sparse'")
279 if num_sampled_edges is not None:
280 num_sampled_edges = remap_keys(
281 num_sampled_edges,
282 self.to_edge_type,
283 )
ImportError: 'NeighborSampler' requires either 'pyg-lib' or 'torch-sparse' This is perplexing because I am certain that pyg-lib is installed on my virtual environment. To validate this, I've successfully imported it manually in the python console running on the same venv. Has anyone encountered a similar issue or have any insights into what might be going wrong? Additionally, I tested with a GPU-based configuration and encountered the same problem. Thanks in advance for any assistance or insights! Environment details:
|
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 16 replies
-
Sorry about this.
More installation options here. |
Beta Was this translation helpful? Give feedback.
-
What does import torch_geometric
print(torch_geometric.typing.WITH_PYG_LIB) return? |
Beta Was this translation helpful? Give feedback.
-
I executed my code on a Linux-based virtual machine, while my local system runs on Windows. It slipped my attention that there was a slight version discrepancy in PyG between the two setups. The error I encountered on the virtual machine stemmed from the fact that the 'if' condition was expanded. Here's the code for reference: # TODO Support induced subgraph sampling in `pyg-lib`.
if (torch_geometric.typing.WITH_PYG_LIB and self.subgraph_type != SubgraphType.induced): Given that my graph was of the 'induced' type, this led to the error. My confusion was amplified because, in my local version of PyG on Windows, only the typing check was present in this line. I appreciate your assistance in resolving this! |
Beta Was this translation helpful? Give feedback.
-
Hi, I also had this problem but today I have solved it! Hope it can help u well! 1- Conda create a new environment, I create 'PyG' environment with Python 3.9. Finally, it works. Wish it will help you too! Good luck! Wuhan University, Gou Zhonghua's Lab. |
Beta Was this translation helpful? Give feedback.
-
I was hitting this issue, and installing all the dependencies as suggested in this thread didn't resolve the issue (despite it taking hours to run to build all the wheels). I noticed it supports Torch 2.2.0, not Torch 2.2.1 (which is what comes with Google Colab), but it's not clear to me if that should be an issue. |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing the Collab link. Note that There is indeed an issue with METIS partitioning. You can fix this for now via
I'll look into it. |
Beta Was this translation helpful? Give feedback.
-
I find the solution !!!Just install pyg cluster sparse and so on before the torch_geometric!!! |
Beta Was this translation helpful? Give feedback.
-
FWIW, this issue was solved for me on a conda env using CUDA 12.2 by simply installing
Further details on the repository: pygteam/pyg-lib. |
Beta Was this translation helpful? Give feedback.
-
Hello, I had the same issue, using Google Collab here. Managed to make pyg work with Pytorch 2.4.0 and Cuda 12.4. Here's my code: Install Cuda 12.4 for ubuntu 22.04 (look up instructions for your specific OS) on nvidia website wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
dpkg -i cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
cp /var/cuda-repo-ubuntu2204-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
apt-get update
apt-get install -y cuda-12-4 cuda-toolkit-12-4
export CUDA_PATH=/usr/local/cuda-12.4/
nvcc --version Install pyg with: pip install torch-geometric \
torch-sparse \
torch-scatter \
torch-cluster \
torch-cluster \
pyg-lib \
-f https://data.pyg.org/whl/torch-2.4.0+cu124.html If you already have any of these librairies installed already, make sure you |
Beta Was this translation helpful? Give feedback.
-
I also encounter this problem. However, I got a True when using |
Beta Was this translation helpful? Give feedback.
I executed my code on a Linux-based virtual machine, while my local system runs on Windows. It slipped my attention that there was a slight version discrepancy in PyG between the two setups. The error I encountered on the virtual machine stemmed from the fact that the 'if' condition was expanded. Here's the code for reference:
Given that my graph was of the 'induced' type, this led to the error. My confusion was amplified because, in my local version of PyG on Windows, only the typing check was present in this line.
I appreciate your assistance in…