Tensorflow extra

30-11-2020

Check if GPU available? #

# check if GPU available?
import tensorflow as tf
tf.config.list_physical_devices('GPU')

Installation with docker #

👉 Official guide.
👉 Docker & GPU note.

The advantage of this method is that you only have to install GPU driver on the host machine.

Note about docker version

Check docker version: docker --version:

  • <19.03: requires nvidia-docker2 (check by nvidia-docker version) and --runtime=nvidia.
  • >=19.03: requires nvidia-container-toolkit (check by which nvidia-container-toolkit) and --gpus all.

Without docker-compose #

👉 Different types of images for tensorflow.

# pull the image
docker pull tensorflow/tensorflow:latest-gpu-jupyter

# run a container
mkdir ~/Downloads/test/notebooks
docker run --name docker_thi_test -it --rm -v $(realpath ~/Downloads/test/notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-gpu-jupyter
# check if gpu available?
nvidia-smi

# check if tf2 working?
docker exec -it docker_thi_test bash
python
import tensorflow as tf
tf.config.list_physical_devices('GPU')

With docker-compose? #

👉 Read this note instead.

On Windows WSL2 #

Install directly on Linux (without docker) #

On my computer, Dell XPS 15 7590 - NVIDIA® GeForce® GTX 1650 Mobile.

{:.alert.alert-danger}
This section is not complete, the guide is still not working!

Installation #

👉 GPU support : TensorFlow

This guide is specific for:

pip show tensorflow # 2.3.1
pip show tensorflow-gpu # 2.3.1
nvidia-smi # NVIDIA-SMI 450.80.02 Driver Version: 450.80.02 CUDA Version: 11.0

👉 PyTorch note.
👉 Ubuntu note.
👉 Linux note.

CUDA Toolkit:

  • If you meet Existing package manager installation of the driver found, try this method to remove some already-installed packages before continuing.
  • Or you can download cuda toolkit .run and then run
sudo sh cuda_11.1.0_*.run --toolkit --silent --override

Errors? #

# Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory

Need to install new cuda & CUDNN libraries and tensorflow. (This note is for tensorflow==2.3.1 and CUDA 11.1). [ref]

# update path
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

# quickly test cuda version
nvcc --version

Notes with this notation aren't good enough. They are being updated.