Complete steps to install PyTorch0.4.1 GPU version (Anaconda3 + Python3.6 + gpu version, including CUDA9.2 installation and environment configuration)

Table of contents

1. Download and install cuda9.2

1. First check the CUDA version of the computer graphics card to see what the highest supported CUDA is.

2. Download cuda9.2 installation package

3. Install cuda9.2

2. Download and install cudnn (for cuda9.2)

1. Download cudnn

2. Install cudnn

3. Configure environment variables

4. Install the GPU version of PyTorch0.4.1

1. Preparation:

2. Download the gpu version of torch and torchvision whl package (cu92):

3. Install the gpu version of torch and torchvision (cu92) offline:


Personal test is useful! ! !

My computer: win10 + NVIDIA graphics card (GeForce GTX 1650) + Anaconda3 5.2.0 (includingAnacondaThe Python version in is 3.6),You need to install CUDA and PyTorch version 0.4.1 (gpu version)

Goal:Install the gpu version of PyTorch0.4.1 (cuda9.2+pytorch0.4.1)

Written in front: Due to the recent need, I need to install an older version of pytorch (a few o'clock version). It happens that my computer has a graphics card, so I want to directly install a GPU version of the older version of pytorch. The pytorch version is old, so the cuda version supported by the corresponding pytorch version is also relatively old, so I plan to: 1) Install cuda9.2 first (roughly cuda8.0, cuda9.0, cuda9.1, cuda9. 2. cuda10.0 and many other versions), and install the corresponding cudnn. If cuda9.2 is too old by then, you can install other versions. . . . . 2) After installing cuda9.2 and cudnn9.2, then install a GPU version (cu92, corresponding to the previous cuda9.2) PyTorch0.4.1 version. (I originally planned to install versions before PyTorch 0.4.0, but firstly, there are quite few installation packages for previous versions, and secondly, the matching CUDA version under the GPU version corresponding to the previous version is also very few and old, so there is less room for choice. So I plan to install cu92/PyTorch0.4.1 first to test the waters. If it doesn’t work, I can try another one.)

1. Download and install cuda9.2

1. First check the CUDA version of the computer graphics card to see what the highest supported CUDA is.

Check the cuda version through the command nvidia-smi on the command line, as shown below. You can see that my graphics card supports up to cuda11.2, that is, it can install cuda10.0, cuda11.0, etc., but cannot install cuda11.3 and above. (To check the graphics card and cuda version, please refer to the previous blog:Win10 to check the Nvidia graphics card and cuda version)

2. Download cuda9.2 installation package

cuda official website download address:CUDA Toolkit Archive | NVIDIA Developer

Click the official website download link above, select cuda9.2, and click in. (Here you choose to download cuda9.2, which is an exe file of about 1.5G.)

Then select the corresponding option (windows, x86_64, win10, exe[local]) and click download. Many blogs on the Internet emphasize that you must select exe[local] for offline installation, otherwise the online installation package will be very confusing and the download will be extremely slow. . .

After cuda9.2 is downloaded, it is an exe installation package.

3. Install cuda9.2

Double-click to run the exe file of cuda9.2 downloaded above, directlyselect the default C drive installation path (try not to customize the path , to avoid unnecessary trouble in configuring environment variables later).

 Choose a custom installation:

Only select the first option CUDA , and there is no need to check the others. (Referring to other blogs on the Internet, many suggest that it is best not to check "Visual Studo Integration" in the first CUDA. CUDA installation failure is usually caused by it. But I have installed VS2015 on my computer before, so this If "Visual Studo Integration" is checked, it shouldn't be a big problem. I did install it successfully later without encountering any problems. Therefore, if you check this option, it is best to install VS first and then install it. cuda.)

For the rest of the process, just click "Next".

Finally cuda9.2 was installed successfully! ! ! No problems encountered.​ 

2. Download and install cudnn (for cuda9.2)

1. Download cudnn

cudnn official website download address:cuDNN Archive | NVIDIA Developer

After downloading CUDA9.2, go to the cudnn official website download link to find the cuDNN that matches the CUDA9.2 version, and select the latest installation. (It seems that you need to register and log in to download from the official website. You can directly use the Baidu Cloud link provided when downloading cuda9.2 above, which contains cudnn9.2 corresponding to cuda9.2, so you don’t need to download it from the official website.)

 Downloaded cudnn compressed package:

2. Install cudnn

Decompress the cudnn compressed package downloaded above, and then copy the .dll, .h and .lib files in the decompressed bin, include, and lib\x64 folders to the corresponding folders in the CUDA installation directory. That’s it. (Note that you copy it, not overwrite it directly!!! I tried it and directly pulled the three folders to the left path, and the corresponding files were copied directly to the corresponding folders.)

3. Configure environment variables

1) Right-click on the computer and open Properties->Advanced System Settings->Environment Variables. You can see that the following two environment variables have been automatically added to the system.

2) Next, continue to add several environment variables to the system:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64

3) After adding the environment variables, use the command nvcc -V in the cmd command line to test. The test fails. . . . show nvcc is not recognized as an internal or external command. . . The command is not recognized. . . (Using the method in the reference blog below, the ncvv -V test was finally successful!!!)

Solution:

Fix nvcc is not an internal or external command_Lonely Planet.'s Blog - Programmer Secrets_nvcc is not an internal or external command - Programmer Secrets

Open "cmd", enter set PATH=c:, then enter echo %PATH%, close "cmd", then open the command prompt again, enter echo %PATH%, you will find that the newly added environment variable has taken effect, again Enter ncvv -V, success.​ 

 

4. Install the GPU version of PyTorch0.4.1

1. Preparation:

1) First install Anaconda. (It’s very simple, search by yourself)

2) Secondly, use Anaconda to build a virtual environment.

Open Anaconda Prompt and enter: conda create -n pytorch0.4.1 python=3.6 (n represents the parameter name, pytorch0.4.1 represents the name of the environment you created, and python=3.6 represents some packages that need to be used.)

create create -n pytorch0.4.1 python=3.6

3) Activate the virtual environment:

conda activate pytorch0.4.1 

2. Download the gpu version of torch and torchvision whl package (cu92):

torch and torchvision whl package download link:http://download.pytorch.org/whl/torch_stable.html(Download the corresponding pytorch version according to the cuda version and python version.)

Download 2 whl packages:

  • cu92/torch-0.4.1-cp36-cp36m-win_amd64.whl (cuda9.2, torch0.4.1, cp36 means the python version is 3.6, download according to your needs .)
  • cu92/torchvision-0.4.1+cu92-cp36-cp36m-win_amd64.whl(cuda9.2,torchvision-0.4.1)

Here, two whl packages are downloaded: torch0.4.1 corresponding to cuda9.2, and torchvision0.4.1 of cuda9.2. (According totorch and torchvision version compatibility matching tablehttps://github.com/pytorch/vision#installation , torch0.4.1 should match torchvision0.2.2 version, but the corresponding torchvision package of cuda9.2 does not have version 0.2.2, so I downloaded the cuda9.2/torchivision0.4.1 version, and I feel that there should be no big problem... But the final test At that time, I changed back to the torchvision0.2.2 version...)

 

Download the whl package to the D drive, as shown in the figure below:

3. Install the gpu version of torch and torchvision (cu92) offline:

Go to the whl package storage directory of torch and torchvision on the cmd command line, and pip install the whl package for offline installation.

1) Install pytorch0.4.1 of gpu version (cu92):

pip install torch-0.4.1-cp36-cp36m-win_amd64.whl

 

2) Install torchvision0.4.1 of gpu version (cu92): 

pip install "torchvision-0.4.1+cu92-cp36-cp36m-win_amd64.whl"

 3) Test:

import torch

torch.__version__

torch.cuda.is_available()

But I got an error when testing torchvision. . . The error is shown below. . . It may be mainly because the versions of torch0.4.1 and torchvision0.4.1 do not match. According to the version compatibility table, the torch0.4.1 version should match the torchvision0.2.2 version. . . . Therefore, I plan to reinstall torchvision0.2.2.

As shown below, reinstall torchvision0.2.2. This time, the test was successful. (But I don’t know if there will be any problems in the future. If there are problems, then reinstall the required version according to your own situation.)

At this point, the gpu version of PyTorch0.4.1 is installed! ! ! (cuda9.2+pytorch0.4.1)

reference:

Guess you like

Origin blog.csdn.net/weixin_39450145/article/details/125452791
Recommended