Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
install-kernels: skip mamba_ssm below sm80 (#12921)
Daniel Han8ba9e67f7d3e
diff --git a/studio/backend/tests/test_kernel_install.py b/studio/backend/tests/test_kernel_install.pyindex 1e45f1e4fdb..5a6416d7c3f 100644--- a/studio/backend/tests/test_kernel_install.py+++ b/studio/backend/tests/test_kernel_install.py@@ -336,14 +336,30 @@ def test_flash_attn_resolution(env, expected):assert kernel_install.resolve_wheel_url("flash_attn", env) == expected[email protected]("name", ["flash_attn", "mamba_ssm"])@pytest.mark.parametrize("capability", ["7 5", "None"])-def test_flash_attn_is_skipped_below_sm80(capability, capsys):+def test_sm80_kernels_are_skipped_below_sm80(name, capability, capsys):run = _Runner([], capability = capability)+ assert kernel_install.install_kernel(name, _COLAB, run = run, exists = lambda url: True) == 0+ assert run.installer_calls == []+ assert f"skipping {name}, which needs sm80 or newer" in capsys.readouterr().out+++def test_causal_conv1d_still_installs_below_sm80(uv):+ uv(False)+ run = _Runner([False, True], capability = "7 5")assert (- kernel_install.install_kernel("flash_attn", _COLAB, run = run, exists = lambda url: True) == 0+ kernel_install.install_kernel("causal_conv1d", _COLAB, run = run, exists = lambda url: True)+ == 0)- assert run.installer_calls == []- assert "skipping flash_attn" in capsys.readouterr().out+ assert run.installer_calls[0][-1].startswith(f"{_CC1D}/causal_conv1d-1.6.1+cu13torch2.10")+++def test_the_gpu_is_probed_once_for_every_sm80_kernel(capsys):+ run = _Runner([], capability = "7 5")+ for name in ("flash_attn", "mamba_ssm"):+ kernel_install.install_kernel(name, _COLAB, run = run, exists = lambda url: True)+ assert sum("get_device_capability" in " ".join(c) for c in run.calls) == 1def test_flash_attn_installs_on_sm80_and_newer(uv):diff --git a/studio/backend/utils/kernel_install.py b/studio/backend/utils/kernel_install.pyindex d401e2ad731..1bb88dae202 100644--- a/studio/backend/utils/kernel_install.py+++ b/studio/backend/utils/kernel_install.py@@ -217,8 +217,22 @@ def resolve_wheel_url(name: str, env: dict[str, str] | None) -> str | None:return _PINNED[name].wheel_url(env)+# FlashAttention 2 needs sm80, and unsloth_zoo turns mamba_ssm's fast path off below sm80+# (patch_mamba_ssm_pre_ampere_fallback), so either wheel would go unused there.+_NEEDS_SM80 = ("flash_attn", "mamba_ssm")+_CAPABILITY: dict = {}++def _gpu_capability(run: Callable[..., subprocess.CompletedProcess]) -> tuple[int, int] | None:- """The best compute capability across the visible GPUs, or None."""+ """The best compute capability across the visible GPUs, or None. Probed once per runner."""+ if run not in _CAPABILITY:+ _CAPABILITY[run] = _probe_gpu_capability(run)+ return _CAPABILITY[run]+++def _probe_gpu_capability(+ run: Callable[..., subprocess.CompletedProcess],+) -> tuple[int, int] | None:check = ("import torch; n = torch.cuda.device_count() if torch.cuda.is_available() else 0; ""print(*max(torch.cuda.get_device_capability(i) for i in range(n))) if n else None"@@ -271,8 +285,7 @@ def install_kernel() -> int:distribution, check = KERNELS[name]url = resolve_wheel_url(name, env)- if name == "flash_attn" and url is not None:- # FlashAttention 2 needs Ampere or newer, and Unsloth only enables it there.+ if name in _NEEDS_SM80 and url is not None:capability = _gpu_capability(run)if capability is None or capability < (8, 0):gpu = (@@ -280,7 +293,7 @@ def install_kernel(if capability is Noneelse "the best GPU is sm%d%d" % capability)- print(f"Unsloth: skipping flash_attn, which needs sm80 or newer ({gpu}).")+ print(f"Unsloth: skipping {name}, which needs sm80 or newer ({gpu}).")return 0torch_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.