GPU version pytorch (Cuda12.1) Tsinghua source quick installation step by step teaching!
When the author installed pytorch for the new computer r9000p, he didn't notice that his cuda version was 12.1 (how to check it on Baidu), and the old version of torch was installed and the import error was reported! After looking for the reason for a long time, I found that it does not correspond to the cuda version. You need to download the Cuda 11.8 version, as shown below:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
The above is the official link. I don’t know why the download is still very slow when I go to the Internet scientifically, and there are still problems after downloading from the Internet, so I decisively choose Tsinghuayuan!
The following is a step-by-step tutorial:
First, make sure that anaconda is installed, and create a virtual environment in the anaconda prompt command line window. I named it pytorch310 (Python version should not be lower than 3.8)
conda create -n pytorch310 python==3.10
Then activate it:
conda activate pytorch310
Set Tsinghua source to speed up the installation:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Start the specified version installation:
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
Should be very fast! My download speed averaged 40M/s, and it took two minutes to download!
Then enter conda list
to see what libraries are there, and there will be no problem when these three come out!
Don’t worry, try again:
input python
, and then import torch
, it’s a bit slow at this time, and then torch.cuda.is_available()
, as shown in the figure below, when it comes out True, it means that cuda can be called! The gpu version of pytorch is installed successfully!