1.检查CUDA版本
【方法1】用nvidia-smi
已装cuda,用nvidia-smi
或 nvcc -V
查看
【方法2】用torch
已装torch,用torch代码打印
import torch
print(torch.__version__) # 查看pytorch安装的版本号
print(torch.cuda.is_available()) # 查看cuda是否可用。True为可用,即是gpu版本pytorch
print(torch.cuda.get_device_name(0)) # 返回GPU型号
print(torch.cuda.device_count()) # 返回可以用的cuda(GPU)数量,0代表一个
print(torch.version.cuda) # 查看cuda的版本
2.安装torch(已装请跳过)
pip安装请看: https://download.pytorch.org/whl/torch_stable.html
找到自己系统环境
+cuda版本
+py版本
对应的torch轮子
我的是cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl
- 【安装方法】 下载安装(Linux可以用wget安装 / windows可以点击下载到本地)
pip install whl的完整路径
pip install https://download.pytorch.org/whl/torch_stable.htmlcu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl
3.安装torch-geometric
去到网站:https://pytorch-geometric.com/whl/index.html
- 【安装方法1】 :pip install
-f 指定网址(带torch和cuda版本的网址)
逐个包指定网址,也可以全部的包,一起指定网址pip install torch-scatter torch-sparse torch-spline-conv torch-cluster torch-geometric -f https://pytorch-geometric.com/whl/torch-1.13.1%2Bcu117.html
- 【安装方法2】 :下载后,再逐个pip(按顺序)
- 先
torch_scatter
pip install torch_scatter-2.1.0+pt113cu117-cp310-cp310-linux_x86_64.whl
- 再
torch_sparse
pip install torch_sparse-0.6.17+pt113cu117-cp310-cp310-linux_x86_64.whl
- 再到
torch_cluster
pip install torch_cluster-1.6.1+pt113cu117-cp310-cp310-linux_x86_64.whl
- 然后到
torch_cluster
pip install torch_spline_conv-1.2.1+pt113cu117-cp310-cp310-linux_x86_64.whl
- 最后到
torch_geometric
(需关闭机场)
pip install torch_geometric==2.0.4 -i https://pypi.doubanio.com/simple 或者 pip install torch_geometric -i https://mirrors.aliyun.com/pypi/simple 或者 pip install torch_geometric -i https://pypi.tuna.tsinghua.edu.cn/simple
- 先
- 检验是否安装成功
import torch_geometric
一下未报错即可
4.常见错误
错误1. RuntimeError
RuntimeError: Detected that PyTorch and torch_scatter were compiled with different CUDA versions. PyTorch has CUDA version 10.2 and torch_scatter has CUDA version 11.3. Please reinstall the torch_scatter that matches your PyTorch install.
- 【解决方案】:检查torch版本 + CUDA版本 + py版本,和
torch-geometric
相关包的版本,是否一致。
.
错误2. An issue occurred xx
UserWarning: An issue occurred while importing ‘torch-scatter’. xxxxxxxx torch_scatter/_scatter_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl
UserWarning: An issue occurred while importing ‘torch-cluster’. xxxxxxxx
torch_cluster/_grid_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl
UserWarning: An issue occurred while importing 'torch-spline-conv’.
torch_spline_conv/_basis_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl
UserWarning: An issue occurred while importing ‘torch-sparse’.
torch_sparse/_diag_cuda.so: undefined symbol: _ZN3c106detail19maybe_wrap_dim_slowIlEET_S2_S2_b
- 【解决方案】:卸载
torch-geometric
相关4个包,再按顺序 依次安装
pip uninstall torch-cluster pip uninstall torch-scatter pip uninstall torch-sparse pip uninstall torch-geometric