pytorch2.0.1 installation and deployment (cpu+gpu) linux+windows

The opening of the official website may be slow, wait patiently for the following operations on the
pytorch official website to be used in the default network environment, updated on August 20, 2023

1. Description and preliminary preparation

1.pytorch is a framework similar to tensorflow

If you need to install tensorflow, you can refer to:
tensorflow 1, 2 cpu+gpu (windows+linux) installation

2. Install anaconda

Mainly for a machine to install multiple environments that do not interfere with each other.
Install the latest version to
install anaconda (windows+linux)
Note: To install anaconda, you need to start the notebook (install the above tutorial)

3. Install cuda

Install cuda11.8 version
cuda windows installation

cuda linux installation

4. Graphics card (optional)

In most cases, the speed of gpu (graphics card) surpasses that of cpu. The friendly point of pytorch is that it supports amd's ROCm (only linux), so that both N card and A card can be
used (ROCm and cuda have many functions that are compatible except for the name. )
All architectures have less cpu pits, and beginners usually use cpu

5. Open the official website

Linux uses the command line, windows uses cmd (also the command line)
insert image description here

2. Install pytorch (linux installation)

The python version is 3.8-3.11, I choose 3.10

(1) linux+cpu

1. Create a conda environment

conda create -n pytorch_cpu python=3.10
conda activate pytorch_cpu 

2. Use conda to install (the speed of pip is too slow)

insert image description here

conda install pytorch torchvision torchaudio cpuonly -c pytorch

3. With notebook

Only after the following operations can it be used under the notebook, otherwise there is no such environment

pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/
python -m ipykernel install --name pytorch_cpu

4. Enter the notebook test

import torch
print(torch.__version__)

The display results are as follows
insert image description here

(2) linux+gpu (N card)

1. Create a conda environment

conda create -n pytorch_gpu python=3.10
conda activate pytorch_gpu

2. Use conda to install (the one of pip needs to adjust the source)

insert image description here

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

There is a lot of download content, wait patiently, if the installation is wrong, just run the command again

3. With notebook

Only after the following operations can it be used under the notebook, otherwise there is no such environment

pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/
python -m ipykernel install --name pytorch_gpu

4. Enter the notebook test

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

insert image description here

(3) linux+gpu (A card)

The installation method is the same as that of the N card, except for ROMc, there is no additional writing here for the time being.
I don’t have a dedicated graphics card, so I can’t test it.
insert image description here

3. Install pytorch (windows installation)

(1) windows+cpu

1. Create a conda environment

conda create -n pytorch_cpu python=3.10
conda activate pytorch_cpu 

2. Use conda to install (the speed of pip is too slow)

insert image description here

conda install pytorch torchvision torchaudio cpuonly -c pytorch

3. With notebook

Only after the following operations can it be used under the notebook, otherwise there is no such environment

pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/
python -m ipykernel install --name pytorch_cpu

4. Enter the notebook test

import torch
print(torch.__version__)

The display results are as follows
insert image description here

(2) windows+gpu (N card)

The ROCm of the A card cannot be used under Windows. It is said that ROCm is working hard to be compatible with Windows and other platforms, and maybe it can be used in the future.

1. Create a conda environment

conda create -n pytorch_gpu python=3.10
conda activate pytorch_gpu

2. Use conda to install (the one of pip needs to adjust the source)

insert image description here

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

There is a lot of download content, wait patiently, if the installation is wrong, just run the command again

3. With notebook

Only after the following operations can it be used under the notebook, otherwise there is no such environment

pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/
python -m ipykernel install --name pytorch_gpu

4. Enter the notebook test

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

insert image description here

Guess you like

Origin blog.csdn.net/ziqibit/article/details/132341934
Recommended