Skip to content

Studio: restore Qwen causal-conv1d on demand, narrow fatal mamba-ssm, provision SSM kernels in export - #13971

Merged
danielhanchen merged 23 commits into
mainfrom
studio-ssm-on-demand-followups
Oct 19, 2026
Merged

danielhanchen merged 23 commits into
mainfrom
studio-ssm-on-demand-followups

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Follow up to #13861 and #13808. An audit of the merged on demand SSM kernel change plus a T4 benchmark found a few gaps, fixed here.

Why

  • On a Kaggle T4 (sm75, torch 2.11 cu130, fp16, Qwen3.5-0.8B), Studio chat decode was 4.4% slower without causal-conv1d (19.10 vs 19.95 tok/s, 6 alternating repeats, slower in all 9 pairs). Training speed, losses and peak memory were unchanged. The zoo Triton conv covers causal_conv1d_fn only, so single token decode fell back to the torch update path. Training with trainable conv weights also allocates an fp32 dW scratch in the Triton backward, and packed seq_idx is not accepted by the zoo dispatcher under transformers 5.20.
  • Mamba-family models that have a working transformers torch path (mamba, mamba2, falcon_mamba, jamba, zamba, zamba2, bamba) were made fatal when mamba-ssm could not be installed.
  • Export, local LoRA continuation, and inference model switching did not provision or pick up kernels correctly once setup stopped installing them.
  • Setup on pre-Ampere GPUs (T4) downloaded flash-attn even though Unsloth only enables FA2 at sm80+.

Changes

  1. Qwen3.5 / Qwen3.6 / Qwen3-Next request causal-conv1d on demand again in training, inference and Clef (same as before Studio: install causal-conv1d and mamba-ssm only when a model needs them #13861, minus the setup time install). The zoo Triton platform probe is removed.
  2. A missing mamba-ssm is fatal only for nemotron_h, falcon_h1, granitemoehybrid. Other Mamba families install best effort and continue on the torch path with a status message.
  3. Local LoRA folders (adapter_config.json, no config.json) resolve kernel needs from base_model_name_or_path; the training adapter_base_pin wins when set.
  4. The export worker provisions SSM kernels before importing Unsloth / the export backend, with the same required vs optional split.
  5. Inference re-enables the modeling source scan by reading transformers/models/<type>/modeling_*.py as text, without importing transformers.
  6. If a kernel is newly installed after the model's transformers.models.<type> module was already imported, the inference worker asks for a restart and the orchestrator respawns it once.
  7. Torch repair removes causal-conv1d / mamba-ssm whose compiled extension no longer imports (never installs anything new). A hung import check keeps the package.
  8. Setup and the long context runtime install skip flash-attn below sm80 (and remove a stale copy at setup). No visible GPU and ROCm keep current behavior.

Tests

New and updated tests fail on main and pass here (test_ssm_runtime.py, test_ssm_restart_respawn.py, test_export_ssm_kernels.py, test_clef_fast_paths.py, test_kernel_install.py, test_training_worker_flash_attn.py, test_ssm_kernels_install_python_stack.py, test_flash_attn_install_python_stack.py, test_windows_torch_flavor_invariant.py). With test_install_python_stack.py and test_cuda_repair.py: 966 passed after merging current main.

Hardening (second commit)

  • Stale SSM kernel removal after torch repair needs proof: torch must import first, and only an ImportError / OSError from the extension itself removes the package. Signals, hangs, launch errors and a broken torch keep it.
  • unsloth install-kernels --without-gpu (or UNSLOTH_INSTALL_KERNELS_WITHOUT_GPU=1) installs GPU gated kernels on a GPU-less image builder. An already working kernel counts as success before any skip, skipped kernels are listed, and the exit code is unchanged (0) unless --strict is passed. The CLI respects UV_OFFLINE / HF offline variables and never falls back from uv to pip offline.
  • Inference respawn refuses to spawn while the old worker survives shutdown. SSM restart and the Xet fallback each get their own one-use retry (3 spawns max).
  • Restart detection only counts native modeling_* modules and the selected checkpoint's remote code modules from its auto_map, matched on the exact transformers_modules namespace.
  • Export provisions SSM kernels inside the existing transformers activation window (no extra Hub reachability probe), and skips provisioning on macOS and for the MLX / CPU export backends.
  • UV_OFFLINE counts as offline for on-demand installs (no URL probes, source builds, or uv to pip fallback).
  • Long context flash-attn install returns early when flash_attn already imports, reuses the worker's own torch for the capability check, and never applies the sm80 floor on ROCm.

Install robustness (platform matrix review)

  • A wheel is downloaded whenever its HEAD check is not a definite 404 (proxies that refuse HEAD no longer push required hybrids into a failure), then import-verified; fallback only after a real failure.
  • A failed install is remembered for the worker process (keyed by kernel, torch, toolchain), so preflight and load share one attempt. Optional Mamba families get mamba-ssm only as a prebuilt wheel, never a source build. ROCm source builds get an 1800 s deadline and CUDA source builds 7200 s (UNSLOTH_SOURCE_BUILD_TIMEOUT overrides); a timeout kills the whole build tree.
  • A runtime install whose extension does not import is uninstalled, so transformers never finds a broken package.
  • One cross-process lock per kernel and environment covers check, install, verify and cleanup (training and runtime), with a recheck after acquiring it.
  • Only a CUDA or ROCm torch provisions anything; CPU, XPU, MPS and unknown torch builds skip (export included).
  • Optional mamba-ssm follows setup's sm80 floor (sm75 with Triton 3.4+); the required hybrids keep the previous behavior.
  • The resolver only returns URLs for cells that are actually published (Unsloth release: torch 2.13/2.14 cp313, win_amd64 torch 2.10 to 2.12 cp311 to cp313; upstream causal-conv1d / mamba-ssm release cells), and there is no source build of the pinned 1.6.1 / 2.3.1 sources on torch 2.13+, which need C++20.
  • Training stays best effort for mamba-ssm, as before Studio: install causal-conv1d and mamba-ssm only when a model needs them #13861.
  • Export runs the malware and remote code consent gates before any kernel provisioning.
  • The extension is probed again after the install lock is acquired, so a concurrent replacement is not treated as broken.
  • The automatic HF offline window (Hub unreachable) no longer blocks package installs; only user set offline variables do.
  • unsloth install-kernels --dry-run prints the resolved URL while offline.
  • A Mamba model whose code needs mamba-ssm fails with a clear error on a torch build without CUDA or ROCm.

GPU checks (merge base vs head 4a6429a)

Kaggle T4, torch 2.11.0+cu130, Qwen3.5-0.8B fp16:

base head
causal-conv1d on demand not installed installed, causal_conv1d_update_kernel engaged
decode tok/s (6 alternating repeats) 18.70 19.41 (+3.8%, 6/6 pairs)
decode peak alloc 1.748 GB 1.748 GB
LoRA step time (3 repeats) 1975.5 ms 1970.7 ms (inside spread)
LoRA peak alloc 2.338 GB 2.338 GB
flash-attn at setup on sm75 downloaded skipped

AMD gfx1151 (torch 2.11.0+rocm7.13.0): Qwen3.5 LoRA losses within 1.2e-4 relative (head vs merge commit bit identical), peak 2.389 GB both, backend suites 262/262 and 275/275 passing.

…rovision SSM kernels in export

- Request causal-conv1d on demand again for Qwen3.5/3.6/Qwen3-Next in training, inference and Clef
- mamba-ssm stays required only for nemotron_h, falcon_h1 and granitemoehybrid; newer SSM families continue on the torch path
- Resolve local adapter bases and the adapter base pin before deciding kernels
- Export worker provisions SSM kernels before importing Unsloth
- Inference re-reads modeling sources without importing transformers and respawns the worker once after a fresh install
- Setup removes causal-conv1d / mamba-ssm builds that no longer import after a torch change
- Skip flash-attn downloads below sm80 at setup and for long-context training
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 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-19T07:39:54.984454Z 609775c New commits
🔒 Security Review ✅ Completed 2026-10-18T11:12:22.321357Z 75fdaa2 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.

- Stale kernel removal needs proof: torch imports, then the extension import completes with an
  ImportError / OSError; a broken torch, a signal, a hang or an unrelated exit keeps the kernel
- unsloth install-kernels --without-gpu (or UNSLOTH_INSTALL_KERNELS_WITHOUT_GPU=1) provisions
  GPU-gated kernels in a GPU-less image build; skipped kernels are listed, and a named kernel
  that was skipped exits non-zero
- Inference respawn never spawns over a worker that survived shutdown
- SSM restart and Xet fallback each get their own one-use retry, at most three spawns, with an
  accurate stall message
- Restart only for imported modeling modules, including the selected remote-code model's
- Export skips SSM provisioning on macOS, MLX and CPU
- UV_OFFLINE counts as offline for on-demand kernel installs
- Long-context flash-attn: no probe when already importable, reuse the worker's torch, never
  apply the sm80 floor on ROCm
… matching

- install-kernels checks an already-working extension before the wheel, GPU and offline skips
  (a ROCm source build or a GPU-hidden builder's install is success); skipped kernels are listed
  and exit 0 as before, --strict opts into exit 2
- install-kernels installs nothing offline (UV_OFFLINE, HF_HUB_OFFLINE, TRANSFORMERS_OFFLINE), and
  install_wheel never falls back from an offline uv to pip
- Restart detection takes the implementation modules from the config's auto_map (any module
  name) and matches transformers_modules.<checkpoint namespace> exactly, both spellings
- Export decides the CPU / MLX / macOS bypass before the connectivity window
… up, lock

- A wheel whose HEAD check is unanswered is still downloaded and verified (as setup did); only a
  real download / import failure falls back, in inference, export and training
- A failed install is not retried in the same process (keyed by kernel, torch and toolchain), so
  a load's preflight and _handle_load share one attempt; configs are read once per process
- Optional mamba-ssm families (mamba, mamba2, falcon_mamba, jamba, zamba, zamba2, bamba) get a
  prebuilt wheel only, never a source build, and are skipped below setup's sm80 / sm75 + Triton
  3.4 floor; Nemotron-H, Falcon-H1 and Granite-4.0-H keep the source fallback and no floor
- CUDA source builds get the 1800 s deadline ROCm had, and a timeout stops the whole build tree
- A failed runtime install removes the distribution whose extension does not import
- One cross-process lock per kernel and environment covers precheck, install, verify and cleanup,
  rechecks after acquiring, reports while waiting and gives up after a bound
- Only a CUDA or ROCm torch provisions kernels; export provisions only for a CUDA / ROCm backend
…source builds

- The Unsloth prebuilt resolver answers only for (platform, torch, interpreter) cells the release
  carries: torch 2.13 / 2.14 are cp313 on every platform, so linux_x86_64 cp310-cp312 and
  win_arm64 cp311 / cp312 no longer get a URL that 404s; no upstream URL for torch 2.13+ either
- No source build of the pinned causal-conv1d 1.6.1 / mamba-ssm 2.3.1 on torch 2.13+ (C++17
  sources against C++20 torch headers): the prebuilt wheel or the torch path, in inference,
  export and training
- Training stops with the inference error when Nemotron-H, Falcon-H1 or Granite-4.0-H cannot get
  mamba-ssm on a CUDA / ROCm torch, including Windows without triton-windows
- The MLX training-worker test stubs the wheel_utils names the worker now imports
The pinned upstream releases (causal-conv1d v1.6.1.post4, mamba-ssm v2.3.1) publish CUDA 11 / 12
/ 13 Linux wheels for a fixed set of torch minors and cp310-cp313 only; CUDA 13 before torch 2.9,
aarch64 before 2.7 and abiFALSE after 2.6 were URLs that 404 in front of the source fallback.
The cells are now a table read from the two asset lists, and a test ties every URL the resolver
can emit to it.
Nemotron-H, Falcon-H1 and Granite-4.0-H keep the source fallback, but a failed install or a
Windows torch without triton-windows no longer stops the run: their native transformers path can
run without mamba-ssm, so training reports it and continues, as it did before.
Nemotron-H, Falcon-H1 and Granite-4.0-H still try mamba-ssm first (source build included), but a
failed install now refuses the chat or export load only when that load imports code that cannot
run without it: remote modeling code (auto_map, under trust_remote_code or with no native class)
that imports mamba_ssm unconditionally, or a model type the installed transformers has no native
implementation of. Their native transformers models run without it, so otherwise the load goes
ahead on the torch path with a warning, as before #13861 (a Nemotron-H checkpoint on Windows
ROCm was refused).
…nel builds

- Training's eager causal-conv1d install and its fast-path hook share the runtime's failed-attempt
  memo (same key), so a failed CUDA / HIP build is never repeated in one worker
- Only successful config reads are cached; a miss is read again next time
- A kernel a peer installed while this worker waited counts as new here, so inference refreshes
  or restarts its already-imported modeling modules
- The install lock lives beside the environment (else one per environment in the temp folder),
  and every mutating entry point takes it: Studio workers, setup's stale-kernel removal and
  unsloth install-kernels. A lock that cannot be opened or taken skips the install instead of
  racing unguarded; optional accelerations wait at most 120 s for a peer, required ones 2400 s
- Force-terminating a training run first stops the processes its worker started, including a
  source build in its own session
- A runtime install whose installer cannot even start still removes a broken copy and is
  remembered as failed
- Tests never take the environment's real install locks
…amba / Zamba / Bamba

_ensure_mamba_ssm defaulted essential to True, so a caller that left it out (the ROCm hardware
probe on gfx1151) compiled mamba-ssm from source for a Mamba2 model for 60 s. Unspecified now
means the name decides: only Nemotron-H, Falcon-H1 and Granite-4.0-H may build it.
@danielhanchen

Copy link
Copy Markdown
Member Author

The (Python 3.13, rest) failure comes from this PR:

studio/backend/tests/test_training_worker_flash_attn.py::test_mamba_ssm_follows_the_resolved_answer_not_the_name
core/training/worker.py:1795: in _ensure_mamba_ssm
    _send_status(event_queue, f"Skipping mamba-ssm, which {reason}")
core/training/worker.py:5362: in _send_status
    event_queue.put(
AttributeError: 'list' object has no attribute 'put'

The new skip message in _ensure_mamba_ssm goes through _send_status, which needs a queue with .put. The test still passes a plain list as event_queue. Pass a small queue stand-in (or queue.Queue()) in that test. Asserting on the new "Skipping mamba-ssm" status would also cover the message itself.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 75fdaa259b

View security finding report

Only the user who started this review can view the report in Codex.

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

@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: 75fdaa259b

ℹ️ 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 +673 to +675
if not _provision_ssm_kernels(
checkpoint_path,
config.get("base_model") or 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 Run export security gates before provisioning kernels

For a checkpoint that the malware or remote-code consent gate rejects, this startup path installs or even source-builds native SSM packages before _handle_load reaches those gates at all. A blocked model can therefore modify the shared Python environment and consume up to the source-build timeout before the export is refused; perform a transformers-free security preflight, as the inference worker does, before calling _provision_ssm_kernels.

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 7c90c5b: the malware and remote code consent gates now run before any kernel provisioning, so a rejected checkpoint never triggers an install or source build.

Comment on lines +8744 to +8745
try:
removed = _uninstall_distribution(distribution)

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 Re-probe the extension after acquiring the install lock

When another process is currently replacing the same kernel, the unlocked probe can observe its transient broken state and then wait for kernel_install_lock; after the peer finishes and releases the lock, this code immediately uninstalls the newly verified package using the stale probe result. Re-run the extension probe while holding the lock before removing the distribution.

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 7c90c5b: the extension is probed again after the install lock is acquired, so a concurrent replacement in progress is not mistaken for a broken install.

"import torch\n"
"try:\n"
" import {extension}\n"
"except (ImportError, OSError) as exc:\n"

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 Treat RuntimeError from extension imports as stale

After a torch/CUDA upgrade, an ABI-incompatible PyTorch extension can raise RuntimeError as well as ImportError or OSError (the runtime installer already treats any of these failures as non-importable). In that case this child exits with an unrelated code, _remove_stale_ssm_kernels keeps the broken distribution, and later model loading can select its metadata and fail instead of reinstalling it.

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.

The stale check imports only the compiled extension module, where a torch ABI mismatch surfaces as ImportError (undefined symbol) and pybind init failures also become ImportError. Anything else is treated as inconclusive on purpose, because this setup time cleanup only removes a kernel on proof. A copy kept here is not left broken: at load, ssm_runtime treats any exception from the import as not importable and reinstalls the wheel, or removes the rejected copy before rebuilding. So the model load does not fail on it.

Comment on lines +673 to +675
if not _provision_ssm_kernels(
checkpoint_path,
config.get("base_model") or 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 Allow kernel provisioning during temporary HF offline windows

When _offline_window_if_unreachable detects only the Hugging Face endpoint is down, it temporarily sets the HF offline state and then calls this provisioner inside that window. package_installs_offline() consequently suppresses GitHub/PyPI kernel downloads too, so exporting a cached or local remote-code SSM model with a missing required kernel fails even when the package hosts remain reachable; keep the HF-only window from being interpreted as an operator-requested package-offline mode.

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 7c90c5b: the automatic HF offline window is now marked, and package installs ignore it. Only a user set HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE / UV_OFFLINE blocks provisioning.

Comment thread studio/backend/utils/kernel_install.py Outdated
Comment on lines +568 to +572
if package_installs_offline_env():
return skip(
f"Unsloth: not installing {name} while offline "
"(UV_OFFLINE / HF_HUB_OFFLINE / TRANSFORMERS_OFFLINE)."
)

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 Preserve dry-run URL resolution while offline

With HF_HUB_OFFLINE, TRANSFORMERS_OFFLINE, or UV_OFFLINE set, this return runs even when dry_run=True, so unsloth install-kernels --dry-run prints no resolved wheel URL despite its documented purpose of printing the URL without installing anything. Offline and air-gapped image workflows commonly need exactly that output for prefetching; apply the offline installation guard only to non-dry runs.

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 7c90c5b: dry run resolves and prints the URL even when offline; the offline early return only applies to real installs.

Comment on lines +1126 to +1129
if not _install(MAMBA_SSM, allow_source_build = mamba_ssm_required):
if mamba_ssm_fatal and _kernel_backend(_torch_env()) is not None:
raise RuntimeError(
f"Could not install mamba-ssm, required by this Mamba model. {offline_hint}"

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 Reject fatal Mamba loads on unsupported torch backends

When mamba_ssm_fatal is true because trusted remote code imports mamba_ssm unconditionally or the active Transformers has no native implementation, a CPU/XPU build or a failed torch probe makes _kernel_backend return None and suppresses this error. The worker then claims it will use a torch fallback that does not exist and proceeds until the modeling import fails cryptically; fatal loads should be rejected here regardless of whether a CUDA/ROCm installation was possible.

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 7c90c5b: a fatal Mamba load on a torch without CUDA or ROCm now raises a clear error instead of continuing into an import failure.

Comment thread studio/backend/utils/kernel_install.py Outdated
Comment on lines +336 to +338
# One overall deadline for every source build, CUDA as well as ROCm: run it through
# run_process_tree so a timeout also stops the compilers pip / uv started.
kwargs["timeout"] = SOURCE_BUILD_TIMEOUT

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 Avoid timing out valid non-ROCm source builds

This newly applies the 1800-second deadline to every CUDA source build, whereas the previous implementation deliberately left non-HIP builds unbounded because causal-conv1d can compile slowly on aarch64 and constrained builders. On a valid build taking more than 30 minutes, the process tree is killed and a required remote-code SSM model may become unloadable; retain a longer or platform-specific deadline rather than reusing the ROCm limit universally.

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 7c90c5b: CUDA source builds use their own 7200 s deadline (UNSLOTH_SOURCE_BUILD_TIMEOUT overrides), ROCm keeps 1800 s, and the lock wait is sized from the larger of the two.

…n CUDA build deadline

- Export worker: run the malware and remote-code consent gates (transformers-free,
  no load-subdir scan) before provisioning SSM kernels, at startup and on each
  "load" command, so a blocked checkpoint never triggers a kernel build.
  _handle_load keeps its authoritative re-check through the shared helper.
- Export offline window: mark an HF offline set only because the Hub was
  unreachable; package_installs_offline() and package_installs_offline_env()
  then honour only UV_OFFLINE, so required kernels can still come from GitHub /
  PyPI. An operator-set HF offline still blocks installs.
- install_python_stack: re-probe a stale SSM extension while holding the kernel
  install lock and remove it only if it still fails the same way.
- unsloth install-kernels --dry-run prints the wheel URL even offline.
- ssm_runtime: a model that cannot load without mamba-ssm now fails clearly on a
  CPU / XPU torch instead of falling through to a torch path that cannot work.
- CUDA source builds get their own 7200 s deadline (UNSLOTH_SOURCE_BUILD_TIMEOUT
  overrides); HIP keeps 1800 s; KERNEL_LOCK_WAIT covers the longer of the two.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 7c90c5bd9e

ℹ️ 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 7729c37 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the studio-ssm-on-demand-followups branch October 19, 2026 11:32
danielhanchen added a commit that referenced this pull request Oct 19, 2026
danielhanchen added a commit that referenced this pull request Oct 19, 2026
danielhanchen added a commit that referenced this pull request Oct 19, 2026
#14268)

## Summary


`studio/backend/tests/test_kernel_install.py::test_a_timed_out_build_stops_its_whole_process_tree`
flakes in the `(Python 3.13, a-k)` shard (seen on #14240):

```
tests/test_kernel_install.py:1041: in test_a_timed_out_build_stops_its_whole_process_tree
    if stat.read().split()[2] == "Z":
E   ProcessLookupError: [Errno 3] No such process
```

## Cause

The test polls the killed grandchild until it is gone. That means
`kill(pid, 0)` fails, or `/proc/<pid>/stat` shows a zombie, or that file
is missing. The grandchild can be reaped between opening
`/proc/<pid>/stat` and reading it. On Linux that read raises
`ProcessLookupError` (ESRCH), not `FileNotFoundError`. So the test
failed exactly when the process had already gone, which is the outcome
it was waiting for. The product (`kernel_install.run_process_tree`) is
fine. The poll came in with #13971.

Reproduced directly: open `/proc/<pid>/stat` of a live child, kill and
reap it, then read. The read raises `ProcessLookupError: [Errno 3] No
such process`.

## Change

Test-only:

- **`_process_gone(pid)`:** the same three checks, with
`(FileNotFoundError, ProcessLookupError)` both counted as gone.
- **`test_a_process_reaped_while_its_stat_is_read_counts_as_gone`:**
makes the race deterministic. `open` of the child's stat file kills and
reaps the child right after opening, and `kill(pid, 0)` reports it
alive, as at the start of the race. It is skipped where there is no
procfs.

## Testing

- **`studio/backend/tests/test_kernel_install.py`:** 119 passed.
- **Sabotage:** with the helper back to catching only
`FileNotFoundError`, the new test fails with `ProcessLookupError: [Errno
3] No such process`. That is the CI failure.
danielhanchen added a commit that referenced this pull request Oct 20, 2026
…h-zoo covers decode (#14148)

Stacked on #13971. Pairs with unslothai/unsloth-zoo#1857.

Qwen3.5 / Qwen3.6 / Qwen3-Next stop downloading causal-conv1d on demand
when the installed unsloth-zoo runs their short conv in Triton for
prefill, training and cached decode.

## Why

unsloth-zoo#1857 adds a Triton `causal_conv1d_update` for GatedDeltaNet
decode (the prefill / training conv was already Triton). On a Kaggle T4
(Qwen3.5-0.8B fp16) decode with it is within noise of the causal-conv1d
package (19.79 vs 19.64 and 19.47 vs 19.20 tok/s, two lanes) at 16.5 us
per call against 46-48 us for the package, with identical memory and
tokens. The binary is then pure download cost for these models.

## Changes

- `ssm_runtime.py`: Qwen3.5 / 3.6 / Qwen3-Next request causal-conv1d
only when zoo cannot cover them: the installed zoo lacks the decode
kernel (read from its source on `sys.path`, nothing imported),
`UNSLOTH_DISABLE_TRITON_CAUSAL_CONV1D=1` is set, or the platform cannot
run zoo's Triton conv (ROCm, macOS, no triton). The config check runs
before the modeling source scan, since those modeling files mention
causal_conv1d. Mixed configs and other conv users (LFM2, the Mamba
families) still request it.
- `clef_runtime.py`: Clef skips the install the same way and keeps the
FLA TileLang guard.
- An already installed causal-conv1d is left alone and still wins inside
zoo.

## Tests

`test_ssm_runtime.py`, `test_clef_fast_paths.py` (new cases fail on
#13971's head and pass here), with `conftest.py` pinning the older-zoo
answer so the suite does not depend on the host's zoo. 453 passed across
the SSM, clef, export, training worker and install stack tests.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 20, 2026
…nsloth-zoo runs their conv on Triton (#14160)

Stacked on #13971. Pairs with unslothai/unsloth-zoo#1865 and the
extension-free mamba-ssm wheel added in #14142.

Mamba-2 hybrids (Nemotron-H, Falcon-H1, Granite-4.0-H, Bamba, Zamba2,
Mamba2) install a 224 KB mamba-ssm wheel without its CUDA extension
instead of the 230 to 594 MB mamba-ssm + causal-conv1d CUDA wheels, when
unsloth-zoo can run their causal conv on Triton.

## Why

On transformers 5.x these models only use mamba-ssm's Triton ops, never
`selective_scan_cuda`. With unsloth-zoo#1865 the causal conv runs on
Triton too. On a Colab T4 (torch 2.10, Falcon-H1-0.5B fp16 LoRA, three
interleaved rounds) that route matches the CUDA wheels: train step +1.4%
(inside the CUDA arm's own spread), decode +1.7% / +1.9%, prefill +0.7%,
identical peak memory.

## Changes

- `ssm_runtime.py` / training worker / export: the pure wheel is used,
and causal-conv1d skipped, only when the config resolves to one of those
six model types, no remote code is needed, torch is a CUDA build with
Triton, transformers is 5.15 or newer, and the installed unsloth-zoo
source carries the Triton drop-ins. `UNSLOTH_MAMBA_CUDA_KERNELS=1` keeps
the CUDA wheels.
- No source build on that route. If the pure wheel is unusable (definite
404, install failure, import failure), the load falls back to today's
CUDA route (causal-conv1d, then CUDA mamba-ssm with the existing
resolver and source build policy). The failure memo is keyed per wheel
source, so a failed pure attempt never blocks the CUDA wheel, and both
routes take the per-env lock one after the other.
- `wheel_utils.mamba_ssm_pure_wheel_url()`.

## Tests

`test_ssm_mamba2_triton.py` (24 tests; the fallback ones exercise the
real `_install_kernel` with lock, memo and cleanup, only network and pip
faked). 509 passed across the clef, export, kernel_install, SSM and
training worker suites.

Not covered: ROCm and macOS stay on the existing route by design;
Windows triton-windows untested on a GPU; Mamba-1 models and
transformers older than 5.15 keep the CUDA wheels.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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