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++
Merge branch 'f-139-big' into f-139-rel
Niko12218ac4b945a0c3
diff --cc serve/server.pyindex 78022ba66,9d0151e6e..cdf0cceb9--- a/serve/server.py+++ b/serve/server.py@@@ -551,9 -443,38 +551,40 @@@ class StrataEngineself.last.update(ram_blobs=int(f[11]), file_blobs=int(f[12]), file_mb=float(f[13]))if len(f) >= 15: # #471 (engine 0.1.36+): the prompt tokens actually readself.last.update(prompt_read=int(f[14]))+ if len(f) >= 16: # #588 (engine 0.1.39+): routed experts read over PCIe+ self.last.update(offloaded=int(f[15]))+ def vram(self, reserve_mib: int | None, timeout: float = 120.0) -> dict:+ """#533: `VRAM <reserve_mib>` between requests (the caller holds the service's FIFO): the engine shrinks its+ expert cache until that much VRAM is free, or grows it back when more is free; None: back to the reserve it+ started with. -> the engine's figures (expert_slots, expert_cache_mib, vram_free_mib, ...); raises ValueError+ with the engine's reason (e.g. it was not started with --vram-elastic), EngineDied when it ended."""+ if not self.alive():+ raise EngineDied("the engine is not running")+ self.proc.stdin.write("VRAM" + ("" if reserve_mib is None else f" {int(reserve_mib)}") + "\n")+ self.proc.stdin.flush()+ deadline = time.time() + timeout+ while True:+ try:+ line = self.lines.get(timeout=max(0.1, deadline - time.time()))+ except queue.Empty:+ raise EngineDied("the engine did not answer the VRAM command") from None+ if line is None:+ raise EngineDied("the engine ended")+ line = line.strip()+ if line.startswith("ERR"):+ raise ValueError(line[4:].strip() or "the engine refused the VRAM command")+ if line.startswith("VRAM "):+ out = {}+ for kv in line.split()[1:]:+ k, _, v = kv.partition("=")+ out[k] = int(v) if v.lstrip("-").isdigit() else v+ self.info.update({k: out[k] for k in ("expert_slots", "vram_free_mib") if k in out})+ self.info["vram"] = out+ return out+ if time.time() > deadline:+ raise EngineDied("the engine did not answer the VRAM command")+@staticmethoddef sampling_keys(sampling: dict) -> str:keys = ""@@@ -1166,8 -1026,8 +1204,9 @@@ class Serviceself.idle_unload_s = 0self.min_free_vram_mib = 0self.before_load = None+ self.vram_reserve = None # #533: the last POST /v1/vram reserve (None: the start's)self.reasoning_budget_tokens = 0 # #123: the config's default thinking budget (0: none)+ self.repeat_stop_tokens = REPEAT_STOP_TOKENS # #606: one token this many times in a row ends a reply (0: off)self.anthropic_think_unasked = True # #278: "anthropic_thinking": "on_request" -> Falseself.stop_ids = set(tokenizer.encode(IM_END, parse_special=True) +tokenizer.encode("<|endoftext|>", parse_special=True))@@@ -2521,11 -2342,20 +2591,22 @@@ def make_handler(svc: Service)result = "loaded"self._json(200, {"status": result, **svc.v1_status()})return+ if path == "/v1/vram": # #533: give VRAM back to other programs, or take it+ if not self._own_page("the VRAM reserve can be changed"):+ return+ r = req.get("reserve_mib")+ if r is not None and (isinstance(r, bool) or not isinstance(r, int) or r < 0):+ raise ValueError("reserve_mib: a whole number of MiB (0 or more), or null for the start's")+ try:+ self._json(200, svc.vram(r))+ except EngineDied as e:+ self._json(503, {"error": {"type": "server_error", "message": str(e)}})+ return- if path in ("/v1/chat/completions", "/v1/messages"):+ if path in ("/v1/chat/completions", "/v1/messages", "/v1/responses"):self.record = svc.begin_request(path, req)- if path == "/v1/chat/completions":+ if path == "/v1/responses":+ self._responses(req)+ elif path == "/v1/chat/completions":self._openai(req)elif path == "/v1/messages":self._anthropic(req)diff --cc setup.pyindex 05dda6aab,818cbb229..acd99f68d--- a/setup.py+++ b/setup.py@@@ -3922,8 -3732,10 +3990,10 @@@ def main() -> intimport calibrate as CALcfg["args"] = CAL.apply(cfg["args"], cal.get("settings") or {})ok("the settings tuned for this PC earlier are used" + (f" ({cal['date']})" if cal.get("date") else ""))+ else: # #642: measured counts (a calibration) win over the rule+ cfg["args"] = recommend_pool_workers(cfg["args"])- write_config(cfg_path, cfg)- script = write_run_script(tag, cfg_path, port)+ write_setup_config(cfg_path, cfg, adopted if adopted is not None and adopted.name == cfg_path.name else None)+ script = write_run_script(tag, cfg_path, port, cfg.get("open_browser") is not False)# offered only when someone answers: --yes installs and adopted earlier installs are not held up by itif cal is None and not hip and not a.no_start and not a.yes and ask("Tune Strata for this PC now? It measures a few engine settings (about 5-10 minutes; the PC is busy "diff --cc src/program/generate.cppindex 1b6ed60e2,e605c787f..f6d98b969--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@@ -600,10 -519,11 +604,13 @@@ void usage()" --conversation-cache-mib N --serve: RAM budget for parked conversations (default 0 = off)\n"" --conversation-cache-slots N --serve: at most N parked conversations (default 4)\n"" --conversation-cache-min-free-mib N --serve: physical RAM floor when parking (default 2560)\n"+ " --vram-elastic --serve (#533, opt-in, NVIDIA): the expert cache in segments (--vram-segment-mib,\n"+ " default 512), so the command `VRAM <reserve_mib>` (the server's POST /v1/vram) can\n"+ " give VRAM back to other programs between requests and take it back later\n"" --prompt-cache-every N --serve: also checkpoint every N fresh prompt tokens (default 16384, 0 = off)\n"" --turn-token ID --serve: the token that opens a chat turn (default 248045, <|im_start|>)\n"+ " --tail-role-token ID --serve: a turn of this role right before the last turn is left out of\n"+ " the conversation checkpoint (a trailing effort turn; default -1 = off)\n"" --short-read N --serve: read at most N fresh text tokens through the decode windows instead\n"" of the batched prompt path (default 64, 0 = off)\n"" --suffix-draft N prompt lookup: draft from an earlier repeat of the last N+ tokens of context\n"@@@ -5277,7 -5024,7 +5315,7 @@@ int main(int argc, char** argv)"expert_slots_primary=%lld expert_cache_primary_mib=%lld spec=%d ""mtp_max=%d lookup=%d vram_free_mib=%lld cvec=%s arena_mib=%lld pool_workers=%d pcie_frac=%.2f ""spec_min_p=%.2f conversation_cache_mib=%lld conversation_cache_slots=%d "- "conversation_cache_min_free_mib=%lld tail_role_token=%lld engine=" STRATA_VERSION "\n",- "conversation_cache_min_free_mib=%lld vram_elastic=%d engine=" STRATA_VERSION "\n",++ "conversation_cache_min_free_mib=%lld tail_role_token=%lld vram_elastic=%d engine=" STRATA_VERSION "\n",(long long) o.max_context, o.kv.c_str(),(long long) (g.n_qsa_layers() > 0 && ss.qsa_states[ss.qsa_primary()].kv_mode == 1? ss.qsa_states[ss.qsa_primary()].n_slots * 4 : 0),@@@ -5288,7 -5035,7 +5326,7 @@@(long long) ((o.mmap_experts ? src.resident_bytes() : strata::kernels::cpu::expert_layout().total) >> 20),pool.workers(), o.pcie_frac,o.spec_min_p, (long long) o.conversation_cache_mib, o.conversation_cache_slots,- (long long) o.conversation_cache_min_free_mib, (long long) o.tail_role_token);- (long long) o.conversation_cache_min_free_mib, xcache.segmented() ? 1 : 0);++ (long long) o.conversation_cache_min_free_mib, (long long) o.tail_role_token, xcache.segmented() ? 1 : 0);}// issue #29: a request whose heartbeat (tokens, prompt chunks, verify windows) stops for this long is stuck on// a flag nobody will raise - end the engine with where it was, so the server starts it again instead of thediff --cc tools/test_setup_golden.pyindex a3c0a2d85,08f75a161..2f2513a4c--- a/tools/test_setup_golden.py+++ b/tools/test_setup_golden.py@@@ -100,9 -100,9 +100,10 @@@ def install(ram, found, argv, answers=Nmock.patch.object(setup, "amd_gpus", lambda: []),mock.patch.object(setup, "ram_gb", lambda: ram),mock.patch.object(setup, "cpu_info", lambda: ("Test CPU", True, avx512)),+ mock.patch.object(setup, "cpu_cores", lambda: None), # #642: not a hybrid CPUmock.patch.object(setup, "page_file_gb", lambda: 16.0),mock.patch.object(setup, "is_wsl", lambda: False),+ mock.patch.object(setup, "rotational_disk", lambda p: None), # #605: the test PC's own diskmock.patch.object(setup, "free_gb", lambda p: 900.0),mock.patch.object(setup, "pip_install", lambda *a, **k: None),mock.patch.object(setup, "get_llama_cpp", lambda: t / "llama.cpp"),diff --cc tools/test_setup_unsloth.pyindex 38caa4e6c,c489497c5..3cd0c9988--- a/tools/test_setup_unsloth.py+++ b/tools/test_setup_unsloth.py@@@ -164,9 -164,9 +164,10 @@@ class Base(unittest.TestCase)mock.patch.object(setup, "amd_gpus", lambda *a: list(amd)),mock.patch.object(setup, "ram_gb", lambda: ram),mock.patch.object(setup, "cpu_info", lambda: ("Test CPU", True, True)),+ mock.patch.object(setup, "cpu_cores", lambda: None), # #642: not a hybrid CPUmock.patch.object(setup, "page_file_gb", lambda: 16.0),mock.patch.object(setup, "free_gb", lambda p: free),+ mock.patch.object(setup, "rotational_disk", lambda p: None), # #605: not the test PC's diskmock.patch.object(setup, "pip_install", lambda *a, **k: None),mock.patch.object(setup, "get_llama_cpp", lambda: self.t / "llama.cpp"),mock.patch.object(setup, "get_prebuilt", lambda *a, **k: eng),