NVIDIA, CUDA, CUDNN, PyTorch installation vomiting blood finishing! ! !

1. Determine the type of graphics card

Determine whether your current computer's graphics card is NVIDIA (N card) or AMD (A card). Pytorch needs to run on an NVIDIA-based graphics card (N card), and A card will not work.
insert image description here

2. Install CUDA, CUDNN (be sure to pay attention to the corresponding version!!!)

2.1 Install CUDA

1. Determine what version of CUDA should be installed on the computer.

Method 1: View in NVIDIA Control Panel

insert image description here

insert image description here

Method 2: View in CMD

Enter in CMD:

nvidia-smi

insert image description here

It is found that CUDA version 12.0 can be installed on this machine, and the version is backward compatible, which means that CUDA 12.0 and below versions can be installed , but it is generally not recommended to use the latest version, because other installation packages may not be updated to the corresponding version and can be downloaded. So it is best to choose one or two versions before CUDA 12.0. I choose CUDA 11.6 here, which can be seen from the official website of pytorch (official website: https://pytorch.org/get-started/locally/). The CUDA versions are generally 11.6 and 11.7 (January 9, 2023).
insert image description here

2. Download the corresponding version CUDA 11.6 (official website address: https://developer.nvidia.com/cuda-toolkit-archive)

insert image description here

These three are all CUDA 11.6 installation packages, choose any one and click to download.

3. Select the CUDA installation package corresponding to the platform of this machine. My computer configuration is (Windows 10, 64-bit), and the download will be a bit slow, about 2 G.
insert image description here

4. Open the exe installation package and click Custom Installation
insert image description here

5. If you are installing for the first time, try to select all; if you have uninstalled and reinstalled before, then only check the first CUDA to install, as follows:
insert image description here

6. Try not to choose to install Visual Studio Integration, otherwise there will be problems later
insert image description here

7. Try to use the default path for the installation location. It is best to take a screenshot here, otherwise the subsequent configuration environment variables do not know which folder it is in .
insert image description here

8. Open [Control Panel] - [Programs] - [Programs and Features] to check whether the CUDA program is installed
insert image description here

9. Configure environment variables
insert image description here

Configure 4 environment variables, the variable names are:

CUDA_PATH
CUDA_PATH_V11_6
NVCUDASAMPLES_ROOT
NVCUDASAMPLES11_0_ROOT

The paths are all the paths in the screenshot above, mine is:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6

10. Use CMD to check whether CUDA is installed successfully, the command is nvcc --version or nvcc -V
insert image description here

So far, CUDA has been installed successfully.

2.2 Install CUDNN

1. Check the installed CUDA, what is the compatible CUDNN version (official website: https://developer.nvidia.com/rdp/cudnn-archive), this website needs to be registered, register and log in and then you can download it.
insert image description here

I downloaded v8.6.0, which matches CUDA 11.x version.
2. The downloaded file is a compressed package, which is as follows after decompression:
insert image description here

Contains bin, include and lib folders.
insert image description here

3. Copy these three folders (bin, include, and lib) to the folder with the same name as the 8th step of installing CUDA above (it is recommended to copy the contents of the folder to the folder with the same name corresponding to the 8th step of CUDA)
insert image description here

Just copy the contents of the bin, include and lib folders under cudnn-windows-x86_64-8.6.0.163_cuda11-archive after decompression to the bin, include and lib folder.
4. Add environment variables
insert image description here

Add 4 paths inside the Path variable:

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

5. Verify whether the configuration is successful,
enter in order in cmd:

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
cd .\extras\demo_suite
.\bandwidthTest.exe

insert image description here

This means the installation is successful! !

3. Install Pytorch

Pytorch is very fragile, you must use Python version + PyTorch version + torchversion version + torchaudio version + CUDA version for one-to-one correspondence! ! My computer is installed with anaconda 3, and the Python version is 3.9. Everyone's version is different, and the things installed are also different.
1. It is best not to go to the official website and use pip to install directly (official website: https://pytorch.org/get-started/locally/), because it is really stuck, and sometimes the mirror will be disconnected halfway due to network problems. It is recommended to use my method to ensure that there will be no mistakes due to mirroring problems or network speed problems!
insert image description here

2. As shown above on the official website, you need to install torch, torchvision and torchaudio (natural language processing is best followed by torchtext), and open the following url (https://download.pytorch.org/whl/cu116)
insert image description here

3. Install torch. Click torch, you will see a bunch of whl files inside, you need to find the most suitable version to download.
First of all, be sure to download the latest version, secondly, it must match your cuda version, then the Python version must also be suitable, then the operating system must also match, and finally, the processor architecture must be suitable.
For example, my computer is cuda11.6, Python 3.9, Windows 10 system 64-bit, then just choose torch-1.12.0+cu116-cp39-cp39-win_amd64.whl, so
my torch version is all after 1.12.0 The package must be installed based on the version corresponding to this version!
4. Install torchvision. The corresponding version is as follows (URL: https://blog.csdn.net/shiwanghualuo/article/details/122860521)
insert image description here

I chose torchvision-0.13.0+cu116-cp39-cp39-win_amd64.whl to download
5. Install torchaudio. The installation version is shown in the table below (URL: https://blog.csdn.net/shiwanghualuo/article/details/122860521)
insert image description here

So I installed torchaudio-0.12.0+cu116-cp39-cp39-win_amd64.whl .
6. Install torchtext. The installation version (URL: https://blog.csdn.net/weixin_45893089/article/details/126533469) is shown in the table below:
insert image description here

I downloaded torchtext-0.13.0-cp39-cp39-win_amd64.whl .
7. Install the four packages of torch, torchvision, torchaudio, and torchtext. I put these four folders into the root directory of the D drive , and enter in cmd:

cd d:\
pip install torch-1.12.0+cu116-cp39-cp39-win_amd64.whl
pip install torchvision-0.13.0+cu116-cp39-cp39-win_amd64.whl
pip install torchaudio-0.12.0+cu116-cp39-cp39-win_amd64.whl
pip install torchtext-0.13.0-cp39-cp39-win_amd64.whl

After the installation is successful, it will display successful!
8. Test whether the installation is successful,
enter in cmd:
insert image description here

python
import torch
torch.cuda.is_available()

If True is displayed, the installation is successful!

Guess you like

Origin blog.csdn.net/weixin_38040996/article/details/128625794