TensorFlow GPU

raw JSON →
2.12.0 verified Fri May 01 auth: no python deprecated

DEPRECATED – You should install 'tensorflow' instead. Since TensorFlow 2.11, the GPU support is built into the main tensorflow package for Windows and Linux. The tensorflow-gpu package on PyPI is now a dummy package that simply installs tensorflow. It was removed entirely as of version 2.12.0. Previous breaking changes include Python 3.6 support dropped in 2.1.0 and the legacy TF 1.x API removal in 2.0.

pip install tensorflow
error ModuleNotFoundError: No module named 'tensorflow-gpu'
cause The tensorflow-gpu package has been removed from PyPI since version 2.12.0.
fix
Use 'import tensorflow' after installing 'tensorflow' (pip install tensorflow).
error ImportError: cannot import name 'is_gpu_available' from 'tensorflow.python.client'
cause tf.test.is_gpu_available() was removed in TensorFlow 2.11.
fix
Use tf.config.list_physical_devices('GPU') to check GPU availability.
error RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
cause Legacy TF 1.x code using tf.Session() in TF 2.x with disabled v1 compatibility.
fix
Enable TF 2.x behavior by default or rewrite using Keras API. Use tf.compat.v1 to retain v1 compatibility if necessary.
deprecated tensorflow-gpu is no longer a separate package. Install 'tensorflow' for both CPU and GPU support.
fix Run 'pip uninstall tensorflow-gpu' and 'pip install tensorflow'.
breaking Python 3.6 support was dropped in TensorFlow 2.1.0.
fix Use Python 3.7 or later.
breaking TensorFlow 2.0 removed legacy TF 1.x API (tf.Session, tf.Graph, etc.)
fix Migrate code to use eager execution and Keras API. See official migration guide.
gotcha CUDA and cuDNN version mismatches cause runtime errors. TensorFlow requires specific versions.
fix Check official compatibility matrix at tensorflow.org/install/source#gpu
pip install tensorflow-gpu==2.11.0

Basic GPU check and matrix multiplication.

import tensorflow as tf
import os

# Check GPU availability
physical_devices = tf.config.list_physical_devices('GPU')
if len(physical_devices) > 0:
    print("GPU available:", physical_devices)
else:
    print("No GPU found.")

# Simple matrix multiplication
import numpy as np
a = tf.constant(np.random.rand(1000, 1000))
b = tf.constant(np.random.rand(1000, 1000))
c = tf.matmul(a, b)
print("Result shape:", c.shape)