0 Some recommended versions
Version adaptation problems often occur in various software. Here are the versions verified by others:
2022 [Super detailed] Building a deep learning environment and configuration tensorflow2.7 + keras2.7 + CUDA11.6 + cuDNN corresponding version_cuda11.6 corresponding cudnn_Huo Lingyuan’s blog-CSDN blog
python3.7.0 + CUDA11.6.0 + cuDNN8.3.2 + tensorflow2.7.0 + Keras2.7.0
python3.7.0 + CUDA11.3.1 + cuDNN8.2.1 + tensorflow2.7.0 + Keras2.7.0
python3.7.0 + CUDA10.1.2 + cuDNN7.6.5 + tensorflow2.2.0 + keras 2.3.1
If you want to find a suitable adaptation version yourself, you can first go to tensorflow or pytorch to see the corresponding version you need, and install it according to your needs.
Build from source | TensorFlow (google.cn)
Previous PyTorch Versions | PyTorch
The installation example for this article is:
python 3.8 + CUDA11.3 + CUDA10.2 + cuDNN8.5.0 + tensorflow2.10
1 Install multiple versions to switch CUDA (take cuda 11.3 and 10.2 as an example)
1.1 Download the required version of the cuda installation package from the official website (you can jump directly to 1.2, this section is only to introduce the download website and uninstall the original cuda method)
https://developer.nvidia.com/cuda-toolkit-archive
Select the required version and use wget + url to download it (if you want to install multiple versions of cuda, select Runfile as the Installer Type (because if you use a deb file to install, the already installed graphics card driver may be replaced)
The correspondence table between cuda and driver is under the CUDA Driver tab of the following connection:
CUDA 12.2 Release Notes – cuda-toolkit-release-notes 12.2 documentation (nvidia.com)
Uninstall the original CUDA:
1. apt method:
sudo apt –purge remove cuda-11.4
sudo apt autoremove
sudo apt autoclean
sudo rm -rf /usr/local/cuda-11.4/
2. cuda comes with an uninstall script
cd /usr/local/cuda-xx.x/bin/
sudo ./cuda-uninstaller
sudo rm -rf /usr/local/cuda-xx.x
1.2 Install cuda
When you choose to download, the installation method is included below:
wget https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.19.01_linux.run
sudo chmod +x cuda_11.3.1_465.19.01_linux.run
use
sudo ./cuda_11.3.1_465.19.01_linux.run
Perform cuda installer. If the cursor stops after execution, please wait.
If Step 1 prompts Existing package manager installation of the driver found. It is strongly recommended that you remove this before continuing. Select continue. After agreeing to the agreement, use the Enter key to remove the driver item in the next step, and then select install.
When completed, the following display should appear:
1.3 Setting environment variables
vim ~/.bashrc
#cuda export LD_LIBRARY_PATH=/usr/local/cuda/lib64 export PATH=$PATH:/usr/local/cuda/bin
use
source ~/.bashrc
Apply environment variables
1.4 Test whether cuda is installed
nvcc -V
2 Install cuDNN
Historical version cuDNN link:
Library DNN Archives | NVIDIA Developers (nvidia.com)
The official installation documentation is as follows:
Installation Guide – NVIDIA Documentation
2.1 Install cudnn (local installation)
Download cudnn 8.5.0 for 11.x (x86_64 version)
cuDNN Archive | NVIDIA Developer
It is not feasible to download directly using wget, probably because downloading cudnn requires login.
To use local installation, you need to download the .deb package in advance and place it in the Ubuntu system, and then use
1.3.2. Debian local installation
install it
The official documentation only mentions the apt network installation method for Ubuntu. However, Ubuntu is based on the Debian system, so the Debian local installation method can be used.
Unzip the .deb package
sudo dpkg -i cudnn-local-repo-ubuntu1804-8.5.0.96_1.0-1_amd64.deb
Add gpg key
After the previous command is executed, you will be prompted to copy the gpg key file. Just copy the prompted command.
something like this
sudo cp /var/cudnn-local-repo-ubuntu1804-8.5.0.96/cudnn-local-7B49EDBC-keyring.gpg /usr/share/keyrings/
Update library:
sudo apt-get update
Install cudnn
sudo apt-get install libcudnn8=8.5.0.96-1 + cuda11.7
sudo apt-get install libcudnn8-dev=8.5.0.96-1 + cuda11.7
sudo apt-get install libcudnn8-samples=8.5.0.96-1 + cuda11.7
Although I am using cuda 11.3 here, I chose 11.7 when installing because version 8.5 does not have a 11.3 version, and an error will be reported when executing. However, cudnn generally supports the entire 11.x series, so it can be used.
How to find the corresponding version:
enter
sudo apt-get install libcudnn8=8.5
After that, press the Tab key twice and you will be prompted for the installable version.
After the installation is complete, jump to section 2.3 of this article to test whether the installation is successful.
2.2 Install cudnn (network installation, local installation is recommended, there are some problems with the official documentation for network installation)
2.2.1 Add network repository
Add the network repository using part 2 of 3.10.3 from the official installation guide:
1. Introduction – cuda-installation-guide-linux 12.2 documentation
$distro/$arch needs to be replaced with ubuntu1804/x86_64 (take ubuntu 18.04 x64 as an example)
Example:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
2.2.2 Install cuDNN example:
Use the official installation guide
1.3.4.1. Ubuntu/Debian network installation
The second part of the installation
Example:
sudo apt-get install libcudnn8=8.2.0.53-1 + cuda11.3
sudo apt-get install libcudnn8-dev=8.2.0.53-1 + cuda11.3
sudo apt-get install libcudnn8-samples=8.2.0.53-1 + cuda11.3But when I install it, an error will be reported in the third sentence.
apt list -a libcudnn-samples
After checking, I found that the samples package does not have versions other than 8.9. In this case, I decided to abandon this installation method and use the local installation method
In fact, if you reach this step, you can also manually start from
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.2.0.53/11.3_04222021/Ubuntu18_04-x64/libcudnn8-samples_8.2.0.53-1 + cuda11.3_amd64.deb
Download the samples package, but I feel that since this is the case, it is better to use the local installation method directly, so remove the previous package and use the local installation method.
2.3 Test whether the installation is successful
sudo apt-get install libfreeimage3 libfreeimage-dev
cp -r /usr/src/cudnn_samples_v8/ $HOME
cd $HOME/cudnn_samples_v8/mnistCUDNN
make clean & amp; & amp; make
./mnistCUDNN
You should get the following results:
3 Multi-version environment installation
3.1 Install multi-version cuda environment
Execute part 1.2 again and change the version to another required version (during the execution, you will be prompted whether the existing symlink has been updated, just update it)
and then use
cd /usr/local/
ls -l
Looking at the directory, you can see that there are two versions of cuda
3.2 Install multi-version cudnn environment
Execute section 3.3 and switch cuda to version 10.2
Execute part 2.1 again and change the version to another required version
Execute section 2.3 to test again whether cudnn on cuda 10.2 is installed.
3.3 Switch cuda version
If you need to switch versions, follow the steps below to replace 10.2 with the version you need.
sudo cd /usr/local/ sudo rm -rf cuda # Delete the original soft link sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda # Link cuda-10.2 to cuda
use
nvcc -V
Check the cuda version currently in use. You can see that it is 10.2 now.
3.4 Multi-version tensorflow and pytorch
Here you only need to use conda to create different virtual environments to achieve version switching, and I will not go into details later.
4 Tensorflow (taking tensorflow2.10 as an example)
Tensorflow version correspondence table:
Build from source | TensorFlow (google.cn)
Use directly
conda install tensorflow-gpu
Just install it and conda will automatically select the appropriate version.
If the following error occurs:
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: conda path
Then execute the following command:
sudo chmod -R 777 conda path
If you need to specify the version (take 2.10.0 as an example):
conda install tensorflow-gpu==2.10.0
5 pyTorch
List of previous versions of pyTorch (including installation commands and version correspondence)
Previous PyTorch Versions | PyTorch
The link contains the installation methods and corresponding versions of each version and system.
Example (taking Linux pyTorch 1.12.1 as an example):
#CUDA 11.3 conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
Reference:
This article explains the corresponding versions of NVIDIA driver, CUDA, cuDNN, Torch, and Tensorflow_The cuda version corresponding to nvidia driver – CSDN Blog
Detailed steps for installing CUDA and cudnn in Ubuntu22.04_Ubuntu installs cuda and cudnn_takedachia’s blog-CSDN blog Detailed process of installing cudnn8.2.1 under Ubuntu20.04 system and problems encountered and solutions (cuda11.3 has been installed, different versions are similar)_qq_43453738 Blog – CSDN Blog 2022 [Super detailed] Building a deep learning environment and configuring tensorflow2.7 + keras2.7 + CUDA11.6 + cuDNN corresponding version_cuda11.6 corresponding cudnn_Huo Lingyuan’s blog – CSDN blog