Pytorch installation tutorial (the most complete and detailed version)

Overview

PyTorch is an open source deep learning framework that provides various tensor operations and can automatically perform gradient calculations through automatic derivation to facilitate the construction of various dynamic neural networks. Supports the use of GPU/TPU for accelerated calculations. (Torch Chinese Encyclopedia)
In January 2017, PyTorch was launched based on Torch by the Facebook Artificial Intelligence Research Institute (FAIR). It is a Python-based sustainable computing package that provides two advanced features: 1. Tensor computing with powerful GPU acceleration (such as NumPy). 2. Deep neural network including automatic derivation system. (Baidu Encyclopedia)
For more detailed introduction to Pytorch, please refer to Pytorch Chinese Encyclopedia: Pytorch Chinese Encyclopedia

Install

1. CUDA installation

(1) Overview of CUDA

The installation of CUDA depends on the version of Pytorch installed. The GPU version requires CUDA to be installed, and the CPU version does not need to install CUDA.

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. It includes the CUDA instruction set architecture (ISA) and the parallel computing engine inside the GPU. Developers can use C language to write programs for the CUDA™ architecture, and the written programs can run at ultra-high performance on CUDA™-enabled processors. (Baidu Encyclopedia)
For more detailed introduction to CUDA, please see the CUDA official website: CUDA official website

(2) Installation

Check your computer's graphics card driver version (if you think the version is too low, you can go to the CUDA driver official website to download the latest driver version of your computer's corresponding graphics card and install the updated driver)
1. Open the NVIDIA Control Panel and click System Information
Insert image description here

2. Then click on the component to see the GPU driver version (for example, my computer is CUDA 12.0.133), and then compare it with the CUDA version comparison table
Insert image description here
Insert image description here

CUDA download address: https://developer.nvidia.com/cuda-toolkit-archive
3. After the download is complete, select "Agree and Continue", then select custom installation to select the components that need to be installed, or you can use recommended installation
Insert image description here
4. Download CUDA toolkit, the next step is to install cudnn, download address: https://developer.nvidia.com/rdp/cudnn-download
CUDA installation is complete (default path recommended), after downloading cudnn, unzip the three folders to the following installation directory of CUDA Overwrite to complete the installation.
Insert image description here
5. After the installation is completed, check whether the installation is successful
. Check the system variables to see if the CUDA environment is configured successfully. If it is not configured, you can configure it manually.
Insert image description here
Then use the Win+R shortcut key to enter cmd to open the terminal and enter nvcc -V, as shown in the figure below. The cuda installation is successful.
Insert image description here
Open extras in the CUDA installation directory, then open demo_suit, and then enter cmd at the file location. The command line at the corresponding location can be opened. Enter bandwidthTest.exe and deviceQuery.exe in the command line. If the following appears, cudnn is successfully installed.
Insert image description hereInsert image description here
For the specific installation process, please refer to the blog post:
https://blog.csdn.net/qq_44442727/article/details/119923070
https://blog.csdn.net/qq_37867431/article/details/127071132

2. Anaconda installation

1. Download the Anaconda official website: https://www.anaconda.com. Select the version to download as needed.
Insert image description here
2. Select the path according to your actual situation, and click "Next" until the installation is completed.

Insert image description here
3. Configure environment variables.
Enter the system environment variables and click Path to add the following path (depending on your installation path):

E:\Anaconda
E:\Anaconda\Scripts
E:\Anaconda\Library\bin
E:\Anaconda\Library\mingw-w64\bin

4. Test whether the installation is successful.
Win+R enter cmd and enter conda --version. If the following is displayed, the installation is successful.
Insert image description here

3. Pytorch installation

(1) GPU version installation

method one

Online installation
1. Open Anaconda Powershell Prompt, enter conda info --envs, and check the installation environment.
Insert image description here
2. Enter the Pytorch official website: https://pytorch.org/ and find the version suitable for your computer.
Insert image description here
3. Copy Run this Command: conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia(depending on your situation) Go to Anaconda Powershell Prompt to confirm the download

Insert image description here
4. Test whether the installation is successful.
Enter the Anaconda Powershell Prompt in sequence.

python
import torch
torch.__version__
torch.cuda.is_available()

If the following is displayed, the installation is successful.
Insert image description here

Method Two

Offline installation
1. Check the Anaconda or locally installed Python version
Insert image description here
2. Corresponding versions of Torch and Torchvision
Insert image description here
3. Go to the Pytorch offline download resource website to download the corresponding version (CPU version and GPU version): https://download.pytorch.org/whl /torch_stable.html
Insert image description here
4. After downloading, copy and switch to the directory where Anaconda is located, and use the "pip" command to install
pip install "file name"
Insert image description here

Insert image description here
5. Test whether the installation is successful

The results are the same as the online installation test results

(2) CPU version installation

Reference blogger: https://blog.csdn.net/weixin_44904136/article/details/123285884

Attachment:
Add Tsinghua source:
execute the following statement under cmd

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

Find the .condarc file under the Anaconda installation file (usually in the user directory of the C drive)
Insert image description here
to restore the default source:
conda config --remove-key channels

Reference:
Pytorch’s most complete installation tutorial (one step in place)
cuda11.2 installation pytorch——torch.cuda.is_available()=false
computer configuration cuda11.3+cudann+torch pitfalls, detailed version
2021.08.26 learning content Win10+GeForce GTX1650 Install NVIDIA graphics card driver and CUDA11.4+cuDNN8.2

Guess you like

Origin blog.csdn.net/MANCXUARY/article/details/128798637