Any version of pytorch-gpu environment construction method

There are many online tutorials about setting up the pytorch-gpu environment. However, if you use the commands on the pytorch official website directly in China, you will often encounter slow downloads. However, if you use Tsinghuayuan, Aliyuan and other websites, the above pytorch version update is not as timely as the official website, and the naming method is also different from the official website. This article provides the easiest and fastest way to install the gpu version of pytorch. The only threshold here is to be able to surf the Internet scientifically.

1. Installation prerequisites

1. If the operating system is windows, you need to install cuda and cudnn. Here, you need to pay attention to the corresponding relationship between cuda and cudnn. Download cuda first, then download cudnn. There are many related tutorials on the Internet, so I won't repeat them here.

2. Install ananconda.

2. Manually install pytorch

1. Log in to the official website of pytorch and download the whl file (requires scientific Internet access)

URL: https://download.pytorch.org/whl/torch/


Corresponding whl files can be found from cuda9 to cuda11 ! ! !

After entering, you can see various versions of torch. So how do you choose the version you want?

Example:

1、torch-1.10.0+cpu-cp38-cp38-win_amd64.whl

1.10.0: pytorch version; cpu: indicates the cpu version of torch; cp38: python3.8; win: operating system

2、torch-1.10.0+cu113-cp36-cp36m-linux_x86_64.whl

Similarly, the difference is that cu113 indicates that the corresponding cuda version is 11.3

2. pip install whl file

1. First create the environment. I installed " torch-1.10.0+cu113-cp39-cp39-win_amd64.whl ", so I need to install the python environment of version 3.9

conda create -n pytorch python=3.9

2. Activate the environment

activate pytorch

result:

3. Switch to the directory where the whl file is located. mine is in the download folder

result:

4. Finally, install the whl file!

pip install "torch-1.10.0+cu113-cp39-cp39-win_amd64.whl"

Wait a moment for this to appear:

 5. torchvision installation

torchvision is a small but very important library, it is recommended that you install it. Since it is relatively small, just pip install torchvision directly.

3. Check whether the installation is successful

If True appears , it indicates that the gpu can be used normally. You're done! ! !

Guess you like

Origin blog.csdn.net/tortorish/article/details/121612604