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-q4-on242' into r131-q4
Niko12214167bd17aca8
diff --cc serve/server.pyindex 14cc38b9b,e363e3fa1..fd25cf9a9--- a/serve/server.py+++ b/serve/server.py@@@ -1016,134 -995,56 +1018,135 @@@ class Serviceself.status["queued"] += 1try:with self.fifo:- with self.status_lock:- self.status["queued"] -= 1- # issue #27: it died in an earlier request (or was unloaded) - start it again instead of failing- self.ensure_loaded()- with self.status_lock:- self.status.update(busy=True, phase="reading the prompt", prompt_tokens=len(ids), generated=0,- started=time.time(), first_token=None, tool=None, tail="", max_tokens=max_new)- self.last_request_at = time.time()- self.rate.clear() # the previous request's samples must not leak into this one- before = getattr(self.engine, "last", None)- last_print = time.time()- gen = self.engine.generate(ids, max_new, sampling, cancel, embeddings=emb) if emb else \- self.engine.generate(ids, max_new, sampling, cancel)try:- for t in gen:- if t is None: # heartbeat while the engine is quiet- last_print = self._progress(last_print)- yield "ping", None- continue- n += 1- if t in self.stop_ids:- finish = "stop"- raw_ids.append(t)+ with self.status_lock:+ self.status["queued"] -= 1+ # issue #27: it died in an earlier request (or was unloaded) - start it again instead of failing+ self.ensure_loaded()+ with self.status_lock:+ self.status.update(busy=True, phase="reading the prompt", prompt_tokens=len(ids),+ generated=0, started=time.time(), first_token=None, tool=None, tail="",+ max_tokens=max_new)+ self.last_request_at = time.time()+ self.rate.clear() # the previous request's samples must not leak into this one+ before = getattr(self.engine, "last", None)+ last_print = time.time()+ prompt, thought = ids, 0 # thought: the reasoning tokens so far (the budget's count)+ while True:+ gen = self.engine.generate(prompt, max_new - n, sampling, cancel, embeddings=emb) if emb \+ else self.engine.generate(prompt, max_new - n, sampling, cancel)+ seg, wrap = [], False # this pass's tokens; the budget is reached+ try:+ for t in gen:+ if t is None: # heartbeat while the engine is quiet+ last_print = self._progress(last_print)+ yield "ping", None+ continue+ n += 1+ if t in self.stop_ids:+ finish = "stop"+ raw_ids.append(t)+ break+ raw_ids.append(t)+ seg.append(t)+ evs = parser.feed(detok.push(t))+ self._note(n, evs)+ last_print = self._progress(last_print)+ for ev in evs:+ yield "event", ev+ if budget and parser.state == "reasoning":+ thought += 1+ # at a clean point: no tag held back, no character split across tokens+ if thought >= budget and not parser.buf and not detok.pending():+ wrap = True+ break+ except EngineDied as e:+ finish = "error"+ note = self.engine.death_note() if hasattr(self.engine, "death_note") else ""+ log = getattr(self.engine, "log_path", None)+ print(f"[strata] {e}. {note} The next request starts the engine again."+ f"{' Its log: ' + log if log else ''}", flush=True)+ raise+ except ValueError as e: # the engine's ERR line (it may have ended after it)+ finish = "error"+ print(f"[strata] the engine reported an error: {e}", flush=True)+ raise+ finally:+ gen.close() # STOP+drain to THIS request's DONE while still holding the+ # fifo, so a stop-token break can't leave the shared engine+ # queue mid-drain for the next request to read as its own DONE+ if not wrap or cancel.is_set():break- raw_ids.append(t)- evs = parser.feed(detok.push(t))- self._note(n, evs)- last_print = self._progress(last_print)- for ev in evs:- yield "event", ev+ # #123: the thinking reached reasoning_budget_tokens. Close it the way the model would (a+ # short wrap-up and </think>) and let it answer: the next pass's prompt is this one plus what+ # was generated plus the wrap-up, so the engine continues from the prefix it already holds.+ budget = None+ extra = self.tok.encode(REASONING_WRAP_UP, parse_special=True)+ if max_new - n - len(extra) < 1:+ break # no room left to answer: "length", as without a budget+ print(f"[strata] thinking budget reached ({thought} tokens): wrapping up the thinking",+ flush=True)+ for t in extra:+ n += 1+ raw_ids.append(t)+ evs = parser.feed(detok.push(t))+ self._note(n, evs)+ for ev in evs:+ yield "event", ev+ prompt = prompt + seg + extraif cancel.is_set():finish = "cancel"- except EngineDied as e:- finish = "error"- note = self.engine.death_note() if hasattr(self.engine, "death_note") else ""- print(f"[strata] {e}. {note} The next request starts the engine again."- f"{' Its log: ' + self.engine.log_path if getattr(self.engine, 'log_path', None) else ''}",- flush=True)- raise- except ValueError as e: # the engine's ERR line (it may have ended after it)- finish = "error"- print(f"[strata] the engine reported an error: {e}", flush=True)+ except GeneratorExit: # the client disconnected mid-stream+ finish = "disconnect"raisefinally:- gen.close() # STOP+drain to THIS request's DONE while still holding the- # fifo, so a stop-token break can't leave the shared engine- # queue mid-drain for the next request to read as its own DONE- except GeneratorExit: # the client disconnected mid-stream- finish = "disconnect"- raise+ # #266: settle this request's status, history and totals while still holding the fifo: once+ # it is released the next request sets its own status, which this must not record or clear+ with self.status_lock:+ if self.status.get("busy"):+ # only this request's DONE counts: same object means no DONE arrived (death, error,+ # disconnect)+ last = dict(getattr(self.engine, "last", {}) or {}) \+ if getattr(self.engine, "last", None) is not engine_last0 else {}+ started = self.status.get("started", time.time())+ cvec = (getattr(self.engine, "info", {}) or {}).get("cvec", 0)+ loaded = str(cvec) not in ("0", "", "None")+ hit_rate = round(last["hits"] / last["lookups"], 3) if last.get("lookups") else None+ self.history.append({+ "projection": (sampling or {}).get("experimental_speed_projection") is not False+ if loaded else None,+ "time": started, "duration_s": round(time.time() - started, 1), "finish": finish,+ "prompt_tokens": len(ids), "reused": last.get("reused"), "output_tokens": n,+ "engine_generated": last.get("generated"),+ "prompt_ms": last.get("prompt_ms"), "decode_ms": last.get("decode_ms"),+ "decode_tok_s": round(last["generated"] / (last["decode_ms"] / 1000), 1)+ if n and last.get("generated") and last.get("decode_ms") else None,- "hit_rate": hit_rate})++ "hit_rate": hit_rate, "ram_blobs": last.get("ram_blobs"),++ "file_blobs": last.get("file_blobs"), "file_mb": last.get("file_mb")})+ t = self.totals+ t["requests"] += 1+ t["prompt_tokens"] += len(ids)+ t["reused"] += last.get("reused") or 0+ t["output_tokens"] += n+ t["prompt_ms"] += last.get("prompt_ms") or 0.0+ t["decode_ms"] += last.get("decode_ms") or 0.0+ fresh = getattr(self.engine, "last", None)+ if fresh is not None and fresh is not before: # the engine's clock for THIS request+ timings = request_timings(len(ids), n, last)+ self.last_timings = dict(timings, at=int(time.time())) if timings else None+ self.last_request_at = time.time()+ now = time.time()+ el = now - self.status.get("started", now)+ ft = self.status.get("first_token")+ rate = n / max(1e-6, now - ft) if ft else 0.0+ hit_msg = f", expert cache {hit_rate*100:.1f}% hit" if hit_rate is not None else ""+ print(f"[strata] done: {n} tokens in {el:.0f} s ({rate:.1f} tok/s) "+ f"({finish}, cancel={cancel.is_set()}){hit_msg}", flush=True)+ if os.environ.get("STRATA_DEBUG") and raw_ids:+ print(f"[strata] raw: {self.tok.decode(raw_ids)!r}", flush=True)+ self.status["busy"] = False+ self.status.pop("tail", None) # #212: the answer's end is not kept once it is done+ self.status.pop("tool", None)finally:if emb:Path(emb).unlink(missing_ok=True)diff --cc src/core/expert_source.cppindex 863c1eee0,e4fccea88..6463c3449--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@@ -1419,21 -1898,8 +1907,14 @@@ LoadStats load_experts_gguf(const std::const auto t0 = std::chrono::steady_clock::now();std::atomic<int64_t> next{0};std::atomic<bool> bad{false};- // a layer's experts may sit in another shard of the model (native_experts.txt v3): a name beside `gguf`- const size_t cut = gguf.find_last_of("/\\");- const std::string dir = cut == std::string::npos ? std::string() : gguf.substr(0, cut + 1);- auto file_of = [&](int64_t l) -> std::string {- if (lay.gguf_file.empty() || lay.gguf_file[(size_t) l].empty()) return gguf;- return dir + lay.gguf_file[(size_t) l];- };auto worker = [&]() {- std::ifstream f;+ // #230: `fread` on a `FILE*`, as load_experts_ranges (#89): MSVC's `std::ifstream::read` splits a request+ // into 4095-byte freads, which took this path to 0.02 GiB/s on a Windows install without experts.bin.+ // The guard closes the handle on every return.+ struct Closer {+ FILE* f = nullptr;+ ~Closer() { if (f != nullptr) std::fclose(f); }+ } file;std::string open_name;std::vector<uint8_t> buf;for (;;) {@@@ -1452,6 -1910,15 +1925,15 @@@const uint64_t per[3] = {fm.up_off, fm.up_off, blob - fm.down_off};const uint64_t at[3] = {0, fm.up_off, fm.down_off};for (int r = 0; r < 3; ++r) {+ // the handle is kept while consecutive roles share a file (every layer of a v3 pack)+ const std::string name = expert_gguf_file(gguf, lay, l, r);+ if (name != open_name) {- f.close();- f.clear();- f.open(name, std::ios::binary);- if (!f) { bad = true; return; }++ if (file.f != nullptr) std::fclose(file.f);++ file.f = std::fopen(name.c_str(), "rb");++ if (file.f == nullptr) { bad = true; return; }+ open_name = name;+ }++ FILE* const f = file.f;const uint64_t src = lay.gguf_off[(size_t) (3 * l + r)];const uint64_t total = per[r] * (uint64_t) lay.n_expert;const uint64_t chunk = per[r] * 16; // 16 experts per read