当前位置:网站首页>Summarize two methods of configuring pytorch GPU environment

Summarize two methods of configuring pytorch GPU environment

2022-06-25 09:12:00 Zitian

A pit that has been trodden on for two days , Summarize two methods to take you step by step
We install all the software we use according to the latest version

One : install anaconda

  1. open anaconda Official website
  anaconda Official website

   Because my English is not very good , I opened the translation button in the browser , But the interface is the same

   2. Scroll bar to the end , Click personal , Go to download page
 Insert picture description here

   3. Click to download
 Insert picture description here

   4. After downloading , Open the downloaded executable
 Insert picture description here
   4.1 Click the second button to make it available to all users
 Insert picture description here
   4.2 Select the installation directory , I'll change it here directly to D disc
 Insert picture description here
   4.3 It's all marked here

 Insert picture description here
 Insert picture description here

   4.4 Remove these two √, Click on Finish Complete the installation
 Insert picture description here

Two : Check and update the graphics card driver

1. Right click to open the control panel
 Insert picture description here

1.1 Click Help → system information

 Insert picture description here

1.2 You can see that the driver version is 425.25
 Insert picture description here

1.3 Click on the component , You can see the support CUDA highest 10.1 edition

 Insert picture description here




1.4 The following is the graphics card driver version and cuda Version of the for diagrams


\

 Insert picture description here



\

2 You can view the graphics card model in the control panel




 Insert picture description here



  NVIDIA Official website https://www.nvidia.cn/Download/index.aspx?lang=cn#
2.2 Here, choose your own graphics card model to download and install , I choose GeForce MX250,
 Insert picture description here



2.3 You can install by default


 Insert picture description here



\

2.4 After restarting, you can enter the control panel again to check the driver version and supported CUDA edition




 Insert picture description here




\

3、 ... and : install PyTorch

  (1): establish pytorch Environmental Science

   Different projects require different environments ,anaconda It can manage each environment well
  1, Click on Anaconda Prompt Enter the command window
 Insert picture description here

2 The preceding parentheses are the current environment ,base It's the name of the environment
 Insert picture description here

3 Create a file called pytorch Environment
   3.1 Enter the following :

conda create -n pytorch python=3.8

  pytorch It's the name of the environment , You can change it yourself
  python=3.8 yes python Version of , You can change it yourself
 Insert picture description here
  3.2 The packages to be installed are listed above , Input y Confirm installation



4 Switch to pytorch Environment

  4.1 Enter the following :

conda activate pytorch

 Insert picture description here




You can see that the preceding parentheses become pytorch

  (2): Switch to Tsinghua source image

   Because you can download it directly from the official website pytorch Or downloading other packages will be very slow , Even the download is interrupted , So switch to some mirror websites in China
1 Switch to Tsinghua source
Run the following command :

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

   You can see that a... Is generated under the user directory .condarc file , The content inside is the index of the mirror website

 Insert picture description here

 (3): install PyTorch

   Method 1:PyTorch One click installation on the official website

1 add to pytorch library
Enter the following command :

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

2 open PyTorch Official website
 Insert picture description here





3 Select the corresponding version

   I choose 10.2( I don't know what the problem is , I choose 11.3 Words , Test returns flase)

   Copy the generated command

conda install pytorch torchvision torchaudio cudatoolkit=10.2

Take care to remove the following -c pytorch ( -c pytorch It's from pytorch Download from the official address , Remove to download from the mirror website )

4 In the command window, enter the command you just copied

conda install pytorch torchvision torchaudio cudatoolkit=10.2

5 test

When the download is complete
Enter the following commands respectively

Python
import torch
torch.cuda.is_available()

 Insert picture description here
If you return true
It's a success



If you return flase Words
1 Check whether the graphics card driver has been updated
2 Reduce CUDA Version to download (10.2/10.0 etc. )

If you still fail, you can look at the following methods 2



\

     Method 2:PIP download



Method 1 The previous steps remain unchanged

Reopen Anaconda Prompt Command window
I will delete the environment just created
1 Enter the following command

conda remove -n pytorch --all

1.1 establish pytorch Environmental Science

conda create -n pytorch python=3.8

1.2 Switch to pytorch Environmental Science

conda activate pytorch

(1.3 Switch to Tsinghua source

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

Because the method was created at one time .condarc The document is still there
So I won't operate here )

2 open pytorch Official website
1 First of all, we define our mission
Download the following three packages manually

	pytorch torchvision torchaudio 

We need to know the corresponding versions of these packages

torch==1.9.0+cu102
torchvision==0.10.0+cu102
torchaudio===0.9.0

2.1 Click on pip Download mode , Select the generated link to open in the browser

 Insert picture description here

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-cVbFETIv-1636987267070)(htts://img-blog.csdnimg.cn/b37b09033486441098093ab12d9102ac.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5a2Q55Sw5ZGA,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)]



2.2 Press ctrl+F Shortcut key search , Input torch-1.9.0%2B

 Insert picture description here
%2B Yes, it is “+” It means cp38 yes c-python3.8 It means

2.3 Same as download win64 edition

torchvision==0.10.0+cu102
torchaudio===0.9.0

I save it directly to the user directory , Facilitate the following operations

 Insert picture description here
2.4 Back to the command window
Input :dir
You can see these bags

torch torchaudio torchvision

 Insert picture description here

2.5 Input :pip install torch Then press Tab Build automatic completion
pip install “torch-1.10.0+cu102-cp38-cp38-win_amd64.whl”
Enter to confirm the installation

2.6 pip install torchaudio Then press Tab Build automatic completion
Enter to confirm the installation

2.7 pip install torchvision Then press Tab Build automatic completion
Enter to confirm the installation

3 test
When the download is complete
Enter the following commands respectively

Python
Import torch
torch.cuda.is_available()

 Insert picture description here

return true It was a success



\

Four : Next blog post

  (1): download Pycharm

  (2): Select the created pytorch Environment creation project

原网站

版权声明
本文为[Zitian]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200555541650.html