Skip to content

amd: require bitsandbytes>=0.50.0 in the amd extra (fixes ROCm 4-bit NaNs) - #7535

Merged
danielhanchen merged 13 commits into
mainfrom
fix/main-amd-bnb-floor
Jul 29, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
fix/main-amd-bnb-floor

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

What

Bump the amd extra's bitsandbytes floor from >=0.49.1 to >=0.50.0, on both marker lines. One file, +4/-2.

Why

bnb <=0.49.2 NaNs at decode shape on every AMD GPU. The ROCm 4-bit GEMV fix (bnb PR #1887) merged after 0.49.2 and first ships in 0.50.0, on PyPI since 2026-07-24, so the old floor could still resolve the broken range. A pip install 'unsloth[amd]' from a main checkout succeeds and silently corrupts 4-bit generation and training output on Linux ROCm.

#7278 made this change on the pip release branch. This is the same change on main, so the development branch stops shipping the broken floor and the two branches agree.

What inherits it

Five ROCm extras pull unsloth[amd] and carry no bnb spec of their own, so they pick up the new floor: rocm702-torch280, rocm72-torch291, rocm711-torch291, rocm72-torch2100, rocm711-torch2100. That propagation is intended.

Nothing else moves. The other bnb pins on main (bitsandbytes==0.45.5, >=0.45.5,!=0.46.0,!=0.48.0) belong to CUDA-era extras like cu118-torch211, and the URL-pinned continuous-release wheels belong to the intelgpu* extras, which inherit huggingfacenotorch rather than amd. I checked for a URL-versus-specifier conflict on the same package and there is none.

Why a version floor rather than a URL pin

main can carry direct URL requirements, and the intelgpu* extras do. I used a floor anyway: it matches what pip must do (PyPI rejects direct URLs in uploaded metadata), it avoids depending on a rolling continuous-release_main artifact, and PyPI 0.50.0 now ships the ROCm binaries the markers select — libbitsandbytes_rocm{64,70,71,714,72}.so on manylinux x86_64 and libbitsandbytes_rocm{72,714}.dll on win_amd64. Keeping the two branches identical also means the extras can be diffed for drift, which is how the pip branch's missing extra went unnoticed for weeks.

Verification

Built the metadata from this branch and read it: the amd extra emits bitsandbytes>=0.50.0 on both marker lines and no 0.49.x bitsandbytes requirement survives anywhere.

Runtime evidence carries over from #7278 — bnb 0.50.0 on ROCm torch 2.11.0+rocm7.13.0, Radeon RX 9060 XT (gfx1200), NF4 and FP4, compress_statistics on and off, batches 1/2/8/64. All 16 combinations produced finite output, relative error against an fp16 reference 0.090-0.096 (nf4) and 0.111-0.112 (fp4), with batch=1 in line with every other batch size.

Known limitation, unchanged by this PR

The Linux marker includes aarch64, but bitsandbytes ships no ROCm binary in its aarch64 wheel at any version — 0.50.0 and the continuous-release build both carry only libbitsandbytes_cpu.so plus CUDA variants. So the extra installs on aarch64 and yields a bnb with no AMD backend. That predates this change and is identical on pip; worth trimming, but not here, since diverging the marker would break parity with #7278.

Follow-up in this PR (installer fallback floors)

Codex was right that raising the extra alone left the two AMD installer fallback paths on the old floor, so the pre-release wheel URL being unreachable would still resolve into the broken range. Both are now >=0.50.0:

  • install.sh _install_bnb_rocm PyPI fallback
  • _BNB_ROCM_PYPI_FALLBACK in studio/install_python_stack.py, which is the path Studio and both PowerShell installers use (install.ps1 and studio/setup.ps1 carry no bitsandbytes spec of their own, they delegate to the stack script)

Checked that the floor is real rather than nominal: the PyPI 0.50.0 manylinux_2_24_x86_64 wheel ships libbitsandbytes_rocm{64,70,71,714,72}.so and the win_amd64 wheel ships libbitsandbytes_rocm{714,72}.dll, the same ROCm set as the continuous-release wheel. bnb #1887 merged 2026-03-09, after 0.49.2 (2026-02-16) and before 0.50.0 (2026-07-24).

TestAmdBnbFloorParity in tests/python/test_cross_platform_parity.py now holds the amd extra, the install.sh fallback and the Studio fallback to one floor, and asserts no installer floors bitsandbytes in the 0.49.x range.

Two comments were stale and are corrected: they told the reader to drop the pre-release pin once bnb 0.50 shipped on PyPI, which has now happened, and they hardcoded the pre-release wheel's metadata version as 0.50.0.dev0 when the rolling artifact now reports 0.50.1.dev0.

The same change on the pip branch is #7581.

The aarch64 limitation noted above is worth restating with evidence: the continuous-release aarch64 wheel contains no libbitsandbytes_rocm*.so either, only cpu and cuda variants, so that install succeeds and the PyPI fallback never fires. Unchanged by this PR, but it means aarch64 in the amd extra marker promises a 4-bit path that does not exist at any bitsandbytes version.

bnb <= 0.49.2 NaNs at decode shape on every AMD GPU. The ROCm 4-bit GEMV
fix (bnb PR #1887) first ships in 0.50.0, on PyPI since 2026-07-24, so the
old >=0.49.1 floor could still resolve the broken range.

Mirrors the same change made on the pip release branch in #7278.
The comment credited bnb PR #1887 as "the ROCm 4-bit GEMV fix" for every
AMD GPU. #1887 decouples blocksize from warp size and fixes a hardcoded
warp size of 32 in kgemm_4bit_inference_naive, which is a CDNA problem by
construction. The RDNA-side work is #1979 (fused 4-bit SIMT GEMM) and
#2012 (RDNA3/4 workgroup resonance). All three first ship in 0.50.0, so
the >=0.50.0 floor is unchanged; only the justification was wrong.
@LeoBorcherding

LeoBorcherding commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Correcting a comment, not the floor. bitsandbytes>=0.50.0 is unchanged and still right.

The comment credited bitsandbytes#1887 as "the ROCm 4-bit GEMV fix" that makes bnb <=0.49.2 NaN "on every AMD GPU". Reading bitsandbytes#1887 rather than the changelog line: it decouples blocksize from warp size and fixes a hardcoded warp size of 32 in kgemm_4bit_inference_naive. A hardcoded 32 is wrong on CDNA (warp=64) and correct on RDNA (warp=32), so that half is CDNA-specific; its title says CDNA too. The RDNA-side work in the same release is bitsandbytes#1979, the fused 4-bit SIMT GEMM validated on gfx1100/gfx1201/gfx1151, and bitsandbytes#2012, the RDNA3/RDNA4 workgroup-count fix.

All three land in 0.50.0 and none are in 0.49.2, so the floor holds either way — 0.50.0 remains the first PyPI release with the complete ROCm 4-bit path. My gfx1200 run was exercising bitsandbytes#1979 and bitsandbytes#2012, not bitsandbytes#1887.

I should also be straight that I never verified the "every AMD GPU" part. I confirmed 0.50.0 works on gfx1200; I never ran 0.49.2 to watch it fail. That phrasing came from install_python_stack.py:391-393 and I repeated it. The new comment states what's checkable and no more.

The original phrasing still lives in install.sh:260-263 and install_python_stack.py:391-393. Those go in the installer PR that drops the continuous-release_main pin.

On sourcing, since bare numbers were the wrong way to cite this: all three are AMD's own ROCm work in bitsandbytes, authored by sstamenk, and the 0.50.0 release notes say it plainly: "Stability and performance improvements bring AMD ROCm support out of preview; it is now considered stable." That page is the citation I should have led with.

Edited: the bnb references above were bare #NNNN, which GitHub autolinked to unrelated unslothai/unsloth issues rather than the bitsandbytes PRs. Now full URLs.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 3c18196304

ℹ️ 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".

Comment thread pyproject.toml
Comment on lines +1230 to +1231
"bitsandbytes>=0.50.0 ; ('linux' in sys_platform) and (platform_machine == 'AMD64' or platform_machine == 'x86_64' or platform_machine == 'aarch64')",
"bitsandbytes>=0.50.0 ; (sys_platform == 'win32') and (platform_machine == 'AMD64' or platform_machine == 'x86_64')",

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 Update the AMD installer fallback floor too

This only raises the floor for the amd extra, but the AMD installer fallback paths still allow the broken range: install.sh falls back to bitsandbytes>=0.49.1 and Studio uses _BNB_ROCM_PYPI_FALLBACK = "bitsandbytes>=0.49.1" (install.sh:351-352, studio/install_python_stack.py:448, studio/install_python_stack.py:2176-2183). When the continuous-release wheel path is unavailable or bypassed, those supported AMD install flows can still resolve 0.49.1/0.49.2 and reintroduce the ROCm 4-bit NaNs this change is trying to prevent, so the fallback floor should be bumped in the same patch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct, and fixed in 82bde5b. Both AMD installer fallbacks floored at 0.49.1, so a host that could not reach the continuous-release_main URL (or ran with it bypassed) fell back to a range that still NaNs at 4-bit decode on ROCm.

Raised to >=0.50.0 in both places:

  • install.sh _install_bnb_rocm PyPI fallback
  • _BNB_ROCM_PYPI_FALLBACK in studio/install_python_stack.py, which is the path Studio and the Windows installers use

Verified the floor is real rather than nominal: the PyPI 0.50.0 manylinux_2_24_x86_64 wheel ships libbitsandbytes_rocm{64,70,71,714,72}.so and the win_amd64 wheel ships libbitsandbytes_rocm{714,72}.dll, the same ROCm set as the continuous-release wheel, and bnb #1887 merged 2026-03-09, after 0.49.2 (2026-02-16) and before 0.50.0 (2026-07-24).

Added TestAmdBnbFloorParity in tests/python/test_cross_platform_parity.py so the amd extra, the install.sh fallback and the Studio fallback cannot drift apart again, plus a check that no installer floors bitsandbytes in the 0.49.x range. Also corrected two comments that said to drop the pre-release pin once 0.50 shipped, and the hardcoded 0.50.0.dev0 metadata version, since the rolling wheel now reports 0.50.1.dev0.

@danielhanchen
danielhanchen self-requested a review as a code owner July 28, 2026 22:05
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@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: 36b0da5327

ℹ️ 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".

Comment thread install.sh Outdated
fi
run_install_cmd "$_label (pypi fallback)" "$_venv_py" -m pip install \
--force-reinstall --no-cache-dir --no-deps "bitsandbytes>=0.49.1"
--force-reinstall --no-cache-dir --no-deps "bitsandbytes>=0.50.0"

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 Stop reporting the repaired fallback as broken

When the pre-release wheel download fails, _install_bnb_rocm still tells the user that the PyPI fallback leaves “4-bit decode broken on ROCm,” even though this changed requirement now selects the first fixed release. The Studio path emits the same stale warning in install_python_stack.py before installing _BNB_ROCM_PYPI_FALLBACK, so successful fallback installs are incorrectly reported as unusable; update both messages with the new floor.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct, and fixed in d568476. Raising the floor made both messages false: the fallback now installs the first release that carries the fix, so telling the user 4-bit decode is broken would send them chasing a problem they do not have.

Both now name the spec instead of asserting brokenness:

  • install.sh: falling back to PyPI $_BNB_ROCM_PYPI_FALLBACK, which carries the ROCm 4-bit fix
  • studio/install_python_stack.py: the same wording, interpolating _BNB_ROCM_PYPI_FALLBACK

Also pulled the shell spec into a _BNB_ROCM_PYPI_FALLBACK variable in install.sh, matching the Python constant, so the message and the install argument cannot drift from each other again. Verified the expansion under /bin/sh, since install.sh is POSIX sh rather than bash.

TestAmdBnbFloorParity now asserts the install.sh variable form and that neither installer still claims 4-bit decode is broken on the fallback path. Same change on the pip branch in #7581.

One scope note: on aarch64 the message is still optimistic, but that predates this PR and is not something the floor can fix. Neither the PyPI 0.50.0 aarch64 wheel nor the continuous-release aarch64 wheel ships any libbitsandbytes_rocm*.so, only cpu and cuda variants, so aarch64 ROCm has no 4-bit path at any version. Tracking that separately rather than widening this PR.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 9db04f8f75

ℹ️ 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".

@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: efe912096b

ℹ️ 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".

Comment thread install.sh Outdated
rm -f "$_bnb_log"
step "warning" "$_label (pre-release) failed (exit code $_bnb_rc)" "$C_WARN" >&2
substep "[WARN] bnb pre-release install failed; falling back to PyPI (4-bit decode broken on ROCm)" "$C_WARN"
substep "[WARN] bnb pre-release install failed; falling back to PyPI $_BNB_ROCM_PYPI_FALLBACK, which carries the ROCm 4-bit fix" "$C_WARN"

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 Keep the fallback warning accurate on aarch64

On Linux aarch64, when the pre-release installation fails, this now claims the PyPI fallback carries the ROCm fix even though the 0.50.0 aarch64 wheel contains no ROCm binary, so the resulting bitsandbytes installation still cannot provide the advertised AMD 4-bit path. Fresh evidence is the explicit aarch64 installer branch above combined with the reviewed commit's own stated aarch64 wheel limitation; retain a broken/unsupported warning for that architecture rather than applying the x86_64 message universally.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct, and fixed in 2d22562. I had flagged the aarch64 gap as out of scope on the previous round; you are right that once the message asserts the fix is present, the gap stops being pre-existing background and becomes a false claim this PR introduced.

Confirmed the premise directly rather than from the release notes: the PyPI 0.50.0 manylinux_2_24_aarch64 wheel contains no libbitsandbytes_rocm*.so, only libbitsandbytes_cpu.so plus the CUDA variants. The continuous-release_main aarch64 wheel is the same, so the success path was misleading too, not just the fallback.

Both installers are now arch-aware:

  • _bnb_rocm_arch_has_binary in install.sh and _bnb_rocm_arch_has_binary() in studio/install_python_stack.py
  • the "carries the ROCm 4-bit fix" clause is dropped on aarch64
  • after either install path, aarch64 gets bitsandbytes ships no ROCm kernels on this arch; 4-bit QLoRA needs a source build with the AMD docs link, matching the existing gfx906 notice

Checked the shell under /bin/sh for both $_ARCH values and confirmed the pypi-fallback exit code is still propagated through the new warning call, and the Python helper for x86_64, AMD64, aarch64, arm64 and ARM64. Regression test added as test_aarch64_is_not_told_it_has_a_rocm_backend. Same change on the pip branch in #7581.

Left the aarch64 marker in the amd extra alone: trimming it would diverge from #7278 and is a packaging decision beyond this PR.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 78d0dded12

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 761a48e4e2

ℹ️ 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".

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Jul 28, 2026
@danielhanchen
danielhanchen merged commit 411cb86 into main Jul 29, 2026
66 of 75 checks passed
@danielhanchen
danielhanchen deleted the fix/main-amd-bnb-floor branch July 29, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants