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.

fix(studio): stop false MTP/vision capability reports (#7332)

Souravrajvi00e800d213aac
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 7d67339c1e9..1fe134c3f98 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -2781,6 +2781,7 @@ class LlamaCppBackend:
"found": False,
"mtp_token": None,
"supports_mtp": False,
+ "mtp_probe_inconclusive": True,
"ngram_mod_flavor": None,
"supports_ngram_mod": False,
"spec_draft_n_max_flag": None,
@@ -2813,6 +2814,9 @@ class LlamaCppBackend:
supports_no_cache_prompt = False
supports_metrics = False
supports_slot_save = False
+ saw_spec_type = False
+ probe_ok = False
+ help_text = ""
try:
probe_env = cls._llama_server_env_for_binary(bin_path)
result = subprocess.run(
@@ -2824,6 +2828,7 @@ class LlamaCppBackend:
check = False,
env = probe_env,
)
+ probe_ok = result.returncode == 0
help_text = (result.stdout or "") + "\n" + (result.stderr or "")
# Split into per-flag blocks (each --flag line + its indented
# continuation), so the "argument has been removed" description
@@ -2868,17 +2873,19 @@ class LlamaCppBackend:
return False
return "argument has been removed" not in desc
- # MTP token from the --spec-type line.
- spec_line = ""
- for line in help_text.splitlines():
- if "--spec-type" in line:
- spec_line = line
- break
- # PR #22673 used draft-mtp; later renamed to mtp.
- if "draft-mtp" in spec_line:
- mtp_token = "draft-mtp"
- elif re.search(r"[|,\[]mtp[|,\]]", spec_line):
- mtp_token = "mtp"
+ # MTP token from the full --spec-type help block (decl + indented
+ # continuation). First-line-only probing missed builds putting the
+ # enum on the next line (#7302). Prefer draft-mtp (PR #22673) over mtp.
+ spec_help = blocks.get("--spec-type") or ""
+ if not spec_help:
+ # Fallback: join --spec-type lines, avoiding incidental "mtp" in --help.
+ spec_help = "\n".join(
+ line for line in help_text.splitlines() if "--spec-type" in line
+ )
+ mtp_token = cls._mtp_token_from_spec_help(spec_help)
+ # Only a resolved --spec-type block confirms missing MTP; empty/crash
+ # leaves saw_spec_type False so supports_mtp fails open.
+ saw_spec_type = bool(spec_help.strip()) and "--spec-type" in spec_help
# ngram-mod flag flavor. Post-rename builds advertise both new
# args (real) and legacy ones (stubs); pre-rename builds only
@@ -2914,11 +2921,29 @@ class LlamaCppBackend:
supports_slot_save = _is_real("--slot-save-path")
except (OSError, subprocess.SubprocessError) as exc:
logger.debug(f"llama-server --help probe failed: {exc}")
+ saw_spec_type = False
+ probe_ok = False
+ help_text = ""
+
+ help_nonempty = bool(help_text.strip())
+ # Confirmed only when a successful --help lists a --spec-type block with
+ # mtp/draft-mtp; nonempty --help without it is a definitive pre-spec
+ # binary; failed/empty probes stay inconclusive (#7302).
+ if saw_spec_type and probe_ok:
+ supports_mtp = mtp_token is not None
+ mtp_probe_inconclusive = False
+ elif help_nonempty and probe_ok:
+ supports_mtp = False
+ mtp_probe_inconclusive = False
+ else:
+ supports_mtp = False
+ mtp_probe_inconclusive = True
info = {
"found": True,
"mtp_token": mtp_token,
- "supports_mtp": mtp_token is not None,
+ "supports_mtp": supports_mtp,
+ "mtp_probe_inconclusive": mtp_probe_inconclusive,
"ngram_mod_flavor": ngram_mod_flavor,
"supports_ngram_mod": ngram_mod_flavor is not None,
"spec_draft_n_max_flag": spec_draft_n_max_flag,
@@ -2934,6 +2959,21 @@ class LlamaCppBackend:
cls._capability_cache[cache_key] = info
return info
+ @staticmethod
+ def _mtp_token_from_spec_help(spec_help: str) -> Optional[str]:
+ """Extract ``draft-mtp`` / ``mtp`` from a ``--spec-type`` help snippet.
+
+ Prefers ``draft-mtp`` (llama.cpp PR #22673) over the later bare ``mtp``
+ rename. Returns ``None`` when neither token appears as an enum value.
+ """
+ text = spec_help or ""
+ if "draft-mtp" in text:
+ return "draft-mtp"
+ # Bare `mtp` enum token (`|mtp|`, `,mtp,`, ...), not a substring.
+ if re.search(r"(?<![A-Za-z0-9_-])mtp(?![A-Za-z0-9_-])", text):
+ return "mtp"
+ return None
+
# ── GPU allocation ────────────────────────────────────────────
@staticmethod
@@ -6015,6 +6055,24 @@ class LlamaCppBackend:
and ("unknown" in text or "unsupported" in text or "not supported" in text)
)
+ @staticmethod
+ def _mmproj_retry_failure_message(*, projector_confirmed: bool, detail: str) -> str:
+ """User-facing error when the text-only --mmproj strip retry also fails.
+
+ Confirmed projector-format mismatches keep the historical wording.
+ Bare signal crashes (common on some ROCm/driver paths) must not be
+ reported as "Vision projector incompatible" — that misled #7302.
+ """
+ if projector_confirmed:
+ return (
+ "Vision projector incompatible with this llama.cpp "
+ "build, and the text-only retry also failed: " + detail
+ )
+ return (
+ "Vision model failed to start (llama-server crashed with "
+ "--mmproj), and the text-only retry also failed: " + detail
+ )
+
@staticmethod
def _output_has_nonprojector_diagnostic(output: str) -> bool:
"""True when the output already names a concrete non-projector cause (out
@@ -8388,23 +8446,29 @@ class LlamaCppBackend:
self._kill_process()
# The #6415 split-axis abort is latched earlier (first spawn).
# Skip if a cancel/unload is pending (mirrors the MTP guard).
+ _projector_msg = self._is_projector_incompatibility(out)
+ _signal_mmproj_guess = self._is_signal_crash(
+ _crash_rc
+ ) and not self._output_has_nonprojector_diagnostic(out)
if (
launched_with_mmproj
and not self._cancel_event.is_set()
- and (
- self._is_projector_incompatibility(out)
- or (
- self._is_signal_crash(_crash_rc)
- and not self._output_has_nonprojector_diagnostic(out)
- )
- )
+ and (_projector_msg or _signal_mmproj_guess)
):
- logger.warning(
- "llama-server could not load this model's vision "
- "projector (--mmproj). The installed llama.cpp build is "
- "likely too old for it. Loading text-only for this "
- "session; run 'unsloth studio update' to enable vision."
- )
+ if _projector_msg:
+ logger.warning(
+ "llama-server could not load this model's vision "
+ "projector (--mmproj). The installed llama.cpp build is "
+ "likely too old for it. Loading text-only for this "
+ "session; run 'unsloth studio update' to enable vision."
+ )
+ else:
+ logger.warning(
+ "llama-server crashed while loading this model's vision "
+ "projector (--mmproj). Retrying text-only for this "
+ "session; if this persists, run 'unsloth studio update' "
+ "or check GPU/driver logs."
+ )
cmd = self._strip_mmproj_args(_last_spawn_cmd)
# This retry bypasses _spawn_and_wait, so refresh the
# launched-argv snapshot itself -- the zero-offload
@@ -8432,14 +8496,16 @@ class LlamaCppBackend:
"(e.g. ROCR_VISIBLE_DEVICES=0 exposes only the first "
"GPU) before launching Unsloth Studio."
)
+ _retry_detail = self._classify_llama_start_failure(
+ "\n".join(self._stdout_lines[-50:]),
+ gguf_path,
+ self._model_identifier,
+ _retry_rc,
+ )
raise RuntimeError(
- "Vision projector incompatible with this llama.cpp "
- "build, and the text-only retry also failed: "
- + self._classify_llama_start_failure(
- "\n".join(self._stdout_lines[-50:]),
- gguf_path,
- self._model_identifier,
- _retry_rc,
+ self._mmproj_retry_failure_message(
+ projector_confirmed = _projector_msg,
+ detail = _retry_detail,
)
)
else:
@@ -8669,18 +8735,29 @@ class LlamaCppBackend:
caps = self.probe_server_capabilities(binary)
mtp_token = caps.get("mtp_token") if caps else None
if not mtp_token:
- logger.warning(
- "Requested MTP speculative decoding but "
- "llama-server lacks --spec-type mtp/draft-mtp; "
- "run `unsloth studio update`. Loading without "
- "speculative decoding."
- )
+ inconclusive = bool(caps.get("mtp_probe_inconclusive")) if caps else True
+ if inconclusive:
+ logger.info(
+ "Requested MTP speculative decoding but llama-server MTP "
+ "capability probe was inconclusive; loading without "
+ "speculative decoding."
+ )
+ else:
+ logger.warning(
+ "Requested MTP speculative decoding but "
+ "llama-server lacks --spec-type mtp/draft-mtp; "
+ "run `unsloth studio update`. Loading without "
+ "speculative decoding."
+ )
# Override an inherited LLAMA_ARG_SPEC_TYPE=draft-mtp (CLI wins
# over env) so the child matches the binary-capability gate and
# the no-MTP budget, like the sibling no-head/non-MTP fallbacks.
flags.append("--spec-default")
self._speculative_type = "default"
- self._spec_fallback_reason = "binary_no_mtp"
+ if inconclusive:
+ self._spec_fallback_reason = None
+ else:
+ self._spec_fallback_reason = "binary_no_mtp"
return False
draft_n_max = _resolved_draft_n_max()
n_max_flag = caps.get("spec_draft_n_max_flag") or "--spec-draft-n-max"
diff --git a/studio/backend/main.py b/studio/backend/main.py
index a538f935ff1..5af25efa74e 100644
--- a/studio/backend/main.py
+++ b/studio/backend/main.py
@@ -438,7 +438,11 @@ def _run_llama_cpp_startup_probes(app: FastAPI) -> None:
import structlog as _structlog
_log = _structlog.get_logger(__name__)
- if _caps.get("found") and not _caps.get("supports_mtp"):
+ if (
+ _caps.get("found")
+ and not _caps.get("supports_mtp")
+ and not _caps.get("mtp_probe_inconclusive")
+ ):
_msg = (
"llama.cpp prebuilt lacks MTP support "
"(--spec-type mtp/draft-mtp). Run `unsloth studio update`. "
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 6dbaa8fcc95..445a26f04d8 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -5835,10 +5835,15 @@ async def get_status(current_subject: str = Depends(get_current_subject)):
try:
_bin = type(llama_backend)._find_llama_server_binary()
_caps = type(llama_backend).probe_server_capabilities(_bin)
- _supports_mtp = bool(_caps.get("supports_mtp", False))
+ # Fail open on inconclusive probes: False means a definitive
+ # "binary lacks MTP" to API consumers.
+ _supports_mtp = bool(
+ _caps.get("supports_mtp", False)
+ or (_caps.get("found", False) and _caps.get("mtp_probe_inconclusive", False))
+ )
except Exception:
_bin = None
- _supports_mtp = True # fail open
+ _supports_mtp = False # no usable binary: MTP genuinely unavailable
try:
from utils.llama_cpp_freshness import check_prebuilt_freshness
_freshness = check_prebuilt_freshness(_bin)
diff --git a/studio/backend/tests/test_llama_cpp_mmproj_fallback.py b/studio/backend/tests/test_llama_cpp_mmproj_fallback.py
index 049058e5115..4332a440a51 100644
--- a/studio/backend/tests/test_llama_cpp_mmproj_fallback.py
+++ b/studio/backend/tests/test_llama_cpp_mmproj_fallback.py
@@ -335,3 +335,24 @@ class TestRetryContract:
def test_external_kill_skips_flash_attn_retry(self):
# SIGKILL (-9, OOM killer) is not a program fault: no FA-off retry.
assert _signal_crash(-9) is False
+
+
+class TestMmprojRetryFailureMessage:
+ """#7302: bare mmproj crashes must not be reported as projector-format."""
+
+ def test_confirmed_projector_keeps_historical_wording(self):
+ msg = LlamaCppBackend._mmproj_retry_failure_message(
+ projector_confirmed = True,
+ detail = "llama-server failed to start",
+ )
+ assert msg.startswith("Vision projector incompatible with this llama.cpp")
+ assert "llama-server failed to start" in msg
+
+ def test_bare_crash_does_not_claim_projector_incompatibility(self):
+ msg = LlamaCppBackend._mmproj_retry_failure_message(
+ projector_confirmed = False,
+ detail = "llama-server failed to start. Check that the GGUF file is valid",
+ )
+ assert "Vision projector incompatible" not in msg
+ assert "crashed with --mmproj" in msg
+ assert "GGUF file is valid" in msg
diff --git a/studio/backend/tests/test_llama_cpp_mtp_detection.py b/studio/backend/tests/test_llama_cpp_mtp_detection.py
index 1d156479677..27c1b17a857 100644
--- a/studio/backend/tests/test_llama_cpp_mtp_detection.py
+++ b/studio/backend/tests/test_llama_cpp_mtp_detection.py
@@ -637,7 +637,9 @@ def test_probe_server_capabilities_uses_binary_library_env(tmp_path, monkeypatch
def fake_run(cmd, **kwargs):
captured["cmd"] = cmd
captured["env"] = kwargs.get("env")
- return _types.SimpleNamespace(stdout = "--spec-type none,mtp,ngram-simple\n", stderr = "")
+ return _types.SimpleNamespace(
+ stdout = "--spec-type none,mtp,ngram-simple\n", stderr = "", returncode = 0
+ )
monkeypatch.setattr("core.inference.llama_cpp.subprocess.run", fake_run)
@@ -678,6 +680,95 @@ def test_probe_server_capabilities_reports_outdated_binary(tmp_path):
assert caps["found"] is True
assert caps["mtp_token"] is None
assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is False
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_reads_mtp_from_multiline_help(tmp_path):
+ # Enum on the indented line: first-line-only probing falsely reported
+ # "lacks MTP" (#7302).
+ fake = _make_fake_llama_server(
+ tmp_path / "llama-server",
+ "--spec-type TYPE\n"
+ " speculative decoding type\n"
+ " (none,draft-simple,draft-mtp,ngram-mod)\n",
+ )
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["mtp_token"] == "draft-mtp"
+ assert caps["supports_mtp"] is True
+ assert caps["mtp_probe_inconclusive"] is False
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_empty_help_fails_open(tmp_path):
+ # --help prints nothing: must not claim the prebuilt lacks MTP (#7302).
+ fake = tmp_path / "llama-server"
+ fake.write_text("#!/usr/bin/env bash\nexit 0\n")
+ fake.chmod(0o755)
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["found"] is True
+ assert caps["mtp_token"] is None
+ assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is True
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_no_spec_type_is_definitive(tmp_path):
+ # Nonempty --help without --spec-type: pre-spec binary, not inconclusive.
+ fake = _make_fake_llama_server(
+ tmp_path / "llama-server",
+ "--gpu-layers N\n GPU layers to offload\n",
+ )
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["found"] is True
+ assert caps["mtp_token"] is None
+ assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is False
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_failed_help_with_output_is_inconclusive(tmp_path):
+ fake = tmp_path / "llama-server"
+ fake.write_text(
+ "#!/usr/bin/env bash\n"
+ 'if [ "$1" = "--help" ]; then\n'
+ " echo 'illegal instruction'\n"
+ " exit 1\n"
+ "fi\n"
+ )
+ fake.chmod(0o755)
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["found"] is True
+ assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is True
+
+
+@_NEEDS_BASH
+def test_probe_server_capabilities_crash_on_help_fails_open(tmp_path):
+ fake = tmp_path / "llama-server"
+ fake.write_text("#!/usr/bin/env bash\nkill -SEGV $$\n")
+ fake.chmod(0o755)
+ _clear_caps_cache()
+ caps = LlamaCppBackend.probe_server_capabilities(str(fake))
+ assert caps["found"] is True
+ assert caps["mtp_token"] is None
+ assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is True
+
+
+def test_mtp_token_from_spec_help_prefers_draft_mtp():
+ assert (
+ LlamaCppBackend._mtp_token_from_spec_help("--spec-type none,draft-mtp,mtp,ngram-mod")
+ == "draft-mtp"
+ )
+ assert LlamaCppBackend._mtp_token_from_spec_help("--spec-type [none|mtp|ngram-cache]") == "mtp"
+ assert LlamaCppBackend._mtp_token_from_spec_help("--spec-type none,ngram-mod") is None
+ # No incidental substring matches.
+ assert LlamaCppBackend._mtp_token_from_spec_help("prompt cache") is None
def test_probe_server_capabilities_handles_missing_binary():
@@ -685,6 +776,7 @@ def test_probe_server_capabilities_handles_missing_binary():
caps = LlamaCppBackend.probe_server_capabilities("/no/such/llama-server")
assert caps["found"] is False
assert caps["supports_mtp"] is False
+ assert caps["mtp_probe_inconclusive"] is True
assert caps["supports_cache_ram"] is False
assert caps["supports_ctx_checkpoints"] is False
assert caps["supports_no_cache_prompt"] is False
@@ -1176,12 +1268,14 @@ def _resolver_backend(
*,
ngram_supported = True,
mtp_token = "draft-mtp",
+ mtp_probe_inconclusive = False,
):
"""Backend with a deterministic probe so the resolver is hermetic."""
fake = {
"found": True,
"mtp_token": mtp_token,
"supports_mtp": bool(mtp_token),
+ "mtp_probe_inconclusive": mtp_probe_inconclusive,
"ngram_mod_flavor": "new" if ngram_supported else None,
"supports_ngram_mod": bool(ngram_supported),
"spec_draft_n_max_flag": "--spec-draft-n-max",
@@ -1879,6 +1973,24 @@ def test_spec_fallback_reason_set_when_binary_lacks_mtp(monkeypatch):
assert backend.spec_fallback_reason == "binary_no_mtp"
+def test_spec_fallback_reason_none_when_mtp_probe_inconclusive(monkeypatch):
+ backend = _resolver_backend(
+ monkeypatch,
+ mtp_token = None,
+ mtp_probe_inconclusive = True,
+ )
+ backend._build_speculative_flags(
+ speculative_type = "mtp",
+ spec_draft_n_max = None,
+ extra_args = None,
+ model_identifier = _MTP_MODEL,
+ model_path = None,
+ gpus = True,
+ binary = "/fake/llama-server",
+ )
+ assert backend.spec_fallback_reason is None
+
+
def test_spec_fallback_reason_none_when_mtp_engages(monkeypatch):
backend = _resolver_backend(monkeypatch)
backend._build_speculative_flags(