开发者

PyTorch与PyTorch Geometric的安装过程

开发者 https://www.devze.com 2023-04-07 09:30 出处:网络 作者: 子非闕
目录PyTorch与PyTorch Geometric的安装1. 查看linux系统中GPU的基础信息/NVIDIA Driver Version2. 查看当前CUDA版本:3. CUDA Toolkit匹配PyTorch安装PyTorch Geometric1. 快速安装2. 自定义安装3. 版本依赖PyTorch与
目录
  • PyTorch与PyTorch Geometric的安装
    • 1. 查看linux系统中GPU的基础信息/NVIDIA Driver Version
    • 2. 查看当前CUDA版本:
    • 3. CUDA Toolkit匹配PyTorch
  • 安装PyTorch Geometric
    • 1. 快速安装
    • 2. 自定义安装
    • 3. 版本依赖

PyTorch与PyTorch Geometric的安装

GPU与CUDA,python,PyTorch的匹配

1. 查看Linux系统中GPU的基础信息/NVIDIA Driver Version

nvidia-smi

PyTorch与PyTorch Geometric的安装过程

nvidia-smi是nvidia 的系统管理界面 ,其中smi是Systphpem management interface的缩写,它可以收集各种级别的信息,查看显存使用情况。此外, 可以启用和禁用 GPU 配置选项 (如 ECC 内存功能)。

系统的Nvidia Driver Version决定着系统最高可以支持什么版本的cuda和cudatoolkit,Nvidia Driver是向下兼容的,详情如下(见Table 3. CUDA Toolkit and Corresponding Driverhttp://www.devze.com Versions):

PyTorch与PyTorch Geometric的安装过程

2. 查看当前CUDA版本:

cat  /usr/local/cuda/version.txt

PyTorch与PyTorch Geometric的安装过程

我自己的环境最高可支持10.1版本的cuda和cudatoolkit,当前是10.0,版本向下兼容,并无什么问题。

3. CUDA Toolkit匹配PyTorch

CUDA Toolkit 和PyTorch的对应关系(见官网)

PyTorch与PyTorch Geometric的安装过程

! 注意事项:服务器本身的CUDA版本与虚拟环境中安装的cudatoolkit包没有太大关系,一般安装pytorch时需要考虑的cuda版本指的应该是虚拟环境中安装的cudatoolkit包的版本

由于我需要用到v1.6.0的Pytorch,因此自己在虚拟环境里安装v10.1的CUDA Toolkit,系统GPU可接受最高版本v10.1。

torch与torchvision对应关系如下(详情见PyTorch / Vision):

PyTorch与PyTorch Geometric的安装过程

因此,我需要安装的如下:

CUDA Toolkit == 10.1

Python == 3.7

PyTorch == 1.6

安装PyTorch

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

安装完成后可通过以下命令检查torch版本及对应的CUDA版本:

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

再通过以下命令查看GPU是否可用:

python

>>> import torch
>>> torch.cuda.is_available() 	# GPU是否可用
>>> torch.cuda.device_count()	# GPU数量
>>> torch.cuda.current_device()	# 当前GPU
>>> exit()

注意,GPU devices从0开始编号。

安装PyTorch Geometric

1. 快速安装

根据官网,如果PyTorch版本≥1.8.0,可以快速下载:

2. 自定义安装

自定义下载需要根据当前的PyTorch版本和CUDA版本下载相关的依赖,下载命令如下:

pip install torch-scatter -f https://pytor编程客栈ch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-sparse -f https://pytorch-geandroidometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-geometric

其中, ${TORCH}替换为当前环境下的PyTorch版本,目前支持1.4.0、1.5.0、1.6.0、1.7.0、1.7.1、1.8.0、1.8.1、和1.9.0; ${CUDA}替换为指定的CUDA版本,目前支持cpu、cu92、cu101、cu102、cu110和cu111。

例如对于PyTorch 1.6.0和CUDA 10.1:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-sparseandroid -f https://pytorc开发者_C入门h-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-geometric

3. 版本依赖

使用自定义安装时,依然可能会出现安装失败的问题,因为pytorch_geometric几个相关库之间有比较强的依赖关系,建议是在自定义安装的基础上指定对应库的版本,例如对于pytorch1.6.0和cuda10.1:

pip install torch-scatter==2.0.5 -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-cluster==1.5.8 -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-sparse==0.6.7 -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-spline-conv==1.2.0 -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-geometric==1.6.1 -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html

到此这篇关于PyTorch与PyTorch Geometric的安装的文章就介绍到这了,更多相关PyTorch Geometric安装内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

精彩评论

暂无评论...
验证码 换一张
取 消