Install Tensorflow-GPU on WSL2
Asked Answered
B

4

13

Has anyone successfully installed Tensorflow-GPU on WSL2 with NVIDIA GPUs? I have Ubuntu 18.04 on WSL2, but am struggling to get NVIDIA drivers installed. Any help would be appreciated as I'm lost.

Bedcover answered 1/9, 2020 at 0:41 Comment(2)
Did you follow this guide? docs.nvidia.com/cuda/wsl-user-guide/index.html#running-dlfwPericlean
@FariborzGhavamian Yes I did. I have an NVIDIA Titan V connected to a Dell Precision 7540 through a Razor Core X Chroma eGPU using Thunderbolt3. The card is detected by Tensorflow 2.3 in Windows, but Docker in Ubuntu-18.04 LTS says it cannot find the GPU.Bedcover
B
0

I can confirm I am able to get this working without the need for Docker on WSL2 thanks to the following article:

https://qiita.com/Navier/items/cf551908bae707db4258

Be sure to update to driver version 460.15, not 455.41 as listed in the CUDA documentation.

Note, this does not work with the card in TCC mode (only WDDM). Also, be sure to place your files on the Linux file system (i.e. not on a mount drive, like /mnt/c/). Performance is significantly faster on the Linux file system (this has to do with the difference in implementation of WSL 1 vs. WSL 2; see 1, 2, and 3).

NOTE: See also Is the class generator (inheriting Sequence) thread safe in Keras/Tensorflow?

Bedcover answered 3/9, 2020 at 0:26 Comment(2)
The article is not in EnglishInexecution
@Inexecution I didn't need to understand Mandarin in order to follow the steps (I was able to read between the lines). However, you can use Google translate if necessary. This method worked for me at the time I wrote this answer.Bedcover
F
12

So I have just got this running.

The steps you need to follow are here. To summarise them:

  1. sign up for windows insider program and get the development builds of windows so that you have the latest version
  2. Install wsl 2
  3. Install Ubuntu from the windows store
  4. Install the wsl 2 cuda driver on windows
  5. Install cuda toolkit
  6. Install cudnn (you can download the linux version from windows and then copy the file to linux)
  7. If you are getting memory errors like 'cannot allocate memory' then you might need to increase the amount of memory wsl can get
  8. Then install tensorflow-gpu
  9. pray it works

bugs I hit along the way:

  • If when you open ubuntu for the first time you get an error you need to enable virutalisation in the bios
  • If you cannot run the ./Blackscholes example in the installation instructions you might not have the right build of windows! You must have the right version
  • if you are getting 'cannot allocate memory' errors when running tf you need to give wsl more ram. It only access half your ram by default
    1. create a .wslconfig file under your user directory in windows with the amount of memory you want. Mine looks like:
[wsl2]
memory=16GB 

Edit after running some code

This is much slower then when I was running on windows directly. I went from 1 minute per epoch to 5 minutes. I'm just going to dualboot.

Flavius answered 8/1, 2021 at 21:32 Comment(3)
The linked instructions are erroneous as well as inadequate. For example, to verify you are running under WSL2, they say: Launch the Linux distribution and make sure it runs in WSL 2 mode using the following command: wsl.exe --list -v commandElectroluminescence
I am having troubles with cudnn installation. can you tell how did you install cudnn on wslCapita
Doesn't work! tensorflow-gpu is deprecated.Sexivalent
S
1

These are the steps I had to follow for Ubuntu 20.04. I am no longer on dev channel, beta channel works fine for this use case and is much more stable.

Install WSL2

Install Ubuntu 20.04 from Windows Store

Install Nvidia Drivers for Windows from: https://developer.nvidia.com/cuda/wsl/download

Install nvcc inside of WSL with: sudo apt install nvidia-cuda-toolkit

Check that it is there with: nvcc --version

For my use case, I do data science and already had anaconda installed. I created an environment with:

conda create --name tensorflow
conda install tensorflow-gpu

Then just test it with this little python program with the environment activated:

import tensorflow as tf
tf.config.list_physical_devices('GPU')
sys_details = tf.sysconfig.get_build_info()
cuda = sys_details["cuda_version"]
cudnn = sys_details["cudnn_version"]
print(cuda, cudnn)

For reasons I do not understand, my machine was unable to find the GPU without installing the nvcc and actually gave an error message saying it could not find nvcc.

Online tutorials I had found which had you downloading CUDA and CUDNN separately but I thinkNVCC includes CUDNN since it is . . . there somehow.

Somniloquy answered 28/4, 2021 at 0:14 Comment(1)
I just attempted this and sys_details does indeed show a cuda version but tf.config.list_physical_devices('GPU') returns empty listHua
B
0

I can confirm I am able to get this working without the need for Docker on WSL2 thanks to the following article:

https://qiita.com/Navier/items/cf551908bae707db4258

Be sure to update to driver version 460.15, not 455.41 as listed in the CUDA documentation.

Note, this does not work with the card in TCC mode (only WDDM). Also, be sure to place your files on the Linux file system (i.e. not on a mount drive, like /mnt/c/). Performance is significantly faster on the Linux file system (this has to do with the difference in implementation of WSL 1 vs. WSL 2; see 1, 2, and 3).

NOTE: See also Is the class generator (inheriting Sequence) thread safe in Keras/Tensorflow?

Bedcover answered 3/9, 2020 at 0:26 Comment(2)
The article is not in EnglishInexecution
@Inexecution I didn't need to understand Mandarin in order to follow the steps (I was able to read between the lines). However, you can use Google translate if necessary. This method worked for me at the time I wrote this answer.Bedcover
C
0

I just want to point out that using anaconda to install cudatoolkit and cudnn does not seem to work in wsl.

Maybe there is some problem with paths that make TF look for the needed files only in the system paths instead of the conda enviroments.

Capita answered 10/2, 2022 at 0:36 Comment(1)
Use the accepted answer. It does not involve conda. All the answers with conda don't work, yes.Bedcover

© 2022 - 2024 — McMap. All rights reserved.