Skip to content

AMD Docker support (stacks on #5748) - #6231

Closed
LeoBorcherding wants to merge 1 commit into
unslothai:docker-blackwell-buildfrom
LeoBorcherding:feature/docker-rocm-support
Closed

LeoBorcherding wants to merge 1 commit into
unslothai:docker-blackwell-buildfrom
LeoBorcherding:feature/docker-rocm-support

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Part of #6230. This is the AMD ROCm counterpart to the Blackwell CUDA docker work in #5748, stacked directly on the docker-blackwell-build branch so the diff is AMD-only.

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). Same docker/ layout, same build.sh / run.sh entry points, same smoke-test shape as the CUDA side.

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.

Diff scope

9 files on top of #5748: 6 net-new rocm files plus the --rocm hooks in build.sh / run.sh / .dockerignore. No changes to the CUDA or Studio files, so the NVIDIA path is untouched.

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.

Base note

Targeting docker-blackwell-build so the diff is AMD-only. Will retarget to main once #5748 merges.

…h workflow)

Adds an AMD ROCm variant alongside the existing CUDA/Blackwell image, wiring
it through the unified build.sh/run.sh (--rocm) entry points.

New:
  docker/Dockerfile.rocm         single-stage ROCm build; ROCm torch wheels +
                                 the bitsandbytes pre-release wheel carrying the
                                 4-bit decode fix (bnb <=0.49.2 NaNs on AMD)
  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-less amd64 build + publish

Changed:
  docker/build.sh, docker/run.sh  --rocm flag selects the ROCm image/flags
  docker/.dockerignore            allowlist the rocm + studio files so the
                                  COPY steps and CI build context resolve
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 078f5e8964

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

RUN mkdir -p "${UNSLOTH_STUDIO_HOME}" \
&& git clone --depth 1 --branch "${UNSLOTH_STUDIO_REF}" https://github.com/unslothai/unsloth "${UNSLOTH_STUDIO_HOME}/src" \
&& cd "${UNSLOTH_STUDIO_HOME}/src" \
&& UNSLOTH_STUDIO_HOME="${UNSLOTH_STUDIO_HOME}" bash install.sh --local \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass the installer’s no-torch flag for Studio

When building the ROCm Studio image, setting SKIP_TORCH=true in the Docker environment does not make install.sh skip torch: the installer initializes SKIP_TORCH=false and only flips it from --no-torch, UNSLOTH_NO_TORCH, or Intel-Mac detection before it calls get_torch_index_url(). In this no-GPU Docker build path, bash install.sh --local therefore still runs the torch auto-detection/install path that the surrounding comments are trying to avoid, which can fail the Studio image build or overwrite the already-installed ROCm torch in the base layer. Pass --no-torch here or set UNSLOTH_NO_TORCH=true for the installer.

Useful? React with 👍 / 👎.

@LeoBorcherding
LeoBorcherding marked this pull request as draft June 12, 2026 05:53
@jaeiclee

jaeiclee commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Strix Halo w/ Arch Linux on 7.0.12-arch1-1:
ROCM_VERSION=7.2.4 TORCH_INDEX_URL=https://download.pytorch.org/whl/rocm7.2 bash docker/build.sh --rocm > bash run.sh --rocm python /workspace/smoke_test_rocm.py

I did see an error during build:

#14 [ 8/14] RUN /opt/unsloth-venv/bin/python - <<'PY'
#14 1.921 OK: torch 2.12.1+rocm7.2  HIP 7.2.53211
#14 1.921   torch          2.12.1+rocm7.2
#14 1.921   bitsandbytes   0.50.0.dev0
#14 1.923   unsloth        2026.6.7
#14 1.923   unsloth-zoo    2026.6.5
#14 1.924   transformers   5.5.0
#14 1.924   trl            0.24.0
#14 1.924   peft           0.19.1
#14 1.925   accelerate     1.14.0
#14 1.925 OK: all required packages present
#14 2.016 Failed to load CPU gemm_4bit_forward from kernels-community: No module named 'kernels'. Please make sure you already `pip install kernels` and the kernels >= 0.11.1
#14 4.678 OK: bitsandbytes 0.50.0.dev0 imports cleanly on no-GPU host
#14 DONE 5.4s

I also had to revise the run.sh a bit to detect the resulting local image (from unsloth/unsloth-rocm:latest to unsloth-rocm:latest),
but in the end the smoke test did run successfully.

Full build log: https://pastebin.com/9FvW3wjY
Full smoke test log: https://pastebin.com/xDHy4xVQ

@LeoBorcherding
LeoBorcherding marked this pull request as ready for review July 7, 2026 01:00
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for putting this together. I built it locally while going through the Docker PRs and the default configuration does not currently build, so flagging it here with the reproduction.

docker build -f docker/Dockerfile.rocm . with the defaults fails at your own HIP assertion:

#14 4.116 AssertionError: Expected a ROCm torch wheel but got: 2.12.1+cu130.
           Check that TORCH_INDEX_URL points to the ROCm index.
ERROR: failed to build ... exit code: 1

The cause is the resolver configuration at docker/Dockerfile.rocm:79-84: --index-strategy unsafe-best-match together with --index-url .../rocm6.2 and --extra-index-url https://pypi.org/simple, on an unpinned torch. unsafe-best-match takes the highest version across every index, and the two indexes are far apart right now:

index newest torch
download.pytorch.org/whl/rocm6.2 2.5.1
pypi.org 2.13.0

So PyPI wins and the build downloads the whole NVIDIA stack into a ROCm image before failing:

#10 0.869 Downloading nvidia-cublas (403.5MiB)
#10 0.869 Downloading nvidia-cudnn-cu13 (349.2MiB)
#10 21.45  + torch==2.13.0

Worth saying: the torch.version.hip is not None guard is the reason this fails loudly at build time instead of shipping a CUDA image labelled ROCm. That guard is doing its job.

The rocm7.2 configuration builds, but only by coincidence. That index is at 2.13.0 and PyPI is also at 2.13.0, and a local version sorts above the same public version under PEP 440, so 2.13.0+rocm7.2 currently wins the tiebreak. The first time PyPI publishes 2.14 before the rocm7.2 index does, that path breaks the same way. Both configurations share one root cause, so pinning the torch version (or dropping the PyPI extra index for the torch install) would fix both at once.

Two smaller things from the same build:

  • The bitsandbytes block is now obsolete. Its own comment says to drop it once bnb 0.50+ ships on PyPI, and 0.50.0 shipped on 2026-07-24, so bitsandbytes>=0.50.0 should replace the rolling CI wheel URL.
  • triton and triton-rocm both end up installed and both own the triton/ package directory, so the ROCm build gets overwritten. The comment at :72-73 describes the opposite.

On sequencing: this stacks on #5748, which has moved since (it picked up a main merge plus a fix for the llama.cpp CUDA backend), and it adds docker/Dockerfile.rocm, which collides directly with #4223. I am planning to land #5748 first, then #4223. It would be easiest to rebase this on top of both once they are in, so the ROCm Dockerfile has a single owner.

@LeoBorcherding LeoBorcherding self-assigned this Jul 31, 2026
@LeoBorcherding LeoBorcherding changed the title AMD ROCm Docker support (stacks on #5748) AMD Docker support (stacks on #5748) Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for keeping this moving. The default rocm6.2 build still resolves torch from PyPI because of the unsafe-best-match plus the PyPI extra index on an unpinned torch, and the bitsandbytes block still points at the continuous-release preview wheel now that 0.50.0 is on PyPI. Could you pin torch, or drop the PyPI extra index for the torch install, and rebase once #5748 and #4223 are in so the ROCm Dockerfile has a single owner?

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.

3 participants