Skip to content

feat(docker): add an AMD ROCm image, for RDNA2 through RDNA4 and CDNA - #10820

Merged
danielhanchen merged 20 commits into
unslothai:mainfrom
LeoBorcherding:feature/docker-rocm-support-v2
Sep 14, 2026
Merged

danielhanchen merged 20 commits into
unslothai:mainfrom
LeoBorcherding:feature/docker-rocm-support-v2

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

adds an AMD ROCm image alongside the CUDA one from #5748. same docker/ layout, same build.sh / run.sh entry points, same smoke-test shape.

this is #6231 resynced. that PR targeted docker-blackwell-build, which was deleted when #5748 merged, so github auto-closed it and won't reopen it. the branch was also 2764 commits behind, and build.sh / run.sh were rewritten underneath it, so the --rocm hooks are reimplemented against the current files rather than merged.

what's here

  • docker/Dockerfile.rocm: ROCm torch wheels plus the bitsandbytes pre-release that carries the 4-bit decode fix. [huggingface] extra, SDPA fallback, since xformers has no ROCm wheel.
  • docker/Dockerfile.studio-rocm: Studio variant on the ROCm base.
  • docker/entrypoint-rocm.sh: preflight for /dev/kfd, rocm-smi, HIP torch, gfx arch.
  • docker/smoke_test_rocm.py: ROCm smoke test with a 5-step LoRA.
  • .github/workflows/docker-publish-rocm.yml: GPU-free amd64 build and publish.
  • build.sh --rocm and run.sh --rocm. run.sh 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.

two things building it turned up

the old default installed a CUDA torch. the torch layer used --index-strategy unsafe-best-match with pypi as a fallback, which compares versions across both indexes. every ROCm wheel index below 7.2 trails pypi, so pypi won:

$ uv pip compile --index-strategy unsafe-best-match \
    --index-url https://download.pytorch.org/whl/rocm6.2 \
    --extra-index-url https://pypi.org/simple
torch==2.14.0
nvidia-cublas==13.1.1.3
nvidia-cudnn-cu13==9.24.0.43
nvidia-nccl-cu13==2.30.7

$ uv pip compile --index-url https://download.pytorch.org/whl/rocm6.2
torch==2.5.1+rocm6.2

rocm6.4 does the same thing (2.14.0 vs 2.9.1+rocm6.4). the build then failed its own assert torch.version.hip is not None. dropped the pypi 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 two tritons in one directory. unsloth-zoo and cut-cross-entropy each declare a bare triton on linux, which is the NVIDIA-targeted pypi wheel, and it installs over torch's triton-rocm in the same site-packages/triton/:

$ python -c "import importlib.metadata as m; print(m.version('triton'), m.version('triton-rocm'))"
3.8.0 3.7.1
$ python -c "import triton; print(triton.__version__)"
3.7.1
$ grep triton-rocm torch-*.dist-info/METADATA
Requires-Dist: triton-rocm==3.7.1; platform_system == "Linux"

neither version describes what's actually on disk. uninstalling the pypi one and reinstalling the pin torch names fixes it:

$ python -c "import importlib.metadata as m; print(m.version('triton-rocm'))"
3.7.1
$ python -c "import triton; print(triton.__version__)"
3.7.1

index selection can't fix this, download.pytorch.org/whl/rocm7.2/triton/ is the pypi wheel mirrored rather than a ROCm build. the durable fix is probably in unsloth-zoo's metadata, where that dependency should be conditional.

hardware and OS coverage

no hosted github runner has an AMD GPU, and the self-hosted Strix Halo runner on ooba's fork is the wrong arch and OS for this, so a green check here says nothing about AMD behaviour. this table is the test report.

measured at 8ee07d6. docker/ is unchanged on main since that commit.

shape changed by this PR what ran still needed
RDNA4 discrete, gfx1201, linux yes, it's the new default build only, on windows a real train on a KFD host
RDNA3 discrete, gfx1100-1102, linux yes, wheel index moved off 6.2 nothing build plus the 5-step LoRA
RDNA2 discrete, gfx1030/1031, linux yes, same nothing build plus the 5-step LoRA, this is the arch most likely to need HSA_OVERRIDE_GFX_VERSION
RDNA3.5 APU, gfx1150/1151 yes, unified memory path untouched but the wheel moved nothing build plus a train, and whether the carve-out reads sanely in a container
CDNA, gfx90a/942 yes, same nothing build plus a train
windows, Docker Desktop no build plus every non-GPU path nothing, see below

where it was run:

machine what it can honestly prove
Radeon AI PRO R9700 (gfx1201), Ryzen 7 8700F, Windows 11 26200, Docker Desktop 4.74, WSL2 backend the image builds and the wheel resolution is right. torch 2.12.1+rocm7.2, HIP 7.2.53211, bitsandbytes 0.50.3.dev0. the entrypoint's refusal path, run.sh --rocm end to end, and 58 existing docker tests. it can prove nothing about a GPU

windows can't test the GPU half of this, and the reason is structural. 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. so no flag combination gets this image onto a GPU there. the entrypoint currently tells such a user to modprobe amdgpu, which is impossible on that host, and that message should say so.

bottom line

solid: the image builds, the wheel resolution is correct on every ROCm index, the triton tree is consistent, and every failure path refuses clearly rather than half-working.

biggest gap: not one line of this has run on a GPU. Dockerfile.studio-rocm has never been built even once, and has two problems that don't need hardware to see. ENV SKIP_TORCH=true does nothing, install.sh derives that from --no-torch / UNSLOTH_NO_TORCH and sets it false unconditionally, so install.sh re-runs torch selection against an absent build-host GPU. and ARG BASE_TAG=test doesn't match the :latest that build.sh --rocm produces. happy to fix both, or drop the Studio image from this PR and do it separately.

closes #6230 when it lands. supersedes #6231.

Reapplies PR unslothai#6231 on top of main. Dockerfile.rocm, Dockerfile.studio-rocm,
entrypoint-rocm.sh, smoke_test_rocm.py, test_locally-rocm.sh and the publish
workflow are unchanged from that branch. build.sh and run.sh were rewritten by
unslothai#5748 after unslothai#6231 was opened, so the --rocm hooks are reimplemented against the
current files instead of merged: run.sh now reuses main's numeric --group-add
gid lookup, and skips the NVIDIA toolkit prompt on the ROCm path.
Two defects found by building the image:

The torch layer used --index-strategy unsafe-best-match with pypi as a
fallback, which compares versions across both indexes. Every ROCm index below
7.2 trails pypi's torch (rocm6.2 tops out at 2.5.1, rocm6.4 at 2.9.1), so the
best match is pypi's CUDA build: the PR's own default of rocm6.2 resolves to a
plain torch==2.14.0 pulling nvidia-cublas and nccl, and then fails the
torch.version.hip assertion. Dropped the fallback and moved the --rocm default
to 7.2.4, which is also the floor for RDNA4.

unsloth-zoo and cut-cross-entropy both declare a bare triton on Linux, the
NVIDIA-targeted pypi wheel. It installs over torch's triton-rocm in the same
site-packages/triton/, leaving triton 3.8.0 by metadata and triton.__version__
3.7.1 in one tree. Uninstall it and reinstall the pin torch names.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T09:28:35.617912Z 870ab1e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

Checked the --rocm hooks in docker/build.sh and docker/run.sh and the existing NVIDIA path stays gated behind the non-ROCm branch, which is the right shape. Since Dockerfile.studio-rocm has not been built and you flagged the SKIP_TORCH and BASE_TAG issues yourself, could you drop it to a follow-up so this lands as the base ROCm image only?

@danielhanchen

Copy link
Copy Markdown
Member

Part of this is not yours. (Python 3.13) and the sidebar failure inside Repo tests (CPU) were hitting every open PR: main has been red since #10706, and the DeepSeek R1 timing assertion was tripping on a real O(N^2) from #10507. Both are fixed in #10832.

Two failures are from this PR's own new files, and both gates are telling you the fix:

tests/studio/install/test_rocm_arch_table_parity.py::TestNoUnregisteredArchTable::test_no_unregistered_copies
  unregistered GPU-name/arch table(s): {'docker/entrypoint-rocm.sh': 7}

tests/studio/test_main_runs_survive_merge_bursts.py::test_every_workflow_that_runs_on_main_is_grouped_per_commit
  ['docker-publish-rocm.yml'] share one concurrency group across main commits
  1. docker/entrypoint-rocm.sh carries a seventh copy of the GPU name to arch table. Wire it into _name_tables() (or the spoof check) and add the path to _REGISTERED_TABLE_FILES, so that when the arch list changes the copies cannot drift apart silently.
  2. docker-publish-rocm.yml needs -${{ github.ref == 'refs/heads/main' && github.sha || '' }} appended to its concurrency group. Without it a merge burst cancels pending runs before they start, and cancel-in-progress does not help since it only spares runs already executing.

Rebase once #10832 is in.

@danielhanchen

Copy link
Copy Markdown
Member

Checked the --rocm hooks in docker/run.sh and docker/build.sh, and the ROCm wheel index change looks right, but this also reshapes the NVIDIA branch of run.sh (GPU_FLAG, the toolkit prompt and the AMD device passthrough inside host_has_nvidia), so could you confirm a plain bash docker/run.sh on an NVIDIA host is unchanged? On your own note about Dockerfile.studio-rocm never having been built with SKIP_TORCH and BASE_TAG wrong, I would rather you drop the Studio image here and land the base ROCm image on its own.

@danielhanchen

Copy link
Copy Markdown
Member

The ROCm base image and the --rocm hooks in docker/run.sh read well, but Dockerfile.studio-rocm has never been built and its ENV SKIP_TORCH=true and ARG BASE_TAG=test do not match what build.sh produces, so could you drop the Studio variant to a follow-up and keep this to the base image? Also, since nothing here has run on a real AMD GPU yet, could you get the 5-step LoRA smoke test through on a KFD host before I review?

…per-arch ROCM_GFX builds, version-aware entrypoint, frozen workflow refs, host-side tests
@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 870ab1e630

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
@danielhanchen
danielhanchen merged commit 28299ac into unslothai:main Sep 14, 2026
11 of 14 checks passed
danielhanchen pushed a commit that referenced this pull request Sep 21, 2026
…CUDA image does (#11286)

The ROCm Studio image from #11218 runs Studio alone, so an AMD user who follows the
Docker quickstart has nowhere to open a notebook. The CUDA core image already carries
JupyterLab, the notebook tooling and the notebooks, which Dockerfile.studio inherits;
the ROCm base carries none of it, so Dockerfile.studio-rocm installs it itself, piece
by piece against the CUDA files, with a suite pinning the two together.

supervisord and studio_launch.sh are not new here: both are already on main driving the
CUDA Studio image, and this points the ROCm image at them rather than adding a second
way to run two services in one container.

An earlier revision also enabled key-only sshd on :22. That rode along with the
notebooks and had no argument of its own, so it was stripped: openssh-server is not
installed, EXPOSE is 8000 8888, and studio_launch.sh's existing `command -v sshd` gate
keeps the shared supervisord program down.

The org Actions queue is 200+ runs deep, so this PR's own checks never reported. Run on
staging instead: 70 passed on ubuntu-latest and on macos-15, and the full repo suite at
8034 + 11465 passed. Eight failures there, seven of which reproduce on a clean
origin/main worktree and one of which pre-commit.ci fixed on the branch. The
windows-latest leg errors on an unguarded os.geteuid() that has been in
tests/python/test_docker_rocm.py since #10820, byte-identical on main; fixed separately
in #11457.

Not verified: the GPU. The author's run went through Docker Desktop's /dev/dxg, where
the torch wheel's bundled HSA runtime has no DXG path, so torch.cuda.is_available() was
False and no notebook in this image has trained.

Closes #11235
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…CUDA image does (unslothai#11286)

The ROCm Studio image from unslothai#11218 runs Studio alone, so an AMD user who follows the
Docker quickstart has nowhere to open a notebook. The CUDA core image already carries
JupyterLab, the notebook tooling and the notebooks, which Dockerfile.studio inherits;
the ROCm base carries none of it, so Dockerfile.studio-rocm installs it itself, piece
by piece against the CUDA files, with a suite pinning the two together.

supervisord and studio_launch.sh are not new here: both are already on main driving the
CUDA Studio image, and this points the ROCm image at them rather than adding a second
way to run two services in one container.

An earlier revision also enabled key-only sshd on :22. That rode along with the
notebooks and had no argument of its own, so it was stripped: openssh-server is not
installed, EXPOSE is 8000 8888, and studio_launch.sh's existing `command -v sshd` gate
keeps the shared supervisord program down.

The org Actions queue is 200+ runs deep, so this PR's own checks never reported. Run on
staging instead: 70 passed on ubuntu-latest and on macos-15, and the full repo suite at
8034 + 11465 passed. Eight failures there, seven of which reproduce on a clean
origin/main worktree and one of which pre-commit.ci fixed on the branch. The
windows-latest leg errors on an unguarded os.geteuid() that has been in
tests/python/test_docker_rocm.py since unslothai#10820, byte-identical on main; fixed separately
in unslothai#11457.

Not verified: the GPU. The author's run went through Docker Desktop's /dev/dxg, where
the torch wheel's bundled HSA runtime has no DXG path, so torch.cuda.is_available() was
False and no notebook in this image has trained.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants