温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PyTorch与PyTorch Geometric的安装过程是什么

发布时间:2023-04-08 17:04:26 来源:亿速云 阅读:74 作者:iii 栏目:开发技术

这篇文章主要讲解了“PyTorch与PyTorch Geometric的安装过程是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PyTorch与PyTorch Geometric的安装过程是什么”吧!

PyTorch与PyTorch Geometric的安装

GPU与CUDA,Python,PyTorch的匹配

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

nvidia-smi

PyTorch与PyTorch Geometric的安装过程是什么

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

系统的Nvidia Driver Version决定着系统最高可以支持什么版本的cuda和cudatoolkit,Nvidia Driver是向下兼容的,详情如下(见Table 3. CUDA Toolkit and Corresponding Driver 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://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-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-sparse -f https://pytorch-geometric.com/whl/torch-1.6.0+cu101.html
pip install torch-geometric

3. 版本依赖

使用自定义安装时,依然可能会出现安装失败的问题,因为pytorch_geometric几个相关库之间有比较强的依赖关系,建议是在自定义安装的基础上指定对应库的版本,例如对于pytorch2.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与PyTorch Geometric的安装过程是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI