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

Show prefill speed alongside decode speed in dashboard

Hendrik Polczynskiba1c8099482c
diff --git a/serve/server.py b/serve/server.py
index fd5ad3ada..9393f2d58 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -173,6 +173,7 @@ class StrataEngine:
self.can_stop = False # the engine honours a STOP line mid-request (READY <ctx> stop)
self.last = {}
self.info = {} # INFO key=value facts (engine 0.1.8+): kv, expert slots, ... (Monitor tab)
+ self.prefill_tok_s_mean = None
self.progress = None # (read, total) prompt tokens while a prompt is read, from PP lines
try: # a ready-made engine's BUILD.json says its version
self.info["version"] = json.loads((Path(exe).parent / "BUILD.json").read_text()).get("version")
@@ -316,6 +317,7 @@ class StrataEngine:
the HTTP layer turns it into an SSE comment, which keeps clients' watchdogs calm and notices a client that
has gone. A consumer that stops early (or `cancel`) makes the engine STOP, so it does not run to max_new."""
self.progress = None
+ self.prefill_tok_s_mean = None
# an image request takes the same sampling keys as text (#75: it used to decode greedily whatever was asked)
head = f"GENI {int(max_new)}{self.sampling_keys(sampling or {})} {embeddings}" if embeddings else \
f"GEN {int(max_new)}{self.sampling_keys(sampling or {})}"
@@ -345,6 +347,7 @@ class StrataEngine:
f = line.split()
if len(f) >= 3 and f[1].isdigit() and f[2].isdigit():
self.progress = (int(f[1]), int(f[2])) # prompt progress, one per chunk: also a heartbeat (the
+ self.prefill_tok_s_mean = float(f[4]) if len(f) >= 5 else None
if cancel.is_set(): # lines reset the 10 s wait, so without this a long prompt
return # would send no keep-alives at all)
yield None
@@ -624,7 +627,8 @@ class Service:
"""The hardware sampler behind GET /metrics (serve/telemetry.py), recording this server's tok/s too."""
if getattr(self, "telemetry", None) is None:
from serve.telemetry import Telemetry
- self.telemetry = Telemetry(extra=lambda: {"tok_s": self._tok_s(), "tok_s_mean": self._tok_s_mean()},
+ self.telemetry = Telemetry(extra=lambda: {"tok_s": self._tok_s(), "tok_s_mean": self._tok_s_mean(),
+ "prefill_tok_s_mean": self._prefill_tok_s_mean()},
gpu_index=int(getattr(self, "gpu_index", 0) or 0),
gpu_indices=getattr(self, "gpu_indices", None))
@@ -650,6 +654,12 @@ class Service:
return 0.0
return s["generated"] / max(1e-6, time.time() - s["first_token"])
+ def _prefill_tok_s_mean(self):
+ """Engine-reported mean over newly read tokens, excluding the cached prefix."""
+ with self.status_lock:
+ reading = self.status.get("busy") and self.status.get("first_token") is None
+ return getattr(self.engine, "prefill_tok_s_mean", None) if reading else 0.0
+
def metrics(self, all_requests=False) -> dict:
"""GET /metrics: what the Monitor tab shows - the engine's facts, what it is doing, the last requests, and
the hardware (with a minute of history per series)."""
@@ -672,6 +682,7 @@ class Service:
"elapsed_s": round(now - s["started"], 1) if s.get("busy") and s.get("started") else None,
"tok_s": round(self._tok_s(), 1) if state == "generating" else None,
"tok_s_mean": round(self._tok_s_mean(), 1) if state == "generating" else None,
+ "prefill_tok_s_mean": getattr(self.engine, "prefill_tok_s_mean", None) if s.get("busy") else None,
"tok_s_window_s": RATE_WINDOW_S if state == "generating" else None}
if state == "reading" and progress:
live["prompt_read"], live["prompt_total"] = progress
diff --git a/serve/telemetry.py b/serve/telemetry.py
index e746b12a6..6cfd0e3be 100644
--- a/serve/telemetry.py
+++ b/serve/telemetry.py
@@ -256,7 +256,7 @@ class Telemetry:
with self.lock:
self.now = s
for k in ("gpu_util", "gpu_mem_used", "gpu_temp", "gpu_power", "gpu_pcie_rx_mb", "cpu", "ram_used",
- "disk_read_mb", "tok_s"):
+ "disk_read_mb", "tok_s", "prefill_tok_s_mean"):
v = s.get(k)
self.hist[k].append(round(v, 2) if isinstance(v, float) else v)
time.sleep(1.0)
diff --git a/serve/test_server.py b/serve/test_server.py
index b3f70c557..76aa9aa21 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -480,6 +480,41 @@ class LiveRate(unittest.TestCase):
with urllib.request.urlopen(self.base + "/metrics", timeout=10) as r:
return json.loads(r.read())
+ def test_prefill_rate_excludes_cached_tokens(self):
+ import io
+ import queue
+ from types import SimpleNamespace
+ engine = StrataEngine.__new__(StrataEngine)
+ engine.proc = SimpleNamespace(stdin=io.StringIO())
+ engine.lines = queue.Queue()
+ engine.can_stop = False
+ engine.max_context = 262144
+ engine.prefill_tok_s_mean = 9999.0
+ engine.lines.put("PP 10000 12000 2000 1000.0") # 8000 cached, 2000 newly read in two seconds
+ engine.lines.put("DONE 1 12000 4000 10 stop 0 0 8000")
+ gen = engine.generate([1], 1, {}, threading.Event())
+ self.assertIsNone(next(gen))
+ self.assertEqual(engine.progress, (10000, 12000))
+ self.assertEqual(engine.prefill_tok_s_mean, 1000.0)
+ self.svc.engine = engine
+ self.svc.status.update(busy=True, first_token=None)
+ self.assertEqual(self.metrics()["live"]["prefill_tok_s_mean"], 1000.0)
+ self.assertNotIn("prefill_tok_s", self.metrics()["live"])
+ self.assertEqual(self.svc._prefill_tok_s_mean(), 1000.0)
+ self.svc.status.update(first_token=time.time(), generated=1)
+ self.assertEqual(self.svc._prefill_tok_s_mean(), 0.0)
+ self.assertEqual(list(gen), [])
+ timings = request_timings(12000, 1, engine.last)
+ self.assertEqual(timings["prompt_per_second"], 1000.0)
+ engine.lines.put("PP 8000 12000")
+ engine.lines.put("DONE 0 12000 0 0 stop 0 0 12000")
+ gen = engine.generate([1], 1, {}, threading.Event())
+ next(gen)
+ self.assertIsNone(engine.prefill_tok_s_mean)
+ list(gen)
+ self.svc.status["busy"] = False
+ self.assertIsNone(self.metrics()["live"]["prefill_tok_s_mean"])
+
def test_the_live_number_is_a_rate(self):
live_samples, stop = [], threading.Event()
diff --git a/serve/web/app.css b/serve/web/app.css
index 82f1f2a93..4e8363d4a 100644
--- a/serve/web/app.css
+++ b/serve/web/app.css
@@ -92,6 +92,11 @@ main { flex: 1; min-height: 0; display: flex; }
.st-metric__value small { font-size: var(--st-fs-md); font-weight: var(--st-fw-medium); color: var(--st-ink-muted); margin-left: 4px; }
.st-metric__sub { font-size: var(--st-fs-xs); color: var(--st-ink-muted); font-variant-numeric: tabular-nums; min-height: 1em; }
.st-metric__spark { display: block; overflow: visible; }
+.speed-values { display: flex; justify-content: space-between; gap: var(--st-s-3); }
+.speed-values > div { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
+.speed-values > div:last-child { text-align: right; }
+.speed-values .st-metric__value { font-size: clamp(20px, 2.2vw, var(--st-fs-stat)); }
+.st-metric__spark .speed-prefill { color: color-mix(in srgb, var(--st-accent) 65%, black); }
.st-metric__spark[data-tone="warn"] { color: var(--st-warn); }
.st-metric__spark[data-tone="info"] { color: var(--st-info); }
.monitor-row { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2.4fr); gap: var(--st-s-4); }
diff --git a/serve/web/app.js b/serve/web/app.js
index d992389c1..6e8fa6b29 100644
--- a/serve/web/app.js
+++ b/serve/web/app.js
@@ -109,7 +109,7 @@ async function loadHealth() {
// ------------------------------------------------------------------ Monitor
const METRICS = [
- {key: "speed", label: "Speed", icon: "gauge", unit: "tok/s", series: "tok_s"},
+ {key: "speed", label: "Speed", icon: "gauge", unit: "t/s", series: "tok_s"},
{key: "gpu", label: "GPU load", icon: "gpu", unit: "%", series: "gpu_util", max: 100},
{key: "vram", label: "VRAM", icon: "layers", unit: "GB", series: "gpu_mem_used"},
{key: "temp", label: "GPU temp", icon: "thermometer", unit: "°C", series: "gpu_temp", tone: "warn"},
@@ -121,11 +121,17 @@ const METRICS = [
$("metrics").innerHTML = METRICS.map((m) => `
<div class="st-card metric-card"><div class="st-metric">
<span class="st-metric__label">${icon(m.icon, "st-icon st-icon--sm")}${esc(m.label)}</span>
- <span class="st-metric__value" id="mv-${m.key}">–</span>
- <span class="st-metric__sub" id="ms-${m.key}"></span>
+ ${m.key === "speed" ? `<div class="speed-values">
+ <div><span class="st-metric__value" id="mv-speed">-</span><span class="st-metric__sub" id="ms-speed">Decode</span></div>
+ <div class="speed-prefill"><span class="st-metric__value" id="mv-prefill">-</span><span class="st-metric__sub" id="ms-prefill">Prefill</span></div>
+ </div>` : `<span class="st-metric__value" id="mv-${m.key}">–</span>
+ <span class="st-metric__sub" id="ms-${m.key}"></span>`}
<svg class="st-metric__spark" id="sp-${m.key}" viewBox="0 0 100 32" preserveAspectRatio="none"${m.tone ? ` data-tone="${m.tone}"` : ""}>
<path class="area" fill="currentColor" opacity=".12"/><path class="line" fill="none" stroke="currentColor"
- stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round" vector-effect="non-scaling-stroke"/></svg>
+ stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round" vector-effect="non-scaling-stroke"/>
+ ${m.key === "speed" ? `<g id="sp-prefill" class="speed-prefill"><path class="area" fill="currentColor" opacity=".12"/>
+ <path class="line" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"
+ stroke-linecap="round" vector-effect="non-scaling-stroke"/></g>` : ""}</svg>
</div></div>`).join("");
function spark(id, values, max) {
@@ -226,8 +232,14 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {
// the eight cards
const speed = live.state === "generating" ? live.tok_s : last ? last.decode_tok_s : null;
- setMetric("speed", speed == null ? null : fmt(speed, 1), "tok/s", live.state === "generating" ? "now" : last ? "last request" : "");
+ setMetric("speed", speed == null ? null : fmt(speed, 1), "t/s",
+ live.state === "generating" ? "Decode now" : last ? "Decode last request" : "Decode");
+ const prefill = live.state !== "idle" ? live.prefill_tok_s_mean
+ : last && last.prompt_ms > 0 ? Math.max(0, last.prompt_tokens - (last.reused || 0)) / (last.prompt_ms / 1000) : null;
+ setMetric("prefill", prefill == null ? null : fmt(prefill), "t/s",
+ live.state === "reading" ? "Prefill now" : live.state === "generating" ? "Prefill this request" : last ? "Prefill last request" : "Prefill");
spark("sp-speed", h.tok_s);
+ spark("sp-prefill", h.prefill_tok_s_mean);
// a model split across several cards (issue #112): the cards show their total / mean / hottest, and each card's own
const per = (f) => (hw.gpus || []).map((g) => `GPU ${g.index} ${f(g)}`).join(" · ");
const multi = (hw.gpus || []).length > 1;