0
点赞
收藏
分享

微信扫一扫

在windows中对torch1.7.1版本环境配置


在windows中对torch1.7.1版本环境配置

  • ​​复杂的安装方式:(不推荐)​​
  • ​​环境内容​​
  • ​​下载 Cudnn 和 CUDA (可选)​​
  • ​​简单粗暴安装方式:(强烈推荐)​​

复杂的安装方式:(不推荐)

环境内容

torch:1.7.1

安装Python版本要求

Python 3.5  3.7

下载 ANACONDA 对 Python版本和第三方库进行管理

官方推荐下载:​​https://pytorch.org/​​​在windows中对torch1.7.1版本环境配置_python

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch -c nvidia

在windows中对torch1.7.1版本环境配置_python_02

下载 Cudnn 和 CUDA (可选)

可在命令行汇总执行查看驱动版本:

nvidia-smi

或者通过NVIDIA控制面板在菜单栏 帮助 中选择 系统信息
在windows中对torch1.7.1版本环境配置_python_03
然后再选择组件
在windows中对torch1.7.1版本环境配置_python_04
根据本地的NVIDIA CUDA 版本去找到官方对应的CUDA版本
在windows中对torch1.7.1版本环境配置_自定义_05
CUDA Toolkit 11.0 Download:
​​​https://developer.nvidia.com/cuda-11.0-download-archive?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exelocal​​​在windows中对torch1.7.1版本环境配置_环境变量_06
下载成功后进行安装在windows中对torch1.7.1版本环境配置_python_07
在windows中对torch1.7.1版本环境配置_python_08
在windows中对torch1.7.1版本环境配置_自定义_09

在windows中对torch1.7.1版本环境配置_自定义_10
在windows中对torch1.7.1版本环境配置_python_11
在windows中对torch1.7.1版本环境配置_自定义_12
在windows中对torch1.7.1版本环境配置_环境变量_13

安装完成之后,还需要下载cuDNN,这里需要登录并填写问卷才能下载
cuDNN:​​​https://developer.nvidia.com/rdp/cudnn-download​​

在windows中对torch1.7.1版本环境配置_自定义_14
下载后进行解压
在windows中对torch1.7.1版本环境配置_环境变量_15
在windows中对torch1.7.1版本环境配置_自定义_16
把 cuda 压缩包解压出来的文件复制到盘符:…\NVIDIA GPU Computing Toolkit\CUDA\v11.0中
在windows中对torch1.7.1版本环境配置_环境变量_17

接下来设置环境变量:
计算机上点右键,打开属性->高级系统设置->环境变量
可以看到系统中多了CUDA_PATH和CUDA_PATH_V11_0两个环境变量
如下图所示:
在windows中对torch1.7.1版本环境配置_自定义_18

接下来,还要在系统中添加以下几个环境变量:

CUDA_SDK_PATH = C:\ProgramData\NVIDIA Corporation\CUDA Samples\v11.0(这是我默认安装位置的路径)
CUDA_LIB_PATH = %CUDA_PATH%\lib\x64
CUDA_BIN_PATH = %CUDA_PATH%\bin
CUDA_SDK_BIN_PATH = %CUDA_SDK_PATH%\bin\win64
CUDA_SDK_LIB_PATH = %CUDA_SDK_PATH%\common\lib\x64

如下图所示:
在windows中对torch1.7.1版本环境配置_环境变量_19

在系统变量 PATH 的末尾添加:

%CUDA_LIB_PATH%;
%CUDA_BIN_PATH%;
%CUDA_SDK_LIB_PATH%;
%CUDA_SDK_BIN_PATH%;

再添加如下4条(默认安装路径):

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin;
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\lib

如果你选用了自定义路径,上述这些默认路径都应该相应替换为你的自定义路径,以上为我的环境变量和PATH的配置情况:

环境变量:
配置完成后,我们可以验证是否配置成功,主要使用CUDA内置的deviceQuery.exe 和 bandwithTest.exe:

首先win+R启动cmd,cd到安装目录下的 …\NVIDIA GPU Computing Toolkit\CUDA\v11.0\extras\demo_suite
然后分别执行​​​bandwidthTest.exe​​​和​​deviceQuery.exe​​​应该得到下图:
在windows中对torch1.7.1版本环境配置_环境变量_20
在windows中对torch1.7.1版本环境配置_环境变量_21
在windows中对torch1.7.1版本环境配置_环境变量_22

如果以上两步都返回了Result=PASS,那么就算成功了。

在ANACONDA 中安装 pytorch 选择安装1.7.1版本

在windows中对torch1.7.1版本环境配置_自定义_23
清华conda源地址:​​​https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/​​

添加清华源

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源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

在cmd中 输入 python 进入python 编译环境后,输入以下命令测试 pytorch GPU版本是否安装成功

import torch
print(torch.version.cuda)
print(torch.cuda.is_available())

在windows中对torch1.7.1版本环境配置_python_24

另一种安装方式

简单粗暴安装方式:(强烈推荐)

安装虚拟环境

conda create -n pytorch ;python=3.6

切换到 刚创建的 pytorch中

conda activate pytorch

在windows中对torch1.7.1版本环境配置_环境变量_25

添加清华源

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源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

安装 pytorch

conda install pytorch torchvision torchaudio cudatoolkit=11.1

通过以下指令,查看当前python环境是否成功安装了 torch 1.7.1

pip list

在windows中对torch1.7.1版本环境配置_自定义_26
在cmd中 输入 python 进入python 编译环境后,输入以下命令测试 pytorch GPU版本是否安装成功

import torch
print(torch.version.cuda)
print(torch.cuda.is_available())

在windows中对torch1.7.1版本环境配置_环境变量_27

在windows中对torch1.7.1版本环境配置_python_24
几步搞定,不需要去 安装Cudnn 和 CUDA!!!!!!

举报

相关推荐

0 条评论