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++
Hit rate: say the PCIe share beside it (#588)
Niko1221b591a45bd7bc
diff --git a/docs/DETAILS.md b/docs/DETAILS.mdindex ce147220d..e2012813d 100644--- a/docs/DETAILS.md+++ b/docs/DETAILS.md@@ -173,6 +173,10 @@ been warmed). The server log has the same per request (`expert tiers: GPU ... hiblobs ... MB read`), and `GET /metrics` lists `ram_blobs`, `file_blobs` and `file_mb` for each recent request (withengine 0.1.31 or newer). It also lists each request's speculative drafts, `drafts_offered` and `drafts_accepted`(`null` when the engine did not report them), and their sums since the server started in `totals` (#457).+Its `hit_rate` is the VRAM share of the experts looked up while answering: experts the GPU reads over PCIe+(`--pcie-frac`) are not in it, so a higher `--pcie-frac` raises it even when decoding gets slower. `pcie_share`+(engine 0.1.39 or newer, #588) is their share of all routed experts, and the server log and the Monitor tab show it+beside the hit rate.Time to first token is prompt length / prompt speed: with Q2_0 about 4 s at 4K, 25 s at 32K, under 2 minutes at 128Kand 4.5 minutes at 262K (engine 0.1.13 made long prompts about twice as fast, below).diff --git a/include/strata/core/expert_source.hpp b/include/strata/core/expert_source.hppindex 0872f49a2..beaa5aa39 100644--- a/include/strata/core/expert_source.hpp+++ b/include/strata/core/expert_source.hpp@@ -347,6 +347,9 @@ struct ExpertDispatch {GpuPlanSink* plan = nullptr;int pcie_num = 0;int64_t pcie_experts = 0; ///< distinct experts the GPU read over PCIe in verify windows+ /// #588: routed (token, expert) entries the GPU computed from outside its cache in verify windows: read over PCIe+ /// (--pcie-frac, kind 1) or on another GPU (kind 2). In neither cache_hits nor cache_refused.+ int64_t offload_entries = 0;double ms_plan = 0, ms_actq = 0, ms_jobs = 0, ms_run = 0; ///< verify-window dispatch sections/// Plan v0.3 P6: decayed routing counts per (layer, expert) during decode (sized by the caller; empty = off),/// which the driver uses to swap the most-routed missing experts into the VRAM tier between rounds.diff --git a/serve/server.py b/serve/server.pyindex e65d1188f..6178f12df 100644--- a/serve/server.py+++ b/serve/server.py@@ -447,6 +447,8 @@ class StrataEngine:self.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]))@staticmethoddef sampling_keys(sampling: dict) -> str:@@ -1604,6 +1606,11 @@ class Service: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+ # #588: the share the GPU read over PCIe (--pcie-frac) or another GPU computed - not in+ # the hit rate's lookups, which is the VRAM share of the rest (None: an older engine)+ routed = (last.get("lookups") or 0) + (last.get("offloaded") or 0)+ pcie_share = round(last["offloaded"] / routed, 3) \+ if last.get("offloaded") is not None and routed else Noneseen = prompt_tokens_seen(len(ids), last) # #471: < len(ids) when cancelled mid-readself.history.append({"projection": (sampling or {}).get("experimental_speed_projection") is not False@@ -1616,7 +1623,7 @@ class Service:"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, "ram_blobs": last.get("ram_blobs"),+ "hit_rate": hit_rate, "pcie_share": pcie_share, "ram_blobs": last.get("ram_blobs"),"file_blobs": last.get("file_blobs"), "file_mb": last.get("file_mb"),# #457: the speculative drafts from the DONE line (None: the engine did not say)"drafts_offered": last.get("drafts_offered"),@@ -1640,6 +1647,8 @@ class Service:ft = self.status.get("first_token")rate = n / max(1e-6, now - ft) if ft else 0.0hit_msg = f", expert cache {hit_rate*100:.1f}% hit" if hit_rate is not None else ""+ if hit_msg and pcie_share:+ hit_msg += f" (+{pcie_share*100:.1f}% of the routed experts over PCIe)"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 finish == "length" and parser.state == "reasoning": # #530diff --git a/serve/test_server.py b/serve/test_server.pyindex 64c54f7fa..813fa66db 100644--- a/serve/test_server.py+++ b/serve/test_server.py@@ -806,6 +806,26 @@ class DraftCounts(unittest.TestCase):self.assertEqual((m["totals"]["drafts_offered"], m["totals"]["drafts_accepted"]), (17, 10))+class PcieShare(unittest.TestCase):+ """#588: the hit rate stays the VRAM share of the lookups; the routed experts the GPU read over PCIe (the DONE+ line's 16th field, engine 0.1.39+) are given as their own share of all routed experts."""++ def test_history(self):+ tok = ByteTokenizer()+ engine = DoneLineEngine(tok, "</think>\n\nok", max_context=CTX, done_lines=[+ "DONE 4 20 40.0 30.0 stop 3 5 0 60 100 0 0 0.0 20 25", # 25 more over PCIe: 20% of 125 routed+ "DONE 4 20 40.0 30.0 stop 3 5 0 60 100 0 0 0.0 20 0",+ "DONE 4 20 40.0 30.0 stop 3 5 0 60 100 0 0 0.0 20"]) # an older engine+ svc = Service(engine, tok, ChatTemplate(ROOT / "serve/chat_template.jinja"))+ with contextlib.redirect_stdout(io.StringIO()) as out:+ for _ in range(3):+ list(svc.run(tok.encode("hi"), False, None, 10, {}, threading.Event()))+ rows = list(svc.history)+ self.assertEqual([r["hit_rate"] for r in rows], [0.6, 0.6, 0.6])+ self.assertEqual([r["pcie_share"] for r in rows], [0.2, 0.0, None])+ self.assertIn("expert cache 60.0% hit (+20.0% of the routed experts over PCIe)", out.getvalue())++class LearnedProfile(unittest.TestCase):"""#477: "expert_profile_save" in the config: the engine saves its learned profile there, and the next startbegins from it when it is a profile of the same model; without the key the arguments are unchanged."""diff --git a/serve/web/app.js b/serve/web/app.jsindex 6e8fa6b29..f6e56374b 100644--- a/serve/web/app.js+++ b/serve/web/app.js@@ -302,7 +302,9 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {const [cls, text] = badge[r.finish] || ["", r.finish || "–"];const t = new Date(r.time * 1000).toLocaleTimeString([], {hour: "2-digit", minute: "2-digit", second: "2-digit"});const proj = r.projection == null ? "" : ` <span class="st-badge${r.projection ? " st-badge--reading" : ""}" title="experimental speed projection ${r.projection ? "on" : "off"}">${r.projection ? "ESP" : "stock"}</span>`;- const hit = r.hit_rate == null ? "–" : `${(r.hit_rate * 100).toFixed(1)}%`;+ // #588: the VRAM share; the PCIe share (--pcie-frac) beside it when there is one+ const hit = r.hit_rate == null ? "–" : `${(r.hit_rate * 100).toFixed(1)}%` ++ (r.pcie_share ? ` <span class="muted" title="routed experts the GPU read over PCIe (--pcie-frac) or another GPU computed">+${(r.pcie_share * 100).toFixed(1)}% PCIe</span>` : "");return `<tr><td>${esc(t)}</td><td><span class="st-badge ${cls}">${esc(text)}</span>${proj}</td><td class="num">${fmt(r.prompt_tokens)}</td><td class="num">${fmt(r.reused)}</td><td class="num">${fmt(r.output_tokens)}</td><td class="num">${fmt(r.decode_tok_s, 1)}</td><td class="num">${hit}</td><td class="num">${fmt(r.duration_s, 1)} s</td></tr>`;diff --git a/serve/web/index.html b/serve/web/index.htmlindex d858d2f08..fbccdad05 100644--- a/serve/web/index.html+++ b/serve/web/index.html@@ -117,7 +117,7 @@<div class="table-wrap" id="req-wrap"><table class="st-table"><thead><tr><th>Time</th><th>Status</th><th class="num">Prompt</th><th class="num">Reused</th><th class="num">Output</th>- <th class="num">Tok/s</th><th class="num" title="While writing the answer: the share of the experts looked up that were already in VRAM (experts copied over PCIe are not counted)">Hit rate</th><th class="num">Duration</th></tr></thead>+ <th class="num">Tok/s</th><th class="num" title="While writing the answer: the share of the experts looked up that were already in VRAM. Experts the GPU read over PCIe (--pcie-frac) are not counted in it; their share of all routed experts is shown after it (+N% PCIe)">VRAM hit rate</th><th class="num">Duration</th></tr></thead><tbody id="req-body"><tr><td colspan="8" class="muted">No requests yet</td></tr></tbody></table></div>diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex ee759515b..08edd46b9 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -2132,7 +2132,8 @@ void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32}if (kind[i] >= 0) { // CUDA0, PCIe, or a remote/peer result staged into this row belowif (kind[i] == 0) ++d.cache_hits;- else if (kind[i] == 2 && d.peer != nullptr) ++d.peer_entries;+ else ++d.offload_entries; // #588: PCIe or another GPU+ if (kind[i] == 2 && d.peer != nullptr) ++d.peer_entries;// multi-GPU: a direct peer launch is writing this row right now - zeroing it would race itif (!(kind[i] == 2 && d.peer != nullptr && d.peer->launched_direct()))std::memset(row, 0, (size_t) H * sizeof(float));diff --git a/src/program/generate.cpp b/src/program/generate.cppindex e71a3e8db..e1f049846 100644--- a/src/program/generate.cpp+++ b/src/program/generate.cpp@@ -5797,6 +5797,7 @@ int main(int argc, char** argv) {const int64_t ram0 = src.ram_reads(), files0 = src.file_reads();const uint64_t file_bytes0 = src.file_read_bytes();const int64_t decode_look0 = drive.d.cache_hits + drive.d.cache_admitted + drive.d.cache_refused;+ const int64_t offload0 = drive.d.offload_entries; // #588if (cancelled) finish = "cancel";while (!cancelled && produced_n < max_new) {int T = S_mtp;@@ -6044,6 +6045,7 @@ int main(int argc, char** argv) {}const int64_t req_hits = drive.d.cache_hits - decode_hits0;const int64_t req_look = (drive.d.cache_hits + drive.d.cache_admitted + drive.d.cache_refused) - decode_look0;+ const int64_t req_offload = drive.d.offload_entries - offload0;// #471: the prompt tokens this request read - all the fresh ones, or as far as the prompt pass got when a// cancel stopped it part-way (a cancelled request used to be logged and counted as having read them all)const int64_t fresh = n - resume;@@ -6051,11 +6053,15 @@ int main(int argc, char** argv) {// DONE <generated> <prompt> <prompt ms> <decode ms> <finish> <drafts accepted> <drafts offered> <reused> [hits] [lookups]// [RAM blobs] [file blobs] [file MB] (CS-T tiers; appended, so an older server reads the rest)// [prompt tokens read] (#471: fewer than <prompt> - <reused> when a cancel stopped the read)- std::printf("DONE %lld %lld %.1f %.1f %s %lld %lld %lld %lld %lld %lld %lld %.1f %lld\n", (long long) produced_n,+ // [offloaded] (#588: the decode's routed experts the GPU read over PCIe or another GPU computed;+ // not in [lookups])+ std::printf("DONE %lld %lld %.1f %.1f %s %lld %lld %lld %lld %lld %lld %lld %.1f %lld %lld\n",+ (long long) produced_n,(long long) n, prompt_ms, decode_ms, finish, (long long) draft_accepted, (long long) draft_offered,(long long) resume, (long long) req_hits, (long long) req_look,(long long) (src.ram_reads() - ram0), (long long) (src.file_reads() - files0),- (double) (src.file_read_bytes() - file_bytes0) / 1e6, (long long) read_n);+ (double) (src.file_read_bytes() - file_bytes0) / 1e6, (long long) read_n,+ (long long) req_offload);std::fflush(stdout);if (drive.routing != nullptr) std::fflush(drive.routing); // the routing trace survives a crash and is watchable mid-session// "12288 of 98179" when cancelled mid-read (#471), the rate from what was read@@ -6071,11 +6077,18 @@ int main(int argc, char** argv) {decode_ms > 0 ? 1000.0 * produced_n / decode_ms : 0.0, (long long) draft_accepted,(long long) draft_offered, checks.size(), cancelled ? " (cancelled)" : "");// the VRAM share of the experts the pool looked up while decoding; experts it sent over PCIe for the GPU- // to read (--pcie-frac) are in neither count+ // to read (--pcie-frac) are in neither count - #588: so that share is said beside it (raising --pcie-frac+ // raises the hit rate while the PCIe reads may make the decode slower)if (req_look > 0) {- std::fprintf(stderr, "strata serve: decode expert cache hit rate: %.1f%% (%lld hits / %lld lookups)\n",+ char off[160] = "";+ if (req_offload > 0)+ std::snprintf(off, sizeof off, "; %lld more read by the GPU over PCIe or from another GPU (%.1f%% of "+ "all %lld routed)", (long long) req_offload,+ 100.0 * (double) req_offload / (double) (req_look + req_offload),+ (long long) (req_look + req_offload));+ std::fprintf(stderr, "strata serve: decode expert cache hit rate: %.1f%% (%lld hits / %lld lookups)%s\n",100.0 * (double) req_hits / (double) req_look,- (long long) req_hits, (long long) req_look);+ (long long) req_hits, (long long) req_look, off);}// the resident RAM mode, cumulative: experts read from experts.bin since the copy was made (what the plain// mmap mode reads through the OS file cache, from the SSD when the RAM could not keep it)