How to use TensorFlow with GPU comes down to three steps on a machine with an NVIDIA card: install a recent NVIDIA driver, run pip install "tensorflow[and-cuda]" inside a fresh virtual environment on Linux or WSL2, then confirm that tf.config.list_physical_devices('GPU') returns a device. After that you don't change your model code at all: TensorFlow and Keras models run on the first visible GPU automatically. The catches are platform-specific. Native Windows lost GPU support after TensorFlow 2.10, and Macs need Apple's separate Metal plugin.
This guide walks through each platform, shows how to prove the GPU is actually doing the work, and covers the fixes for the errors people hit most.
What you need before you start
TensorFlow's official GPU path is NVIDIA plus CUDA. The pip install page lists NVIDIA cards with CUDA architectures 3.5, 5.0, 6.0, 7.0, 7.5, 8.0 and higher, and minimum driver versions of 525.60.13 on Linux and 528.33 for WSL on Windows. There is no official AMD or Intel GPU wheel on that page.
The good news is that you no longer have to install the CUDA Toolkit and cuDNN by hand for the pip route. The [and-cuda] extra pulls NVIDIA's CUDA and cuDNN libraries in as ordinary pip packages. You only need the driver on the host.
Here is the version picture as of October 14, 2026:
| Item | Current value | Where it comes from |
|---|---|---|
| Latest TensorFlow | 2.21.0 | PyPI |
| Python for 2.21 | 3.10 to 3.13 | Tested build configurations |
| CUDA / cuDNN TF 2.21 was tested with | CUDA 12.5, cuDNN 9.3 | Tested build configurations |
| Last GPU build for native Windows | TensorFlow 2.10 | pip install page |
| Mac GPU path | tensorflow-metal plugin | Apple's Metal plugin page |
One thing to know: the "Software requirements" list further down the pip page still mentions older CUDA and cuDNN numbers. When the two disagree, trust the tested build configurations table for the exact release you install, and let the [and-cuda] extra pick matching libraries for you.
How to use TensorFlow with GPU on Linux (step by step)
Linux (Ubuntu is the only distro TensorFlow officially supports) is the smoothest path.
- Check the driver. Run
nvidia-smi. If it prints your GPU and a driver version, you're ready. If not, install the NVIDIA driver from your distro or NVIDIA first. - Create a virtual environment. The TensorFlow docs recommend
venv:
python3 -m venv tf
source tf/bin/activate
pip install --upgrade pip
- Install TensorFlow with the CUDA extra:
pip install "tensorflow[and-cuda]"
- Verify the GPU:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
A list like [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] means you're done. An empty list [] means TensorFlow loaded but couldn't find the GPU. Jump to the troubleshooting section below.
The docs also warn against installing TensorFlow with conda, because conda may not carry the latest stable release; TensorFlow is only officially released to PyPI.
TensorFlow GPU on Windows: use WSL2
This is where most people get stuck. According to the official install page, TensorFlow 2.10 was the last release that supported the GPU on native Windows. From 2.11 on, a plain pip install tensorflow on Windows runs on the CPU only.
You have two real choices:
- WSL2 (recommended). Windows Subsystem for Linux 2 on Windows 10 build 19044 (version 21H2) or higher is supported for GPU access, with a driver at or above the WSL minimum listed above. Set up WSL2 and NVIDIA's CUDA-on-WSL support (the install page links both), then follow the exact Linux steps above inside your WSL2 distro, including
pip install "tensorflow[and-cuda]". - Pin TensorFlow 2.10 on native Windows. The install page still documents installing
cudatoolkit=11.2andcudnn=8.1.0through conda-forge, thenpip install "tensorflow<2.11". That works, but you're stuck on an old release that the tested build table lists for Python 3.7 to 3.10, so treat it as a legacy option only.
The page also mentions the TensorFlow-DirectML plugin as an optional experiment for native Windows. It's not part of the main supported path.
Use Docker for a GPU setup you can throw away
If you'd rather not touch your Python environment at all, the TensorFlow Docker guide has official GPU images. On the host you need the NVIDIA driver and the NVIDIA Container Toolkit (Docker 19.03 and later use the --gpus all flag). Then:
docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu \
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
There's also a latest-gpu-jupyter tag if you want a notebook server in the same container. Docker is a good fit for servers, CI, and for keeping an older TensorFlow version around without it fighting your main environment.
TensorFlow GPU on a Mac (Metal plugin)
TensorFlow's own page says there's no official GPU support on macOS. Apple fills the gap with the tensorflow-metal PluggableDevice. Per Apple's setup page, it needs a Mac with Apple silicon or an AMD GPU, macOS 12.0 or later, and Python 3.9 or later:
python3 -m venv ~/venv-metal
source ~/venv-metal/bin/activate
python -m pip install -U pip
python -m pip install tensorflow
python -m pip install tensorflow-metal
The newest plugin release on PyPI is 1.2.0, uploaded in January 2025, and its compatibility table stops at TensorFlow 2.18 (noted as a fix for 2.18 and later). TensorFlow itself is at 2.21, so if you see import or op errors, try pinning a TensorFlow version the table lists. If you're on a Mac mainly to run or fine-tune language models, Apple's MLX is another route worth a look; our MLX vs GGUF on Mac guide covers that side.
How to confirm TensorFlow is really using the GPU
list_physical_devices only proves TensorFlow can see the card. To see where operations actually run, turn on placement logging, as the TensorFlow GPU guide shows:
import tensorflow as tf
tf.debugging.set_log_device_placement(True)
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
print(tf.matmul(a, b))
You should see a line like Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0. The guide explains that when an op has both CPU and GPU kernels, TensorFlow picks the GPU by default, and when an op has no GPU kernel it quietly falls back to the CPU. So a slow model isn't always a broken install; sometimes a few ops are on the CPU.
You can also watch nvidia-smi in a second terminal while training. Rising GPU utilisation and memory use mean the work is landing on the card.
Control GPU memory and pick a GPU
By default TensorFlow grabs nearly all the memory on every visible GPU, which surprises people who share a card with a desktop or another process. The GPU guide gives two fixes. Run them before any tensors are created:
gpus = tf.config.list_physical_devices('GPU')
for gpu in gpus:
tf.config.experimental.set_memory_growth(gpu, True)
Memory growth starts small and expands as needed (it doesn't give memory back). Setting the environment variable TF_FORCE_GPU_ALLOW_GROWTH=true does the same thing. For a hard cap, use tf.config.set_logical_device_configuration with a memory_limit in megabytes.
To use one specific GPU on a multi-GPU box, call tf.config.set_visible_devices(gpus[0], 'GPU') or set CUDA_VISIBLE_DEVICES. To train across several GPUs, wrap model creation in tf.distribute.MirroredStrategy().scope(), which copies the model to each GPU and splits each batch between them.
Get more speed: mixed precision
Once the GPU works, the cheapest speed-up in Keras is mixed precision:
from tensorflow import keras
keras.mixed_precision.set_global_policy("mixed_float16")
The mixed precision guide says NVIDIA GPUs with compute capability 7.0 or higher benefit most because their Tensor Cores accelerate float16 matrix maths, naming RTX cards, the V100 and the A100 as examples. Older GPUs get little math speed-up, though the memory savings can still help. The guide also says a softmax at the end of the model should stay in float32, so give your output layer dtype="float32".
Troubleshooting: TensorFlow GPU not detected
| Symptom | Likely cause | What to try |
|---|---|---|
[] from list_physical_devices('GPU') on Windows | Native Windows + TF 2.11 or newer | Move to WSL2 or Docker |
[] on Linux after pip install tensorflow | Installed without the CUDA extra | pip install "tensorflow[and-cuda]" in the same venv |
[] on Linux with [and-cuda] installed | Bundled CUDA libs not found, or clashing with a system CUDA install | Follow the symlink fix in step 6 of the pip guide (links the nvidia/*/lib libraries and ptxas into the venv) |
nvidia-smi fails | Driver missing or too old | Install a driver at or above the minimum listed on the install page |
| "device kernel image is invalid" | Your GPU's architecture isn't compiled into the wheel | Build from source for that compute capability, or use a newer GPU |
| Out-of-memory on a shared GPU | TensorFlow pre-allocated the whole card | Turn on memory growth or set a memory limit |
Also check the obvious: run the verify command with the same Python that's inside your venv, and confirm your Python version is in the supported range for the TensorFlow release you installed.
No GPU? Free cloud options
If your machine has no suitable GPU, Google Colab is the quickest route. Its FAQ describes free access to GPUs and TPUs in a hosted notebook, with the caveat that resources aren't guaranteed and usage limits fluctuate. Pick a GPU runtime and run the same verify line to confirm TensorFlow sees it. Kaggle notebooks are another hosted option.
Should you use TensorFlow at all?
For classic vision, tabular and production pipelines already built on TensorFlow, a GPU setup like the one above is all you need. If you're starting fresh on open-weight LLMs and fine-tuning, most of that ecosystem is built on PyTorch. Our TensorFlow vs PyTorch vs Keras comparison and PyTorch vs JAX guide help you decide, and how much VRAM you need for an LLM helps size the card. When you're ready to train, see how to fine-tune an LLM locally.
FAQ
Do I need to install CUDA separately for TensorFlow?
Not for the pip route on Linux or WSL2. pip install "tensorflow[and-cuda]" installs NVIDIA's CUDA and cuDNN libraries as pip packages. You still need the NVIDIA driver on the host. The old native-Windows path for TensorFlow 2.10 is the exception: it needs CUDA 11.2 and cuDNN 8.1 from conda-forge.
Why doesn't TensorFlow see my GPU on Windows?
Because TensorFlow 2.10 was the last release with GPU support on native Windows. Newer versions installed directly on Windows run on the CPU. Install TensorFlow inside WSL2, or use the GPU Docker image, to get GPU access.
Does TensorFlow work with AMD or Intel GPUs?
The official pip packages target NVIDIA CUDA GPUs only. On Macs with Apple silicon or AMD graphics, Apple's tensorflow-metal plugin adds GPU acceleration. Native Windows users can try the TensorFlow-DirectML plugin, which the install page lists as optional.
Do I have to change my code to run on the GPU?
No. The TensorFlow GPU guide says TensorFlow code and Keras models run on a single GPU with no code changes. You only add code to control memory, pick a specific GPU, or spread work across several GPUs.
Is TensorFlow free?
Yes. TensorFlow is open source under the Apache 2.0 licence, and so is Keras. The only costs are your own hardware or whatever cloud GPU you rent.
Is tensorflow-gpu still a separate package?
No. The modern tensorflow package handles both CPU and GPU; on Linux you add the [and-cuda] extra to pull in the GPU libraries. If you only want the CPU build, the install page points to tensorflow-cpu.



