Skip to content

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.

Studio: skip causal-conv1d for Qwen3.5 / 3.6 / Qwen3-Next when unsloth-zoo covers decode (#14148)

Daniel Han670d9b8d4d81
diff --git a/studio/backend/core/systemone/clef_runtime.py b/studio/backend/core/systemone/clef_runtime.py
index 547a6414e10..1a575dc1d20 100644
--- a/studio/backend/core/systemone/clef_runtime.py
+++ b/studio/backend/core/systemone/clef_runtime.py
@@ -46,10 +46,20 @@ class _Events:
def _fast_paths(folder: str) -> None:
- # The same prebuilt causal-conv1d a Qwen3.5 training run gets; the gated delta kernels ship with
- # unsloth_zoo. A failed install leaves transformers' torch path, which is slower but right.
+ # Clef is a Qwen3.5 backbone: unsloth_zoo ships its gated delta kernels and Triton causal conv
+ # (prefill and decode), so nothing is installed. Where that conv cannot run (switched off, ROCm,
+ # no Triton, an older zoo) it gets the prebuilt causal-conv1d a training run would; a failed
+ # install leaves transformers' torch path, which is slower but right.
try:
+ from utils.ssm_runtime import zoo_triton_causal_conv1d_usable
+
+ if zoo_triton_causal_conv1d_usable():
+ # The hooks below also steer FLA off TileLang where it faults; keep that part.
+ from core.training.worker import _guard_fla_tilelang
+ _guard_fla_tilelang()
+ return
from core.training.worker import _ensure_causal_conv1d_fast_path, _install_fast_path_hooks
+
_ensure_causal_conv1d_fast_path(_Events(), folder, required = True)
_install_fast_path_hooks(_Events(), folder, install_causal_conv1d = True)
except Exception as exc:
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index 43d214cdb5a..d5486f433e0 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -121,6 +121,19 @@ def _skills_home_root(tmp_path_factory):
_skills_home_counter = itertools.count()
[email protected](autouse = True)
+def _zoo_without_gdn_decode_kernel(monkeypatch):
+ # Whether Qwen3.5 / Qwen3-Next ask for causal-conv1d depends on the installed unsloth_zoo; pin the
+ # older-zoo answer so results do not follow the host. Tests of the newer zoo patch it back.
+ ssm_runtime = sys.modules.get("utils.ssm_runtime")
+ if ssm_runtime is None:
+ try:
+ from utils import ssm_runtime
+ except Exception:
+ return
+ monkeypatch.setattr(ssm_runtime, "_zoo_gdn_decode_kernel_present", lambda: False, raising = False)
+
+
@pytest.fixture(autouse = True)
def _no_real_mxc_drive_aliases(monkeypatch):
# A Windows test host would otherwise map real drive letters; test_mxc_drive_alias.py and the native
diff --git a/studio/backend/tests/test_clef_fast_paths.py b/studio/backend/tests/test_clef_fast_paths.py
index 26838a370f1..613543fafb9 100644
--- a/studio/backend/tests/test_clef_fast_paths.py
+++ b/studio/backend/tests/test_clef_fast_paths.py
@@ -2,7 +2,7 @@
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
"""Clef (a Qwen3.5 backbone) installs the prebuilt causal-conv1d and its availability hook, whose
-setup also applies the FLA TileLang guard."""
+setup also applies the FLA TileLang guard, unless unsloth_zoo's Triton conv covers it."""
import sys
from pathlib import Path
@@ -13,6 +13,7 @@ if str(_BACKEND) not in sys.path:
from core.systemone import clef_runtime # noqa: E402
from core.training import worker # noqa: E402
+from utils import ssm_runtime # noqa: E402
def test_clef_installs_causal_conv1d_and_its_hooks(monkeypatch):
@@ -37,3 +38,15 @@ def test_the_fast_path_hooks_apply_the_tilelang_guard(monkeypatch):
monkeypatch.setenv(worker._FAST_PATH_HOOKS_SKIP_ENV, "1")
worker._install_fast_path_hooks(event_queue = [], model_name = "/models/clef")
assert guarded == [True]
+
+
+def test_clef_installs_nothing_when_zoo_covers_prefill_and_decode(monkeypatch):
+ calls: list = []
+ monkeypatch.setattr(ssm_runtime, "zoo_triton_causal_conv1d_usable", lambda: True)
+ monkeypatch.setattr(worker, "_guard_fla_tilelang", lambda: calls.append("guard"))
+ monkeypatch.setattr(
+ worker, "_ensure_causal_conv1d_fast_path", lambda *a, **k: calls.append("install")
+ )
+ monkeypatch.setattr(worker, "_install_fast_path_hooks", lambda *a, **k: calls.append("hooks"))
+ clef_runtime._fast_paths("/models/clef")
+ assert calls == ["guard"]
diff --git a/studio/backend/tests/test_ssm_runtime.py b/studio/backend/tests/test_ssm_runtime.py
index 4b4f01acaaf..a727f2359cd 100644
--- a/studio/backend/tests/test_ssm_runtime.py
+++ b/studio/backend/tests/test_ssm_runtime.py
@@ -974,13 +974,88 @@ def test_qwen_gdn_configs_resolve_to_causal_conv1d(monkeypatch, tmp_path, config
assert ssm_runtime.resolved_model_wants_causal_conv1d("acme/x", target, None) is True
-def test_the_zoo_exemption_is_gone():
- for name in (
- "ZOO_GDN_MODEL_TYPES",
- "zoo_triton_causal_conv1d_usable",
- "_zoo_triton_platform_usable",
+def _zoo_covers_gdn(
+ monkeypatch,
+ *,
+ decode = True,
+ platform = True,
+):
+ monkeypatch.delenv("UNSLOTH_DISABLE_TRITON_CAUSAL_CONV1D", raising = False)
+ monkeypatch.setattr(ssm_runtime, "_zoo_gdn_decode_kernel_present", lambda: decode)
+ monkeypatch.setattr(ssm_runtime, "_zoo_triton_platform_usable", lambda: platform)
+
+
[email protected]("name", _QWEN_GDN_NAMES)
+def test_qwen_gdn_models_skip_causal_conv1d_when_zoo_covers_decode(monkeypatch, name):
+ _zoo_covers_gdn(monkeypatch)
+ assert ssm_runtime.model_wants_causal_conv1d(name) is False
+ installed = []
+ monkeypatch.setattr(
+ ssm_runtime,
+ "_install_kernel",
+ lambda *, import_name, **_: installed.append(import_name) or True,
+ )
+ ssm_runtime.ensure_ssm_runtime(name)
+ assert installed == []
+
+
+ "config",
+ [
+ {"model_type": "qwen3_next", "architectures": ["Qwen3NextForCausalLM"]},
+ {
+ "model_type": "qwen3_5_moe",
+ "architectures": ["Qwen3_5MoeForConditionalGeneration"],
+ "text_config": {"model_type": "qwen3_5_moe_text"},
+ "vision_config": {"model_type": "qwen3_5_moe_vision"},
+ },
+ ],
+ ids = ["qwen3_next", "qwen3_5_moe"],
+)
+def test_qwen_gdn_configs_skip_causal_conv1d_when_zoo_covers_decode(monkeypatch, tmp_path, config):
+ _zoo_covers_gdn(monkeypatch)
+ target = str(_write_config(tmp_path / "renamed", config))
+ # The transformers modeling source names causal_conv1d; zoo's coverage is checked first.
+ assert ssm_runtime.model_config_wants_causal_conv1d(config) is False
+ assert ssm_runtime.resolved_model_wants_causal_conv1d("acme/x", target, None) is False
+
+
[email protected]("missing", ["kill_switch", "decode_kernel", "platform"])
+def test_qwen_gdn_request_returns_without_full_zoo_coverage(monkeypatch, missing):
+ _zoo_covers_gdn(monkeypatch, decode = missing != "decode_kernel", platform = missing != "platform")
+ if missing == "kill_switch":
+ monkeypatch.setenv("UNSLOTH_DISABLE_TRITON_CAUSAL_CONV1D", "1")
+ assert ssm_runtime.model_wants_causal_conv1d("unsloth/Qwen3.5-2B") is True
+ assert ssm_runtime.model_config_wants_causal_conv1d({"model_type": "qwen3_5"}) is True
+
+
+def test_zoo_coverage_never_drops_other_causal_conv1d_models(monkeypatch):
+ _zoo_covers_gdn(monkeypatch)
+ for name in ("LiquidAI/LFM2-1.2B", "nvidia/Nemotron-H-8B", "state-spaces/mamba-2.8b-hf"):
+ assert ssm_runtime.model_wants_causal_conv1d(name) is True, name
+ # A config mixing a zoo-covered type with another causal-conv1d user still asks.
+ mixed = {"model_type": "qwen3_5", "text_config": {"model_type": "lfm2"}}
+ assert ssm_runtime.model_config_wants_causal_conv1d(mixed) is True
+
+
+def test_the_decode_kernel_probe_reads_zoo_source_without_importing_it(monkeypatch, tmp_path):
+ monkeypatch.undo() # drop the conftest pin: probe the real function
+ probe = ssm_runtime._zoo_gdn_decode_kernel_present
+ patches = tmp_path / "unsloth_zoo" / "temporary_patches"
+ patches.mkdir(parents = True)
+ (tmp_path / "unsloth_zoo" / "__init__.py").write_text("raise ImportError('never imported')\n")
+ source = patches / "gdn_causal_conv1d.py"
+ monkeypatch.syspath_prepend(str(tmp_path))
+ # An import-guard stub in sys.modules does not answer for the real package.
+ monkeypatch.setitem(sys.modules, "unsloth_zoo", types.ModuleType("unsloth_zoo"))
+ for text, expected in (
+ ("def triton_causal_conv1d(x): ...\n", False),
+ ("def triton_causal_conv1d_update(x, conv_state, weight): ...\n", True),
):
- assert not hasattr(ssm_runtime, name)
+ source.write_text(text)
+ probe.cache_clear()
+ assert probe() is expected
+ probe.cache_clear()
@pytest.mark.parametrize(
diff --git a/studio/backend/utils/ssm_runtime.py b/studio/backend/utils/ssm_runtime.py
index ae05fd30cc7..db7f1b1fdaa 100644
--- a/studio/backend/utils/ssm_runtime.py
+++ b/studio/backend/utils/ssm_runtime.py
@@ -7,7 +7,10 @@ the inference-path counterpart of the training worker's install.
from __future__ import annotations
+import functools
import importlib
+import importlib.machinery
+import importlib.metadata
import importlib.util
import os
import shutil
@@ -68,12 +71,6 @@ SSM_MODEL_TYPES = REQUIRED_SSM_MODEL_TYPES | frozenset(
{"bamba", "jamba", "zamba", "zamba2", "mamba", "mamba2", "falcon_mamba"}
)
CAUSAL_CONV1D_MODEL_SUBSTRINGS = (
- "qwen3.5",
- "qwen3_5",
- "qwen3.6",
- "qwen3_6",
- "qwen3-next",
- "qwen3_next",
"nemotron_h",
"nemotron-h",
"nemotron-3-nano",
@@ -87,9 +84,85 @@ CAUSAL_CONV1D_MODEL_SUBSTRINGS = (
"zamba",
"bamba",
)
+# GatedDeltaNet models unsloth-zoo runs without causal_conv1d: its Triton causal conv for prefill /
+# training and Triton causal_conv1d_update for cached decode (temporary_patches/gdn_causal_conv1d.py,
+# `_GDN_MODELING`), plus the vendored FLA kernels. Qwen3.6 reuses the qwen3_5 model types. A usable
+# causal_conv1d still wins inside zoo; this only stops Studio from downloading it. Zoo's kill switch,
+# a zoo without the decode kernel (decode was slower on a T4 without it), ROCm, macOS or no Triton
+# bring the request back.
+ZOO_GDN_MODEL_TYPES = frozenset({"qwen3_5", "qwen3_5_moe", "qwen3_next"})
+ZOO_GDN_MODEL_SUBSTRINGS = (
+ "qwen3.5",
+ "qwen3_5",
+ "qwen3.6",
+ "qwen3_6",
+ "qwen3-next",
+ "qwen3_next",
+)
+ZOO_TRITON_CAUSAL_CONV1D_KILL_SWITCH = "UNSLOTH_DISABLE_TRITON_CAUSAL_CONV1D"
+# Present in the zoo source from the release that added the decode kernel.
+_ZOO_GDN_DECODE_KERNEL_MARKER = "def triton_causal_conv1d_update("
_TRANSFORMERS_CAUSAL_CONV1D_MODEL_TYPE_CACHE: dict[tuple[str, str], bool | None] = {}
+def zoo_triton_causal_conv1d_enabled() -> bool:
+ return os.environ.get(ZOO_TRITON_CAUSAL_CONV1D_KILL_SWITCH, "0") != "1"
+
+
[email protected]_cache(maxsize = 1)
+def _zoo_triton_platform_usable() -> bool:
+ """Whether zoo's Triton conv can engage here: a CUDA torch (not ROCm) with Triton importable.
+ macOS, ROCm and a Windows install without triton-windows keep the prebuilt causal-conv1d.
+ Read from torch's distribution version, so no model load pays for importing torch: ROCm and
+ CPU builds carry `+rocm` / `+cpu`, a Windows CUDA build `+cu`, and a Linux PyPI torch with no
+ local version is the CUDA build."""
+ if sys.platform == "darwin" or importlib.util.find_spec("triton") is None:
+ return False
+ torch = sys.modules.get("torch")
+ if torch is not None:
+ version = getattr(torch, "version", None)
+ return bool(getattr(version, "cuda", None)) and not getattr(version, "hip", None)
+ try:
+ local = importlib.metadata.version("torch").partition("+")[2].lower()
+ except importlib.metadata.PackageNotFoundError:
+ return False
+ if local.startswith(("rocm", "cpu")):
+ return False
+ return local.startswith("cu") or (not local and sys.platform.startswith("linux"))
+
+
[email protected]_cache(maxsize = 1)
+def _zoo_gdn_decode_kernel_present() -> bool:
+ """Whether the installed unsloth_zoo ships the Triton decode update. Read from its source on
+ sys.path, so nothing is imported and an import-guard stub in sys.modules cannot answer."""
+ try:
+ spec = importlib.machinery.PathFinder.find_spec("unsloth_zoo")
+ except (ImportError, ValueError):
+ return False
+ for location in (spec.submodule_search_locations or ()) if spec is not None else ():
+ source = Path(location) / "temporary_patches" / "gdn_causal_conv1d.py"
+ try:
+ if _ZOO_GDN_DECODE_KERNEL_MARKER in source.read_text(encoding = "utf-8", errors = "ignore"):
+ return True
+ except OSError:
+ continue
+ return False
+
+
+def zoo_triton_causal_conv1d_usable() -> bool:
+ """zoo runs Qwen3.5 / 3.6 / Qwen3-Next prefill, training and decode without causal_conv1d here."""
+ return (
+ zoo_triton_causal_conv1d_enabled()
+ and _zoo_triton_platform_usable()
+ and _zoo_gdn_decode_kernel_present()
+ )
+
+
+def _is_zoo_gdn_model_type(model_type: str) -> bool:
+ """The model type or one of its `_text` / `_vision` sub-configs belongs to a zoo-covered model."""
+ return _base_model_type(model_type) in ZOO_GDN_MODEL_TYPES
+
+
class SsmKernels(NamedTuple):
"""What one model needs: ``causal_conv1d`` and ``mamba_ssm`` (best effort), and whether a
missing ``mamba_ssm`` must stop the load. ``probe`` is the identifier the decision was made for
@@ -132,9 +205,14 @@ def model_requires_mamba_ssm(model_name: str) -> bool:
def model_wants_causal_conv1d(model_name: str) -> bool:
- """Whether *model_name* needs ``causal_conv1d`` (the SSM set plus linear-attention hybrids like Qwen3.5 / 3.6 / Qwen3-Next / LFM2 whose modeling files lazy-import it)."""
+ """Whether *model_name* needs ``causal_conv1d`` (the SSM set plus linear-attention hybrids like LFM2 whose modeling files lazy-import it; Qwen3.5 / 3.6 / Qwen3-Next only where zoo's Triton conv cannot run)."""
name = (model_name or "").lower()
- return any(sub in name for sub in CAUSAL_CONV1D_MODEL_SUBSTRINGS)
+ if any(sub in name for sub in CAUSAL_CONV1D_MODEL_SUBSTRINGS):
+ return True
+ return (
+ any(sub in name for sub in ZOO_GDN_MODEL_SUBSTRINGS)
+ and not zoo_triton_causal_conv1d_usable()
+ )
def _normalized_model_identifier(value: str) -> str:
@@ -414,20 +492,23 @@ def model_config_wants_causal_conv1d(model_config: dict) -> bool | None:
model_types, architectures = _config_identifiers(model_config)
if model_config_is_ssm(model_config):
return True
+ # Before the source scan: their modeling files name causal_conv1d, which zoo covers.
+ if model_types and all(_is_zoo_gdn_model_type(model_type) for model_type in model_types):
+ return not zoo_triton_causal_conv1d_usable()
source_requirements = {
_transformers_model_type_uses_causal_conv1d(model_type) for model_type in model_types
}
if True in source_requirements:
return True
- config_identifiers = model_types | architectures
- normalized_needles = {
- _normalized_model_identifier(value) for value in CAUSAL_CONV1D_MODEL_SUBSTRINGS
- }
- if any(
- needle in _normalized_model_identifier(identifier)
- for identifier in config_identifiers
- for needle in normalized_needles
- ):
+ normalized = {_normalized_model_identifier(i) for i in model_types | architectures}
+
+ def _matches(substrings: tuple[str, ...]) -> bool:
+ needles = {_normalized_model_identifier(value) for value in substrings}
+ return any(needle in identifier for identifier in normalized for needle in needles)
+
+ if _matches(CAUSAL_CONV1D_MODEL_SUBSTRINGS):
+ return True
+ if _matches(ZOO_GDN_MODEL_SUBSTRINGS) and not zoo_triton_causal_conv1d_usable():
return True
if False in source_requirements:
return False