Skip to content

Studio: fix flash-attn and torchao install on Blackwell (sm_100+) GPUs (Closes #6961) - #6970

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
ThomasEricB:main
Jul 8, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
ThomasEricB:main

Conversation

@ThomasEricB

Copy link
Copy Markdown
Contributor

On Blackwell GPUs, the Studio Setup left two things broken. Both are fixed here, and both are scoped so non-Blackwell setups are unchanged.

Screenshot_20260708_025042

ThomasEricB and others added 3 commits July 8, 2026 06:15
Fixes #6961. This function skipped flash-attn on Blackwell GPUs because no prebuilt wheel existed;
Dao-AILab now ships one and url_exists() already gates resolution.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fixes #6961. Torchao 0.16.0's cpp extensions are built against CUDA 12, so on a CUDA-13
torch (cu130 / Blackwell) they fail to load with "libcudart.so.12: cannot
open shared object file". Select 0.17.0 there instead: its cpp targets torch
2.11, so it is skipped cleanly rather than crashing. CUDA-12 / ROCm / CPU
torch 2.10 keeps 0.16.0 and its working kernels.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request removes the has_blackwell_gpu check and instead dynamically selects the appropriate torchao version based on the CUDA major version extracted from the PyTorch installation tag. This prevents loading incompatible CUDA-12 C++ extensions on CUDA-13 (Blackwell) environments, avoiding runtime crashes. Feedback on the changes highlights a potential parsing bug in _cuda_major_from_torch_version when handling two-digit CUDA tags (e.g., +cu13), which would incorrectly resolve the major version to 1 instead of 13.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread studio/install_python_stack.py Resolved
@ThomasEricB ThomasEricB changed the title Studio: fix flash-attn and torchao install on Blackwell (sm_100+) GPUs (Closes unslothai/unsloth#6961) Studio: fix flash-attn and torchao install on Blackwell (sm_100+) GPUs (Closes #6961) Jul 8, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for this. I went through both changes on a B200 and they hold up.

torchao 0.16 to 0.17 on CUDA 13: confirmed. On a clean torch==2.10.0+cu130 venv the only CUDA runtime present is libcudart.so.13 (bundled by torch), but torchao 0.16.0's compiled extensions carry a hard NEEDED libcudart.so.12, so import torchao fails with libcudart.so.12: cannot open shared object file exactly as you reported. 0.17.0 imports cleanly (its cpp is skipped because it targets torch 2.11), and since no torchao build ships working cpp for torch 2.10 anyway, a clean import is strictly better than a crash on import. cu12 / ROCm / CPU stay on 0.16.0 and keep their working kernels, so the change is correctly scoped.

flash-attn: confirmed. Dropping the has_blackwell_gpu() skip is right. The prebuilt cu13 wheels do contain sm_100 and sm_120 kernels (checked end to end: flash_attn-2.8.1+cu13torch2.10... runs a real flash_attn_func on a B200 matching a reference to 1e-3), and the existing url_exists() HEAD check plus graceful fallback already covers the case where no wheel is published.

On the review note at _cuda_major_from_torch_version: the int(digits) // 10 parse is correct for every CUDA tag PyTorch actually emits (cu92 -> 9, cu118 -> 11, cu128 -> 12, cu130 -> 13). PyTorch never ships a +cu13 / +cu12 style tag, so no change is needed there.

I pushed one small commit on top that condenses the torchao selection comments. It is comment-only, the AST is unchanged, and the tests pass: test_torchao_select.py (27), test_flash_attn_install_python_stack.py (15), and the runtime flash-attn cases in test_training_worker_flash_attn.py.

This supersedes #6971, which I had opened for the same issue before seeing yours. I will close that one and take this.

… wheels

Map torch 2.11 to the torch2.10 prebuilt wheels for flash-attn, causal-conv1d,
and mamba through wheel_utils.prebuilt_wheel_torch_mm, applied in direct_wheel_url
(filename) and flash_attn_wheel_url (version). Those torch2.10 CUDA wheels load and
pass each project's own test suite on torch 2.11 (verified on B200), so a torch 2.11
environment gets the prebuilt accelerators instead of skipping or building from source.

Raise _CUDA_TORCH_PKG_SPEC to <2.12.0 (torchvision <0.27.0, torchaudio <2.12.0) so
the CUDA torch repair path can install torch 2.11, where torchao 0.17's cpp kernels
load cleanly. Add tests for the mapping.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed a commit to make torch 2.11 work end to end for anyone who lands on it. The torch2.10 prebuilt wheels for flash-attn, causal-conv1d and mamba all import and pass their own test suites on torch 2.11 (checked on a B200: FA2 forward/backward, causal-conv1d, and mamba selective scan all match reference), so there is no reason to skip them or build from source on 2.11.

What changed:

  • wheel_utils.prebuilt_wheel_torch_mm maps torch 2.11 to the torch2.10 wheels, applied in both direct_wheel_url (the filename) and flash_attn_wheel_url (the version lookup). One mapping point covers all three accelerators, so a torch 2.11 install now resolves the prebuilt wheels instead of returning None and falling back to a source build or a skip.
  • _CUDA_TORCH_PKG_SPEC now allows torch 2.11 (<2.12.0, torchvision <0.27.0, torchaudio <2.12.0) so the CUDA torch repair path can land on 2.11, where torchao 0.17's cpp kernels load cleanly.

Note on scope: this does not change what a fresh CUDA install lands on. The base torch is still pinned by TORCH_CONSTRAINT in install.sh / setup.ps1 (torch>=2.4,<2.11.0), so fresh installs stay on torch 2.10 and pick up the same prebuilt wheels. Moving the default to 2.11 is a separate change that touches those two scripts plus their constraint tests, and I want to run a broader smoke pass (bitsandbytes, xformers/vLLM, our compiled kernels, triton) on 2.11 before flipping every CUDA user. Can do that as a follow-up if we want the default to move.

@ThomasEricB

Copy link
Copy Markdown
Contributor Author

Pushed a commit to make torch 2.11 work end to end for anyone who lands on it. The torch2.10 prebuilt wheels for flash-attn, causal-conv1d and mamba all import and pass their own test suites on torch 2.11 (checked on a B200: FA2 forward/backward, causal-conv1d, and mamba selective scan all match reference), so there is no reason to skip them or build from source on 2.11.

Nice work!

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2394d0421c

ℹ️ 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. Keep them coming!

Reviewed commit: 98756d8572

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

…h gating

Keep the nvidia-smi compute_cap detection and its two call sites, but short-circuit
with return False at the top so flash-attn is no longer skipped on Blackwell (sm_100+
now has prebuilt wheels and url_exists gates resolution). Drop the early return to
re-enable arch-based detection later.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 96f444c12a

ℹ️ 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
danielhanchen merged commit 03cbe21 into unslothai:main Jul 8, 2026
1 check passed

@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: 6d4cc8b292

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

"torch>=2.4,<2.11.0",
"torchvision>=0.19,<0.26.0",
"torchaudio>=2.4,<2.11.0",
"torch>=2.4,<2.12.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 Avoid upgrading Volta repairs to torch 2.11

When a Linux Volta/V100 host with a CUDA 12.8+ driver reaches _ensure_cuda_torch(), _detect_cuda_torch_index_url() selects the cu128 index from the driver version alone; widening this spec lets pip resolve torch==2.11.0 from that index. PyTorch 2.11's cu128/cu129 wheels no longer include SM 7.0 support, so this repair path can replace the previous working torch<2.11 CUDA wheel with one that cannot run on V100. Please keep Volta repairs below 2.11 or choose a compatible index/spec based on compute capability.

Useful? React with 👍 / 👎.

Comment on lines 38 to 42
"direct_wheel_url",
"flash_attn_wheel_url",
"has_blackwell_gpu",
"install_wheel",
"probe_torch_wheel_env",
"url_exists",

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 has_blackwell_gpu in the test stub

core/training/worker.py still imports has_blackwell_gpu from utils.wheel_utils at module import time, but this lightweight MLX test loader now stubs utils.wheel_utils without that attribute. When the loader reaches the wheel_utils import, spec.loader.exec_module(module) raises ImportError before any MLX config assertions can run; add the stubbed name back or remove the production import first.

Useful? React with 👍 / 👎.

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