pytorch installation tutorial (GPU: Nvidia GTX 3060)

  Recently, for deep learning, a pytorch needs to be installed and a GPU needs to be used. Although I found many tutorials on the Internet, although it can be successfully installed, the GPU shows that it cannot be used in the end. This article explains this situation:

  To use the GPU version of pytorch, you need to choose the appropriate pytorch version and cuda version according to the model of the graphics card. This article uses 3060 as an example. If it is different, you need to adjust it yourself.

1. Install the Anaconda environment

You can refer to the first part of this article for installation: https://blog.csdn.net/qq_41856733/article/details/127498268

2. Create a virtual environment

// 创建虚拟环境pytorch python版本为3.8(这里选择3.8的原因是,我自己亲测3.8是适配的,别的没试过)
conda create -n pytorch python=3.8

After the creation is complete, enter the virtual environment

conda activate pytorch

3. Install pytorch

Before installing, you must confirm your own 3060 support, which is different at different times: incmdEnter:

nvidia-smi

Check the maximum supported version of cuda (generally backward compatible):
insert image description here
Go to the official website: https://pytorch.org/get-started/previous-versions/ to find the appropriate version (I chose the pip version 1.13.1 to download):
insert image description here
The download command is:

pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117

Wait for the installation to succeed

4. Verify that the GPU version of pytorch is successfully installed

After entering the python environment, enter:

import torch
torch.cuda.is_available()

If the result is True, the installation is successful:
insert image description here
if it is still False, you can check whether the above steps are correct~

Guess you like

Origin blog.csdn.net/gls_nuaa/article/details/132020230