snap-stanford / GraphGym

Platform for designing and evaluating Graph Neural Networks (GNN)
Other
1.69k stars 185 forks source link

error when running test script: #66

Open Spartanzhao opened 8 months ago

Spartanzhao commented 8 months ago

I had installed the graph gym step by step as readme mentioned, But I got this error: Traceback (most recent call last): File "main.py", line 5, in from torch_geometric import seed_everything File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/init.py", line 1, in import torch_geometric.utils File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/utils/init.py", line 3, in from .scatter import scatter File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/utils/scatter.py", line 7, in import torch_geometric.typing File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/typing.py", line 37, in import torch_sparse # noqa File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/init.py", line 40, in from .tensor import SparseTensor # noqa File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/tensor.py", line 13, in class SparseTensor(object): File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py", line 974, in script _compile_and_register_class(obj, _rcb, qualified_name) File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py", line 67, in _compile_and_register_class torch._C._jit_script_class_compile(qualified_name, ast, defaults, rcb) RuntimeError: Tried to access nonexistent attribute or method 'crow_indices' of type 'Tensor'.: File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/tensor.py", line 109 def from_torch_sparse_csr_tensor(self, mat: torch.Tensor, has_value: bool = True): rowptr = mat.crow_indices()


        col = mat.col_indices()

How Can I solve this issue?
Spartanzhao commented 8 months ago

Here is the answer from gpt4: The error message indicates that the torch_sparse package is attempting to access a method crow_indices on a torch.Tensor object which does not exist. This could be due to several reasons: Version Incompatibility: The version of PyTorch you're using might not be compatible with the version of torch_sparse. The crow_indices method might have been introduced in a newer version of PyTorch, and if you're using an older version, this method would not be available. Incorrect Tensor Type: The function from_torch_sparse_csr_tensor is expecting a tensor of type CSR (Compressed Sparse Row), which should have the method crow_indices. If the tensor mat is not of the correct sparse format, this method would not be present. To solve this issue, consider the following steps: Update PyTorch: Ensure that you're using the latest version of PyTorch that supports CSR format and has the crow_indices method for sparse tensors. bash 复制 pip install --upgrade torch Check Tensor Format: Make sure that the tensor you're providing to from_torch_sparse_csr_tensor is indeed a CSR tensor. In PyTorch, CSR tensors are created with torch.sparse_csr_tensor. Compatibility Check: Verify that all related libraries (torch_geometric, torch_sparse, and torch) are compatible with each other. Sometimes, libraries are updated to leverage new features in dependencies, and using mismatched versions can cause errors. Environment Clean-Up: If you're working in a conda environment and encountering package conflicts, it may be helpful to create a new environment from scratch, ensuring that you install packages that are compatible with each other. bash

conda create -n new_env_name python=3.7 conda activate new_env_name pip install torch torch_geometric torch_sparse Please replace new_env_name with your desired environment name and adjust the Python version if needed. If after these steps you're still facing issues, it could be helpful to check the documentation of torch_sparse or open an issue on the relevant GitHub repository for assistance from the developers.

Is this correct answer? I have been tried to install graphgym for month, and called some professional helpers, but still don't work, what other information I need provide to you, then you can help me to install the graphgym successfully?

Spartanzhao commented 8 months ago

When I am import these torch packages, I got this error: In [1]: import torch_geometric

RuntimeError Traceback (most recent call last)

in ----> 1 import torch_geometric ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/__init__.py in ----> 1 import torch_geometric.utils 2 import torch_geometric.data 3 import torch_geometric.sampler 4 import torch_geometric.loader 5 import torch_geometric.transforms ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/utils/__init__.py in 1 import copy 2 ----> 3 from .scatter import scatter 4 from .segment import segment 5 from .sort import index_sort ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/utils/scatter.py in 5 from torch import Tensor 6 ----> 7 import torch_geometric.typing 8 from torch_geometric.typing import torch_scatter 9 ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_geometric/typing.py in 35 36 try: ---> 37 import torch_sparse # noqa 38 from torch_sparse import SparseTensor 39 WITH_TORCH_SPARSE = True ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/__init__.py in 38 39 from .storage import SparseStorage # noqa ---> 40 from .tensor import SparseTensor # noqa 41 from .transpose import t # noqa 42 from .narrow import narrow, __narrow_diag__ # noqa ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/tensor.py in 11 12 @torch.jit.script ---> 13 class SparseTensor(object): 14 storage: SparseStorage 15 ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py in script(obj, optimize, _frames_up, _rcb) 972 if _rcb is None: 973 _rcb = _jit_internal.createResolutionCallbackFromFrame(_frames_up + 1) --> 974 _compile_and_register_class(obj, _rcb, qualified_name) 975 return obj 976 else: ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py in _compile_and_register_class(obj, rcb, qualified_name) 65 ast = get_jit_class_def(obj, obj.__name__) 66 defaults = torch.jit.frontend.get_default_args_for_class(obj) ---> 67 torch._C._jit_script_class_compile(qualified_name, ast, defaults, rcb) 68 torch.jit._state._add_script_class(obj, qualified_name) 69 RuntimeError: Tried to access nonexistent attribute or method 'crow_indices' of type 'Tensor'.: File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/tensor.py", line 109 def from_torch_sparse_csr_tensor(self, mat: torch.Tensor, has_value: bool = True): rowptr = mat.crow_indices() ~~~~~~~~~~~~~~~~ <--- HERE col = mat.col_indices() In [2]: import torch_scatter In [3]: import torch_sparse --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in ----> 1 import torch_sparse ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/__init__.py in 38 39 from .storage import SparseStorage # noqa ---> 40 from .tensor import SparseTensor # noqa 41 from .transpose import t # noqa 42 from .narrow import narrow, __narrow_diag__ # noqa ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_sparse/tensor.py in 11 12 @torch.jit.script ---> 13 class SparseTensor(object): 14 storage: SparseStorage 15 ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py in script(obj, optimize, _frames_up, _rcb) 972 if _rcb is None: 973 _rcb = _jit_internal.createResolutionCallbackFromFrame(_frames_up + 1) --> 974 _compile_and_register_class(obj, _rcb, qualified_name) 975 return obj 976 else: ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py in _compile_and_register_class(obj, rcb, qualified_name) 65 ast = get_jit_class_def(obj, obj.__name__) 66 defaults = torch.jit.frontend.get_default_args_for_class(obj) ---> 67 torch._C._jit_script_class_compile(qualified_name, ast, defaults, rcb) 68 torch.jit._state._add_script_class(obj, qualified_name) 69 RuntimeError: class '__torch__.torch_sparse.tensor.SparseTensor' already defined. In [4]: import torch_cluster --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in ----> 1 import torch_cluster ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_cluster/__init__.py in 43 from .nearest import nearest # noqa 44 from .radius import radius, radius_graph # noqa ---> 45 from .rw import random_walk # noqa 46 from .sampler import neighbor_sampler # noqa 47 ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_cluster/rw.py in 16 num_nodes: Optional[int] = None, 17 return_edge_indices: bool = False, ---> 18 ) -> Union[Tensor, Tuple[Tensor, Tensor]]: 19 """Samples random walks of length :obj:`walk_length` from all node indices 20 in :obj:`start` in the graph given by :obj:`(row, col)` as described in the ~/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch/jit/_script.py in script(obj, optimize, _frames_up, _rcb) 988 _rcb = _jit_internal.createResolutionCallbackFromClosure(obj) 989 fn = torch._C._jit_script_compile( --> 990 qualified_name, ast, _rcb, get_default_args(obj) 991 ) 992 # Forward docstrings RuntimeError: General Union types are not currently supported. Only Union[T, NoneType] (i.e. Optional[T]) is supported.: File "/data02/home/scv9476/.conda/envs/graphgym_env/lib/python3.7/site-packages/torch_cluster/rw.py", line 18 num_nodes: Optional[int] = None, return_edge_indices: bool = False, ) -> Union[Tensor, Tuple[Tensor, Tensor]]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE """Samples random walks of length :obj:`walk_length` from all node indices in :obj:`start` in the graph given by :obj:`(row, col)` as described in the I think may be these torch packages are incompatible ? Do you know any way that I can install these packages which are not incompatible at all and can run your graphgym?