Installing Tensorflow/Keras in WSL2 for Windows with NVIDIA GPU
If you are working with machine learning and deep learning models, you may want to leverage the power of your NVIDIA GPU to speed up training. With the Windows Subsystem for Linux 2 (WSL2) and its support for GPU acceleration, you can now install Tensorflow and Keras in your WSL2 environment and utilize your NVIDIA GPU.
Prerequisites
Before you begin, make sure you have the following:
- Windows 10 with WSL2 enabled
- NVIDIA GPU with the latest drivers installed
- WSL2 with GPU support enabled
- Ubuntu 20.04 installed in your WSL2 environment
Installing Tensorflow/Keras
To install Tensorflow and Keras in your WSL2 environment with GPU support, follow these steps:
- Open your WSL2 terminal and update the package list:
sudo apt update
- Install the required dependencies:
sudo apt install -y python3-venv python3-dev build-essential libgl1-mesa-glx
- Create a virtual environment:
python3 -m venv tf_env
- Activate the virtual environment:
source tf_env/bin/activate
- Install Tensorflow and Keras:
pip install tensorflow-gpu Keras
Testing
Once the installation is complete, you can test the setup by running a simple Tensorflow/Keras program that utilizes your GPU for training.
Conclusion
By following these steps, you can install Tensorflow and Keras in your WSL2 environment for Windows with NVIDIA GPU support. This setup allows you to take advantage of the powerful capabilities of your GPU for training machine learning and deep learning models.
Jeff! Thank you so much for the information. It's so much better than rifling through the docs and GitHub issues. Subscribed!
Thank you so much, man! It worked with a few tweaks. I used the newest versions of cuda and tf, it worked fine!
So I got to the end of this process and was heartbroken to see :-
PS C:UsersPando> wsl
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
(base) andyorbit@DESKTOP-7IA5CHS:/mnt/c/Users/Pando$ conda activate ts
(ts) andyorbit@DESKTOP-7IA5CHS:/mnt/c/Users/Pando$ python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
2023-10-29 23:46:44.821911: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-10-29 23:46:44.908546: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:44.908579: I tensorflow/compiler/xla/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2023-10-29 23:46:45.325497: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.327634: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.327657: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
2023-10-29 23:46:45.801628: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:967] could not open file to read NUMA node: /sys/bus/pci/devices/0000:26:00.0/numa_node
Your kernel may have been built without NUMA support.
2023-10-29 23:46:45.803746: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.805844: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.807814: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.809923: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.812067: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcurand.so.10'; dlerror: libcurand.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.814093: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.816259: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.818455: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: :/home/andyorbit/miniconda3/envs/ts/LIB/
2023-10-29 23:46:45.818482: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices…
[]
(ts) andyorbit@DESKTOP-7IA5CHS:/mnt/c/Users/Pando$
The best of the videos I've seen! Thank you!
Do any of those errors on your screen mean anything important? I have the same ones and I am not sure whether I need to fix it or whether tensorflow should be able to run using my gpu just fine
Jeff, I cannot thank you enough. You've not only shown us the entire installation process but also explained it. Thanks a lot!
I think they already update their docs. I don't found the miniconda part.
Link for miniconda installation site pls
I have an integrated GPU and a GTX 1650 in my laptop. At the end, was I supposed to get 2 gpu's as a return?
After Following that , how to use this to run pycharm ?
Thank you for providing an amazing video but how to use jupyter notebook after all the installation is done so that I can use the gpu?
THANKS A LOT JEFF !!!!
PowerShell recognize the GPU but GPU isn't recognized in jupyter notebook.
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 14413204623170981570
xla_global_id: -1]
How can I solve this problem?
dank je wel!
Do you have a tutorial for working this with Rstudio on a windows system with GPU?
I've been looking into Rstudio-server on WSL with Tensorflow and Keras but having no luck installing it.
hello when i verify install, this message appears "Could not find cuda drivers on your machine, GPU will not be used." i install the tensorflow 2.13, cudnn 8.6 and cuda 11.8 and i have rtx3060ti with the NVIDIA STUDIO, what is the possible problem?
most worthless video ever…
Thank you so much!!! I have been struggling on how to setup tf GPU for wsl
It didn't work for me the cuDNN was not properly configured. I installed the version that was on the website. cuda was properly installed and configured. tensorflow can find my gpu but the code does not work
This really helped me. Thanks a lot Dr. Heaton