TensorFlow 2.5.0 RC on WSL2
I wanted to try the upcoming version of tensorflow 2.5
But the challenge is to try it on my wsl2 machine on top on windows.
Here is the recipe !
This Nvidia documentation is to follow along, i just updated the parts for my specific install:
Unfortunately this is only available with windows insider
I recommend having a safe windows environnement to play with, i don’t recommend using this in a work or personal computer for instance, as it can be broken sometimes.
Use the DEV channel.
After installing and done a few updates, you should be on a version 20145+ (recommended 21332+)
after installation type WIN+R and type this command to check your windows version
winver
WSL2
Next you have to install wsl2
wsl — install
You have to make sure that you have the right version of the linux kernel
You may have to change your preferences in advanced option of windows updates and check
receive updates of other Microsoft products
After updating your system you should have an update on this specific item
“Windows Subsystem for Linux Update — 5.10.16”
I recommend uninstall / install a new distro installation to make sure you have the right version
from powershell:
# install ubuntu 18.04 version
wsl — install -d Ubuntu-18.04#launch wsl
wsl
Then inside Ubuntu check your kernel version
uname -r
# return 5.10.16.3-microsoft-standard-WSL2
Nvidia driver
First you have to update for nvidia driver from WINDOWS.
Do not install nvidia driver inside wsl !
Here is a guide:
Install it according to your product.
CUDA on WSL2
You should install a specific version of cuda, the cuda toolkit with the right version
The version 2.5 is in release candidate so no information on this page yet.
TensorFlow pip packages are now built with CUDA11.2 and cuDNN 8.1.0
Inside WSL install CUDA Toolkit
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pubsudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'sudo apt-get updatesudo apt-get install -y cuda-toolkit-11–2cd /usr/local/cuda-11.2/samples/4_Finance/BlackScholes
sudo make
./BlackScholes
## result shoud be Test passed
CUDNN on WSL2
Next we need to install manually cudnn
https://docs.nvidia.com/deeplearning/cudnn/install-guide/index.html
I choose “Download cuDNN v8.1.0 (January 26th, 2021), for CUDA 11.0,11.1 and 11.2” , here are the 2 links to download on windows:
https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.0.77/11.2_20210127/Ubuntu18_04-x64/libcudnn8-dev_8.1.0.77-1+cuda11.2_amd64.debhttps://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.0.77/11.2_20210127/Ubuntu18_04-x64/libcudnn8_8.1.0.77-1+cuda11.2_amd64.deb
Download, copy the files to you home inside wsl, install them in this order
cp /mnt/c/Users/<username>/Downloads/libcudnn8* .sudo dpkg -i libcudnn8_8.1.0.77–1+cuda11.2_amd64.deb
sudo dpkg -i libcudnn8-dev_8.1.0.77–1+cuda11.2_amd64.deb
TensorRT is optionnal, here is the install procedure
https://developer.nvidia.com/nvidia-tensorrt-download
sudo sh -c 'echo “deb http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /” > /etc/apt/sources.list.d/nvidia-machine-learning.list'sudo apt-get updatesudo apt-get install -y — no-install-recommends libnvinfer7=7.1.3–1+cuda11.0 \
libnvinfer-dev=7.1.3–1+cuda11.0 \
libnvinfer-plugin7=7.1.3–1+cuda11.0
Tensorflow
I recommend using miniconda for creating specific python virtual env,
conda activate tf25
pip3 install tensorflow-gpu==2.5.0-rc1
Check that the gpu is detected by tensorflow
import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
print(“Num GPUs:”, len(physical_devices))
#Num GPUs: 1