GPU version PyTorch detailed installation tutorial

Table of contents

1. Install the graphics card driver

1. Check the graphics card driver model

2. Download the graphics card driver

3. View GPU status

2. Install Visual Studio 2019

3. Install CUDA

1. Download the corresponding version of CUDA

2. Install the downloaded CUDA

3. Set environment variables

 Fourth, install cudnn

Five, install anaconda

6. Install PyTorch

1. Create a virtual environment

2. Activate and enter the virtual environment

3. Install PyTorch

4. Verify that PyTorch is successfully installed

Note: The graphics cards of the 30 series do not support versions below cuda11 for the time being! ! !

1. Install the graphics card driver

1. Check the graphics card driver model

Right-click the bottom right corner to start, and check the computer graphics card model in the device manager. For example, my graphics card is GTX1050:

2. Download the graphics card driver

Enter the official website of Nvidia and download the corresponding graphics card driver: Official Driver | NVIDIA https://www.nvidia.cn/Download/index.aspx?lang=cn

Select the corresponding version parameters and download and install, just go to the next step during installation.

3. View GPU status

After the installation is complete, open the CMD terminal (shortcut key: Win+R), enter the command line: nvidia-smi to view the GPU status:

 Note: The CUDA version displayed in the upper right corner (in the red box) is the highest CUDA version supported by the current version.

2. Install Visual Studio 2019

Since you need to use cuda, you must have a compilation tool, here is Visual Studio 2019 installed

Download the Visual Studio Community Edition link : https://visualstudio.microsoft.com/zh-hans/downloads/

After the installation is complete, enter the following interface, note: check "Python development " and "C++ desktop development "

3. Install CUDA

1. Download the corresponding version of CUDA

 Official download address of each version of CUDA: CUDA Toolkit Archive | NVIDIA Developer https://developer.nvidia.com/cuda-toolkit-archive

 CUDA uses version 10.2, so go to the cuda official website to find the corresponding version to download:

 

2. Install the downloaded CUDA

After the download is complete , install CUDA. Note: The default path is recommended. You need to add environment variables later. Choose custom installation during installation :

Check Visual Studio Integration:

3. Set environment variables

Right-click the computer (this computer), open Properties-> Advanced System Settings- > Environment Variables, you can see that there are two more environment variables, CUDA_PATH and CUDA_PATH_V10_2 , in the system variables.

Next, "create new" in the system variables, add the following environment variables, the following are the environment variables of the path of the default installation location (the left is the variable name, the right is the variable value) :

CUDA_SDK_PATH = C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2

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

Add at the end of the system variable Path :

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

Double-click Path, and add the following 5 items (default installation path): C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\extras\CUPTI\lib64

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2\bin\win64

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.2\common\lib\x64

 

Fourth, install cudnn

1. Download cudnn corresponding to cuda10.2

       cudnn download address : https://developer.nvidia.com/cudnn

2. After downloading cudnn, unzip it directly, and then need to copy and paste the decompressed bin, include, and lib folders to the default path folder during cuda installation (for example, mine is in: C:\Program Files \NVIDIA GPU Computing Toolkit\CUDA\v10.2)

Note: copy and paste the entire folder bin, include, lib

3. Finally, test whether cuda is configured successfully:

Win+R opens the CMD terminal and executes: nvcc -V to see cuda information:

Five, install anaconda

Detailed installation tutorial can refer to the following link:

(42 messages) Python installation tutorial step 1: installation of Pycharm and Anaconda

6. Install PyTorch

1. Create a virtual environment

Add mirror source in 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/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/pytorch/
conda config --set show_channel_urls yes

Open the anaconda prompt just installed in the start bar to create a project and run the virtual environment:

conda create -n your_env_name(虚拟环境名称) python==xx(想要创建的虚拟环境的python版本号)

Note: If you do not know the python version, Win+R opens the CMD terminal and executes : python, then enter to see the installed python version number.

You can modify it according to your needs, for example: conda create -n mytorch python==3.9.7

Enter y, then press enter to confirm and start the download and installation.

When the above interface appears, the virtual environment has been created.

2. Activate and enter the virtual environment

1. On the basis of the previous step, activate the created virtual environment, and enter the following command in the anaconda prompt terminal :

conda activate mytorch

2. To exit the current virtual environment, execute the following command:

conda deactivate

3. Install PyTorch

1. At this point we have activated and entered the created mytorch environment. 

2. Next, enter the PyTorch official website, select relevant parameters, obtain the PyTorch installation instructions, and execute the instructions in the red box in the anaconda prompt  terminal (this instruction is the latest version of PyTorch) :

Note: When installing, delete the content after the command -c pytorch, and download it from domestic sources, which will be faster. PyTorchhttps ://pytorch.org/

Another: If you need to select other versions of PyTorch, just click the command in the green box 

Then go to the following page, find the required version and install it

3. After entering the PyT orch installation command , check conda to find out whether the package to be installed is to be installed

If yes, after entering y, press enter to confirm the download;

If not, you will need to recheck the command to install PyTorch .

3.  Install PyT orch. So far, the basic environment has been deployed.

4. Verify that PyT orch is installed successfully

1. After the installation is complete, continue to execute the following commands in the anaconda prompt  terminal to verify whether PyT orch is successfully installed :

python 
import torch 
torch.cuda.is_available() 

2. The following figure prompts True to indicate that the framework configuration is successful and the GPU is available

 3. After the verification is completed, press Ctrl+Z to return to the command line, and then execute the conda list command to see the installed packages in the virtual environment

If the above two packages can be found in the conda list, it means that the configuration has been completed.

Guess you like

Origin blog.csdn.net/uuhhy/article/details/124638448