Repository navigation
Closed
Description
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
- Add Unsloth Docker images (base + Studio) for any NVIDIA GPU host, Ampere through Blackwell #5748 (Add Docker build for Blackwell that runs on any NVIDIA GPU host, branch docker-blackwell-build) added the CUDA side. This is the AMD counterpart: same docker/ layout, same build.sh/run.sh entry points, same smoke-test shape.
- [ROCm] add rocm dockerfile #3324 ([ROCm] add rocm dockerfile by @billishyahao) was an earlier ROCm dockerfile attempt that was closed; there's also the dh/recover-3324-rocm-dockerfile branch. This picks that thread back up with a maintained, CI-published image and the AMD-specific gotchas baked in.
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
Metadata
Metadata
Assignees
Labels
No labels
Activity
LeoBorcherding commentedon Jun 12, 2026
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.
[-]AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/-][+][Feature] AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/+][-][Feature] AMD ROCm Docker support (mirrors the Blackwell image from #5748)[/-][+][Feature] AMD Docker support (mirrors the Blackwell from #5748)[/+]LeoBorcherding commentedon Sep 11, 2026
Resynced this onto current main and built it on an AMD box. #6231 closed itself when
docker-blackwell-buildwas deleted on #5748's merge, and that base branch is gone, so it can't be reopened — the work is now onfeature/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-matchand pypi as a fallback, which compares versions across both indexes. Every ROCm wheel index below 7.2 trails pypi, so pypi wins:torch==2.14.0+ nvidia-cublas / cudnn-cu13 / nccl-cu13torch==2.5.1+rocm6.2torch==2.14.0(same CUDA build)torch==2.9.1+rocm6.4torch==2.14.0+rocm7.2torch==2.14.0+rocm7.2The 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
tritonon Linux, the NVIDIA-targeted pypi wheel, and it installs into the samesite-packages/triton/as torch'striton-rocm. Before the fix: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.shandrun.shwere rewritten by #5748 after this branch was opened, so the--rocmhooks are reimplemented against the current files rather than merged.run.shnow reuses main's numeric--group-addgid 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 --rocmat ROCm 7.2.4 / rocm7.2 wheelsdocker runwith no device flagsrun.sh --rocmend to endThe GPU half is untested and could not be tested here. Docker Desktop's WSL2 backend has no
/dev/kfdand no/dev/dri, only/dev/dxg. The host's own WSL Ubuntu does see the card through DXG because its ROCm shipslibrocdxg.so; therocm/dev-ubuntu-22.04base images don't ship that shim, and mounting the host's copy in still segfaultsrocminfo. No flag combination gets this image onto a GPU under Docker Desktop on Windows. Worth documenting, since the entrypoint currently tells such a user tomodprobe amdgpu.Still needs a real KFD host for: the 5-step LoRA in
smoke_test_rocm.py; whetherrocm-smi --showidon a 7.x image still prints the bracketedGPU[N]the entrypoint greps for; whether the gfx table's RDNA4 rows match whatgcnArchNamereturns; and the wholeDockerfile.studio-rocmpath, which has never been built once. That last one has two problems independent of hardware:ENV SKIP_TORCH=truedoes nothing (install.sh derives it from--no-torch/UNSLOTH_NO_TORCHand sets it false unconditionally), andARG BASE_TAG=testdoesn't match the:latestthatbuild.sh --rocmproduces.