Skip to content

Studio setup: install causal-conv1d and mamba-ssm prebuilt wheels next to flash-attn - #13396

Merged
danielhanchen merged 9 commits into
mainfrom
studio-setup-ssm-kernels
Oct 12, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-setup-ssm-kernels

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Studio setup now installs the causal-conv1d and mamba-ssm prebuilt wheels during install, right after flash-attn, on Linux and Windows. Before this, setup installed flash-attn from prebuilt-wheels-cu13 but left causal-conv1d and mamba-ssm until the first Mamba / hybrid model load (ensure_ssm_runtime), so a fresh install reported both as missing. The desktop app runs the same install_python_stack.py, so it gets them too.

What changes

  • New _ensure_ssm_kernels() in studio/install_python_stack.py, called after _ensure_flash_attn() at all three sites: the main pass, the Linux torch repair (step 13) and the Windows torch flavor invariant (13w), so a torch that moved during a repair gets matching kernels.
  • It reuses kernel_install.install_kernel, the same code as unsloth install-kernels and the SSM runtime: wheel-only, --no-deps, never a source build, never a torch change, import-verified (a wheel that does not load is removed). A kernel that already imports is left alone without any network lookup; cells with no published wheel are skipped with a note, and a resident build that no longer imports with the current torch is removed, as the flash-attn resync does. Import probes are bounded like flash-attn's, and each call uses a fresh runner so a torch repair re-probes Triton. mamba-ssm installs even where no GPU is visible yet (an image build); a visible pre-Ampere GPU still skips it, and the CLI / SSM runtime keep their gate (install_kernel(..., install_without_gpu=True) is setup-only). On Windows it needs triton-windows, which setup installs before this step.
  • One progress slot, counted in base_total under the same gate.
  • UNSLOTH_STUDIO_SKIP_SSM_KERNELS_INSTALL=1 opts out, like UNSLOTH_STUDIO_SKIP_FLASHATTN_INSTALL.

The wheels are large (causal-conv1d about 197 MB, mamba-ssm about 333 MB for torch 2.13 x86_64), so a GPU install downloads about 530 MB more than before. A re-run is a no-op once both import.

Tested

Fresh install.sh --local from main on Linux x86_64 (B200, driver 590, Python 3.13): torch 2.13.0+cu130 and flash-attn 2.8.4, causal-conv1d and mamba-ssm absent. Running this branch's step in that same environment:

installed causal_conv1d (causal_conv1d-1.7.0+cu13torch2.13cxx11abiTRUE-cp313-cp313-linux_x86_64.whl).
installed mamba_ssm (mamba_ssm-2.3.2.post1+cu13torch2.13cxx11abiTRUE-cp313-cp313-linux_x86_64.whl).

Windows staging (windows-2022, no GPU, cu130, Python 3.13 with #13399): a fresh install ends with torch 2.13.0+cu130, flash-attn 2.8.4, causal-conv1d 1.7.0 and mamba-ssm 2.3.2.post1. One earlier run hit a GitHub 504 on the mamba-ssm wheel: setup warned Continuing without mamba_ssm and finished, and the model-load path installs it later.

On the B200, all three kernels then run on the GPU and match a torch reference (flash-attn vs SDPA 9.8e-04, causal-conv1d vs conv1d 9.5e-07, selective scan vs reference 3.4e-05). A second run prints already installed and loads for both, with no wheel lookup (12 s including the GPU lease).

tests/python/test_ssm_kernels_install_python_stack.py: both kernels install for the resident torch; an already-loading kernel is not looked up online; a resident build that no longer loads is removed; a hung probe is bounded and never read as broken; each call gets a fresh runner; a failure warns and the next kernel still runs; nothing runs without torch, on macOS, when opted out, or without a CUDA torch; every flash-attn site also resyncs these. The existing install_python_stack, flash-attn, CUDA repair, ROCm and kernel_install suites pass; the four TestProgressStepCountMatchesTotal::test_progress_reaches_total_on_both_core_paths[*-False] cases fail identically on main.

Not covered

  • No Windows GPU here: on Windows the step is exercised on a GPU-less runner only.
  • A fresh Windows install only reaches torch 2.13 (and so these wheels) on Python 3.13; the installer reusing an existing system Python is fixed separately.

…t to flash-attn

Setup already installed flash-attn from prebuilt-wheels-cu13 but left
causal-conv1d and mamba-ssm to the first Mamba / hybrid model load. Install
both at setup through the same wheel-only install_kernel the CLI and SSM
runtime use: never a source build, never a torch change, skipped where no
wheel is published, GPU-gated for mamba-ssm, and resynced wherever
flash-attn is after a torch repair. UNSLOTH_STUDIO_SKIP_SSM_KERNELS_INSTALL=1
opts out.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…r, no-GPU install, stale removal

Skip the wheel lookup when the resident kernel already loads, so an offline
re-run does not wait on two HEAD requests. Each call gets its own runner,
which bounds the import probes and resets install_kernel's per-runner GPU
and Triton cache after a torch repair. Setup installs mamba-ssm where no GPU
is visible yet (an image build); a visible pre-Ampere GPU still skips it. A
resident build that no longer loads and has nothing replacing it is removed,
as flash-attn's resync does.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

No wheel lookup and no install when uv is told to stay offline: the pip
fallback in install_wheel does not read UV_OFFLINE. A kernel that already
loads is still reported.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@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: b9336a8fe8

ℹ️ 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 self-assigned this Oct 12, 2026
install_kernel only replaces the wheel URL; uv / pip failure text or an
exception can name another index carrying credentials.
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0185151286

ℹ️ 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 9f4a868 into main Oct 12, 2026
@danielhanchen
danielhanchen deleted the studio-setup-ssm-kernels branch October 12, 2026 13:23
danielhanchen added a commit that referenced this pull request Oct 12, 2026
…3445)

test_return_logits_survives_for_training lifts for_training into a stub namespace that predates #13374's switch_training_mode, so the missing name came back as None. Stub it and the three-argument resolve, and make that namespace raise NameError on any unstubbed name.
test_windows_torch_flavor_invariant: count #13396's causal-conv1d + mamba-ssm slot in the torch totals and its call in step 13.
test_token_count_prompt_parity: stub #13372's browser agent store with its defaults; the count and the request both call browserAgentToolsForTurn.
test_diffusion_mlx_engine_router (from #13379): read install_python_stack.py as UTF-8 for test_source_read_encoding.
danielhanchen added a commit that referenced this pull request Oct 15, 2026
…hem (#13861)

Studio setup stops downloading causal-conv1d and mamba-ssm. They are
installed when a model that needs them is first trained or loaded, and
Qwen3.5 / Qwen3.6 / Qwen3-Next no longer request causal-conv1d at all.

## Why

#13396 added both kernels to every NVIDIA Linux / Windows setup next to
flash-attn: about 555 MB of downloads (~620 MB installed) for every
user, while only a few model families use them. Studio already installs
them on demand when such a model is trained (`core/training/worker.py`)
or loaded for chat (`core/inference/worker.py` through
`utils/ssm_runtime.ensure_ssm_runtime`), so the setup step only
duplicated that.

Qwen3.5 / 3.6 / Qwen3-Next do not need causal-conv1d with Unsloth:
unsloth-zoo runs their GatedDeltaNet with its vendored FLA kernels and
its own Triton causal conv
(`unsloth_zoo/temporary_patches/gdn_causal_conv1d.py`, model types
`qwen3_5`, `qwen3_5_moe`, `qwen3_next`). Studio still downloaded the
CUDA package for them because their transformers modeling files mention
`causal_conv1d`.

## What changes

- `studio/install_python_stack.py`: the setup-time SSM install is gone
from all three places (initial setup, Linux torch repair, Windows torch
flavor repair), with its progress step. flash-attn stays where it was.
`unsloth install-kernels` still installs every kernel, for offline
images.
- `studio/backend/utils/ssm_runtime.py`: `ZOO_GDN_MODEL_TYPES` (equal to
zoo's list; a test reads zoo's source to keep them equal). Names and
configs of those models, including `_text` / `_vision` sub-configs,
resolve to no causal-conv1d request, checked before the modeling-source
scan. A config that mixes in another model type that needs it still asks
for it. Zoo's own kill switch `UNSLOTH_DISABLE_TRITON_CAUSAL_CONV1D=1`
brings the old request back.
- `core/training/worker.py` and `core/systemone/clef_runtime.py` use the
same predicate, so the eager install, the `is_causal_conv1d_available`
hook and Clef (a Qwen3.5 backbone) all agree.
- Only where zoo's Triton conv can run: a CUDA torch (not ROCm, not
CPU), Triton importable, not macOS. This is read from torch's
distribution version (`+rocm` / `+cpu` / `+cu`), so no load imports
torch to decide. On ROCm, macOS or Windows without triton-windows, Qwen
keeps getting causal-conv1d as before.
- With setup no longer covering for it, the on-demand install now
decides from the model's config, not only its name:
`resolved_model_is_ssm` maps `nemotron_h`, `falcon_h1`,
`granitemoehybrid`, `bamba`, `jamba`, `zamba`, `zamba2`, `mamba`,
`mamba2`, `falcon_mamba` (and their `_text` sub-configs) to mamba-ssm +
causal-conv1d, for training and for the inference load of the resolved
base. Previously `NVIDIA-Nemotron-Nano-9B-v2`,
`granite-4.0-tiny-preview`, renamed local checkpoints, Jamba, Zamba and
Bamba never got mamba-ssm on demand.
- After an install inside an inference worker that already imported
transformers, the cached `is_causal_conv1d_available` /
`is_mamba_ssm_available` / `is_mamba_2_ssm_available` and cached
hub-kernel misses are cleared, so switching from Qwen3.5 to Nemotron-H
in one session gets the fast path.
- The mamba-ssm error raised when it cannot be installed (e.g. offline)
says to run `unsloth install-kernels` once while online.
- `install_kernel(install_without_gpu=)` is gone; setup was its only
caller.
- Clef still applies the FLA TileLang guard when it skips the install.

Unchanged: LFM2, Mamba / Jamba / Zamba / Bamba still get causal-conv1d
on demand; Nemotron-H, Falcon-H1 and Granite-4.0-H still get
causal-conv1d then mamba-ssm on demand; nothing already installed is
removed, and a usable causal_conv1d still wins inside zoo.

## Tests

- `tests/python/test_ssm_kernels_install_python_stack.py`: setup has no
SSM step; flash-attn is still installed at all three sites; the CLI
kernels are still there.
- `test_windows_torch_flavor_invariant.py`: the torch progress totals
drop by one on Windows and Linux.
- `studio/backend/tests/test_ssm_runtime.py`: Qwen3.5 / 3.6 / Next names
and configs install nothing, the kill switch restores the request, a
mixed config still asks, the Mamba2 hybrids still install both kernels
in order, and the model-type list equals zoo's.
- 21 of the new cases fail against main, and the follow-up cases
(config-based SSM detection, platform check, cache refresh, offline
message) fail against this PR's first commit; all pass here. The touched
test files and the setup / resolver suites pass (test_ssm_runtime 84,
test_training_worker_flash_attn 67, test_install_python_stack 295,
test_cuda_repair 284, test_windows_torch_flavor_invariant 54, among
others).

## Accuracy and speed without causal-conv1d (Qwen3.5)

Tiny Qwen3.5 / Qwen3-Next through Unsloth, bf16: zoo's Triton conv is
bit-identical to torch's reference conv (logits, loss, LoRA grads, 5
optimizer steps); the CUDA package differs from both at bf16 rounding
(5.9e-3 logits, grads cos 0.99993). Prefill plus cached token-by-token
decode matches a full forward equally with and without the package
(4.0e-3 vs 3.9e-3). The profiler shows which kernels ran in every arm.

Qwen3.5-0.8B bf16 on a Colab L4, torch 2.14.1+cu130, 3 alternating
repeats per arm:

| | Without causal-conv1d (zoo Triton) | With causal-conv1d (CUDA) |
|---|---|---|
| LoRA training, batch 4 x 1024, 30 timed steps | 911.5 ms/step (spread
11.2) | 917.5 ms/step (spread 15.9) |
| Greedy decode, 256 new tokens, batch 1 | 19.3 tok/s (spread 0.6) |
19.0 tok/s (spread 0.2) |

Both differences are inside the run-to-run spread. Without the package,
single-token decode uses torch's `conv_depthwise2d`; with it,
`causal_conv1d_update`.

A tiny NemotronH also runs identically with a pure-Python mamba-ssm (the
Mamba2 path never calls `selective_scan_cuda`), and a merged 16-bit
export of a NemotronH LoRA works with neither kernel installed.

## Not covered here
- `test_decision_native.py` / `test_decision_serving.py` were not
collected locally (missing `fastmcp`).
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