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++

"The draft head does not fit" says what to change (#474)

Niko1221c472ff04c8b3
diff --git a/docs/DETAILS.md b/docs/DETAILS.md
index e0737ce83..acc986239 100644
--- a/docs/DETAILS.md
+++ b/docs/DETAILS.md
@@ -98,7 +98,10 @@ English/code subset from before (40,525 ids, ~110 MiB less VRAM, English answers
almost no drafts). `--draft-vocab cyrillic` takes the English/code subset plus the whole Cyrillic script (58,963
ids): the shipped subsets hold 142 of the vocabulary's 18,580 Cyrillic tokens, so Ukrainian or Russian answers got
1.4 tokens a round; with it 2.1, and 83 -> 109 tokens/s (RTX 5090, the NVFP4 fork), English unchanged.
-`tools/draft_vocab.py` builds and inspects subsets.
+`tools/draft_vocab.py` builds and inspects subsets. When the start stops with "the draft head does not fit" (a
+12 GB card with a long context, #474), the engine says how much the head needs, how much VRAM is free and which
+smaller subset fits, and the server's start error repeats it; setup suggests `--draft-vocab en` on cards under
+14 GB (only a suggestion: nothing changes unless you pass it).
**Low-RAM mode (engine 0.1.26, chosen by setup):** normally all of a model's experts are copied into RAM (23-50 GB,
pinned) and the GPU holds a copy of the most-used ones. On a PC whose RAM cannot hold them beside the system (the
diff --git a/serve/server.py b/serve/server.py
index e50c01d58..00b55ee4b 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -131,6 +131,31 @@ ENGINE_REQUEST = re.compile(
_echoing: set[str] = set() # the logs echo_requests already follows (restart() runs StrataEngine.__init__ again)
+DRAFT_HEAD_FAIL = "the draft head does not fit"
+DRAFT_HEAD_HINT = ("a smaller draft vocabulary needs less VRAM: --draft-vocab cyrillic (English, code and the Cyrillic "
+ "script) or --draft-vocab en (English and code, ~215 MiB less than the default). Start once with "
+ "it - START-HERE.bat --draft-vocab en (Windows) or ./setup.sh --draft-vocab en - and the model "
+ "keeps it; or a smaller --context in setup.")
+
+
+def start_failure_hint(log: str | None, offset: int) -> str:
+ """#474: what to change when the engine stopped at the start because the MTP draft head did not fit the VRAM
+ left: the engine's own `strata mtp:` lines after that failure (0.1.36+: what it needs, what is free, the smaller
+ subsets), else the same advice in words for an older engine. "" for any other failure: the log says why."""
+ if not log:
+ return ""
+ try:
+ with open(log, "rb") as f:
+ f.seek(offset)
+ text = f.read().decode("utf-8", "replace")
+ except (OSError, ValueError):
+ return ""
+ if DRAFT_HEAD_FAIL not in text:
+ return ""
+ said = [x.strip()[len("strata mtp: "):] for x in text.splitlines()
+ if x.strip().startswith("strata mtp: ") and ("draft head over" in x or "hint:" in x)]
+ return ". mtp: " + DRAFT_HEAD_FAIL + ". " + (" ".join(said) if said else "Hint: " + DRAFT_HEAD_HINT)
+
def echo_requests(log_path: str, offset: int) -> None:
"""STRATA_REQUEST_LINES=1: one stdout line per finished request, from the engine's own summary in its log.
@@ -238,6 +263,7 @@ class StrataEngine:
self.unloaded = False # `ended` stays True until READY (below): not alive while starting (#344)
self.log = open(log, "a", encoding="utf-8") if log else subprocess.DEVNULL
loading = threading.Event() # set once READY: the narrator below stops
+ log_start = os.path.getsize(log) if log else 0 # where this start's lines begin (start_failure_hint)
if log:
threading.Thread(target=narrate_start, args=(log, os.path.getsize(log), args, loading),
daemon=True).start()
@@ -261,7 +287,8 @@ class StrataEngine:
break
loading.set()
if self.max_context <= 0:
- raise RuntimeError("the engine exited before it was ready" + (f" (see {log})" if log else ""))
+ raise RuntimeError("the engine exited before it was ready" + (f" (see {log})" if log else "") +
+ start_failure_hint(log, log_start))
# (from PR #41, midhatn) a locally built engine can sit next to another release's BUILD.json: engines that
# report their own version (INFO engine=, 0.1.8+) win, the manifest stays the fallback for older ones
if self.info.get("engine"):
diff --git a/serve/test_server.py b/serve/test_server.py
index 85192668a..2000f1ae6 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -19,7 +19,7 @@ from unittest import mock
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from serve.frontend import ChatTemplate # noqa: E402
from serve.server import (CTX_SLACK, ByteTokenizer, EngineDied, GpuBusy, MockEngine, Service, StrataEngine, # noqa: E402
- prompt_tokens_seen, request_timings, serve)
+ prompt_tokens_seen, request_timings, serve, start_failure_hint)
from types import SimpleNamespace # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
@@ -801,6 +801,39 @@ class DraftCounts(unittest.TestCase):
self.assertEqual((m["totals"]["drafts_offered"], m["totals"]["drafts_accepted"]), (17, 10))
+class DraftHeadHint(unittest.TestCase):
+ """#474: a start that stopped at "the draft head does not fit" says what to change, from this start's log lines."""
+
+ def log(self, text, before=""):
+ d = tempfile.mkdtemp()
+ p = Path(d) / "engine.log"
+ p.write_text(before + text, encoding="utf-8")
+ return str(p), len(before.encode())
+
+ def test_the_engines_hint_is_relayed(self):
+ p, off = self.log("strata mtp: the draft head over 106299 tokens needs 348 MiB of VRAM and 120 MiB is free.\n"
+ "strata mtp: hint: a smaller draft vocabulary needs less VRAM: --draft-vocab en (...)\n"
+ "strata serve: mtp: the draft head does not fit\n")
+ h = start_failure_hint(p, off)
+ self.assertIn("the draft head does not fit", h)
+ self.assertIn("348 MiB", h)
+ self.assertIn("--draft-vocab en", h)
+
+ def test_an_older_engine_gets_the_advice_in_words(self):
+ p, off = self.log("strata serve: mtp: the draft head does not fit\n")
+ self.assertIn("--draft-vocab en", start_failure_hint(p, off))
+
+ def test_other_failures_and_earlier_starts_add_nothing(self):
+ p, off = self.log("strata serve: cannot open the pack\n")
+ self.assertEqual(start_failure_hint(p, off), "")
+ # an earlier start's failure (before this start's offset) is not this one's
+ p, off = self.log("strata serve: cannot open the pack\n",
+ before="strata serve: mtp: the draft head does not fit\n")
+ self.assertEqual(start_failure_hint(p, off), "")
+ self.assertEqual(start_failure_hint(None, 0), "")
+ self.assertEqual(start_failure_hint(str(Path(tempfile.mkdtemp()) / "missing.log"), 0), "")
+
+
class CancelledRead(unittest.TestCase):
"""#471: a request cancelled while its prompt was read is recorded with the tokens the engine read (the DONE
line's 15th field), not the whole prompt; an older engine's line (no such field) keeps the whole prompt."""
diff --git a/setup.py b/setup.py
index d91900b30..f3830ec20 100644
--- a/setup.py
+++ b/setup.py
@@ -2572,6 +2572,25 @@ def saved_draft_vocab(cfg_path: Path) -> str | None:
return v if v in DRAFT_VOCABS else None
+DRAFT_VOCAB_MIB = {"cjk": 348, "cyrillic": 193, "en": 133} # the draft head's VRAM per subset (IQ3_S: the largest)
+SMALL_DRAFT_VRAM_GB = 14 # #474: below this the default subset's head can be what does not fit
+
+
+def draft_vocab_note(vram_gb: float, chosen: str | None) -> list[str]:
+ """#474: on a card under 14 GB, the default draft subset (cjk, ~348 MiB of VRAM) can be what does not fit at the
+ start ("the draft head does not fit"), and the engine's expert cache gets what a smaller one leaves. Setup
+ RECOMMENDS a smaller one here and changes nothing (the owner's rule, #403 #406): a subset chosen with
+ --draft-vocab, or kept from an earlier install, gets no note. [] for every other case."""
+ if chosen or not 0 < vram_gb < SMALL_DRAFT_VRAM_GB:
+ return []
+ start = "START-HERE.bat" if WIN else "./setup.sh"
+ return [f"Tip for a {vram_gb:.0f} GB card: the draft layer's default token subset (with Chinese, Japanese and "
+ f"Korean) needs up to ~{DRAFT_VOCAB_MIB['cjk']} MiB of VRAM.",
+ f" For English and code answers, {start} --draft-vocab en needs up to ~{DRAFT_VOCAB_MIB['en']} MiB "
+ f"(cyrillic: ~{DRAFT_VOCAB_MIB['cyrillic']}) and leaves the rest to the expert cache - and it is the",
+ " fix when the start stops with \"the draft head does not fit\". The model keeps the choice."]
+
+
def mtp_corrupt(mtp: Path, env=None) -> bool:
"""#327: True when the MTP tensors an install fetched are not the pinned checkpoint's (tools/mtp_fetch.py verify,
which hashes only files that changed since they last checked out). A mirror that ignored range requests left the
@@ -3274,6 +3293,8 @@ def main() -> int:
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}")
+ for line in draft_vocab_note(gpu.get("vram_gb", 0.0), draft_vocab): # #474: a recommendation, nothing changes
+ say(" " + line)
# ---- 7. the start script
step(7, "writing the start script")
diff --git a/src/core/mtp.cpp b/src/core/mtp.cpp
index 17e36556a..e2b89b6ff 100644
--- a/src/core/mtp.cpp
+++ b/src/core/mtp.cpp
@@ -372,6 +372,45 @@ void MtpDrafter::set_draft_history(const int32_t* tail, int64_t n_tail, int32_t
coupled_hist_base(tail, n_tail, next, h, h_chist_ + (kCoupledHistCap - h));
}
+namespace {
+// #474: what to change when the draft head's token subset does not fit the VRAM left - a smaller subset that setup
+// ships (data/draft_vocab_*.bin; their token counts below), and how to pick it. The start used to stop at "the draft
+// head does not fit" with no hint. Text only, after the failure: nothing changes for a start that fits.
+void draft_head_hint(int64_t n_tokens, int64_t row_bytes) {
+ size_t free_b = 0, total_b = 0;
+ const bool have_free = cudaMemGetInfo(&free_b, &total_b) == cudaSuccess;
+ auto mib = [&](int64_t n) { return (double) (n * row_bytes) / 1048576.0; };
+ std::string free_s;
+ if (have_free) {
+ char b[64];
+ std::snprintf(b, sizeof(b), " and %.0f MiB is free", (double) free_b / 1048576.0);
+ free_s = b;
+ }
+ std::fprintf(stderr, "strata mtp: the draft head over %lld tokens needs %.0f MiB of VRAM%s.\n",
+ (long long) n_tokens, mib(n_tokens), free_s.c_str());
+ struct Subset { const char* name; int64_t tokens; const char* what; };
+ static const Subset smaller[] = {{"cyrillic", 58963, "English, code and the Cyrillic script"},
+ {"en", 40525, "English and code"}};
+ std::string opts;
+ for (const Subset& s : smaller)
+ if (s.tokens < n_tokens) {
+ char b[160];
+ std::snprintf(b, sizeof(b), "%s--draft-vocab %s (%s, ~%.0f MiB)", opts.empty() ? "" : " or ", s.name,
+ s.what, mib(s.tokens));
+ opts += b;
+ }
+ if (!opts.empty())
+ std::fprintf(stderr, "strata mtp: hint: a smaller draft vocabulary needs less VRAM: %s. Start once with it - "
+ "START-HERE.bat --draft-vocab en (Windows) or ./setup.sh --draft-vocab en - and the model "
+ "keeps it (\"draft_vocab\" in its strata-*.json config); or a smaller --context in "
+ "setup.\n",
+ opts.c_str());
+ else
+ std::fprintf(stderr, "strata mtp: hint: this is already the smallest shipped draft vocabulary: a smaller "
+ "--context (or closing what else uses the GPU) leaves it room.\n");
+}
+} // namespace
+
bool MtpDrafter::bind(const WeightTable& wt, const NativeHead* head, const float* window_R, std::string& err) {
const OnDevice on_device(device_);
wt_ = &wt;
@@ -395,6 +434,7 @@ bool MtpDrafter::bind(const WeightTable& wt, const NativeHead* head, const float
if (cudaMalloc((void**) &dvocab_, raw.size()) != cudaSuccess ||
cudaMalloc((void**) &dhead_, (size_t) (n_dvocab_ * row_bytes)) != cudaSuccess) {
err = "mtp: the draft head does not fit";
+ draft_head_hint(n_dvocab_, row_bytes);
return false;
}
cudaMemcpy(dvocab_, raw.data(), raw.size(), cudaMemcpyHostToDevice);
diff --git a/tools/test_setup_draft_vocab.py b/tools/test_setup_draft_vocab.py
index f0b756928..6fedb4a81 100644
--- a/tools/test_setup_draft_vocab.py
+++ b/tools/test_setup_draft_vocab.py
@@ -49,5 +49,29 @@ class Refresh(unittest.TestCase):
self.assertEqual(hashlib.sha256((rt / "draft_vocab.bin").read_bytes()).hexdigest(), want)
+class SmallCardNote(unittest.TestCase):
+ """#474: a card under 14 GB is told about a smaller draft subset - a note only, and not when one was chosen."""
+
+ def test_note_on_a_small_card_only(self):
+ note = setup.draft_vocab_note(12.0, None)
+ self.assertTrue(note)
+ self.assertIn("--draft-vocab en", " ".join(note))
+ self.assertIn("the draft head does not fit", " ".join(note))
+ for vram, chosen in ((16.0, None), (24.0, None), (12.0, "en"), (12.0, "cyrillic"), (12.0, "cjk"), (0.0, None)):
+ self.assertEqual(setup.draft_vocab_note(vram, chosen), [], (vram, chosen))
+
+ def test_sizes_follow_the_shipped_subsets(self):
+ # the MiB the note gives scale with the subsets' token counts (4 bytes per token id in data/)
+ sizes = {}
+ for choice, name in setup.DRAFT_VOCABS.items():
+ p = ROOT / "data" / name
+ if not p.exists():
+ self.skipTest(f"data/{name} is not in this checkout")
+ sizes[choice] = p.stat().st_size // 4
+ for choice in ("en", "cyrillic"):
+ want = setup.DRAFT_VOCAB_MIB["cjk"] * sizes[choice] / sizes["cjk"]
+ self.assertAlmostEqual(setup.DRAFT_VOCAB_MIB[choice], want, delta=3)
+
+
if __name__ == "__main__":
unittest.main()