pytorch installation of win10 (beginner experience summary)

background

Xiaobai, who is studying at Research 0, installed pytorch for in-depth learning. First, I watched the senior sister install the environment on Linux ignorantly. I probably got a little bit of impression, and then tried to install it on my win10 computer. After anaconda+pycharm has been installed, I am really tired of this pytorch.

The first time I installed pytorch, I thought that my computer configuration could only be installed with cuda9.0 version, so I installed a lower version of torch. As a result, I ran the code of the boss, and some parameters could not be used, because the lower version of torch library did not exist at all! Reinstalling it for the second time, there are still many problems, but at least it is installed!

Record my experience, hoping to give some inspiration to pure white friends like me.

cuda download

1. What is cuda? Why do you want to pretend?

(From Baidu Encyclopedia:)

CUDA (Compute Unified Device Architecture) is a computing platform launched by graphics card manufacturer NVIDIA. CUDA™ is a general-purpose parallel computing architecture introduced by NVIDIA that enables GPUs to solve complex computing problems.

With the development of graphics cards, GPUs have become more and more powerful, and GPUs are optimized for displaying images. It has surpassed the general-purpose CPU in calculation. Such a powerful chip would be too wasteful if it is only used as a graphics card, so NVIDIA launched CUDA, so that the graphics card can be used for purposes other than image computing.

(In other simple words :)

It is too slow to run the code only with the CPU. After installing cuda, you can use the GPU to assist the CPU, and the code for deep learning will suddenly become faster~~

2. What is the relationship between cuda and the configuration of your computer?

Not all computers can install cuda!

Open the computer's device manager and check what graphics card you have in the display adapter column. In addition to the integrated graphics card that every computer has, there must be at least one discrete graphics card before it is possible to install cuda.

 As shown in the picture, in addition to the integrated graphics card, I also have a discrete graphics card, the model is NVDIA GeForce GTX 1050 Ti.

After knowing the model of your graphics card, there are 2 questions:

(1) Can this type of graphics card be installed with cuda?

Basically, all NVIDIA graphics cards support CUDA, including Quadro graphics cards, Tesla accelerated computing cards, GeForce game cards, NVS and Jetson, etc. You can check whether your model supports cuda through the official website (but this step is not very necessary):

CUDA GPUs | NVIDIA Developer

(2) What version of cuda can be installed on this type of graphics card?

The highest version of cuda that can be installed is determined by the driver version.

Right-click on the blank space of the computer desktop, open the NVIDIA control panel, click Help -> System Information, select components, check the product name after NVCUDA64.DLL, you can see the highest cuda version supported by the driver, install this version or a higher version Lower versions are fine.

 If you find that the version supported by your driver is very low, don’t worry, we can go to NVIDIA’s official website to update our driver first, and then go back and download cuda.

Download Drivers | NVIDIA

 Find your own graphics card model, download and install normally (you can choose simplified installation later). Then check the highest cuda version supported by the following drivers according to the previous method. Is it higher?

3. Install cuda

https://developer.nvidia.com/cuda-toolkit-archive

Enter the official website and select a version (as long as it is lower than the highest supported version of the computer driver, you can install it according to the environmental requirements of the big guy code you want to run). I chose version 10.2 (base installer):

 After downloading, enter your installation location, double-click to run, and follow the prompts on the interface. If you don't want to install it on the C drive, pay attention to the installation location. Many installation tutorials say that there will be problems installing VS, so you need to choose a custom installation and manually uncheck the VS item. I don't know what will happen, so I followed suit.

4. cudnn download

cuDNN Archive | NVIDIA Developer

Go to the official website to find the cudnn corresponding to the cuda version and download it. After decompression, copy and paste the three folders bin, include, and lib in the folder to the CUDA installation directory (the default path is C:\Program Files\NVIDIA GPU Computing Toolkit \CUDA\v10.2), just overwrite it directly.

5. Check if the cuda installation is successful?

Search cmd to enter the command window, use the following command to enter a folder in the cuda installation path 

cd C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\extras\demo_suite

Press Enter, then type:

bandwidthTest.exe

If PASS is displayed, there is no problem. Let’s do another check and enter:

deviceQuery.exe

If PASS is displayed, both cuda and cudnn are installed successfully.

6. Set environment variables

It is recommended to find other people's tutorials, there are no screenshots for children.

pytorch install

Start Locally | PyTorch

Find the download command corresponding to the cuda version on the pytorch official website:

For example, I have cuda version 10.2, so I select it as shown in the picture and get a command.

1. Set Tsinghua mirror source

It is relatively slow to install the python library of the server abroad. It can be faster to change to our domestic mirror source. Tsinghua mirror source is one of them.

Enter the following code in the command window of the anaconda prompt:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/

2. Create a virtual environment

To run the python code, the environment must be configured first, and pytorch is also one of the contents of the environment. There is no container and nothing can be installed, so let's create the environment first:

Then type the command in the command window of the anaconda prompt (in fact, cmd can also be used):

conda create -n pytorch python=3.8

The pytorch in the command is the name I gave to this environment, and you can choose it at will, and the python version does not have to be = 3.8, depending on your needs.

Then there is the crackling installation, and when you encounter y/n, enter y and you're done.

After creating the environment, you need to activate it to enter this environment:

conda activate pytorch

After entering the environment, you can see that there is a (pytorch) before the command line, indicating that you have entered the environment named pytorch.

 

Then we just copy the command we got on the official website before, remember to remove the -c python on the tail, because we are using the Tsinghua mirror source!

conda install pytorch torchvision torchaudio cudatoolkit=10.2

Then y/n still choose y, just wait for it to install.

But I am unlucky, it keeps failing to install, and keeps reporting CondaHTTPError: HTTP 403 FORBIDDEN for url. I used an unstable campus network at school. I turned off the gateway and reluctantly turned on the hotspot on my mobile phone, and everything was solved... silently feel sorry for the 1.6G traffic spent.

When successfully installed, enter python on the command line, press Enter, and after seeing >>>, use the code to debug to see if our cuda-based pytorch works well:

import torch
torch.cuda.is_available()

 Getting True like me means it's easy to use, it's done!

Guess you like

Origin blog.csdn.net/qq_43522986/article/details/121748886