Skip to content

install-kernels: add flash-attn and install every kernel by default - #12744

Merged
danielhanchen merged 3 commits into
mainfrom
feat/install-kernels-all
Oct 6, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
feat/install-kernels-all

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow up to #12732. Notebooks should install every kernel with one line, so unsloth install-kernels with no names now installs all of them:

!unsloth install-kernels

What changes

  • Bare unsloth install-kernels installs 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.
  • New flash_attn kernel, resolved through wheel_utils.flash_attn_wheel_url, the resolver Studio already uses:
    • torch up to 2.10: the upstream Dao-AILab wheels
    • torch 2.11 / 2.12: the measured torch 2.10 wheels
    • torch 2.13 / 2.14: the prebuilt-wheels-cu13 builds
  • flash-attn is skipped below sm80, because FlashAttention 2 does not run there and Unsloth never enables it, so a T4 does not download it. It is also skipped when no CUDA GPU is visible.
  • The extension check for flash-attn loads flash_attn_2_cuda, the same way causal_conv1d / mamba_ssm load their compiled modules.

Testing

  • Unit tests:
    • flash-attn resolution for torch 2.11 cu130, 2.13 cu130, Windows and CPU
    • the sm75 / no-GPU skip and the sm80 install
    • install-all order, plus named kernels being deduplicated into dependency order
    • the existing kernel / wheel_utils / ssm_runtime / module entry tests: 148 passed, 20 skipped
  • Real install on B200, torch 2.11.0+cu130 / Python 3.13: unsloth install-kernels installed xformers-0.0.35 (cu130), flash_attn-2.8.1+cu13torch2.10, causal_conv1d-1.6.1+cu13torch2.10 and mamba_ssm-2.3.1+cu13torch2.10. A second run reported all four already installed and loading.
  • The prebuilt-wheels-cu13 torch 2.13 builds were installed against torch 2.13.0+cu130 and run on GPU:
    • the wheels contain flash_attn_2_cuda, selective_scan_cuda and causal_conv1d_cuda
    • flash_attn_func matches SDPA and causal_conv1d_fn matches a torch conv1d + SiLU reference, both within bf16 precision
  • Python 3.12 on torch 2.13 resolves to a cp312 asset that is not published (404), so the command skips it and keeps the torch fallback.

`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.
@danielhanchen danielhanchen self-assigned this Oct 5, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-05T14:20:38.562527Z cb80808 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 5, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member 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: 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"),

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 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread studio/backend/utils/kernel_install.py Outdated
Comment on lines +79 to +81
result = run(
[sys.executable, "-c", check], stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, text = True
)

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 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread studio/backend/utils/kernel_install.py Outdated


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"

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 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.
@danielhanchen

Copy link
Copy Markdown
Member 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: 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".

Comment on lines +131 to +133
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)

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 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

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

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: cb80808cb0

ℹ️ 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 33f100b into main Oct 6, 2026
@danielhanchen
danielhanchen deleted the feat/install-kernels-all branch October 6, 2026 02:00
Penguinjanator pushed a commit to Penguinjanator/notebooks that referenced this pull request Oct 7, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant