Skip to content

Install kernels with unsloth install-kernels - #385

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

danielhanchen merged 3 commits into
mainfrom
feat/install-kernels

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Replaces the hand-written kernel install lines in the Colab / Kaggle install cells with one line:

!unsloth install-kernels

The command shipped in unsloth 2026.10.1 (unslothai/unsloth#12732, #12744, #12828). It installs the prebuilt xformers, flash-attn, causal_conv1d and mamba_ssm wheels that match the resident torch / CUDA / Python. It uses --no-deps, so torch is never touched. Each kernel is skipped, with exit 0, when no wheel matches: flash-attn below sm80, and anything without a published wheel. It never builds from source.

What it replaces

  • The xformers version map plus the cu130 wheel URL override, and {xformers} in the pip install --no-deps line.
  • The SSM notebooks' kernel lines. These were --no-build-isolation source builds of mamba_ssm / causal_conv1d, the causal_conv1d 1.7.0 wheel template, and the flash-linear-attention uninstall. They now use the same one line.
  • The torch pin the Nemotron block forced for its kernel builds. It now keeps the resident torch.

Generator changes (update_all_notebooks.py)

  • KERNELS_INSTALL = "!unsloth install-kernels" goes right after the unsloth install line in the default, Gemma 4, DiffusionGemma, EmbeddingGemma 2 and QAT blocks. An assert checks it always follows a line that installs unsloth, since the CLI only exists after that.
  • AMD cells never call it, because ROCm has no prebuilt wheels. They keep their own lines, and the SSM kernel pins are mapped back for ROCm source builds.
  • molab: the line is stripped from the install cell, since dependencies move to the PEP 723 header. The kernel install becomes its own cell, subprocess.run(["unsloth", "install-kernels"]).
  • original_template: the Falcon H1, Granite 4.0 350M and LFM2 kernel cells now use the same line.

Testing

  • New tests/test_install_kernels_line.py, added to the notebook tests workflow. It checks that:
    • no retired xformers / causal_conv1d wheel picks remain in nb/
    • every kernel line follows an unsloth install
    • the SSM notebooks no longer build kernels from source
    • AMD cells never call the command
    • molab runs the command as its own cell
  • The full notebook test suite fails the same 24 tests on this branch and on main, so there are no new failures.
  • Every notebook below ran on Colab against the released unsloth 2026.10.1, with no branch install.
Notebook GPU Kernels Result
Llama3.2 (1B and 3B) Conversational T4 xformers, causal_conv1d, mamba_ssm installed; flash-attn skipped (sm75) all cells ran, 5 training steps, inference ok
Llama3.2 (1B and 3B) Conversational L4 xformers 0.0.35, flash-attn 2.8.1, causal_conv1d 1.6.1, mamba_ssm 2.3.1 installed all cells ran, 5 training steps, inference ok
Granite4.0_350M T4 same as T4 above; second call reports both SSM kernels already loading all cells ran, 5 training steps
Falcon_H1 (0.5B) Alpaca T4 same as Granite all cells ran, 5 training steps
EmbeddingGemma2 (300M) T4 same as T4 above all cells ran, training ok

In every run, the only cells without output are the if False: save blocks at the end.

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).
`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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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 ⚠️ Failed 2026-10-07T04:09:26.030634Z c0580c2 Manual request
🔒 Security Review ✅ Completed 2026-10-07T04:07:09.041131Z c0580c2 PR opened

Security findings

Blocking findings (1)

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

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

ℹ️ 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 update_all_notebooks.py
Comment on lines +313 to +314
!pip install --no-deps unsloth_zoo bitsandbytes accelerate peft trl triton unsloth
__KERNELS_INSTALL__

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 Require the new CLI version before invoking it

When a Colab runtime already contains an older Unsloth release, the preceding pip install --no-deps ... unsloth treats that installation as satisfying the unversioned requirement and does not upgrade it. The argument-free form was only added in the Oct. 6 upstream change, so an older CLI either lacks this subcommand or still requires explicit kernel names; because the output is captured, the notebooks then continue without installing xformers after its explicit install was removed. Require unsloth>=2026.10.1 or force an upgrade before running the command.

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 this one. The unversioned install only keeps an older unsloth if one is already present, and neither target runtime ships it: the Colab image has no unsloth (the Colab runs for this PR all logged Successfully installed ... unsloth-2026.10.1), and Kaggle's kaggle_requirements.txt in Kaggle/docker-python has no unsloth either (Kaggle also takes the pip install unsloth branch, not this one). That leaves a user who hand-installed an older unsloth in the same session, and there a missing subcommand only means no xformers, which is optional: Unsloth falls back to torch SDPA. A version floor on every notebook's install line is not worth that.

@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 Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: c0580c2f40

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread update_all_notebooks.py
)
# Every prebuilt kernel (xformers, flash-attn, causal_conv1d, mamba_ssm) for the resident torch +
# CUDA, each skipped when no wheel matches. Runs the `unsloth` CLI, so it must follow the unsloth install.
KERNELS_INSTALL = "!unsloth install-kernels"

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 Security Review · Automatically triggered

P0 Badge Security: Install only required, integrity-pinned kernel wheels

If a compatible Colab/molab user runs a notebook while any newly added kernel release is compromised, this no-argument command installs all four kernels—not just the prior xformers—and the upstream installer imports each native extension during validation (implementation). The change emits it into 142 default notebook cells and 123 molab scripts, so compromise of flash-attn/causal_conv1d/mamba_ssm now yields runtime code execution with access to tokens and private data even where those kernels are not needed. Pass explicit required names and verify immutable hashes before loading wheels.

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.

1 participant