Pytorch GPU配置与安装
pytorch相较于tensorflow有了更多的发展,越来越多的网络基于pytorch架构,因此配置好相应的环境尤为重要。
本篇教程目录:
①cuda安装与配置;
②版本对应关系;
③正式安装;
④验证;

①cuda安装与配置
可以参考这篇文章中的“第四步:选择要安装CUDA和CuDNN”
TensorFlow-GPU丝滑全流程安装攻略 - 哔哩哔哩 (bilibili.com)
注:系统层面需要配置好cuda和cudnn,否则无法使用gpu加速
②版本对应关系

③正式安装
在Anaconda Prompt终端输入:
conda create -n pytorch python=3.6
conda activate pytorch
pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
注:使用pip安装基本上没问题,若是用conda进行安装则为:conda install pytorch torchvision torchaudio cudatoolkit=10.1 。但需要注意的是,conda可能会下载cpu版本的pytorch导致验证失败;
官方命令参考:https://pytorch.org/get-started/locally/
④验证
python
import torch
x = torch.rand(4, 3)
print(x)
torch.cuda.is_available()
注:能创建tensor,返回结果为true即安装成功