Test whether your current environment already supports:
import tensorflow as tf
if tf.test.gpu_device_name():
print(f"Default GPU device: {
tf.test.gpu_device_name()}")
else:
print("GPU device not found. Please check your settings.")
If the GPU is properly configured, there will be:
Default GPU device: /device:GPU:0
Install TensorFlow using pip
Note: TensorFlow 2.10 is the last TensorFlow release. Supported GPUs on native Windows. Starting with TensorFlow 2.11, you need to install TensorFlow in WSL2, or install TensorFlow-cpu
The default has been followed: Miniconda
Create a new conda environment
conda create --name tfGPU python=3.9
GPU installation
First install the NVIDIA GPU driver,
Then install CUDA, cuDNN with conda
conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0
Install TensorFlow
First upgrade the latest pip
pip install --upgrade pip
TensorFlow 2.10 is the last TensorFlow release. Supported GPUs on native Windows.
So install a version prior to 2.11
pip install "tensorflow<2.11"
Verify TensorFlow CPU installation
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Output tensor tensor data, it is installed.
Verify TensorFlow GPU installation
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"