Pytorch Geometric Environment

本地 GPU 配 pytorch_geometric 被 GCC version 坑过一次了,这次在系里服务器(NVIDIA Quadro RTX 8000)又从头搞了一次,这里记录一下,毕竟以后还要经常和 geometric 打交道(。

PyG Version Update

因为使用到新的transformer和WikiCS数据集进行PyG版本更新,感谢 qz分享的更新脚本。以下指令存成文件,chmod + x,再执行即可在当下环境中更新。

#!/bin/bash
TORCH=$(python -c "import torch; print(torch.__version__)")
CUDA=$(python -c "import torch; version = torch.version.cuda.replace('.', ''); print(f'cu{version}')")
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html --upgrade
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html --upgrade
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html --upgrade
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html --upgrade
pip install torch-geometric --upgrade

torch_sparse

在虚拟环境下安装"torch_sparse” 出现 GNU 版本不支持问题

/usr/local/cuda/include/crt/host_config.h:138:2: error: #error -- unsupported GNU version! gcc versions later than 8 are not supported!
  138 | #error -- unsupported GNU version! gcc versions later than 8 are not supported!
      |  ^~~~~
error: command '/usr/local/cuda/bin/nvcc' failed with exit status 1

查看 CUDA 和 gcc version

cat /usr/local/cuda/version.txt
CUDA Version 10.1.243

gcc -v
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)

As already pointed out, nvcc depends on gcc 8.0. It is possible to configure nvcc to use the correct version of gcc without passing any compiler parameters by adding softlinks to the bin directory created with the nvcc install.

网上给的 solution: basically adding a softlink to the correct version of gcc from this directory:

sudo ln -s /usr/bin/gcc-8.0 /usr/local/cuda/bin/gcc

(ref: https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version)

pytorch 和 torch_sparse 调用的 CUDA 版本不一致

安装 pytorch 1.6 时注意 CUDA 版本选 10.1,因为 torch_sparse 只支持到 10.1

pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

修正以后的各种 version

pytorch 1.6
CUDA Version 10.1.243
gcc version 8.4.0 (Ubuntu 8.4.0-3ubuntu2)

然后按照 torch-geometric 的文档安装其他相关 package 即可

pip install torch-scatter==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
pip install torch-sparse==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
pip install torch-cluster==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
pip install torch-spline-conv==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
pip install torch-geometric

参考资料

https://pytorch.org/ Pytorch 选安装版本

https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html Installation torch-geometric via Binarie

Hejie Cui
Hejie Cui
Doctoral Student in CS

My research interests include graph data mining and AI for Health.