PyTorch installation and configuration (detailed steps)

1. Anaconda installation and configuration

This step has already been written in my previous blog, so I won’t repeat it here!

https://blog.csdn.net/wzk4869/article/details/126714956?spm=1001.2014.3001.5502

2. Download and configuration of PyTorch

1. Create a virtual environment

Before downloading PyTorch, first we need to create a virtual environment, find it in the "Start" column in the lower left corner of the computer Anaconda Prompt, and click to open:

Enter the following codeconda create -n PyTorch python=3.7

Here is an explanation of this line of code, which means creating an environment called PyTorch, in which the Python interpreter version is 3.7. This needs to be written according to the python version you downloaded.

After entering the code and pressing Enter, it will appear ([y]/[n]?), enter yand wait for the installation to complete, and our virtual environment will be created.

2. Download PyTorch in the virtual environment

After creating the virtual environment, open Anaconda Prompt, enter conda activate PyTorch, and activate the created virtual environment.

Then enter the official website of pytorch:

https://pytorch.org/get-started/locally/


The computer does not have a choice of graphics card CPU版本, but you can choose a graphics card CUDA版本(the speed of the CPU version will definitely be slower in the subsequent large-scale data training).

Open the cmd console and enter nvidia-smito view the cuda version of the machine:


For example, my CUDA version is 11.6, which is backward compatible. You can choose PyTorch of 10.2 and 11.3 versions.

Because 10.2 is currently stopped for download, I choose the 11.3 version:

insert image description here

Copy our code into the virtual environment we just created:

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

will appear ([y]/[n]?), enter it y, and wait for it to download.

After the download is complete, let's verify that PyTorch has been successfully downloaded.

We open Pycharm and configure the virtual environment we just built:

import torch
a=torch.cuda.is_available()
print(a)

If the result is True, the configuration is successful!

3. How to download the CUDA version of Pytorch if the native CUDA version is low

The initial cuda version of my computer was lower than the 11.6 shown above. What's going on?

The cuda version supported by almost all laptops can be upgraded. My graphics card is from NVIDIA. Open the NVIDIA control panel to check the graphics card type. My graphics card is GeForce 940MX:

insert image description here

Then log in to NVIDIA's official website:

https://www.nvidia.cn/Download/index.aspx?lang=cn


Select the same option as the graphics card model of your own computer (the one with Notebooks is a notebook), and then click Search:

Finally click download. The following installation tutorial is also relatively simple, so I won’t talk about it here. You can take a look at this blog:

https://blog.csdn.net/m0_37870649/article/details/105356540

After the installation is complete, check the cuda version of the computer again to find that it has been upgraded to the latest version. At this time, you can download Pytorch with CUDA 11.3 according to the previous method.

Guess you like

Origin blog.csdn.net/wzk4869/article/details/126737684#comments_25997861