Repository navigation
[ROCm] add rocm dockerfile - #4223
danielhanchen wants to merge 15 commits into
Conversation
(cherry picked from commit 6d6ab6b)
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a dedicated Dockerfile to streamline the setup of a development environment for ROCm-enabled Instinct mi30x GPUs. Its primary goal is to simplify the process of getting started with Unsloth and BitsAndBytes on the ROCm platform, thereby improving the overall user experience for developers targeting these specific hardware configurations. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a Dockerfile for ROCm. The review identifies a few areas for improvement. There is a critical issue with a likely typo in a future date in the base image tag, which will probably cause the build to fail. Additionally, there are several suggestions to optimize the Dockerfile for smaller image size and faster builds by combining RUN instructions for apt and pip commands, and using a more efficient method to clone a specific git commit. These changes follow Docker best practices.
This comment was marked as low quality.
This comment was marked as low quality.
Combine apt-get update/install into one RUN with --no-install-recommends and list cleanup (a cached standalone update layer goes stale for later installs), fetch only the pinned bitsandbytes commit instead of cloning the default branch first, and fold the three pip verification probes into a single layer.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: abfe2b680c
ℹ️ 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".
…OCm image Two review items, both reproduced before fixing. The pinned bitsandbytes commit (0.48.0.dev0, 2025-09-15) predates bnb PR 1887, which enabled the 4-bit GEMV kernels on AMD CDNA; every build at or below 0.49.2 NaNs at the GEMV decode shape on AMD GPUs, the exact floor install.sh already enforces for its ROCm wheel. BNB_COMMIT now defaults to the PR 1887 merge commit (0.50.0.dev0), which carries the fix. The unsloth install used bare pip install -e ., which pulls only the CLI dependencies (typer, rich, pydantic, pyyaml, nest-asyncio); the pip show probe passed on metadata alone while transformers, trl, peft, datasets, and accelerate were all absent, so the image built green but could not train. It now installs the huggingfacenotorch extra, which delivers the full HF training stack without torch or torchvision so the ROCm torch in the vLLM base image is never clobbered by a PyPI CPU/CUDA build.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Main moved the llama_extra_args pass-through inheritance out of the GGUF branch into _resolve_inherited_extra_args, which runs before it, so the source-order assertion's "if request.llama_extra_args is None" anchor no longer exists inside the branch and the check failed after the main merge. The test now asserts the same property in the current shape: inheritance before the GGUF branch (a carried --no-mmproj still shapes the hub guard's companion requirement), and marker, hub guard, unload in order within the branch. Full file passes (32 tests).
…tion
source.index("_resolve_inherited_extra_args(") matched the function
definition, which always precedes the endpoint, so the ordering
assertion was vacuously true. Anchoring on "= _resolve_inherited_
extra_args(" pins the first call site inside the load endpoint (line
4505), which is the statement whose position relative to the GGUF
branch the test is meant to guard. 32 tests pass.
Main fixed the stale ordering assertion in PR 7252; adopting its version verbatim removes this file from the branch diff entirely and avoids a conflict on the next main merge. 32 tests pass.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c6fb65fa1
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…dockerfile One conflict: studio/backend/tests/test_gguf_load_cache_reuse.py. Took main's assertion, which anchors on the _resolve_inherited_extra_args call site. This branch does not touch studio/backend/routes/inference.py, so the merged source is main's, and that is the landmark it now carries.
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Drop the commented-out GPU_ARCH arg, the shallow-fetch note, and the install verification banner, and fold the huggingfacenotorch note onto one line. The bitsandbytes commit pin note stays: it records the upstream 4-bit GEMV NaN behaviour on AMD. No build instruction changed.
…le to fail The image did not build. bitsandbytes pins scikit-build-core unbounded in build-system.requires, so the builder always resolves the newest release. 1.0.0 (2026-07-06) added a PEP 660 gate to the setuptools plugin backend that bitsandbytes uses, rejecting editable installs unless pyproject sets editable.mode = "inplace". The pin here is from March and predates upstream adding that line, so pip install -e . dies in prepare_metadata_for_build_editable with "setuptools editable installs require editable.mode = 'inplace'". Verified by version bisection in the image: 0.11.6 and 0.12.2 install cleanly, 1.0.0, 1.0.1 and 1.0.3 all fail. Install non-editable instead. Upstream's own install docs annotate the -e as being for bitsandbytes development and say to leave it out otherwise, and an editable checkout buys nothing in an image while tying the build to a scikit-build-core knob that keeps moving. CMakeLists writes the library straight into the package dir, so setuptools package-data ships exactly what cmake built: the installed libbitsandbytes_rocm64.so is md5 identical to the compiled one and its .hip_fatbin still holds a single gfx942 bundle. The verification step could not fail. pip show passes on dist-info alone, so a missing or unloadable HIP library left it green on precisely the broken image it exists to catch. Load the artifacts instead. bitsandbytes cannot self-report here: with no AMD GPU on the builder get_cuda_specs returns None, it loads libbitsandbytes_cpu.so and hands back a healthy BNBNativeLibrary even after the ROCm library is deleted, so the check globs for libbitsandbytes_rocm*.so beside the installed package and ctypes.CDLL loads it. unsloth_zoo raises NotImplementedError on import without a torch accelerator, so it and unsloth are resolved with importlib.util.find_spec rather than executed. Deleting the library now fails the check; the intact image passes. The amdgpu-arch warning at configure time is benign and left alone. It comes from hip-config-amd.cmake, pulled in by find_package(hipblas), and only governs --offload-arch on the hip::device interface for CXX sources. bitsandbytes links hip::host and compiles its kernels as HIP, taking the arch from CMAKE_HIP_ARCHITECTURES, which BNB_ROCM_ARCH sets before enable_language(HIP). The built library contains gfx942 and no gfx906.
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Checked docker/Dockerfile.rocm against main, which has no docker build path today, and the bitsandbytes pin now sits on the 0.50.0.dev0 commit that fixes 4-bit GEMV decode on CDNA. Will get this reviewed. @LeoBorcherding could you take a look at this one? |
Drop the self-explanatory note on the apt layer and collapse the bitsandbytes install and final verification blocks to one line each where they still read clearly. The reasons behind the pinned commit, the plain (non-editable) install, the huggingfacenotorch extra and the limits of the verification layer are kept. No instruction changes.
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Closing this rather than merging it. The Dockerfile itself is sound and was driven to convergence, but the image is not something we are set up to stand behind. Nothing in CI builds it, so it would go stale silently. The base is a dated ROCm nightly pinned to a single day rather than a stable release. The default Carrying an unbuilt, unexercised image that claims MI300 support is worse than not shipping one, so it is better to close this until there is a maintained ROCm lane to attach it to. The work is preserved here and in #3324 if we pick this up again. Thanks for the original contribution. |
Replacement for #3324 due to Studio rebasing.
Summary
Adds one new file,
docker/Dockerfile.rocm, for running Unsloth on AMD Instinct MI300 series hardware. Nothing else in the repository changes: the diff isdocker/Dockerfile.rocm, +69/-0.The image layers on top of a ROCm vLLM base, builds bitsandbytes from source against HIP for
gfx942, installs Unsloth and unsloth_zoo from git without disturbing the base image's ROCm PyTorch, and ends with a build-time check that fails the build if the ROCm bitsandbytes library did not actually get compiled and cannot be loaded.Build it with:
What the image does
Base.
rocm/vllm-dev:nightly_main_20250914, overridable through theBASE_DOCKERbuild arg. The working directory is/unsloth-workspace. System packages (zip,unzip,wget,build-essential,cmake) are installed in a singleRUNso the apt index cannot go stale between the update and the install, with/var/lib/apt/listsremoved in the same layer.bitsandbytes, built from source for HIP. Configured with
-DCOMPUTE_BACKEND=hipand-DBNB_ROCM_ARCH=gfx942, thencmake --build -j"$(nproc)", then installed. The source is pinned to commit713a3b83e405d32449e1cb392e5e25985ab927c6, which is the merge commit of bitsandbytes-foundation/bitsandbytes#1887, "[ROCm] Enable blocksize 32 4-bit quantization and GEMV kernels on AMD CDNA". That PR is the floor: builds from before it are wrong at 4-bit GEMV decode on CDNA, where the wavefront size is 64. The checkout is a shallowgit initplusfetch --depth 1 <commit>rather than a full clone, and.gitandbuild/are both removed in the same layer.bitsandbytes is installed plainly rather than with
-e, and the Dockerfile says why inline: upstream reserves editable installs for bitsandbytes development, and scikit-build-core 1.0.0 rejects an editable install unlesspyproject.tomlopts intoeditable.mode = "inplace", which this pin predates. cmake has already placed the.sointo the package directory by that point, so setuptools package-data ships it as a built artifact.Unsloth and unsloth_zoo. Both are shallow-cloned by branch and installed editable. Unsloth uses the
[huggingfacenotorch]extra specifically, not a bare-e ., because that extra omitstorchandtorchvisionand so leaves the base image's ROCm PyTorch in place. A bare-e .would pull a CUDA PyTorch over the top and the image could not train. Note that[huggingfacenotorch]does declareunsloth_zoo, so a PyPI unsloth_zoo is installed first and is then superseded by the editable clone in the following layer.Build args.
BASE_DOCKER,COMPUTE_BACKEND,BNB_ROCM_ARCHS,BNB_COMMIT,BNB_REPO,UNSLOTH_REPO,UNSLOTH_BRANCH,UNSLOTH_ZOO_REPO,UNSLOTH_ZOO_BRANCH. Retargeting another CDNA part is--build-arg BNB_ROCM_ARCHS=<arch>.The verification layer
The final
RUNis the part worth reviewing. It is a real guard, and it exists because the two obvious ways of checking both return green on a broken image:pip showreadsdist-infoonly. It stayed green on an image whose freshly compiled HIP library was missing entirely.libbitsandbytes_cpu.soand reports success.So the check goes at the library directly. It asserts that at least one
libbitsandbytes_rocm*.soexists in the installed package directory, thenctypes.CDLLs everylibbitsandbytes*.soit finds there, so a library that is present but unloadable is also caught. For Unsloth and unsloth_zoo it usesimportlib.util.find_specrather than importing them, because unsloth_zoo refuses to import without a torch accelerator and there is no AMD GPU on the builder.The known gap is documented in the file rather than papered over: a build for the wrong architecture still loads fine at this point and only fails once a 4-bit GEMV runs on real AMD silicon.
ctypes.CDLLresolves the library, it does not validate the code objects inside it against the target.Scope and limits
gfx942, which covers MI300A, MI300X and MI325X. CDNA4 parts (MI350X, MI355X,gfx950) needBNB_ROCM_ARCHSoverridden and are not otherwise exercised here.Attribution
Original work by @billishyahao in #3324. That PR was closed because of a Studio rebase; this branch carries the same contribution forward, plus the bitsandbytes commit pin, the
[huggingfacenotorch]install and the verification layer described above.