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

serve: the start narrator says what happens to the experts with --mmap-experts (#505)

Niko1221455fc8a7947d
diff --git a/serve/server.py b/serve/server.py
index 3913b1f27..270955606 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -218,6 +218,27 @@ def echo_requests(log_path: str, offset: int) -> None:
m["tg"]), flush=True)
+def experts_loading_words(args: list, size: str) -> str:
+ """#505: what the start does with the experts, by the engine's flags (generate.cpp's option parsing): a RAM budget
+ copies the hottest N GiB into RAM (--resident-budget-gib), the resident low-RAM mode the ones the GPU does not hold
+ (--resident-experts), plain --mmap-experts reads them from the model files through the OS file cache (nothing is
+ loaded into RAM up front); otherwise all of them go into RAM."""
+ if "--resident-budget-gib" in args:
+ try:
+ n = f"up to {float(args[args.index('--resident-budget-gib') + 1]):g} GiB"
+ except (IndexError, ValueError):
+ n = "a RAM budget"
+ return (f"loading the most-used experts into RAM ({n}; the rest are read from the model files as needed) "
+ "and locking part of them for the GPU.")
+ if "--resident-experts" in args:
+ return (f"loading the experts the GPU does not hold into RAM (of {size}) and locking part of them for the "
+ "GPU.")
+ if "--mmap-experts" in args:
+ return (f"mapping the experts from the model files ({size}, --mmap-experts): they are not loaded into RAM - "
+ "the OS file cache reads them as the GPU's expert cache fills and as requests need them.")
+ return f"loading the experts into RAM ({size}) and locking part of them for the GPU."
+
+
def narrate_start(log_path: str, offset: int, args: list, done: threading.Event, heartbeat=20.0) -> None:
"""While the engine starts, say in the server window what it is doing, from its log: the start reads tens of GB
into RAM and locks part of it for the GPU, and on many PCs everything is slow or frozen for a minute or more -
@@ -229,6 +250,7 @@ def narrate_start(log_path: str, offset: int, args: list, done: threading.Event,
except (OSError, IndexError):
pass
size = f"about {gb:.0f} GB" if gb >= 1 else "tens of GB"
+ loading = experts_loading_words(args, size)
t0 = last = time.time()
said = set()
@@ -252,8 +274,8 @@ def narrate_start(log_path: str, offset: int, args: list, done: threading.Event,
cut = chunk.rfind(b"\n") + 1
pos += cut
for line in chunk[:cut].decode("utf-8", "replace").splitlines():
- if "PLE on" in line or "expert arena:" in line:
- say("arena", f"[strata] loading the experts into RAM ({size}) and locking part of them for the GPU.\n"
+ if "PLE on" in line or "expert arena:" in line or "experts via mmap" in line: # #505: mapped
+ say("arena", f"[strata] {loading}\n"
" YOUR PC CAN BE SLOW OR STOP RESPONDING FOR 1-3 MINUTES NOW - this is normal.\n"
" Please wait and don't close this window; the browser opens when it is ready.")
elif " loaded " in line and "GiB at" in line:
diff --git a/serve/test_server.py b/serve/test_server.py
index 2497455ed..8f34a74b0 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -918,6 +918,49 @@ class StartFailureLog(unittest.TestCase):
self.assertNotIn("an earlier start", text)
+class StartNarrator(unittest.TestCase):
+ """#505: the start's words say what happens to the experts - --mmap-experts loads nothing into RAM up front."""
+
+ def test_the_words_follow_the_flags(self):
+ from serve.server import experts_loading_words
+ self.assertIn("loading the experts into RAM (about 38 GB)", experts_loading_words([], "about 38 GB"))
+ mapped = experts_loading_words(["--mmap-experts"], "about 47 GB")
+ self.assertIn("mapping the experts from the model files (about 47 GB", mapped)
+ self.assertIn("not loaded into RAM", mapped)
+ self.assertIn("the GPU does not hold", experts_loading_words(["--resident-experts"], "about 47 GB"))
+ budget = experts_loading_words(["--mmap-experts", "--resident-budget-gib", "71"], "about 50 GB")
+ self.assertIn("up to 71 GiB", budget)
+ self.assertNotIn("about 50 GB", budget)
+
+ def narrate(self, args, lines):
+ import contextlib
+ import io
+ from serve.server import narrate_start
+ d = tempfile.mkdtemp()
+ log = Path(d) / "engine.log"
+ log.write_text("".join(x + "\n" for x in lines), encoding="utf-8")
+ done, out = threading.Event(), io.StringIO()
+ with contextlib.redirect_stdout(out):
+ t = threading.Thread(target=narrate_start, args=(str(log), 0, args, done))
+ t.start()
+ time.sleep(0.8)
+ done.set()
+ t.join(5)
+ return out.getvalue()
+
+ def test_a_mapped_start(self):
+ said = self.narrate(["--mmap-experts"], ["strata generate: experts via mmap (--mmap-experts; the GGUF shards "
+ "in place, no experts.bin)"])
+ self.assertIn("mapping the experts from the model files", said)
+ self.assertNotIn("loading the experts into RAM", said)
+
+ def test_an_arena_start(self):
+ said = self.narrate([], ["strata generate: expert arena: resident, 31.64 GiB",
+ "strata generate: loaded 31.64 GiB at 3.17 GiB/s"])
+ self.assertIn("loading the experts into RAM (tens of GB)", said)
+ self.assertIn("experts loaded: 31.64 GiB at 3.17 GiB/s", said)
+
+
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 c5119aa79..81bcf050d 100644
--- a/setup.py
+++ b/setup.py
@@ -2569,8 +2569,15 @@ def start(cfg_path: Path, port: int | None, gpu: int | list | None = None, open_
pass
say()
say(" " + "-" * 100)
- say(f" Starting {cfg.get('model_name', 'the model')}: it loads {f'about {gb:.0f} GB' if gb >= 1 else '34-55 GB'} "
- "into RAM and locks part of it for the GPU.")
+ size = f'about {gb:.0f} GB' if gb >= 1 else '34-55 GB'
+ a_ = cfg["args"]
+ if "--mmap-experts" in a_ and "--resident-budget-gib" not in a_ and "--resident-experts" not in a_:
+ # #505: the mapped low-RAM mode loads nothing into RAM up front (the server's narrator says the same)
+ say(f" Starting {cfg.get('model_name', 'the model')}: it maps {size} of experts from the model files (the OS "
+ "file cache reads them).")
+ else:
+ say(f" Starting {cfg.get('model_name', 'the model')}: it loads {size} into RAM and locks part of it for the "
+ "GPU.")
say(" While it does, YOUR PC CAN BE SLOW OR STOP RESPONDING FOR 1-3 MINUTES (longer the first time after a")
say(" restart). That is normal: please wait and don't close this window - the browser opens when it is ready.")
say(" Later, closing this window stops the model.")