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++
#287 follow-up: setup run again without --draft-vocab keeps the model's earlier choice
Niko1221d672a5f44380
diff --git a/setup.py b/setup.pyindex 060edab47..a5cbb38be 100644--- a/setup.py+++ b/setup.py@@ -1814,6 +1814,16 @@ OLD_DRAFT_VOCABS = {"369151522226a5edaa5f12cfd1e2ae7db8f4fbdbd222f3dcf327dced959DRAFT_VOCABS = {"cjk": "draft_vocab.bin", "en": "draft_vocab_en.bin", "cyrillic": "draft_vocab_cyrillic.bin"}+def saved_draft_vocab(cfg_path: Path) -> str | None:+ """The draft subset a model's config chose earlier (--draft-vocab), or None: a setup run again without the flag+ rewrites the config, and would otherwise put the default subset back."""+ try:+ v = json.loads(cfg_path.read_text(encoding="utf-8-sig")).get("draft_vocab")+ except (OSError, ValueError, AttributeError):+ return None+ return v if v in DRAFT_VOCABS else None++def refresh_draft_vocab(rt: Path, choice: str = "cjk") -> None:"""The draft layer's token subset in the MTP folder: `cjk` (data/draft_vocab.bin, since 0.1.27, #137), `en`(data/draft_vocab_en.bin, the English/code subset before it: ~110 MiB less VRAM, English answers 1-2% faster) or@@ -2393,7 +2403,9 @@ def main() -> int:"--out", str(mtp / "mtp-q2_0.gguf")], env=env)run([sys.executable, str(ROOT / "tools" / "mtp_rt.py"), "--gguf", str(mtp / "mtp-q2_0.gguf"), "--out", str(rt)],env=env)- refresh_draft_vocab(rt, a.draft_vocab or "cjk")+ # a setup run again without --draft-vocab keeps the subset this model's config chose before (cyrillic, en)+ draft_vocab = a.draft_vocab or saved_draft_vocab(ROOT / f"strata-{tag.lower()}.json")+ refresh_draft_vocab(rt, draft_vocab or "cjk")ok(f"MTP draft layer: {rt}")# ---- 7. the start script@@ -2463,8 +2475,8 @@ def main() -> int:cfg["host"] = a.hostif a.api_key:cfg["api_key"] = a.api_key- if a.draft_vocab:- cfg["draft_vocab"] = a.draft_vocab+ if draft_vocab:+ cfg["draft_vocab"] = draft_vocabif vision != "none":cfg["vision"] = {"exe": str(eng / VEXE), "mmproj": str(mmproj), "model": str(shards[0]),"gpu": vision == "gpu", "max_tokens": VISION[vision]["max_tokens"]}diff --git a/tools/test_setup_draft_vocab.py b/tools/test_setup_draft_vocab.pynew file mode 100644index 000000000..f0b756928--- /dev/null+++ b/tools/test_setup_draft_vocab.py@@ -0,0 +1,53 @@+"""Tests for setup.py's draft-vocabulary choice (#287): a setup run again without --draft-vocab keeps the subset the+model's config chose before (cyrillic, en), and refresh_draft_vocab copies the chosen shipped subset. Pure file work+in a temporary folder - no GPU, no downloads, no prompts.++ python -m unittest tools.test_setup_draft_vocab+"""+from __future__ import annotations++import hashlib+import json+import sys+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT))+import setup # noqa: E402+++class SavedChoice(unittest.TestCase):+ def test_a_config_keeps_its_choice(self):+ with tempfile.TemporaryDirectory() as d:+ for choice in setup.DRAFT_VOCABS:+ p = Path(d) / "strata-x.json"+ p.write_text(json.dumps({"args": [], "draft_vocab": choice}), encoding="utf-8")+ self.assertEqual(setup.saved_draft_vocab(p), choice)++ def test_no_choice_without_a_valid_config(self):+ with tempfile.TemporaryDirectory() as d:+ self.assertIsNone(setup.saved_draft_vocab(Path(d) / "missing.json"))+ for text in ("{}", "[1]", "not json", json.dumps({"draft_vocab": "klingon"})):+ p = Path(d) / "strata-y.json"+ p.write_text(text, encoding="utf-8")+ self.assertIsNone(setup.saved_draft_vocab(p), text)+++class Refresh(unittest.TestCase):+ def test_cyrillic_replaces_a_shipped_subset_and_stays(self):+ if not (ROOT / "data" / setup.DRAFT_VOCABS["cyrillic"]).exists():+ self.skipTest("data/draft_vocab_cyrillic.bin is not in this checkout")+ want = hashlib.sha256((ROOT / "data" / setup.DRAFT_VOCABS["cyrillic"]).read_bytes()).hexdigest()+ with tempfile.TemporaryDirectory() as d:+ rt = Path(d)+ (rt / "draft_vocab.bin").write_bytes((ROOT / "data" / setup.DRAFT_VOCABS["cjk"]).read_bytes())+ setup.refresh_draft_vocab(rt, "cyrillic")+ self.assertEqual(hashlib.sha256((rt / "draft_vocab.bin").read_bytes()).hexdigest(), want)+ setup.refresh_draft_vocab(rt, "cyrillic") # again: nothing changes+ self.assertEqual(hashlib.sha256((rt / "draft_vocab.bin").read_bytes()).hexdigest(), want)+++if __name__ == "__main__":+ unittest.main()