TensorFlow can use CPU and GPU to compute the complex Artificial Intelligence (AI) and Machine Learning (ML) calculations. TensorFlow can use any CUDA-supported NVIDIA GPU to accelerate the AI/ML programs. If you don’t have a CUDA-supported GPU, TensorFlow will use the CPU for AI/ML codes. Without GPU acceleration, the performance of TensorFlow will degrade in complex AI/ML programs.
In this article, we will show you how to install TensorFlow with NVIDIA CUDA/cuDNN acceleration on Debian 12 “Bookworm”.
Topic of Contents:
- Checking If You Have NVIDIA GPU Installed on Your Computer
- Installing Python 3 PIP and Python Venv on Debian 12
- Creating a Python 3 Virtual Environment for TensorFlow
- Upgrading Python 3 PIP on the Python 3 Virtual Environment
- Installing TensorFlow with NVIDIA CUDA Acceleration Support
- Installing TensorRT on Debian 12
- Activating TensorFlow Python 3 Virtual Environment
- Accessing TensorFlow and Checking If NVIDIA GPU/CUDA Acceleration Is Available
- Conclusion
Checking If You Have NVIDIA GPU Installed on Your Computer
For TensorFlow to accelerate the AI programs with NVIDIA GPU/CUDA, you must have the NVIDIA GPU drivers and NVIDIA CUDA and cuDNN installed on your Debian 12 operating system.
If you need any assistance in installing the NVIDIA GPU drivers on your Debian 12 operating system, read this article.
If you need any assistance in installing the NVIDIA CUDA and cuDNN drivers on your Debian 12 operating system, read this article.
Once you have the NVIDIA GPU drivers installed on your Debian 12 system, the “nvidia-smi” command should be available.
The NVIDIA kernel modules should also be loaded on your Debian 12 system.
Once you have the NVIDIA CUDA drivers installed, you should have the “nvcc” command available on your Debian 12 system.
Installing Python 3 PIP and Python Venv on Debian 12
To install TensorFlow on Debian 12, you need to have the Python 3 PIP and Python virtual environment (venv) module installed.
First, update the APT package repository cache with the following command:
To install Python 3 PIP and Python 3 virtual environment (venv), run the following command:
To confirm the installation, press “Y” and then press <Enter>.
Python 3 PIP and Python 3 venv are being installed. It takes a while to complete.
At this point, Python 3 PIP and Python 3 venv should be installed.
Creating a Python 3 Virtual Environment for TensorFlow
The standard practice for installing the Python libraries on Debian 12 is installing them in a Python virtual environment so that they don’t interfere with the system’s Python packages/libraries.
To create a new Python 3 virtual environment for TensorFlow in the “/opt/tensorflow” directory, run the following command:
Upgrading Python 3 PIP on the Python 3 Virtual Environment
To upgrade Python 3 PIP to the latest version on the Python 3 virtual environment “/opt/tensorflow”, run the following command:
Installing TensorFlow with NVIDIA CUDA Acceleration Support
To install TensorFlow with NVIDIA CUDA acceleration support on the Python “/opt/tensorflow” virtual environment, run the following command:
TensorFlow with NVIDIA CUDA acceleration is being installed. It takes a while to complete.
At this point, TensorFlow with NVIDIA CUDA acceleration support should be installed.
Installing TensorRT on Debian 12
NVIDIA TensorRT optimizes the performance of TensorFlow deep learning even more. You can install TensorRT on the TensorFlow Python “/opt/tensorflow” virtual environment with the following command:
NVIDIA TensorRT is being installed on the Python virtual environment. It takes a while to complete.
At this point, NVIDIA TensorRT should be installed.
Activating TensorFlow Python 3 Virtual Environment
To activate the TensorFlow Python “/opt/tensorflow” virtual environment, run the following command:
The TensorFlow Python 3 virtual environment should be activated.
Accessing TensorFlow and Checking If NVIDIA GPU/CUDA Acceleration Is Available
To open the Python 3 interactive shell, run the following command:
Python 3 interactive shell should be opened.
First, import TensorFlow with the following line of code:
Once TensorFlow is imported, you can check the version number of TensorFlow that you installed with the following line of code. As you can see, we have TensorFlow 2.13.1 installed on our Debian 12 system.
To verify that TensorFlow can use the NVIDIA GPU that you installed on your computer for CUDA acceleration, run the following line of code. As you can see, our NVIDIA GPU is accessible from TensorFlow.
To exit out of the Python interactive shell, run the following line of code:
Conclusion
In this article, we showed you how to install the Python 3 PIP and Python 3 virtual environment (venv) on Debian 12. We also showed you how to create a Python 3 virtual environment for TensorFlow on Debian 12 and how to install TensorFlow with NVIDIA GPU/CUDA acceleration support and NVIDIA TensorRT on Debian 12 as well. Finally, we showed you how to activate the TensorFlow Python virtual environment and access TensorFlow on Debian 12.