4070 Configure pytorch-GPU process recording

Configure a deep learning environment for a newly purchased computer, and record a few pitfalls

My computer information: 4070 graphics card, up to CUDA12.0, installed pycharm, anaconda and created environment python=3.10

Before installing CUDA, you need to determine the CUDA supported by pytorch. As of 2023.3.3, the highest version of pytorch supports 11.8 (the stable version is 11.7, but the search information shows that pytorch only supports 40 series graphics cards from version 11.8 );

Therefore, the CUDA version to be installed is 11.8, and the corresponding cudnn version is 8.8 downloaded and installed from the NVIDIA official website. For the installation process of CUDA and cudnn, please refer to the link: CUDA and cudnn installation

After the installation is complete, start downloading pytorch-GPU:

Go to the pytorch official website to find the first version 11.8:

At this point, please note: If you have replaced the conda download source with the Tsinghua image source, please do not use the conda command to download! ! Using conda installation will automatically download the cpu version of pytorch, because the pytorch of Tsinghua source does not support CUDA11.8. Be sure to pay attention, this pitted me for a day.

There are three installation methods at this time:

1. After removing the Tsinghua source, return to the official website and use conda to download:

Remove command:

conda config --remove-key channels

2. Use pip to download:

If pytorch is downloaded repeatedly during pip download, the reason is that the python version does not match, and the python version supported by pytorch-CUDA11.8 is >=3.10. (The path of the pip installation package is attached here: C:\Users\xhb\AppData\Local\pip, because it will take up space on the C drive)

3. Download the installation package first and then install it in cmd:

The download address is the URL behind the pip installation command, here is

https://download.pytorch.org/whl/nightly/cu118;

 The download content is the front part of the pip command, here is

torch torchvision torchaudio

After the download is complete, enter cmd in the download directory and activate the environment (use cmd, not anaconda prompt)

Then install the above three downloaded files in sequence:

pip install torch-2.1.0.dev20230302+cu118-cp310-cp310-win_amd64.whl
pip install torchaudio-2.0.0.dev20230302+cu118-cp310-cp310-win_amd64.whl
pip install torchvision-0.15.0.dev20230302+cu118-cp310-cp310-win_amd64.whl

Summary: Among the three methods, I used the third method to install successfully. The first method was too slow to download and finally stopped directly, causing the installation to fail. In the second method, I will download torch repeatedly after changing the python version to 3.10. I don't understand why; the third method is a bit cumbersome, but easy to use.

Finally verify that the GPU is available:

python
import torch
torch.cuda.is_available()

If the result is True, the installation is successful!

Guess you like

Origin blog.csdn.net/weixin_49379314/article/details/129315863