TensorFlow, Torch install GPU version records

Installed version:

python=3.7

CUDA=11.3.1

cuDNN=8.2.1

Torch=1.11.0

TensorFlow-gpu=2.6.0


foreword

The cpu version of TensorFlow and Torch is easy to install, but the gpu version has many limitations and is prone to many problems.

Document the solution here.


Notice

The GPU version of the library runs with dual limitations based on hardware and software:

1. Hardware: The computer must have Nvida graphics card, AMD graphics card is not supported;

2. Software: CUDA and cuDNN corresponding to TensorFlow and Torch versions need to be installed

It should be noted that the CUDA version is backward compatible. Even if the higher version is compatible with the lower version, it is best to correspond, and the version difference is not big.

My own understanding is: the highest cuda version supported by my computer > the cuda version installed in anaconda > the cuDNN version installed in anaconda (meaning the cuDNN version corresponding to the installed cuda version; cuDNN and CUDA corresponding version query: cuDNN Archive | NVIDIA Developer )

For example: my computer supports the highest cuda version = 11.5;

cuda version installed by anaconda = 11.3;

(For example: cuda=11.3 corresponds to cuDNN=8.1; cuda=11.2 corresponds to cuDNN=8.0)

Then the cuDNN version installed by anaconda can be 8.1 or 8.0 (because the higher version cuda=11.3 is compatible with cuda=11.2, that is, it is compatible with cuDNN=8.0)

Before installation, it is best to understand the version information and know the version information of the various libraries that you need to install, and then you can install it quickly, and it is not easy to cause problems

1. Check the graphics card

(1) View graphics card information:

Right-click [My Computer] → [Properties] → [Hardware] → [Explorer] → [Display Card], double-click the graphics card model, open a dialog box, and display the graphics card information (N card only supports GPU)

(2) View the highest version of CUDA supported by the graphics card

[Open the graphics card control panel]

 

 

Check the highest supported CUDA version: CUDA 11.5 (less than or equal to this version when installed) 

(3) need to pay attention

2. Download and install Anaconda

Anaconda installation has a lot of experience to share, so I won't go into details.

Notice:

After Anaconda is installed, you need to create an environment, and the subsequent libraries are installed in the environment you created, which is convenient for management. (Mainly for the convenience of solving problems after they occur)

Create your own environment:

conda create -n torch_ten_gpu python=3.7

Pay special attention to the language version of the environment, you need to check the language version supported by the library you installed: some versions do not support python3.6 or above

Activate the environment:

activate torch_ten_gpu

Set mirroring:

channels:
  - https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
  - https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
  - https://mirrors.bfsu.edu.cn//anaconda/cloud/pytorch/
  - defaults
show_channel_urls: true

There are many ways to set the mirror image, add the above mirror address to

3. Torch-gpu installation

When installing the GPU version of TensorFlow and Torch at the same time, it is recommended to install Torch first.

Enter Torch official website Start Locally | PyTorch

Because of Torch's new version restrictions:

CUDA-10.2 PyTorch builds are no longer available for Windows, please use CUDA-11.3

CUDA-10.2 version is no longer available; so you need to install CUDA-11.3 version

So the first step: install CUDA-11.3 (computer graphics card needs to be supported)

Just install cudatoolkit

conda install cudatoolkit=11.3

Install cuDNN:

conda install cudnn=8.1.0

Install Torch:

Command to install:

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch

(Some tutorials say to remove: -c ;

I have not removed it here and there is no problem. If there is a problem in the end, it may be the problem here, you can remove it and try again)

 Test installation results:

Check the installed library version: conda list

 Code test:

python
import torch
torch.cuda.is_available()

The result is True, indicating that the installation was successful

Install TensorFlow-gpu

(1) View the corresponding version: Build from source code in Windows environment | TensorFlow

According to the CUDA backward compatibility mentioned earlier, you can install TensorFlow-gpu=2.6.0

Installation: (mirror installation, speed flies)

pip install tensorflow-gpu==2.6.0 -i https://pypi.tuna.tsinghua.edu.cn/simple 

test:

python
import tensorflow as tf
print(tf.test.is_gpu_available())

 The result is True, the installation is successful

Summarize

I hope this can help you solve some of the same problems you encountered.

Guess you like

Origin blog.csdn.net/qq_38767359/article/details/125207675