Repository navigation
Add unsloth install-kernels for prebuilt xformers / causal_conv1d / mamba_ssm wheels - #12732
Conversation
…amba_ssm wheels Notebook install cells currently carry a hand-maintained torch -> xformers map plus a cu130 URL, and a 3 line causal_conv1d URL template. Studio already resolves these wheels exactly (wheel_utils.xformers_wheel_url and direct_wheel_url), so expose that resolver as a one-line command: !unsloth install-kernels xformers causal_conv1d Wheel-only: when no wheel exists for this torch / CUDA / Python (CPU, ROCm, macOS, an unmeasured torch) nothing is installed and the torch fallback is kept. Installs are --no-deps so torch is never touched, an install that already loads is left alone, and a wheel whose extension fails to load is removed again. The console script dispatches before typer and the command modules are imported, because notebooks install unsloth with --no-deps. The causal-conv1d and mamba-ssm pins move into wheel_utils so ssm_runtime and the new module share one source of truth.
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 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. |
A uv-created venv has no pip, and pip keeps an installed same-version build even when its extension does not load. Route through wheel_utils.install_wheel (uv first, --system outside a venv, pip fallback) with a new opt-in reinstall flag, and uninstall a wheel that does not load with the same tool.
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e819cd8dca
ℹ️ 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 dry_run: | ||
| print(url) | ||
| return 0 |
There was a problem hiding this comment.
Redact mirror credentials before printing wheel URLs
When UNSLOTH_PYTORCH_MIRROR contains userinfo or a query token, xformers_wheel_url() deliberately preserves those credentials, so printing url exposes them in notebook output and logs; the same leak occurs in the install-failure and post-install messages below. wheel_utils.redact_url_credentials() already documents and implements the required redaction, so use it for every displayed URL while continuing to pass the original URL to the installer.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in be9fbc2: every printed URL and the installer output tail go through redact_url_credentials.
| if not _loads(check, run): | ||
| # A wheel that imports but whose extension cannot load would be picked up and crash later. | ||
| _uninstall(distribution, run) | ||
| print( | ||
| f"Unsloth: {name} from {url} does not load with {torch_desc}; removed it, using the torch fallback." |
There was a problem hiding this comment.
Verify that the rejected wheel was actually uninstalled
If the uninstall subprocess fails—for example because uv is present but cannot modify the selected interpreter—its return code is discarded, yet the command reports that the incompatible wheel was removed. This leaves a wheel known not to load installed, so later imports can still fail or crash despite the fallback message; check the uninstall result and explicitly report that manual removal is required when it fails.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in be9fbc2: the message only says removed when the uninstall returned 0, otherwise it names the pip uninstall command.
| "causal_conv1d": ("causal-conv1d", "import causal_conv1d"), | ||
| "mamba_ssm": ("mamba-ssm", "import mamba_ssm"), |
There was a problem hiding this comment.
Probe selective_scan_cuda when validating mamba_ssm
When the mamba wheel lacks its CUDA extension or contains an ABI-incompatible one, import mamba_ssm can still succeed because that package treats selective_scan_cuda as optional, so this check reports the kernel as usable even though the command was meant to install that compiled fast path. The repository's own .github/scripts/prebuilt_wheels_forward.py explicitly notes that importing mamba_ssm alone proves nothing and separately imports selective_scan_cuda; make this validation do the same so a broken wheel is rejected rather than reported as installed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in be9fbc2: mamba_ssm is judged by importing selective_scan_cuda and causal_conv1d by causal_conv1d_cuda. Importing the packages was the wrong check in both directions: import causal_conv1d never loads the extension, and import mamba_ssm fails on einops under --no-deps.
|
|
||
| def _loads(check: str, run: Callable[..., subprocess.CompletedProcess]) -> bool: | ||
| result = run( | ||
| [sys.executable, "-c", check], stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL | ||
| ) |
There was a problem hiding this comment.
Bound native-extension import probes with a timeout
When a mismatched native extension stalls during initialization rather than exiting, both the pre-install and post-install _loads calls wait forever because this subprocess has no timeout. The existing isolated probes in core/training/worker.py and install_python_stack.py use a 300-second bound specifically because native initialization can hang; apply the same timeout here and treat TimeoutExpired as a failed load so an interactive install command cannot remain stuck indefinitely.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: the probe imports one installed extension once per command run, and a hang there would also hang the model load that follows. A timeout would only turn that into a different failure.
…e the -m fast path - causal_conv1d / mamba_ssm are judged by loading causal_conv1d_cuda / selective_scan_cuda. import causal_conv1d never loads the extension, and import mamba_ssm fails on einops under --no-deps, which removed a good wheel. - Printed URLs go through redact_url_credentials, since UNSLOTH_PYTORCH_MIRROR may carry credentials. - A failed uninstall is no longer reported as removed. - Under python -m, dispatch only when the module run is unsloth_cli, not a host package that happens to import it.
|
@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: be9fbc241f
ℹ️ 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".
| url = resolve_wheel_url(name, env) | ||
| torch_desc = f"torch {env.get('torch_version')}" if env else "this environment" | ||
| # Only a 404 proves nothing is published; an unreachable check falls through to the install. | ||
| if url is None or exists(url) is False: |
There was a problem hiding this comment.
Redact credentials in the availability-probe warning
When UNSLOTH_PYTORCH_MIRROR contains userinfo or a query token and the HEAD request encounters a non-404 HTTP error or network failure, this call reaches wheel_utils.url_exists(), whose warning interpolates the raw URL, so the credential still lands in stderr/logs before shown is computed. Fresh evidence beyond the prior print-site report is the raw-argument logging in url_exists()'s error path; keep using the original URL for the request but redact it in that diagnostic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ebb6514: url_exists logs the redacted URL, and drops the error text when the URL carried credentials, since urllib echoes the userinfo as a bad port.
| if (_is_entry_point or (_entry_base == "-m" and _runs_unsloth_cli)) and _sys.argv[1:2] == [ | ||
| "install-kernels" | ||
| ]: | ||
| from unsloth_cli._install_kernels import main as _install_kernels_main | ||
| _sys.exit(_install_kernels_main(_sys.argv[2:])) |
There was a problem hiding this comment.
Run the SSL keylog guard before fast-path dispatch
When SSLKEYLOGFILE points to an unwritable machine-wide path, this fast-path exit occurs before _drop_unwritable_ssl_keylog_file() runs. The subsequent url_exists() HTTPS check therefore cannot create an SSL context, and on systems without uv the pip download fails for the same reason, making the new command unusable in exactly the environment the existing entry-point guard handles. Invoke that guard before dispatching install-kernels while retaining plain-import behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ebb6514: the fast path now runs drop_unwritable_ssl_keylog_file before dispatch.
…OGFILE first url_exists logged the raw wheel URL, and urllib's error text can echo the userinfo of a credentialed UNSLOTH_PYTORCH_MIRROR. The fast path also ran before the CLI's SSLKEYLOGFILE guard, so an unwritable key log broke the availability probe and the installers' HTTPS clients.
|
@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". |
* 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
Notebook install cells currently carry a hand-maintained torch to xformers map plus a cu130 wheel URL, and the Qwen3.5 / Qwen3.6 notebooks carry a 3 line causal_conv1d URL template. Studio already resolves these wheels exactly, so this exposes that resolver as one command:
What it does
wheel_utils.probe_torch_wheel_env.wheel_utils.xformers_wheel_url(exact torch patch x CUDA minor table, 0.0.35 above the stable ABI floor, honoursUNSLOTH_PYTORCH_MIRROR).wheel_utils.direct_wheel_url, so torch 2.11 / 2.12 reuse the measured torch 2.10 wheels and torch 2.13 / 2.14 use theprebuilt-wheels-cu13release, the same as Studio.--no-deps, so torch is never touched. An install that already loads is left alone. A wheel whose extension fails to load after install is removed again, and the command exits 1.--dry-runprints the resolved URL only.Entry points
unsloth install-kernels ...dispatches inunsloth_cli/__init__.pybefore typer and the command modules are imported, because notebooks install unsloth with--no-depsand may not have typer.python -m unsloth_cli install-kernels ...takes the same path.unsloth --helplists it.ssm_runtime.pytowheel_utils.py, so there is one source of truth.ssm_runtimere-imports them, so its existing lockstep tests are unchanged.Testing
studio/backend/tests/test_kernel_install.py: resolution matrix (torch 2.8.0+cu126, 2.9.0+cu128, 2.10.0+cu128, 2.11.0+cu130, 2.12.1+cu130, CPU, Windows, no torch), no install when nothing is published,--no-depsargv, idempotence, removal of a wheel that does not load,--dry-run, and the console entry running with typer made unimportable.test_ssm_runtime.py,test_wheel_utils_xformers.py,test_wheel_utils_url_exists.py, module entry point, typer floor and CI matrix tests pass.xformers-0.0.35(cu130) andcausal_conv1d-1.6.1+cu13torch2.10. A second run reports both already installed. On GPU,causal_conv1d_fnmatches a torch conv1d + SiLU reference (max err 3.8e-3, fp16) andmemory_efficient_attentionmatches SDPA (max err 2.0e-3).pip install --no-depsof this branch into a venv without typer: theunsloth install-kernelsconsole script runs, and--helpworks.--dry-run: resolves xformers 0.0.35 cu130 plus theprebuilt-wheels-cu13causal_conv1d 1.7.0 and mamba_ssm 2.3.2.post1 wheels.A follow up in unslothai/notebooks will replace the xformers map and the causal_conv1d lines with this command once a release containing it is on PyPI.