rusty1s / pytorch_cluster

PyTorch Extension Library of Optimized Graph Cluster Algorithms
MIT License
824 stars 148 forks source link

pip install not working with torch==2.3.0 #223

Open hsharsh opened 3 months ago

hsharsh commented 3 months ago

I am trying to create a torch repo which has a C++ backend and I wanted to use pytorch_cluster as a reference for it. I have installed pytorch_cluster with pip from the cloned repo

pip install torch==2.3.0
pip install .

But when I try to import pytorch_cluster, it seems like there are some discrepancies with the installation?

Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch_cluster
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/hsharsh/envs/torch_cluster/lib/python3.11/site-packages/torch_cluster/__init__.py", line 18, in <module>
    torch.ops.load_library(spec.origin)
  File "/Users/hsharsh/envs/torch_cluster/lib/python3.11/site-packages/torch/_ops.py", line 1032, in load_library
    ctypes.CDLL(path)
  File "/opt/homebrew/Cellar/python@3.11/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ctypes/__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(/Users/hsharsh/envs/torch_cluster/lib/python3.11/site-packages/torch_cluster/_version_cpu.so, 0x0006): Symbol not found: __ZN5torch3jit17parseSchemaOrNameERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEb
  Referenced from: <615DC186-B48E-343A-9ED1-B43018EB4628> /Users/hsharsh/envs/torch_cluster/lib/python3.11/site-packages/torch_cluster/_version_cpu.so
  Expected in:     <2A8DB508-8AAF-3FF1-BDFE-9EF17CC2B482> /Users/hsharsh/envs/torch_cluster/lib/python3.11/site-packages/torch/lib/libtorch_cpu.dylib

When I try the same thing with torch==2.4.0, it seems to work fine. The problem here is that I am also going to use torch_geometric as dependency in my library but the wheels for torch==2.4.0 don't exist for torch_geometric, as that version is not supported yet.

Environment details: Python: 3.11.9 OS: Darwin Kernel Version 23.5.0 pip: 24.0

rusty1s commented 3 months ago

If you are switching between PyTorch versions, did you make sure to correctly uninstall all existing installations of torch-cluster and re-install them? Usually, an error like Symbol not found: __ZN5torch3jit17parseSchemaOrNameERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEb means that torch-cluster is build on a different PyTorch version than the one you are running it on.

hsharsh commented 3 months ago

I definitely am running a fresh venv for the install. But your comment got me thinking that this might be a problem with pyproject.toml which was recently added to fix the torch dependency issue for setup. If I understand this correctly, this probably installs torch==2.4.0 as the build dependency.

[build-system]
requires = ["setuptools", "torch"]
build-backend = "setuptools.build_meta"

If I specify the version of torch to use, everything seems to work fine:

[build-system]
requires = ["setuptools", "torch==2.3.0"]
build-backend = "setuptools.build_meta"

Maybe it would be nice to specify the version of torch being used for the build automatically but I don't know if this is something you need/want.

stslxg-nv commented 3 months ago

I had to use the --no-build-isolation flag to use the preinstalled pytorch.