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

telemetry: per-request decode expert cache hit rate in DONE and web monitor

code-martin51fce4c83e22
diff --git a/serve/server.py b/serve/server.py
index b0a2f3126..d46cd870e 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -223,6 +223,8 @@ class StrataEngine:
"decode_ms": float(f[4]), "finish": f[5]}
if len(f) >= 9: # the conversation cache's fields (engine 0.1.3+)
self.last.update(drafts_accepted=int(f[6]), drafts_offered=int(f[7]), reused=int(f[8]))
+ if len(f) >= 11: # decode hit rate fields
+ self.last.update(hits=int(f[9]), lookups=int(f[10]))
@staticmethod
def sampling_keys(sampling: dict) -> str:
@@ -743,6 +745,7 @@ class Service:
last = dict(getattr(self.engine, "last", {}) or {})
started = self.status.get("started", time.time())
loaded = str((getattr(self.engine, "info", {}) or {}).get("cvec", 0)) 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,
@@ -750,7 +753,8 @@ class Service:
"prompt_tokens": len(ids), "reused": last.get("reused"), "output_tokens": n,
"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})
+ if n and last.get("generated") and last.get("decode_ms") else None,
+ "hit_rate": hit_rate})
t = self.totals
t["requests"] += 1
t["prompt_tokens"] += len(ids)
@@ -762,8 +766,9 @@ class Service:
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()})", flush=True)
+ 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
diff --git a/serve/web/app.js b/serve/web/app.js
index 43757b9a6..6892f9654 100644
--- a/serve/web/app.js
+++ b/serve/web/app.js
@@ -274,7 +274,7 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {
// recent requests
const body = $("req-body");
if (!requests.length) {
- body.innerHTML = `<tr><td colspan="7" class="muted">No requests yet</td></tr>`;
+ body.innerHTML = `<tr><td colspan="8" class="muted">No requests yet</td></tr>`;
} else {
const badge = {stop: ["", "Done"], length: ["", "Max tokens"], cancel: ["st-badge--queued", "Stopped"],
disconnect: ["st-badge--queued", "Closed"], error: ["st-badge--error", "Error"]};
@@ -282,9 +282,10 @@ 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)}%`;
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">${fmt(r.duration_s, 1)} s</td></tr>`;
+ <td class="num">${hit}</td><td class="num">${fmt(r.duration_s, 1)} s</td></tr>`;
}).join("");
}
const all = $("req-all");
diff --git a/serve/web/index.html b/serve/web/index.html
index bdf2b86e3..4a9dcc900 100644
--- a/serve/web/index.html
+++ b/serve/web/index.html
@@ -117,8 +117,8 @@
<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">Duration</th></tr></thead>
- <tbody id="req-body"><tr><td colspan="7" class="muted">No requests yet</td></tr></tbody>
+ <th class="num">Tok/s</th><th class="num">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>
<p class="muted req-totals" id="req-totals"></p>
diff --git a/src/program/generate.cpp b/src/program/generate.cpp
index d84d86476..1aa8d19e6 100644
--- a/src/program/generate.cpp
+++ b/src/program/generate.cpp
@@ -3011,6 +3011,8 @@ int main(int argc, char** argv) {
for (int64_t i = 0; i < n - 1; ++i) consumed.push_back((int32_t) ids[(size_t) i]);
const char* finish = "length";
const Clock::time_point d0 = Clock::now();
+ const int64_t decode_hits0 = drive.d.cache_hits;
+ const int64_t decode_look0 = drive.d.cache_hits + drive.d.cache_admitted + drive.d.cache_refused;
if (cancelled) finish = "cancel";
while (!cancelled && produced_n < max_new) {
int T = S_mtp;
@@ -3190,9 +3192,12 @@ int main(int argc, char** argv) {
(unsigned long long) h_pool, (unsigned long long) h_kv, (unsigned long long) h_mtp,
(unsigned long long) h_stale, ss.ple_prev[0], ss.ple_prev[1]);
}
- // DONE <generated> <prompt> <prompt ms> <decode ms> <finish> <drafts accepted> <drafts offered> <reused>
- std::printf("DONE %lld %lld %.1f %.1f %s %lld %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);
+ 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;
+ // DONE <generated> <prompt> <prompt ms> <decode ms> <finish> <drafts accepted> <drafts offered> <reused> [hits] [lookups]
+ std::printf("DONE %lld %lld %.1f %.1f %s %lld %lld %lld %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);
std::fflush(stdout);
const int64_t fresh = n - resume;
std::fprintf(stderr, "strata serve: prompt %lld tokens = %lld reused + %lld read in %.0f ms (%.1f tok/s), "
@@ -3201,6 +3206,11 @@ int main(int argc, char** argv) {
prompt_ms > 0 ? 1000.0 * fresh / prompt_ms : 0.0, (long long) produced_n, decode_ms,
decode_ms > 0 ? 1000.0 * produced_n / decode_ms : 0.0, (long long) draft_accepted,
(long long) draft_offered, checks.size(), cancelled ? " (cancelled)" : "");
+ if (req_look > 0) {
+ std::fprintf(stderr, "strata serve: decode expert cache hit rate: %.1f%% (%lld / %lld hits)\n",
+ 100.0 * (double) req_hits / (double) req_look,
+ (long long) req_hits, (long long) req_look);
+ }
if (g.n_qsa_layers() > 0 && ss.qsa_states[0].kv_mode == 1) {
// KV streaming, cumulative over the process: blocks the selections named vs blocks read from RAM
uint64_t miss = 0, look = 0;