Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Server: a config that names no "arch" but ships DeepSeek's tokenizer is served as deepseek41 (#4137)

Niko1221b18292d702e8
diff --git a/serve/server.py b/serve/server.py
index 8c5213b1f..d332e97ab 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -8584,6 +8584,16 @@ def model_card_sampling(arch, thinking) -> dict:
return dict(sets["thinking" if thinking else "instruct"]) if sets else {}
+def arch_from_tokenizer(arch, pre) -> str | None:
+ """#4137: the model family a config that names none is served as. A hand-written config (serve/server.py run on its own, a gateway) often leaves
+ "arch" out; for DeepSeek-V4.1 that meant the Qwen defaults: the stop ids of <|im_end|> (the DeepSeek tokenizer splits that into pieces, so a "|" or a
+ ">" in the reply ended it: `finish_reason: stop` at token 19 in front of a table), no end token (the raw <|end▁of▁sentence|> came out as text)
+ and no DSML tool calls. The pack's tokenizer says what it is (its pre-tokenizer is "deepseek3"); an arch the config names is never changed."""
+ if arch:
+ return arch
+ return "deepseek41" if str(pre or "").startswith("deepseek") else None
+
+
def default_model_name(cfg: dict) -> str:
"""The config's "model_name", else its family's name ("arch": qwen4exp, qwen35moe), else Flash-Next's."""
return cfg.get("model_name") or FAMILY_MODEL_NAMES.get(cfg.get("arch") or "qwen4exp", "qwen3.8-flash-next")
@@ -8834,6 +8844,7 @@ def main(argv=None, *, lifecycle_event=None, interrupt_exit_code: int = 0) -> in
if cfg.get("tokenizer"):
a.tokenizer = cfg["tokenizer"]
tok = ByteTokenizer()
+ tcfg = {}
tpath = Path(a.tokenizer)
if a.engine == "strata" and not (tpath / "vocab.json").exists():
ap.error(f"the model's tokenizer is missing ({tpath / 'vocab.json'}); run setup again")
@@ -8845,12 +8856,15 @@ def main(argv=None, *, lifecycle_event=None, interrupt_exit_code: int = 0) -> in
tokens[i] = t
merges = (tpath / "merges.txt").read_text(encoding="utf-8").split("\n")
types = json.loads((tpath / "token_type.json").read_text())
- tcfg = {}
try: # the pack's pre-tokenizer name and special ids (DeepSeek's differ)
tcfg = json.loads((tpath / "tokenizer.json").read_text(encoding="utf-8"))
except (OSError, ValueError):
pass
tok = ST.Tokenizer(tokens, merges, types, tcfg.get("pre") or "qwen35", tcfg.get("special_ids") or None)
+ if a.engine == "strata" and not cfg.get("arch") and arch_from_tokenizer(None, tcfg.get("pre")):
+ cfg["arch"] = arch_from_tokenizer(None, tcfg.get("pre"))
+ print(f"[strata] the config names no \"arch\" and this tokenizer is DeepSeek's: serving it as {cfg['arch']} (its end token, DSML tool "
+ f"calls and effort words); add \"arch\": \"{cfg['arch']}\" to the config to say it outright", flush=True)
hub = hub_from_config(cfg, a.mcp_config) # before the minutes of loading: a bad entry stops here
if a.offline and (hub is not None or cfg.get("before_load") or a.before_load):
ap.error("--offline requires MCP servers and before_load commands to be disabled in this profile")
diff --git a/serve/test_dsv41.py b/serve/test_dsv41.py
index e47224d9f..122a3ab60 100644
--- a/serve/test_dsv41.py
+++ b/serve/test_dsv41.py
@@ -761,5 +761,33 @@ class PickTemplateTests(unittest.TestCase):
self.assertTrue(dsml.v41_template_ok(dsml.FIXTURE_TEMPLATE.read_text(encoding="utf-8")))
+class ArchFromTokenizer(unittest.TestCase):
+ """#4137: a config without "arch" (serve/server.py run on its own) must not serve DeepSeek with the Qwen stop ids."""
+
+ def test_a_deepseek_tokenizer_without_an_arch_is_deepseek41(self):
+ self.assertEqual(server.arch_from_tokenizer(None, "deepseek3"), "deepseek41")
+ self.assertEqual(server.arch_from_tokenizer("", "deepseek3"), "deepseek41")
+
+ def test_an_arch_the_config_names_is_kept(self):
+ self.assertEqual(server.arch_from_tokenizer("qwen4exp", "deepseek3"), "qwen4exp")
+ self.assertEqual(server.arch_from_tokenizer("deepseek41", "qwen35"), "deepseek41")
+
+ def test_a_qwen_tokenizer_names_nothing(self):
+ self.assertIsNone(server.arch_from_tokenizer(None, "qwen35"))
+ self.assertIsNone(server.arch_from_tokenizer(None, None))
+
+ def test_without_the_family_the_end_token_is_not_a_stop_id_and_pieces_of_im_end_are(self):
+ # what the reporter's config got: the DeepSeek tokenizer splits <|im_end|> into pieces, so "|" and ">" stopped a reply (a table's first
+ # cell), and the end token (id 1) did not stop it at all
+ tok = mini_tokenizer()
+ wrong = Service(DsEngine(tok, "x"), tok, ChatTemplate(TEMPLATE))
+ self.assertNotIn(EOS, wrong.stop_ids)
+ self.assertTrue(wrong.stop_ids & set(tok.encode("|", parse_special=True)))
+ right = Service(DsEngine(tok, "x"), tok, ChatTemplate(TEMPLATE))
+ right.set_family("deepseek41")
+ self.addCleanup(frontend.use_family, None)
+ self.assertEqual(right.stop_ids, {EOS})
+
+
if __name__ == "__main__":
unittest.main()