Repository navigation
Install Flash Attention on Blackwell when a CUDA >= 12.8 wheel exists - #6971
danielhanchen wants to merge 1 commit into
Conversation
The Studio installer skipped Flash Attention on any Blackwell GPU (compute capability >= 10.0: sm_100 B200/B100, sm_120 RTX 50 series), on the assumption that no prebuilt wheels existed for those archs. That assumption is stale: Dao-AILab has shipped wheels with sm_100 / sm_120 kernels since flash-attn v2.7.3, built for CUDA >= 12.8. Replace the blanket has_blackwell_gpu() skip in _ensure_flash_attn and _ensure_flash_attn_for_long_context with a CUDA-version-aware gate. The normal prebuilt-wheel path already builds the exact wheel URL, HEAD-checks it, and falls back gracefully, so it now runs on Blackwell unless the installed torch's CUDA build is older than 12.8 (in which case the matching wheel would lack Blackwell kernels and crash at kernel launch). - wheel_utils: probe now reports full cuda_version; add cuda_supports_blackwell_flash_attn and should_skip_flash_attn_for_blackwell. - install_python_stack / training worker: use the new gate. - Update the corresponding tests.
There was a problem hiding this comment.
Code Review
This pull request updates the flash-attn installation logic to support Blackwell GPUs when the installed PyTorch is built with CUDA >= 12.8, rather than skipping the installation unconditionally. It introduces helper functions to parse and validate the CUDA version and updates the training worker and python stack installer accordingly, along with adding comprehensive unit tests. The feedback suggests using a sentinel object instead of None as the default parameter in should_skip_flash_attn_for_blackwell to prevent redundant, slow subprocess calls when None is explicitly passed.
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.
| def should_skip_flash_attn_for_blackwell(env: dict[str, str] | None = None) -> bool: | ||
| """True when a Blackwell GPU is present but the installed torch's CUDA build is | ||
| older than 12.8, so the matching prebuilt flash-attn wheel would lack sm_100 / | ||
| sm_120 kernels (installs fine, then crashes at kernel launch). Returns False for | ||
| non-Blackwell GPUs and for Blackwell on CUDA >= 12.8, letting the normal | ||
| prebuilt-wheel install path run. Pass a pre-probed ``env`` to avoid re-probing. | ||
| """ | ||
| if not has_blackwell_gpu(): | ||
| return False | ||
| if env is None: | ||
| env = probe_torch_wheel_env() | ||
| cuda_version = env.get("cuda_version") if env else None | ||
| return not cuda_supports_blackwell_flash_attn(cuda_version) |
There was a problem hiding this comment.
When probe_torch_wheel_env() fails and returns None in the caller (such as in studio/install_python_stack.py), env is explicitly passed as None to should_skip_flash_attn_for_blackwell(env). Because the default parameter check is if env is None:, it will trigger a redundant call to probe_torch_wheel_env(), causing a duplicate slow subprocess execution (and potentially double timeouts).
Using a unique sentinel object instead of None as the default value avoids this redundant call when None is explicitly passed.
_UNSPECIFIED = object()
def should_skip_flash_attn_for_blackwell(env: dict[str, str] | None | object = _UNSPECIFIED) -> bool:
"""True when a Blackwell GPU is present but the installed torch's CUDA build is
older than 12.8, so the matching prebuilt flash-attn wheel would lack sm_100 /
sm_120 kernels (installs fine, then crashes at kernel launch). Returns False for
non-Blackwell GPUs and for Blackwell on CUDA >= 12.8, letting the normal
prebuilt-wheel install path run. Pass a pre-probed env to avoid re-probing.
"""
if not has_blackwell_gpu():
return False
if env is _UNSPECIFIED:
env = probe_torch_wheel_env()
cuda_version = env.get("cuda_version") if env else None
return not cuda_supports_blackwell_flash_attn(cuda_version)|
Oops I accidentally made my own commits and PR #6970 |
|
Closing in favor of #6970 from the original reporter. That PR covers the same flash-attn fix (dropping the has_blackwell_gpu skip) and additionally fixes the torchao 0.16.0 libcudart.so.12 crash on cu130 by moving torch 2.10 + CUDA 13 to torchao 0.17.0, which this PR did not. Verified both changes on a B200. |
Summary
Fixes the Flash Attention part of #6961: the Unsloth Studio installer skips Flash Attention on every Blackwell GPU, even though prebuilt wheels with Blackwell kernels have existed for months.
has_blackwell_gpu()returns True for any compute capability>= 10.0, and two call sites used it as a blanket "no compatible prebuilt wheel, skip" guard:studio/install_python_stack.py::_ensure_flash_attn(setup time)studio/backend/core/training/worker.py::_ensure_flash_attn_for_long_context(runtime, long context)That premise is stale. flash-attention added
sm_100+sm_120gencode in commit07bddf9("Blackwell support"), first released in v2.7.3, gated on CUDA>= 12.8. The published cu13 wheels contain those kernels, and our ownflash_attn_wheel_url()already builds the exact filename the reporter points at.The fix
Replace the blanket skip with a CUDA-version-aware gate. The existing install path already builds the exact wheel URL, HEAD-checks it with
url_exists(), and falls back gracefully, so it just needs to be allowed to run on Blackwell. The only real nuance is that wheel filenames encode the CUDA major only (cu12/cu13), while Blackwell kernels require a CUDA>= 12.8build, so we gate on the installed torch's full CUDA version.wheel_utils.py:probe_torch_wheel_env()now also reportscuda_version; new pure helpercuda_supports_blackwell_flash_attn()(True iff CUDA>= 12.8) andshould_skip_flash_attn_for_blackwell()(Blackwell present AND CUDA< 12.8).>= 12.8) the installer now installs the prebuilt wheel; on an old-CUDA edge case it skips with a clear message instead of crashing at kernel launch.Verification
flash_attn-2.8.1+cu13torch2.10cxx11abiTRUE-cp313-cp313-linux_x86_64.whl) withcuobjdump --list-elf: it contains 72sm_100and 72sm_120SASS kernels.torch==2.10.0+cu130+ that wheel imports and runs a realflash_attn_funcforward matching a naive attention reference tomax|err| = 9.95e-4.tests/python/test_flash_attn_install_python_stack.py(39 passed) and the runtime-install cases instudio/backend/tests/test_training_worker_flash_attn.py(including new Blackwell-installs and old-CUDA-skips cases).Not included: torchao 0.17
The issue also asks to force
torchao==0.17. That is intentionally left as is. The installer already maps torch 2.10 to torchao 0.16 and torch 2.11 to torchao 0.17, because torchao 0.17's C++/CUDA extensions require torch>= 2.11(on torch 2.10 it prints "Skipping import of cpp extensions due to incompatible torch version. Please upgrade to torch >= 2.11.0" and falls back to the slow Python path). Forcing 0.17 onto a torch 2.10 Blackwell stack would disable its kernels rather than help. torchao 0.17 already ships automatically once the user is on torch 2.11.The pip
unslothpackage andinstall.share unaffected: they never auto-install Flash Attention (only print a hint), so the relevant "setup" here is Studio.