TensorFlow#

This guide is for installing TensorFlow with GPU support on Windows WSL2.

Option 1: TensorFlow package#

Prerequisites#

Verify that NVIDIA GPU Driver is installed

Installation#

Installation is straightforward

pip install --upgrade pip
pip install tensorflow==2.13

Option 2: TensorFlow[and-cuda] package#

Prerequisites#

In this documentation called “option 2”, no prerequisites, except installing NVIDIA Graphics driver on your windows machine, do nothing ;-)

Installation#

Installation is straightforward

pip install --upgrade pip
pip install tensorflow[and-cuda]

Verify Installation#

Terminal (WSL2 guest)#
   python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Note

You could expect some error messages, that doesn’t mean TensorFlow didn’t work properly. For me, April 2024, tensorflow v2.13, still works best.

From my side you could ignore, error/warings, like:

I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F AVX512_VNNI AVX512_BF16 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.

Your kernel may have been built without NUMA support.

This is the important part:

[PhysicalDevice(name=’/physical_device:GPU:0’, device_type=’GPU’)]

That means GPU is available.