diff --git a/docs/DETAILS.md b/docs/DETAILS.md index ce147220..e2012813 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 ... hi blobs ... MB read`), and `GET /metrics` lists `ram_blobs`, `file_blobs` and `file_mb` for each recent request (with engine 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 128K and 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.hpp index 0872f49a..beaa5aa3 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.py index e65d1188..6178f12d 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 read self.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])) @staticmethod def 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 None seen = prompt_tokens_seen(len(ids), last) # #471: < len(ids) when cancelled mid-read self.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.0 hit_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": # #530 diff --git a/serve/test_server.py b/serve/test_server.py index 64c54f7f..813fa66d 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, "\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 start begins 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.js index 6e8fa6b2..f6e56374 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 ? "" : ` ${r.projection ? "ESP" : "stock"}`; - 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 ? ` +${(r.pcie_share * 100).toFixed(1)}% PCIe` : ""); return `
| Time | Status | Prompt | Reused | Output | -Tok/s | Hit rate | Duration | Tok/s | VRAM hit rate | Duration |
|---|---|---|---|---|---|---|---|
| No requests yet | |||||||