【PyTorch】torch-geometric 安装

文章目录

任务简介:

由于 torch-geometric 的安装需要一定的依赖,所以直接 pip install torch_geometric 安装会出现问题,并且 torch-geometric 的版本需要和 cuda 版本对应。

本文记录 torch-geometric 的正确安装过程。

  1. 查看cuda版本

查看安装的pytorch对应的cuda版本,比如 cuda10.2 或 cpu 版本

代码:

import torch
print(torch.version.cuda)

输出:

10.2
  1. 安装依赖

根据1.中的对应版本安装以下依赖

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html

其中,${TORCH} 和 ${CUDA} 分别替换为(1)中确认的版本。

${TORCH} 可选 {1.4.0, 1.5.0, 1.6.0, 1.7.0, 1.8.0}等,PyTorch 1.8.1 选 1.8.0;

${CUDA} 可选 {cpu,cu92,cu101,cu102,cu110};

对应 torch 可设置版本可通过以下链接查看最新版本:

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

假设使用 PyTorch 1.8.1 cu102 版本,安装以上依赖为:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html
  1. 完成安装

上述依赖安装完成后,torch-geometric 即可正常安装,命令:

pip install torch-geometric
  1. 遇到的问题

我使用的是 torch1.8.1,在上述安装完成后,torch-geometric会默认安装 2.0.4版本,2.0.4版本在代码中会出现一些问题,重新安装 torch-geometric 1.7.2 后可正常使用。

以下是 torch1.8.1 对应能正常使用的依赖版本:

【PyTorch】torch-geometric 安装
安装时加上版本号即可,如:
pip install torch-scatter==2.0.7 -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html

Original: https://blog.csdn.net/weixin_40633696/article/details/124964881
Author: 尊新必威
Title: 【PyTorch】torch-geometric 安装

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/691169/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球