Install Conda CUDA10.2 cuDNN7.6.5 Pytorch1.3.1 and Tensorflow2.0 in ubuntu 18.04 for deep learning

Source: Deep Learning on Medium

Install Conda CUDA10.2 cuDNN7.6.5 Pytorch1.3.1 and Tensorflow2.0 in ubuntu 18.04 for deep learning

– A complete step by step guide

Photo by Mukil Menon on Unsplash

I got a GPU card at black Friday sales. Got it installed and now would like to update all my SW framework in my Ubuntu 18.04 TLS with the GPU support.

First thing first (assume you already installed the Nvidia driver correctly (otherwise you will often get the GNOME freeze — check out this post if you have this problem: https://askubuntu.com/questions/1030060/freeze-after-login-ubuntu-18-04)

  1. Anaconda install

Go to the anaconda page https://www.anaconda.com/distribution/ check the latest version, for the time of writing, we have the 2019–10 release.

cd /tmp
curl -O https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh

After downloading, verify it.

sha256sum Anaconda3-2019.10-Linux-x86_64.sh

you should get a correct checksum as something like below:

output:
46d762284d252e51cd58a8ca6c8adc9da2eadc82c342927b2f66ed011d1d8b53 Anaconda3-2019.10-Linux-x86_64.sh

Everything looks alright, proceed to install

bash Anaconda3-2019.10-Linux-x86_64.sh

Press enter to continue when asked about accepting the license agreement.

Now we have the conda installed.

check what do we installed with the conda

conda list

you got a long list of packages installed together with Conda

Do a conda update immediately — it will update to the latest version

conda update conda

then update the packages

conda update anaconda

Like to use Anaconda GUI, start the conda navigator

anaconda-navigator&

2. Install Nvidia CUDA

Go the NVidia Download package, chose the right combination and follow the command sequence. I recommend to use the local Deb route.

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pinsudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.debsudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.debsudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pubsudo apt-get updatesudo apt-get -y install cuda

After installation is complete, add PATH variable by adding following line to the .bashrc
vim ~/.bashrc
adding
export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
at the end of file.

source the file and make it visible

source ~/.bashrc

do a quick check

cat /proc/driver/nvidia/version
nvcc -V

You are good to Go.

3. Install cuDNN7.6.5

Go to the cuDNN download page (need registration) and select the latest cuDNN 7.6.5 version made for CUDA 10.2. Download the 3 deb file for the ubuntu18.04 and go to the download folder and install from there.

first install the runtime library

sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb

then developer library

sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb

Last the sample codes

sudo dpkg -i libcudnn7-doc_7.6.5.32-1+cuda10.2_amd64.deb

Done. Do a sample code check with the mnistCUDNN

cd
cp -r /usr/src/cudnn_samples_v7/ .
cd cudnn_samples_v7/mnistCUDNN
make clean && make

then run the MNIST classification

./mnistCUDNN

You should see the test passed

4. install TF2.0-GPU

Strongly recommended to use conda install for Tensorflow (since you get the conda support now)

first create a conda channel for Tensorflow GPU

conda create --name tf-gpu

then activate the channel

conda activate tf-gpu

install

conda install -c anaconda tensorflow-gpu

So you get everything for Tensorflow2.0 with GPU in your virtual enviroment now. (note it will downgrade our cuda10.2 to cuda10.0 in the virtual env only -;)

Let’s check the installation

python3 -c 'import tensorflow as tf; print(tf.__version__)'

you should get the 2.0

5. install Pytorch for GPU

First exit from the tf-gpu virtual environment by:

conda deactivate

you should back to your base and then create a Pytorch channel

conda create --name pytorch

activate it

conda activate pytorch

then go the pytorch webpage: https://pytorch.org/get-started/locally/

chose the conda version, it is always easier with conda.

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

let’s test it

python3

under python import the PyTorch and check the GPU availability (BTW, Pytorch1.3.1 -the latest PyTorch, is using CUDA10.1-:)

import torch
torch.cuda.is_available()

it should return “true”

Now back to the conda navigator, you should be able to see the two additional channels.