DGL on ROCm#

2025-07-21

6 min read time

Applies to Linux

Deep Graph Library (DGL) is an easy-to-use, high-performance and scalable Python package for deep learning on graphs. DGL is framework agnostic, meaning if a deep graph model is a component in an end-to-end application, the rest of the logic is implemented using PyTorch.

For hardware, software, and third-party framework compatibility between ROCm and DGL, see the following resources:

Install DGL#

To install DGL on ROCm, you have the following options:

Use a prebuilt Docker image with DGL pre-installed#

The recommended way to set up a DGL environment and avoid potential installation issues is with Docker. The tested, prebuilt image includes DGL, PyTorch, ROCm, and other dependencies.

Important

To follow these instructions, input your chosen tag into <TAG>. Example: dgl-2.4_rocm6.4_ubuntu24.04_py3.12_pytorch_release_2.6.0.

You can download Docker images for DGL with specific ROCm, PyTorch, Python and operating system versions. See the available tags on Docker Hub and see docker image support below.

  1. Download your required public DGL Docker image

    docker pull rocm/dgl:<TAG>
    
  2. Launch and connect to the Docker container using the image

    docker run -it --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
    --device=/dev/kfd --device=/dev/dri --group-add video \
    --ipc=host --shm-size 8G rocm/dgl:<TAG>
    

    Note

    This will automatically download the image if it does not exist on the host. You can also pass the -v argument to mount any data directories from the host onto the container.

Docker image support#

AMD validates and publishes ready-made DGL Docker images with ROCm backends on Docker Hub. The following Docker image tags and associated inventories are validated for ROCm 6.4.

Build your own Docker image#

  1. Clone the ROCm/dgl repository

    git clone --recurse-submodules https://github.com/ROCm/dgl
    cd dgl
    
  2. Build the Docker container

    To build the Docker container, run the following command:

    # DGL on Ubuntu 22.04 + ROCm 6.4 + Py 3.10 + PyTorch 2.4.1
    docker build \
       -t dgl:dgl-2.4_rocm6.4_ubuntu22.04_py3.10_pytorch_release_2.4.1 \
       --build-arg BASE_IMAGE=rocm/pytorch:rocm6.4_ubuntu22.04_py3.10_pytorch_release_2.4.1 \
       --build-arg ARG_CONDA_ENV=py_3.10 \
       --build-arg ARG_MAX_JOBS=8 \
       --build-arg ARG_GPU_BUILD_TARGETS="gfx90a,gfx942" \
       -f Dockerfile.rocm \
       .
    

    To build the Docker container, run the following command:

    # DGL on Ubuntu 22.04 + ROCm 6.4 + Py 3.10 + PyTorch 2.3.0
    docker build \
       -t dgl:dgl-2.4_rocm6.4_ubuntu22.04_py3.10_pytorch_release_2.3.0 \
       --build-arg BASE_IMAGE=rocm/pytorch:rocm6.4_ubuntu22.04_py3.10_pytorch_release_2.3.0 \
       --build-arg ARG_CONDA_ENV=py_3.10 \
       --build-arg ARG_MAX_JOBS=8 \
       --build-arg ARG_GPU_BUILD_TARGETS="gfx90a,gfx942" \
       -f Dockerfile.rocm \
       .
    

    To build the Docker container, run the following command:

    # DGL on Ubuntu 24.04 + ROCm 6.4 + Py 3.12 + PyTorch 2.4.1
    docker build \
       -t dgl:dgl-2.4_rocm6.4_ubuntu24.04_py3.12_pytorch_release_2.4.1 \
       --build-arg BASE_IMAGE=rocm/pytorch:rocm6.4_ubuntu24.04_py3.12_pytorch_release_2.4.1 \
       --build-arg ARG_CONDA_ENV=py_3.12 \
       --build-arg ARG_MAX_JOBS=8 \
       --build-arg ARG_GPU_BUILD_TARGETS="gfx90a,gfx942" \
       -f Dockerfile.rocm \
       .
    

    To build the Docker container, run the following command:

    # DGL on Ubuntu 24.04 + ROCm 6.4 + Py 3.12 + PyTorch 2.6.0
    docker build \
       -t dgl:dgl-2.4_rocm6.4_ubuntu24.04_py3.12_pytorch_release_2.6.0 \
       --build-arg BASE_IMAGE=rocm/pytorch:rocm6.4_ubuntu24.04_py3.12_pytorch_release_2.6.0 \
       --build-arg ARG_CONDA_ENV=py_3.12 \
       --build-arg ARG_MAX_JOBS=8 \
       --build-arg ARG_GPU_BUILD_TARGETS="gfx90a,gfx942" \
       -f Dockerfile.rocm \
       .
    

Test the DGL installation#

To verify that DGL has been successfully installed, run the Docker container as described in the installing DGL section. Once inside the container, ensure you have access to the Bash shell.

To check for a shared library:

find / -name libdgl.so -print -quit 2>/dev/null && echo "libdgl.so found" || echo "libdgl.so NOT found"

To check for Python import:

conda activate py_<python version> #You can check this with conda info --envs

export DGLBACKEND=pytorch

python -c "import dgl; print('dgl import successful, version:', dgl.__version__)" || echo "Failed to import DGL"

Run a DGL example#

Multiple use cases of DGL have been tested and verified. However, a recommended example follows a drug discovery pipeline using the SE3Transformer. This detailed procedure and steps will be outlined in the AMD ROCm blog, where you can search for DGL examples.

Troubleshooting#

  • Unable to access Docker or GPU in user accounts? Ensure the user is added to docker, video, and render groups. See Configuring permissions for GPU access.

  • Profiling DGL workloads? Use the PyTorch Profiler, as explained in PyTorch Profiler to profile GPU kernels on ROCm.