Monitor: the VRAM hit rate column only when a request has one (#5484, part 2)

On a Mac (unified memory) and for a model wholly in VRAM the engine
reports no expert-cache lookups, so the recent-requests table showed a
column of dashes that read as something missing. The web page
(serve/web) and the app's Monitor (apps/host) now show the column only
when at least one listed request has a hit rate; the empty-table row
spans the columns shown. No text changed.

Part 1 of the issue (say that "GPU load" is the share of time the GPU
had work, not how much of its compute is in use) is new text: drafted
for the coordinator, not in this commit.

Test: serve/test_web_monitor_hitrate.py (the web table run in node, and
the app's Monitor source): 4 of 5 fail on the base, 5 pass; monitor and
export tests 56/56; tsc clean.
This commit is contained in:
Niko1221 committed 2026-11-16 17:12:27 +01:00
1 parent fcfe18e555
commit 9596893822
4 files changed
+78 -4

No files matched your search

+3 -1
View File
@@ -137,6 +137,8 @@ function LegacyMonitorScreen({ native }: {
const gen = singleReading?.pcieGenMax ?? singleReading?.pcieGen, width = singleReading?.pcieWidth;
const cpu = cpuChoice === 'all' ? data.hardware.cpuLoad : data.hardware.cpus?.find(p => p.id === cpuChoice)?.utilizationPct;
const requests = data.requests ?? [], last = requests.find(r => r.state === 'done'), visibleRequests = showAll ? requests : requests.slice(0, 12);
// #5484: the VRAM hit rate column only when a request has one (a Mac and a model wholly in GPU memory have no expert cache to hit)
const anyHit = requests.some(r => hasReading(r.hitRate));
const throughput = sourceLabel(data.telemetry?.throughput), throughputKnown = throughput !== 'Unavailable';
const writing = ['generating', 'thinking'].includes(data.phase);
const decode = throughputKnown ? (writing ? data.outputTps : last?.tps) : null;
@@ -204,7 +206,7 @@ function LegacyMonitorScreen({ native }: {
<div className="monitor-bar-reading"><span>{tr("GPU temperature")}</span><span className="muted num">{tr(number(temperature))}{tr(hasReading(temperature) ? ' °C' : '')}</span></div><ReadingBar label={tr("GPU temperature")} value={temperature} tone="warn"/>
</section>
<section className="st-card monitor-requests"><div className="section-toolbar"><h2 className="h4">{tr("Recent requests")}</h2>{tr(requests.length > 12 ? <Btn size="sm" onClick={() => setShowAll(!showAll)}>{tr(showAll ? 'Show fewer' : `Show all (${requests.length})`)}</Btn> : null)}</div>
<div className="st-tablewrap monitor-request-table" data-expanded={showAll}><table className="st-table"><thead><tr><th>{tr("Time")}</th><th>{tr("Status")}</th>{tr(multipleModels ? <th>{tr("Model")}</th> : null)}<th className="num">{tr("Prompt")}</th><th className="num">{tr("Reused")}</th><th className="num">{tr("Output")}</th><th className="num">{tr("Tok/s")}</th><th className="num" title={tr("Experts already in GPU memory; PCIe share is shown separately when reported.")}>{tr("VRAM hit rate")}</th><th className="num">{tr("Duration")}</th></tr></thead><tbody>{tr(visibleRequests.length ? visibleRequests.map(r => <tr key={r.id}><td>{tr(new Date(r.at).toLocaleTimeString(localeTag(), { hour: '2-digit', minute: '2-digit', second: '2-digit' }))}</td><td><span className="request-status" data-state={r.state}>{tr(requestStatus(r))}</span>{tr(r.usageSource === 'demo' ? <span className="monitor-request-source xs muted">{tr("Illustrative")}</span> : null)}</td>{tr(multipleModels ? <td><span className="xs">{tr(r.model)}</span></td> : null)}<td className="num">{tr(number(r.tokensIn))}</td><td className="num">{tr(number(r.cachedTokens))}</td><td className="num">{tr(number(r.tokensOut))}</td><td className="num">{tr(number(r.tps, 1))}</td><td className="num">{tr(hasReading(r.hitRate) ? `${number(r.hitRate * 100, 1)}%` : '—')}{tr(hasReading(r.pcieShare) && r.pcieShare > 0 ? <span className="xs muted"> +{tr(number(r.pcieShare * 100, 1))}{tr("% PCIe")}</span> : null)}</td><td className="num">{tr(r.durationMs ? duration(r.durationMs) : '—')}</td></tr>) : <tr><td colSpan={multipleModels ? 9 : 8} className="muted">{tr("No requests yet")}</td></tr>)}</tbody></table></div>
<div className="st-tablewrap monitor-request-table" data-expanded={showAll}><table className="st-table"><thead><tr><th>{tr("Time")}</th><th>{tr("Status")}</th>{tr(multipleModels ? <th>{tr("Model")}</th> : null)}<th className="num">{tr("Prompt")}</th><th className="num">{tr("Reused")}</th><th className="num">{tr("Output")}</th><th className="num">{tr("Tok/s")}</th>{tr(anyHit ? <th className="num" title={tr("Experts already in GPU memory; PCIe share is shown separately when reported.")}>{tr("VRAM hit rate")}</th> : null)}<th className="num">{tr("Duration")}</th></tr></thead><tbody>{tr(visibleRequests.length ? visibleRequests.map(r => <tr key={r.id}><td>{tr(new Date(r.at).toLocaleTimeString(localeTag(), { hour: '2-digit', minute: '2-digit', second: '2-digit' }))}</td><td><span className="request-status" data-state={r.state}>{tr(requestStatus(r))}</span>{tr(r.usageSource === 'demo' ? <span className="monitor-request-source xs muted">{tr("Illustrative")}</span> : null)}</td>{tr(multipleModels ? <td><span className="xs">{tr(r.model)}</span></td> : null)}<td className="num">{tr(number(r.tokensIn))}</td><td className="num">{tr(number(r.cachedTokens))}</td><td className="num">{tr(number(r.tokensOut))}</td><td className="num">{tr(number(r.tps, 1))}</td>{tr(anyHit ? <td className="num">{tr(hasReading(r.hitRate) ? `${number(r.hitRate * 100, 1)}%` : '—')}{tr(hasReading(r.pcieShare) && r.pcieShare > 0 ? <span className="xs muted"> +{tr(number(r.pcieShare * 100, 1))}{tr("% PCIe")}</span> : null)}</td> : null)}<td className="num">{tr(r.durationMs ? duration(r.durationMs) : '—')}</td></tr>) : <tr><td colSpan={(multipleModels ? 9 : 8) - (anyHit ? 0 : 1)} className="muted">{tr("No requests yet")}</td></tr>)}</tbody></table></div>
{/* One request is already the row above: the aggregate sentence would only
restate it, and in English it also read “In 1 requests”. Show it from two
requests on, where it carries information the table cannot. */}
+69
View File
@@ -0,0 +1,69 @@
"""#5484: the Monitor's recent-requests table shows the VRAM hit rate column only when a request has a hit rate. On a Mac
(unified memory) and for a model wholly in VRAM the engine reports none, and a column of dashes read as something
missing. The web page (serve/web/app.js, run in node with stand-ins) and the app's Monitor (apps/host) both."""
from __future__ import annotations
import json
import re
import shutil
import subprocess
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
WEB = ROOT / "serve" / "web"
NODE = shutil.which("node")
def requests_block(text: str) -> str:
start = text.index(" // recent requests")
return text[start:text.index(' const all = $("req-all");', start)]
@unittest.skipUnless(NODE, "node is needed to run the page's own code")
class WebTable(unittest.TestCase):
def table(self, requests):
app = (WEB / "app.js").read_text(encoding="utf-8")
script = ("const els = {}; const $ = (id) => (els[id] ||= {id, innerHTML: '', hidden: false});\n"
"const esc = (s) => String(s); const fmt = (n, d = 0) => (n == null ? '–' : Number(n).toFixed(d)); let reqShowAll = false;\n"
f"function run(requests) {{\n{requests_block(app)}\n}}\nrun({json.dumps(requests)});\n"
"console.log(JSON.stringify({hidden: $('req-hit').hidden, body: $('req-body').innerHTML}));")
done = subprocess.run([NODE, "-e", script], capture_output=True, text=True, encoding="utf-8", timeout=60, check=True)
out = json.loads(done.stdout)
return out["hidden"], [len(re.findall(r"<td", row)) for row in out["body"].split("</tr>") if "<td" in row]
ROW = {"time": 1, "finish": "stop", "prompt_tokens": 200, "reused": 0, "output_tokens": 50, "prompt_ms": 100,
"decode_tok_s": 80, "duration_s": 1.2}
def test_a_mac_run_has_no_hit_rate_column(self):
hidden, cells = self.table([dict(self.ROW, hit_rate=None), dict(self.ROW)])
self.assertTrue(hidden)
self.assertEqual(cells, [8, 8])
def test_one_request_with_a_hit_rate_shows_the_column_for_all(self):
hidden, cells = self.table([dict(self.ROW, hit_rate=0.91, pcie_share=0.05), dict(self.ROW, hit_rate=None)])
self.assertFalse(hidden)
self.assertEqual(cells, [9, 9])
def test_the_empty_table_spans_the_columns_shown(self):
hidden, _ = self.table([])
self.assertTrue(hidden)
app = (WEB / "app.js").read_text(encoding="utf-8")
self.assertIn('colspan="${anyHit ? 9 : 8}"', requests_block(app))
def test_the_header_cell_is_the_one_the_page_hides(self):
html = (WEB / "index.html").read_text(encoding="utf-8")
self.assertRegex(html, r'<th class="num" id="req-hit"[^>]*>VRAM hit rate</th>')
class AppTable(unittest.TestCase):
def test_the_app_monitor_shows_the_column_only_with_a_reading(self):
src = (ROOT / "apps" / "host" / "src" / "screens" / "Monitor.tsx").read_text(encoding="utf-8")
self.assertIn("const anyHit = requests.some(r => hasReading(r.hitRate));", src)
self.assertRegex(src, r'\{tr\(anyHit \? <th className="num"[^>]*>\{tr\("VRAM hit rate"\)\}</th> : null\)\}')
self.assertRegex(src, r"\{tr\(anyHit \? <td className=\"num\">\{tr\(hasReading\(r\.hitRate\)")
self.assertIn("colSpan={(multipleModels ? 9 : 8) - (anyHit ? 0 : 1)}", src)
if __name__ == "__main__":
unittest.main()
+5 -2
View File
@@ -540,8 +540,11 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {
// recent requests
const body = $("req-body");
// #5484: the VRAM hit rate column only when a request has one (a Mac and a model wholly in VRAM have no expert cache to hit)
const anyHit = requests.some((r) => r.hit_rate != null);
$("req-hit").hidden = !anyHit;
if (!requests.length) {
body.innerHTML = `<tr><td colspan="9" class="muted">No requests yet</td></tr>`;
body.innerHTML = `<tr><td colspan="${anyHit ? 9 : 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"],
@@ -558,7 +561,7 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {
const prefillRate = fresh > 0 && r.prompt_ms > 0 ? fresh / (r.prompt_ms / 1000) : null;
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(prefillRate)}</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>`;
${anyHit ? `<td class="num">${hit}</td>` : ""}<td class="num">${fmt(r.duration_s, 1)} s</td></tr>`;
}).join("");
}
const all = $("req-all");
+1 -1
View File
@@ -161,7 +161,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" title="New prompt tokens per second, excluding reused cache tokens (engine prompt time)">Prefill t/s</th><th class="num">Decode t/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>
<th class="num" title="New prompt tokens per second, excluding reused cache tokens (engine prompt time)">Prefill t/s</th><th class="num">Decode t/s</th><th class="num" id="req-hit" 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="9" class="muted">No requests yet</td></tr></tbody>
</table>
</div>