Install TensorFlow for ROCm#
This page guides you through installing TensorFlow with ROCm support on AMD hardware running Linux. It applies to supported AMD GPUs and platforms.
Prerequisites#
Ensure your system has the AMD GPU Driver (amdgpu) installed. See the ROCm compatibility matrix for driver support information. For installation instructions, see the AMD GPU Driver documentation.
Ensure your system has the AMD GPU Driver (amdgpu) installed. See the ROCm compatibility matrix for driver support information. For installation instructions, see the AMD GPU Driver documentation.
Ensure your system has the AMD GPU Driver (amdgpu) installed. See the ROCm compatibility matrix for driver support information. For installation instructions, see the AMD GPU Driver documentation.
Ensure your system has the AMD GPU Driver (amdgpu) installed. See the ROCm compatibility matrix for driver support information. For installation instructions, see the AMD GPU Driver documentation.
Ensure the host system has Docker Engine installed. For more guidance on running ROCm workloads in Docker containers, see Run ROCm Docker containers.
Install ROCm 10.2.0.
Install ROCm 10.1.0.
Install ROCm 10.0.0.
Install ROCm 7.14.1.
Ensure your system has a supported Python version installed and accessible: 3.12
Get started#
Pull the ROCm TensorFlow 2.21 Docker image.
docker pull rocm/tensorflow:rocm10.2-ubuntu24.04-py3.12-tf2.21
Pull the ROCm TensorFlow 2.20 Docker image.
docker pull rocm/tensorflow:rocm10.2-ubuntu24.04-py3.12-tf2.20
Start the Docker container.
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.2-ubuntu24.04-py3.12-tf2.21 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.2-ubuntu24.04-py3.12-tf2.20 \ bash
Get started#
Pull the ROCm TensorFlow 2.21 Docker image.
docker pull rocm/tensorflow:rocm10.1-ubuntu24.04-py3.12-tf2.21
docker pull rocm/tensorflow:rocm10.1-ubuntu22.04-py3.12-tf2.21
Pull the ROCm TensorFlow 2.20 Docker image.
docker pull rocm/tensorflow:rocm10.1-ubuntu24.04-py3.12-tf2.20
docker pull rocm/tensorflow:rocm10.1-ubuntu22.04-py3.12-tf2.20
Start the Docker container.
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.1-ubuntu24.04-py3.12-tf2.21 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.1-ubuntu22.04-py3.12-tf2.21 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.1-ubuntu24.04-py3.12-tf2.20 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.1-ubuntu22.04-py3.12-tf2.20 \ bash
Get started#
Pull the ROCm TensorFlow 2.21 Docker image.
docker pull rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.21
Pull the ROCm TensorFlow 2.20 Docker image.
docker pull rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.20
Pull the ROCm TensorFlow 2.19.1 Docker image.
docker pull rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.19.1
docker pull rocm/tensorflow:rocm10.0-ubuntu22.04-py3.12-tf2.19.1
Start the Docker container.
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.21 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.20 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.0-ubuntu24.04-py3.12-tf2.19.1 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm10.0-ubuntu22.04-py3.12-tf2.19.1 \ bash
Get started#
Pull the ROCm TensorFlow 2.21 Docker image.
docker pull rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.21
Pull the ROCm TensorFlow 2.20 Docker image.
docker pull rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.20
Pull the ROCm TensorFlow 2.19.1 Docker image.
docker pull rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.19.1
docker pull rocm/tensorflow:rocm7.14.1-ubuntu22.04-py3.12-tf2.19.1
Start the Docker container.
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.21 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.20 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm7.14.1-ubuntu24.04-py3.12-tf2.19.1 \ bash
docker run -it --rm \ --device /dev/kfd \ --device /dev/dri \ --network=host \ --ipc=host \ --group-add=video \ --cap-add=SYS_PTRACE \ --security-opt seccomp=unconfined \ rocm/tensorflow:rocm7.14.1-ubuntu22.04-py3.12-tf2.19.1 \ bash
Install TensorFlow using pip#
Set up and activate your Python virtual environment.
python3.12 -m venv .venv source .venv/bin/activate
If you don’t have an existing ROCm 10.2.0 installation, install it following the ROCm 10.2.0 installation instructions; on that page, select your installation environment and method.
Important
If you installed ROCm 10.2.0 using
pip, TensorFlow might be unable to find ROCm’s shared libraries. UpdateLD_LIBRARY_PATHas a workaround so TensorFlow can discover ROCm libraries and system dependencies.export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
Install the ROCm-enabled TensorFlow libraries.
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.21.0+rocm10.2.0"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.20.0+rocm10.2.0"
Verify your TensorFlow installation.
python -c "from packaging.version import Version; import tensorflow as tf; print('TensorFlow:', Version(tf.__version__).base_version); print('Built with ROCm:', tf.test.is_built_with_rocm()); print('Devices:', tf.config.list_physical_devices('GPU'))"
You should see output similar to the following with at least one GPU listed:
TensorFlow: 2.21.0 Built with ROCm: True Devices: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
TensorFlow: 2.20.0 Built with ROCm: True Devices: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
Install TensorFlow using pip#
Set up and activate your Python virtual environment.
python3.12 -m venv .venv source .venv/bin/activate
If you don’t have an existing ROCm 10.1.0 installation, install it following the ROCm 10.1.0 installation instructions; on that page, select your installation environment and method.
Important
If you installed ROCm 10.1.0 using
pip, TensorFlow might be unable to find ROCm’s shared libraries. UpdateLD_LIBRARY_PATHas a workaround so TensorFlow can discover ROCm libraries and system dependencies.export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
Install the ROCm-enabled TensorFlow libraries.
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.21.0+rocm10.1.0"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.20.0+rocm10.1.0"
If you installed ROCm using pip, update
LD_LIBRARY_PATHas a workaround so TensorFlow can discover ROCm libraries and system dependencies.export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
Verify your TensorFlow installation.
python -c "import tensorflow as tf; print('Built with ROCm:', tf.test.is_built_with_rocm()); print('Visible GPUs:', tf.config.list_physical_devices('GPU'))"
Install TensorFlow using pip#
Set up and activate your Python virtual environment.
python3.12 -m venv .venv source .venv/bin/activate
If you don’t have an existing ROCm 10.0.0 installation, install it following the ROCm 10.0.0 installation instructions; on that page, select your installation environment and method.
Important
If you installed ROCm 10.0.0 using
pip, TensorFlow might be unable to find ROCm’s shared libraries. UpdateLD_LIBRARY_PATHas a workaround so TensorFlow can discover ROCm libraries and system dependencies.export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
Install the ROCm-enabled TensorFlow libraries.
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.21.0+rocm10.0.0"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.20.0+rocm10.0.0"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.19.1+rocm10.0.0"
Verify your TensorFlow installation.
python -c "import tensorflow as tf; print('Built with ROCm:', tf.test.is_built_with_rocm()); print('Visible GPUs:', tf.config.list_physical_devices('GPU'))"
Install TensorFlow using pip#
Set up and activate your Python virtual environment.
python3.12 -m venv .venv source .venv/bin/activate
If you don’t have an existing ROCm 7.14.1 installation, you can install ROCm using pip as follows. See the ROCm 7.14.1 installation instructions for complete guidance and other ROCm installation methods. Otherwise, proceed to installing TensorFlow packages.
python -m pip install --index-url https://repo.amd.com/rocm/whl-multi-arch/ \ "rocm[libraries,device-gfx950]==7.14.1"
python -m pip install --index-url https://repo.amd.com/rocm/whl-multi-arch/ \ "rocm[libraries,device-gfx942]==7.14.1"
python -m pip install --index-url https://repo.amd.com/rocm/whl-multi-arch/ \ "rocm[libraries,device-gfx90a]==7.14.1"
Install the ROCm-enabled TensorFlow libraries.
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.21.0+rocm7.14.1"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.20.0+rocm7.14.1"
python -m pip install --extra-index-url https://rocm.frameworks.amd.com/whl-multi-arch/ \ "tensorflow-rocm==2.19.1+rocm7.14.1"
Update
LD_LIBRARY_PATHas a workaround so TensorFlow can discover ROCm libraries and system dependencies.export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
If ROCm was installed using a different method, update this path to point to your actual ROCm installation location.
Verify your TensorFlow installation.
python -c "import tensorflow as tf; print('Built with ROCm:', tf.test.is_built_with_rocm()); print('Visible GPUs:', tf.config.list_physical_devices('GPU'))"
Known issues#
If you installed ROCm using pip, attempting to run TensorFlow can result in
multiple ImportErrors because TensorFlow can’t find ROCm’s shared
libraries.
As a workaround, update LD_LIBRARY_PATH to link to the required ROCm
libraries and system dependencies in your installation path:
export LD_LIBRARY_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_core/lib/rocm_sysdeps/lib:$VIRTUAL_ENV/lib/python3.12/site-packages/_rocm_sdk_libraries/lib:$LD_LIBRARY_PATH
If ROCm was installed using a different method, update this path to point to your actual ROCm installation location.