GPU version pytorch (Cuda12.1) installation tutorial

When we install torch through the Pytorch official website, we will find that the installation is often unsuccessful due to network speed problems. The following provides a simple method to successfully install Cuda12.1, and the personal test is effective.

Table of contents

1. Conventional method 

2. Effective methods

2.1 Create and activate a virtual environment

2.2 Add Tsinghua source

2.3 install torch


 

1. Conventional method 

Install torch through the Pytorch official website, the URL link is as follows: PyTorch 

You will find that the installation speed is very slow, and it is easy to fail.

2. Effective methods

2.1 Create and activate a virtual environment

Create a virtual environment 

conda create -n pytorch39 python==3.9

Activate the virtual environment

conda activate pytorch39

2.2 Add Tsinghua source

Adding Tsinghua source can achieve network acceleration and greatly improve the success rate of installation

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

2.3 install torch

pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html

Verify that the installation was successful

Anaconda prompt 里输入 python
>>> import torch
>>> torch.__version__
'2.0.0+cu118'
>>> torch.cuda.is_available()
True
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce RTX 3090'

As shown in the figure above, pytorch (Cuda12.1) is installed successfully!

Guess you like

Origin blog.csdn.net/weixin_43734080/article/details/132503679