Repository navigation
install-kernels: add flash-attn and install every kernel by default - #12744
Conversation
`unsloth install-kernels` with no names now installs xformers, flash-attn, causal_conv1d and mamba_ssm in that order (mamba_ssm's fast path imports causal_conv1d), each skipped when no wheel matches this torch / CUDA / Python, so notebooks can call it once. flash-attn resolves through wheel_utils.flash_attn_wheel_url, which covers the upstream wheels up to torch 2.12 and the prebuilt-wheels-cu13 builds for torch 2.13 / 2.14. It is skipped below sm80, where FlashAttention 2 does not run and Unsloth never enables it, so a T4 does not download it.
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. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b7dd36ac2
ℹ️ 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".
| "xformers", | ||
| "from xformers._cpp_lib import _register_extensions; _register_extensions()", | ||
| ), | ||
| "flash_attn": ("flash-attn", "import torch, flash_attn_2_cuda"), |
There was a problem hiding this comment.
Validate the public flash-attn package before accepting it
When flash_attn_2_cuda loads but the Python package cannot be imported—for example because a Python-level dependency is missing after this --no-deps installation or the package files are damaged—this probe succeeds both before and after installation, so the command reports flash-attn as usable and never removes the broken wheel. Unsloth actually imports flash_attn.flash_attn_interface, and the existing Studio installer deliberately tests import flash_attn; include that package-level import while retaining the extension check so success means consumers can use the installation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: under --no-deps the package import fails only on a missing pure-Python dependency (einops), which is why mamba_ssm is also judged by its extension. Unsloth's FA2 detection already falls back when that import fails, so the wheel is harmless there, while the extension check still catches a wheel that cannot load against this torch.
| result = run( | ||
| [sys.executable, "-c", check], stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, text = True | ||
| ) |
There was a problem hiding this comment.
Bound the flash-attn capability probe
When importing torch hangs, main() initially bounds probe_torch_wheel_env to 120 seconds and receives no environment, but install-all then reaches this second import torch subprocess with no timeout. The command can therefore hang indefinitely instead of skipping flash-attn after the bounded environment probe failed; either avoid this probe when env is None, or give it a timeout and handle TimeoutExpired as an unavailable GPU.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6068ed0: the wheel is resolved first, so a failed torch probe skips flash-attn with no second probe, and the capability probe now has a 120 s timeout that counts as no GPU.
|
|
||
|
|
||
| def _gpu_capability(run: Callable[..., subprocess.CompletedProcess]) -> tuple[int, int] | None: | ||
| check = "import torch; print(*torch.cuda.get_device_capability()) if torch.cuda.is_available() else None" |
There was a problem hiding this comment.
Check every visible GPU before skipping flash-attn
On a heterogeneous host where visible device 0 is pre-Ampere but another visible GPU is Ampere or newer, this child process always queries the default device and returns the capability of device 0. The installer consequently skips the environment-wide flash-attn wheel even when subsequent training targets the supported GPU; inspect the visible device set (or an explicitly selected device) and skip only when none of those devices supports flash-attn.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 6068ed0: the probe takes the best capability across every visible GPU.
…ounded, across all GPUs Resolve the wheel first, so a torch probe that already failed or timed out skips flash-attn without a second, unbounded torch import. The capability probe now has a timeout and takes the best visible GPU, so a pre-Ampere device 0 does not hide an Ampere card next to it.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6068ed07e6
ℹ️ 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".
| if name == "flash_attn" and url is not None: | ||
| # FlashAttention 2 needs Ampere or newer, and Unsloth only enables it there. | ||
| capability = _gpu_capability(run) |
There was a problem hiding this comment.
Honor --dry-run before probing the GPU
When flash_attn is requested with --dry-run on a headless or pre-Ampere machine, this branch runs the capability subprocess (potentially waiting 120 seconds) and returns without printing the resolved wheel URL. That contradicts the option's documented purpose of printing the resolved URL without installing anything and makes it impossible to inspect the flash-attn artifact from CI or a build host without a supported GPU; handle dry_run before the capability gate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: --dry-run reports the decision a real run would make, and on a pre-sm80 GPU that decision is the flash-attn skip. The probe only reads the device capability in a bounded subprocess and installs nothing.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! 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 |
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". |
* Install xformers / causal_conv1d with unsloth install-kernels
Replace the hand-written wheel picks in the Colab install cells with the
unsloth CLI, which resolves the prebuilt wheel for the installed torch and
CUDA (or installs nothing and keeps the torch fallback):
- xformers: drop the torch probe, the version map, the CUDA 13 URL line
and {xformers}; run `!unsloth install-kernels xformers` after unsloth
is installed (default, Gemma 4, DiffusionGemma, QAT and the
hand-maintained notebooks).
- Qwen3.5 / Qwen3.6: replace the causal_conv1d URL template, which 404s
on Colab's torch 2.11, and the fla uninstall with
`!unsloth install-kernels causal_conv1d`. unsloth_zoo's vendored fla
already wins over an older pip install.
- Qwen3.8: drop the fla uninstall and the uv install it needed. The
Kaggle GRPO notebook's pinned causal_conv1d URL becomes the same line.
- AMD cells are unchanged: the composer maps the new line back to the fla
uninstall and the causal_conv1d source build.
- molab: strip the line before marimo conversion, so it no longer leaves
an empty `import subprocess` cell behind.
Needs an unsloth release that ships install-kernels (unslothai/unsloth#12732).
* Install every kernel with bare unsloth install-kernels
`unsloth install-kernels` with no names installs xformers, flash-attn,
causal_conv1d and mamba_ssm, each skipped when no wheel matches the torch
(unslothai/unsloth#12744), so every Colab cell now runs the bare form.
- Granite 4.0 / Nemotron Nano: keep the resident torch instead of pinning
torch 2.7.1 for mamba_ssm 2.2.5 wheels, and drop the --no-build-isolation
install that took ~30 minutes on Blackwell. Wheels exist for every torch
these cells see (2.7, 2.10 cp312, 2.11, 2.13).
- Falcon H1, LFM2 and Granite 4.0 350M templates and the hand-maintained
Falcon H1 / LFM2 notebooks: replace the pinned or git-main kernel builds
with named install-kernels lines.
- AMD notebooks are unchanged: ROCm has no wheels, so the composer maps
each kernel line back to the line it read before, and
install-kernels counts as install code when it collects install cells.
- molab: the kernel install becomes its own runtime cell, so molab gets
wheels for its torch (still pinned to 2.7.1 for the Mamba hybrids)
instead of the old pins in the PEP 723 header.
* Install EmbeddingGemma 2 kernels with unsloth install-kernels
Follow up to #12732. Notebooks should install every kernel with one line, so
unsloth install-kernelswith no names now installs all of them:What changes
unsloth install-kernelsinstalls xformers, flash-attn, causal_conv1d and mamba_ssm, in that order (mamba_ssm's fast path imports causal_conv1d). Each one is skipped, with exit 0, when no wheel matches this torch / CUDA / Python. Named kernels still work and are installed in the same dependency order.flash_attnkernel, resolved throughwheel_utils.flash_attn_wheel_url, the resolver Studio already uses:prebuilt-wheels-cu13buildsflash_attn_2_cuda, the same way causal_conv1d / mamba_ssm load their compiled modules.Testing
unsloth install-kernelsinstalledxformers-0.0.35(cu130),flash_attn-2.8.1+cu13torch2.10,causal_conv1d-1.6.1+cu13torch2.10andmamba_ssm-2.3.1+cu13torch2.10. A second run reported all four already installed and loading.prebuilt-wheels-cu13torch 2.13 builds were installed against torch 2.13.0+cu130 and run on GPU:flash_attn_2_cuda,selective_scan_cudaandcausal_conv1d_cudaflash_attn_funcmatches SDPA andcausal_conv1d_fnmatches a torch conv1d + SiLU reference, both within bf16 precision