折腾torch geometric环境

如此不智能不便利不友好的库竟然还有人喜欢用。
不会吧不会吧不会吧不会吧

记录傻X环境依赖。

torch1.2.0 torchvision0.4.0 cuda10.0 3.5<=python<=3.7
torch1.3.0 torchvision0.4.1 cuda10.0 3.5<=python<=3.7
torch1.3.1 torchvision0.4.2 cuda10.0 3.5<=python<=3.7
torch1.4.0 torchvision0.5.0 默认cuda10.1(支持10.0) 3.5<=python<=3.8
torch1.5.0 torchvision0.6.0 默认cuda10.1 python>=3.6
torch1.6.0 torchvision0.7.0 默认cuda10.1 python>=3.6
torch1.7.0 torchvision 0.8.0 默认cuda10.2 python>=3.6
torch1.7.1 torchvision0.8.2 默认cuda10.2 python>=3.6

如果装的是cu10.0,只能用torch1.4之前的低版本了。
torch版本太高了会报错

OSError: libcusparse.so.10: cannot open shared object file: No such file or directory

因为torch里面用的是10.1,但我本地是10.0,找不到这个文件。

查询torch里面用的版本

python -c 'import torch; print(torch.__version__)'
python -c 'import torch; print(torch.version.cuda)'

打印结果是

10.1

你看看这个东西,
一个库弄出4个库来。

pip install torch-sparse
pip install torch-scatter
pip install torch-cluster
pip install torch-geometric
pip install torch-spline-conv(optional)

官网

https://pytorch-geometric.com/whl/

装geometric依赖于torch版本。
torch版本决定了torchvision版本。
torchvision版本疑似决定了默认使用的cudatoolkit版本。
所以最终geometric需要跟cuda版本对应。

如果是cuda10.0!只能用torch1.4.0!还要指定cuda版本,不然默认给你装10.1。(21.04.15)

pip install torch1.4.0+cu100 torchvision0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html

文件链接

https://download.pytorch.org/whl/cu100/torch-1.4.0%2Bcu100-cp37-cp37m-linux_x86_64.whl
https://download.pytorch.org/whl/cu100/torchvision-0.5.0%2Bcu100-cp37-cp37m-linux_x86_64.whl

配合torch1.4.0+cuda10.0+python3.7装geometric。

https://pytorch-geometric.com/whl/torch-1.4.0+cu100.html

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.4.0+cu100.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.4.0+cu100.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.4.0+cu100.html
pip install torch-geometric

上面不行就本地安装

wget https://pytorch-geometric.com/whl/torch-1.4.0+cu100/torch_cluster-1.5.4-cp37-cp37m-linux_x86_64.whl
wget https://pytorch-geometric.com/whl/torch-1.4.0+cu100/torch_scatter-2.0.4-cp37-cp37m-linux_x86_64.whl
wget https://pytorch-geometric.com/whl/torch-1.4.0+cu100/torch_sparse-0.6.1-cp37-cp37m-linux_x86_64.whl
pip install *.whl
pip install torch-geometric

配合torch1.7.0+cuda11.0

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+cu110.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+cu110.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.7.0+cu110.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.7.0+cu110.html
pip install torch-geometric

卸载

pip uninstall torch-scatter
pip uninstall torch-sparse
pip uninstall torch-cluster
pip uninstall torch-spline-conv
pip uninstall torch-geometric

其他版本

跑geometric的开源项目,经常离不开ogb数据包。
截止21.04最新的ogb包是1.3.1版本的。
然而ogb1.3.1要求torch>=1.6.0。
所以我们为了适配cuda10.0,torch1.4.0。
只能降格使用ogb
1.2.0,(torch>=1.2.0)

如果还要用dgl库(目前最前0.6.1)
推荐降格使用dgl==0.4.3

补充
遇到nvcc执行失败

vim ~/.bashrc

修改

export CUDA_HOME=/usr/local/cuda

export PATH="/usr/local/cuda-10.0/bin:$PATH"  
export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH"

中间文件夹的名字跟cuda版本对应。
参考的是官方提供的解决方案

https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html#installation-via-binaries

更新 torch1.9.0 + cuda11.1 + pyg2.0.3

torch 1.10 , cuda 10.2 python 3.7.9
torch-geometric 2.0.2

pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0%2Bcu102/torch_sparse-0.6.12-cp37-cp37m-linux_x86_64.whl
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0%2Bcu102/torch_scatter-2.0.9-cp37-cp37m-linux_x86_64.whl
pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0%2Bcu102/torch_cluster-1.5.9-cp37-cp37m-linux_x86_64.whl

配合torch 1.9.0 + cuda11.1 + python3.9.7

pip install torch1.9.0+cu111 torchvision0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html

pip install torch-geometric==2.0.3
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0%2Bcu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0%2Bcu111.html
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0%2Bcu111.html

更新 torch 1.11.0 + cuda11.3 + pyg2.0.4

torch1.11.0

https://download.pytorch.org/whl/cu113/torch-1.11.0%2Bcu113-cp39-cp39-linux_x86_64.whl

有两个源路径

https://pytorch-geometric.com/whl/torch-1.11.0%2Bcu113.html
https://pytorch-geometric.com/whl/torch-1.11.0%2Bcu115.html

pip install torch-geometric==2.0.4
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.11.0%2Bcu113.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.11.0%2Bcu113.html
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.11.0%2Bcu113.html

对cuda10.2 ,用torch1.11 + pyg2.0.4+ torch-sparse0.6.13有问题。
import torch_geometric.nn 会报 segmentfault
回退
torch 1.10.2
torch-geometric 2.0.3
torch-scatter 2.0.9
torch-sparse 0.6.12
torch-cluster 1.5.9

你可能感兴趣的:(GNN,pytorch,深度学习,python)