Windows上搭建GPU版本的Pytorch
电脑配置详情:RTX3060, cuda 11.4, windows11
总结:具体步骤如下:
安装anaconda——> torch官网查看对应版本——>安装cuda——>安装cudnn
——>创建环境——>安装GPU版本的pytorch——>验证搭建完成
附加设置:
1.安装anaconda
官网下载:https://repo.anaconda.com/archive/
下载版本为 :(python 版本3.7.3)具体安装过程参考此处
2.查看torch版本
进入该网站可查看到适配的cuda版本为11.3,且能获得安装指令Run this Command:
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
(安装的pytorch版本为1.11.0)
3.安装cuda
安装详细过程参考此处
cuda toolkit下载地址: https://developer.nvidia.com/cuda-toolkit-archive
选择:
点击后按图选取:
4.安装cudnn
下载链接:https://developer.nvidia.com/rdp/cudnn-archive
cuda和cudnn的安装过程参考此博客,下载版本选择如下图
5.创建环境,搭建GPU版本Pytorch
首先,需要使用清华镜像源,参考该博客。
步骤1:打开Anaconda prompt,依次输入下面几行代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
步骤2:创建pytorch环境,输入下面代码,使用的python版本是3.7.3(其他版本的python应该也可以):
conda create -n pytorch_env_name python=3.7.3`
步骤3:进入环境
activate pytorch_env_name
步骤4:输入torch的安装指令Run this Command(使用清华源后要删去 -c pytorch)
conda install pytorch torchvision torchaudio cudatoolkit=11.3
步骤5:搭建完成!!!
6.验证搭建完成
此处查看,在pycharm中如何使用搭建的pytorch环境。
输入以下代码验证是否搭建成功:
import torch
print("torch {}".format(torch.__version__))
print(torch.cuda.is_available())
print(torch.version.cuda)
成功将显示
参考:
Pytorch入门+实战系列一:Windows下的Pytorch环境手把手搭建
cuda11.3安装+cudnn11.3安装+torch1.10.2安装+torchvision0.11.3下载
Python&aconda系列:GPU深度学习环境搭建:Win11+CUDA 11.7+Pytorch1.12.1+Anaconda以及对应版本