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 the SNAC detokenize probe when the ids are past the vocab (#13297)

Daniel Han0abda7aa5914
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 2c2f2ff91b3..d221a8bf640 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -42174,8 +42174,13 @@ class LlamaCppBackend:
return []
return r.json().get("tokens", [])
- # Codec-specific tokens (not generic ones that non-audio models may have)
- if "<custom_token_" in _detok(128258) and "<custom_token_" in _detok(128259):
+ from utils.audio_tokens import SNAC_PROBE_TOKEN_IDS
+
+ # Codec-specific tokens; ids past the vocab log a llama-server 500 (#10336).
+ vocab_size = getattr(self, "_vocab_size", None)
+ if (not vocab_size or vocab_size > max(SNAC_PROBE_TOKEN_IDS)) and all(
+ "<custom_token_" in _detok(tid) for tid in SNAC_PROBE_TOKEN_IDS
+ ):
return "snac"
if len(_tok("<|AUDIO|>")) == 1 and len(_tok("<|audio_eos|>")) == 1:
return "csm"
diff --git a/studio/backend/tests/test_gguf_tts_audio_type.py b/studio/backend/tests/test_gguf_tts_audio_type.py
index 21a6b21510c..c51d372066f 100644
--- a/studio/backend/tests/test_gguf_tts_audio_type.py
+++ b/studio/backend/tests/test_gguf_tts_audio_type.py
@@ -176,3 +176,65 @@ def test_remote_prefix_rejects_truncation(tmp_path):
data = Path(path).read_bytes()
assert classify_gguf_tts_audio_prefix(data) == ("dac", True)
assert classify_gguf_tts_audio_prefix(data[:-1]) == (None, False)
+
+
+class _ProbeServer:
+ """Fake llama-server: an id past the vocab answers 500, as llama.cpp does."""
+
+ def __init__(self, vocab):
+ self.vocab = vocab
+ self.detokenized = []
+
+ def __call__(self, *_a, **_kw):
+ return self
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *_exc):
+ return False
+
+ def post(self, url, json):
+ if url.endswith("/detokenize"):
+ (tid,) = json["tokens"]
+ self.detokenized.append(tid)
+ if tid >= len(self.vocab):
+ return SimpleNamespace(status_code = 500, json = lambda: {})
+ return SimpleNamespace(status_code = 200, json = lambda: {"content": self.vocab[tid]})
+ return SimpleNamespace(status_code = 200, json = lambda: {"tokens": [1, 2]})
+
+
+def _probe(monkeypatch, vocab, vocab_size):
+ from core.inference import llama_cpp
+ from core.inference.llama_cpp import LlamaCppBackend
+
+ server = _ProbeServer(vocab)
+ monkeypatch.setattr(llama_cpp.httpx, "Client", server)
+ backend = LlamaCppBackend.__new__(LlamaCppBackend)
+ backend._process = object()
+ backend._healthy = True
+ backend._port = 1
+ backend._api_key = None
+ backend._vocab_size = vocab_size
+ return backend._detect_audio_type_strict(), server.detokenized
+
+
+def test_snac_probe_skips_ids_past_a_smaller_vocab(monkeypatch):
+ # Laguna-S-2.1: 100352 tokens; detokenizing 128258 logged a range-check 500 (#10336).
+ vocab = [f"t{i}" for i in range(100352)]
+ detected, detokenized = _probe(monkeypatch, vocab, len(vocab))
+ assert detected is None
+ assert detokenized == []
+
+
+def test_snac_probe_still_detects_orpheus(monkeypatch):
+ vocab = _snac_vocab()
+ detected, detokenized = _probe(monkeypatch, vocab, len(vocab))
+ assert detected == "snac"
+ assert detokenized == list(SNAC_PROBE_TOKEN_IDS)
+
+
+def test_snac_probe_runs_when_the_vocab_size_is_unknown(monkeypatch):
+ detected, detokenized = _probe(monkeypatch, _snac_vocab(), None)
+ assert detected == "snac"
+ assert detokenized == list(SNAC_PROBE_TOKEN_IDS)