Skip to content

[Feature] AMD Docker support (mirrors the Blackwell from #5748) #6230

Closed

Description

@LeoBorcherding

What

Adds an AMD ROCm variant of the Docker setup alongside the NVIDIA/Blackwell image, so Unsloth runs in a container on AMD GPUs (RDNA2/3/4 and CDNA/Instinct). It mirrors the structure of the CUDA image so the two stay symmetric. Branch: LeoBorcherding/unsloth@feature/docker-rocm-support

Why / relationship to existing work

What's included

  • docker/Dockerfile.rocm: ROCm torch wheels + the bitsandbytes pre-release wheel that carries the 4-bit decode fix (bnb <= 0.49.2 NaNs at decode on AMD). [huggingface] extra, SDPA fallback (no xformers on ROCm).
  • docker/Dockerfile.studio-rocm: Studio variant layered on the ROCm base.
  • docker/entrypoint-rocm.sh: preflight (/dev/kfd reachable, rocm-smi, HIP torch, gfx-arch check with HSA_OVERRIDE hints).
  • docker/smoke_test_rocm.py: ROCm smoke test incl. a 5-step LoRA train.
  • docker/test_locally-rocm.sh: end-to-end local build + smoke + notebook check.
  • .github/workflows/docker-publish-rocm.yml: GPU-free amd64 build + publish to Docker Hub.
  • build.sh / run.sh gain a --rocm flag; .dockerignore allowlists the new files.

GPU coverage

  • Default build (ROCM_VERSION=6.2.4, torch rocm6.2): RDNA2/RDNA3, CDNA/Instinct.
  • RDNA4 / Strix (gfx1200/1201, gfx1150/1151): ROCM_VERSION=7.2.4 + torch rocm7.2.

Validation so far

  • Base RDNA4 image (ROCM_VERSION=7.2.4, torch rocm7.2) builds cleanly on a GPU-free host, verified end to end at build time: torch 2.12.0+rocm7.2, HIP 7.2.53211, bitsandbytes 0.50.0.dev0 imports cleanly, all required packages present.
  • Static checks pass (shell, python, workflow yaml, .dockerignore COPY coverage).
  • Not yet built: the default rocm6.2 image and the Studio image (Dockerfile.studio-rocm).
  • Pending: the GPU smoke test (5-step LoRA) on real AMD hardware. Needs an AMD GPU runner or a cloud instance; the workflow's self-hosted amd-gpu smoke job can also cover it.
  • Strix image

Activity

  1. LeoBorcherding commented on Jun 12, 2026

    @LeoBorcherding
    CollaboratorAuthor

    the AMD work is now stacked directly on docker-blackwell-build as a companion PR (#6231) so the two can go in together. The diff is AMD-only: 6 new rocm files plus the --rocm hooks in build.sh / run.sh / .dockerignore, with no changes to the CUDA or Studio files. It targets docker-blackwell-build and will retarget to main once #5748 merges.

    The feature/docker-rocm-support branch holds this stacked version.

  2. changed the title [-]AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/-] [+][Feature] AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/+] on Jul 13, 2026
  3. changed the title [-][Feature] AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/-] [+][Feature] AMD Docker support (mirrors the Blackwell from #5748)[/+] on Aug 1, 2026
  4. LeoBorcherding commented on Sep 11, 2026

    @LeoBorcherding
    CollaboratorAuthor

    Resynced this onto current main and built it on an AMD box. #6231 closed itself when docker-blackwell-build was deleted on #5748's merge, and that base branch is gone, so it can't be reopened — the work is now on feature/docker-rocm-support-v2, two commits on main.

    Building it turned up two defects that would have shipped.

    The default build installs a CUDA torch. The torch layer resolved with --index-strategy unsafe-best-match and pypi as a fallback, which compares versions across both indexes. Every ROCm wheel index below 7.2 trails pypi, so pypi wins:

    index with the pypi fallback ROCm index alone
    rocm6.2 (the old default) torch==2.14.0 + nvidia-cublas / cudnn-cu13 / nccl-cu13 torch==2.5.1+rocm6.2
    rocm6.4 torch==2.14.0 (same CUDA build) torch==2.9.1+rocm6.4
    rocm7.2 torch==2.14.0+rocm7.2 torch==2.14.0+rocm7.2

    The build then fails its own assert torch.version.hip is not None. Dropped the fallback, and moved the default to ROCm 7.2.4 — 6.2 tops out at torch 2.5.1, which current unsloth-zoo and transformers won't sit on, and RDNA4 has no kernels before 7.x anyway.

    The image shipped a spliced Triton. unsloth-zoo and cut-cross-entropy each declare a bare triton on Linux, the NVIDIA-targeted pypi wheel, and it installs into the same site-packages/triton/ as torch's triton-rocm. Before the fix:

    triton               3.8.0     <- pypi, by metadata
    triton-rocm          3.7.1     <- what torch pins
    import triton -> __version__ 3.7.1
    

    One directory, two distributions, neither version describing what's on disk. Uninstalling the pypi one and reinstalling the pin torch names gives a consistent triton-rocm 3.7.1. This isn't fixable by index selection: download.pytorch.org/whl/rocm7.2/triton/ is the pypi wheel mirrored, not a ROCm build. The durable fix probably belongs in unsloth-zoo's metadata, where that dependency should be conditional.

    build.sh and run.sh were rewritten by #5748 after this branch was opened, so the --rocm hooks are reimplemented against the current files rather than merged. run.sh now reuses main's numeric --group-add gid lookup instead of passing the group by name, and skips the NVIDIA toolkit prompt on the ROCm path. 58 existing docker tests pass.

    What ran, and where

    Measured at 8ee07d6 on a Radeon AI PRO R9700 (gfx1201, RDNA4), Ryzen 7 8700F, Windows 11, Docker Desktop 4.74 on the WSL2 backend. docker/ is unchanged on main since that commit.

    build.sh --rocm at ROCm 7.2.4 / rocm7.2 wheels builds clean: torch 2.12.1+rocm7.2, HIP 7.2.53211, bitsandbytes 0.50.3.dev0
    docker run with no device flags entrypoint refuses, exit 1, message is clear
    run.sh --rocm end to end warns, launches, entrypoint refuses. Correct behaviour
    58 docker tests pass

    The GPU half is untested and could not be tested here. Docker Desktop's WSL2 backend has no /dev/kfd and no /dev/dri, only /dev/dxg. The host's own WSL Ubuntu does see the card through DXG because its ROCm ships librocdxg.so; the rocm/dev-ubuntu-22.04 base images don't ship that shim, and mounting the host's copy in still segfaults rocminfo. No flag combination gets this image onto a GPU under Docker Desktop on Windows. Worth documenting, since the entrypoint currently tells such a user to modprobe amdgpu.

    Still needs a real KFD host for: the 5-step LoRA in smoke_test_rocm.py; whether rocm-smi --showid on a 7.x image still prints the bracketed GPU[N] the entrypoint greps for; whether the gfx table's RDNA4 rows match what gcnArchName returns; and the whole Dockerfile.studio-rocm path, which has never been built once. That last one has two problems independent of hardware: ENV SKIP_TORCH=true does nothing (install.sh derives it from --no-torch / UNSLOTH_NO_TORCH and sets it false unconditionally), and ARG BASE_TAG=test doesn't match the :latest that build.sh --rocm produces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions