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: install mamba_ssm on sm75 with Triton 3.4+ (#12944)
Daniel Hane00ca8728ec5
diff --git a/studio/backend/tests/test_kernel_install.py b/studio/backend/tests/test_kernel_install.pyindex 5a6416d7c3f..333a58df955 100644--- a/studio/backend/tests/test_kernel_install.py+++ b/studio/backend/tests/test_kernel_install.py@@ -109,15 +109,21 @@ class _Runner:self,loads,capability = "9 0",+ triton = None,):self.loads = list(loads)self.capability = capability+ self.triton = tritonself.calls = []def __call__(self, cmd, **kwargs):self.calls.append(cmd)if cmd[1] == "-c" and "get_device_capability" in cmd[2]:return SimpleNamespace(returncode = 0, stdout = self.capability)+ if cmd[1] == "-c" and "import triton" in cmd[2]:+ if self.triton is None:+ return SimpleNamespace(returncode = 1, stdout = "")+ return SimpleNamespace(returncode = 0, stdout = self.triton + "\n")if cmd[1] == "-c":return SimpleNamespace(returncode = 0 if self.loads.pop(0) else 1, stdout = "")return SimpleNamespace(returncode = 0, stdout = "")@@ -338,11 +344,91 @@ def test_flash_attn_resolution(env, expected):@pytest.mark.parametrize("name", ["flash_attn", "mamba_ssm"])@pytest.mark.parametrize("capability", ["7 5", "None"])-def test_sm80_kernels_are_skipped_below_sm80(name, capability, capsys):+def test_sm80_kernels_are_skipped_below_sm80(name, capability, capsys, monkeypatch):+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: (3, 3))run = _Runner([], capability = capability)assert kernel_install.install_kernel(name, _COLAB, run = run, exists = lambda url: True) == 0assert run.installer_calls == []- assert f"skipping {name}, which needs sm80 or newer" in capsys.readouterr().out+ assert f"skipping {name}, which needs sm80" in capsys.readouterr().out+++# unsloth_zoo keeps mamba_ssm's fast path on sm75 with Triton 3.4+ (torch 2.8+).++[email protected]("triton", [(3, 4), (3, 6), (4, 0)])+def test_mamba_ssm_installs_on_sm75_with_a_new_triton(uv, monkeypatch, triton):+ uv(False)+ monkeypatch.delenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", raising = False)+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: triton)+ run = _Runner([False, True], capability = "7 5")+ assert kernel_install.install_kernel("mamba_ssm", _COLAB, run = run, exists = lambda url: True) == 0+ assert run.installer_calls[0][-1].endswith(+ "mamba_ssm-2.3.1+cu13torch2.10cxx11abiTRUE-cp313-cp313-linux_x86_64.whl"+ )++[email protected]("triton", [(3, 3), (3, 2), None])+def test_mamba_ssm_is_skipped_on_sm75_with_an_old_triton(monkeypatch, capsys, triton):+ monkeypatch.delenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", raising = False)+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: triton)+ run = _Runner([], capability = "7 5")+ assert kernel_install.install_kernel("mamba_ssm", _COLAB, run = run, exists = lambda url: True) == 0+ assert run.installer_calls == []+ out = capsys.readouterr().out+ assert "sm75 with Triton 3.4+" in out+ assert ("missing" if triton is None else "%d.%d" % triton) in out+++ "triton, installs",+ [("3.4.0", True), ("3.6.0+git1a2b3c", True), ("3.3.1", False), (None, False)],+)+def test_triton_is_read_from_the_module(uv, monkeypatch, triton, installs):+ """pytorch-triton and other providers ship the `triton` import under another+ distribution name, so the version comes from `triton.__version__`."""+ uv(False)+ monkeypatch.delenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", raising = False)+ run = _Runner([False, True], capability = "7 5", triton = triton)+ assert kernel_install.install_kernel("mamba_ssm", _COLAB, run = run, exists = lambda url: True) == 0+ assert bool(run.installer_calls) is installs+++def test_mamba_ssm_is_skipped_below_sm75_whatever_the_triton(monkeypatch, capsys):+ monkeypatch.delenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", raising = False)+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: (3, 6))+ run = _Runner([], capability = "7 0")+ assert kernel_install.install_kernel("mamba_ssm", _COLAB, run = run, exists = lambda url: True) == 0+ assert run.installer_calls == []+ assert "the best GPU is sm70" in capsys.readouterr().out+++ "forced, capability, installs",+ [+ ("1", "7 0", True),+ ("1", "7 5", True),+ ("0", "7 5", False),+ ],+)+def test_mamba_ssm_follows_the_unsloth_zoo_override(uv, monkeypatch, forced, capability, installs):+ uv(False)+ monkeypatch.setenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", forced)+ monkeypatch.setattr(+ kernel_install, "_triton_version", lambda run: (3, 6) if forced == "0" else (3, 3)+ )+ run = _Runner([False, True], capability = capability)+ assert kernel_install.install_kernel("mamba_ssm", _COLAB, run = run, exists = lambda url: True) == 0+ assert bool(run.installer_calls) is installs+++def test_flash_attn_stays_sm80_only_with_a_new_triton(monkeypatch):+ monkeypatch.setenv("UNSLOTH_MAMBA_PRE_AMPERE_FAST", "1")+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: (3, 6))+ run = _Runner([], capability = "7 5")+ assert (+ kernel_install.install_kernel("flash_attn", _COLAB, run = run, exists = lambda url: True) == 0+ )+ assert run.installer_calls == []def test_causal_conv1d_still_installs_below_sm80(uv):@@ -355,7 +441,8 @@ def test_causal_conv1d_still_installs_below_sm80(uv):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):+def test_the_gpu_is_probed_once_for_every_sm80_kernel(capsys, monkeypatch):+ monkeypatch.setattr(kernel_install, "_triton_version", lambda run: (3, 3))run = _Runner([], capability = "7 5")for name in ("flash_attn", "mamba_ssm"):kernel_install.install_kernel(name, _COLAB, run = run, exists = lambda url: True)diff --git a/studio/backend/utils/kernel_install.py b/studio/backend/utils/kernel_install.pyindex 1bb88dae202..4ff8020e6b5 100644--- a/studio/backend/utils/kernel_install.py+++ b/studio/backend/utils/kernel_install.py@@ -217,12 +217,59 @@ 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.+# FlashAttention 2 needs sm80. mamba_ssm's Triton kernels also run on sm75 with Triton 3.4++# (torch 2.8+), the same rule unsloth_zoo's patch_mamba_ssm_pre_ampere_fallback applies, which+# turns the fast path off anywhere else, so the wheel would go unused there._NEEDS_SM80 = ("flash_attn", "mamba_ssm")+_MAMBA_SM75_MIN_TRITON = (3, 4)_CAPABILITY: dict = {}+_TRITON: dict = {}+++def _triton_version(run: Callable[..., subprocess.CompletedProcess]) -> tuple[int, int] | None:+ """The `triton` module's version, as unsloth_zoo reads it. Probed once per runner.++ Asked of the module, not the `triton` distribution: pytorch-triton and other+ providers ship the same import under another name.+ """+ if run not in _TRITON:+ try:+ result = run(+ [sys.executable, "-c", "import triton; print(triton.__version__)"],+ stdout = subprocess.PIPE,+ stderr = subprocess.DEVNULL,+ text = True,+ encoding = "utf-8",+ errors = "replace",+ timeout = 120,+ )+ major, minor = result.stdout.strip().split(".")[:2]+ _TRITON[run] = (int(major), int(minor))+ except Exception:+ _TRITON[run] = None+ return _TRITON[run]+++def _pre_ampere_skip_reason(+ name: str, capability: tuple[int, int], run: Callable[..., subprocess.CompletedProcess]+) -> str | None:+ """Why a kernel stays off a pre-sm80 GPU, or None when unsloth_zoo uses it there."""+ if name != "mamba_ssm":+ return "needs sm80 or newer"+ forced = os.environ.get("UNSLOTH_MAMBA_PRE_AMPERE_FAST", "").strip()+ if forced in ("0", "1"):+ return None if forced == "1" else "UNSLOTH_MAMBA_PRE_AMPERE_FAST=0 is set"+ if capability < (7, 5):+ return "needs sm80, or sm75 with Triton 3.4+"+ triton = _triton_version(run)+ if triton is not None and triton >= _MAMBA_SM75_MIN_TRITON:+ return None+ found = "missing" if triton is None else "%d.%d" % triton+ return f"needs sm80, or sm75 with Triton 3.4+ (torch 2.8+), and Triton is {found}"++def _gpu_capability(run: Callable[..., subprocess.CompletedProcess]) -> tuple[int, int] | None:"""The best compute capability across the visible GPUs, or None. Probed once per runner."""if run not in _CAPABILITY:@@ -287,14 +334,17 @@ def install_kernel(url = resolve_wheel_url(name, env)if name in _NEEDS_SM80 and url is not None:capability = _gpu_capability(run)- if capability is None or capability < (8, 0):- gpu = (- "no CUDA GPU is visible"- if capability is None- else "the best GPU is sm%d%d" % capability- )- print(f"Unsloth: skipping {name}, which needs sm80 or newer ({gpu}).")+ if capability is None:+ print(f"Unsloth: skipping {name}, which needs sm80 or newer (no CUDA GPU is visible).")return 0+ if capability < (8, 0):+ reason = _pre_ampere_skip_reason(name, capability, run)+ if reason is not None:+ print(+ f"Unsloth: skipping {name}, which {reason} "+ f"(the best GPU is sm{capability[0]}{capability[1]})."+ )+ 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.if url is None or exists(url) is False: