diff --git a/serve/test_web_monitor_notes.py b/serve/test_web_monitor_notes.py
new file mode 100644
index 0000000000..b08b9bbcfb
--- /dev/null
+++ b/serve/test_web_monitor_notes.py
@@ -0,0 +1,89 @@
+"""#5457: the web Monitor's GPU temp, Power and PCIe cards say why they have no reading (the server's gpu_note, as the
+card's line "not available" and its tooltip) also when the GPU has a name - a Mac always has one - and About shows the
+reason beside the name. serve/web/app.js is run in node with stand-ins for the page's helpers (no browser)."""
+from __future__ import annotations
+
+import json
+import shutil
+import subprocess
+import unittest
+from pathlib import Path
+
+WEB = Path(__file__).resolve().parent / "web"
+NODE = shutil.which("node")
+MAC_NOTE = ("no GPU temperature or power reading without root (powermetrics), and an Apple Silicon GPU sits on the "
+ "die, so there is no PCIe link to show; the engine's own figures are in its log")
+
+
+def run_node(source: str) -> object:
+ done = subprocess.run([NODE, "-e", source], capture_output=True, text=True, encoding="utf-8", timeout=60, check=True)
+ return json.loads(done.stdout)
+
+
+def function_source(text: str, name: str) -> str:
+ start = text.index(f"function {name}(")
+ return text[start:text.index("\n}\n", start) + 3]
+
+
+def gpu_cards_block(text: str) -> str:
+ """renderMonitor's lines from the GPU load card to the PCIe card's sparkline."""
+ start = text.index(" const per = (f) =>")
+ return text[start:text.index(' spark("sp-pcie"', start)]
+
+
+STUBS = """
+const els = {};
+const $ = (id) => (els[id] ||= {id, textContent: "", innerHTML: "", title: ""});
+const esc = (s) => String(s);
+const fmt = (n, d = 0) => (n == null ? "–" : Number(n).toFixed(d));
+const gb = (b, d = 1) => (b == null ? "–" : fmt(b / 1073741824, d));
+const spark = () => {};
+"""
+
+
+@unittest.skipUnless(NODE, "node is needed to run the page's own code")
+class GpuNote(unittest.TestCase):
+ def cards(self, hw, st, eng=None):
+ app = (WEB / "app.js").read_text(encoding="utf-8")
+ script = (STUBS + function_source(app, "setMetric") +
+ f"function run(hw, st, eng, h) {{\n{gpu_cards_block(app)}\n}}\n"
+ f"run({json.dumps(hw)}, {json.dumps(st)}, {json.dumps(eng or {})}, {{}});\n"
+ "console.log(JSON.stringify(Object.fromEntries(['temp', 'power', 'pcie', 'gpu'].map(k => "
+ "[k, [$('mv-' + k).innerHTML, $('ms-' + k).textContent, $('ms-' + k).title]]))));")
+ return run_node(script)
+
+ MAC_HW = {"gpu_util": 95, "gpu_mem_used": 88_000_000_000, "gpu_mem_total": 131_000_000_000, "gpu_temp": None,
+ "gpu_power": None, "gpus": [{"index": 0}]}
+ MAC_ST = {"gpu_name": "Apple M5 Max", "gpu_note": MAC_NOTE}
+
+ def test_a_named_mac_gpu_explains_its_three_empty_cards(self):
+ cards = self.cards(self.MAC_HW, self.MAC_ST)
+ for key in ("temp", "power", "pcie"):
+ value, line, tip = cards[key]
+ self.assertEqual(value, "–", key)
+ self.assertEqual(line, "not available", key)
+ self.assertEqual(tip, MAC_NOTE, key)
+ self.assertEqual(cards["gpu"][1], "Apple M5 Max", "the load card keeps the GPU's name")
+ self.assertEqual(cards["gpu"][2], "", "and no reason: it has a reading")
+
+ def test_a_card_with_a_reading_or_no_note_says_nothing_more(self):
+ nvidia = {"gpu_util": 50, "gpu_temp": 61, "gpu_power": 210, "gpu_power_limit": 450, "gpu_pcie_gen": 4,
+ "gpu_pcie_width": 16, "gpu_pcie_rx_mb": 12.5, "gpus": [{"index": 0}]}
+ cards = self.cards(nvidia, {"gpu_name": "NVIDIA GeForce RTX 4090"})
+ self.assertEqual(cards["temp"], ["61°C", "", ""])
+ self.assertEqual(cards["power"][1:], ["of 450 W limit", ""])
+ self.assertEqual(cards["pcie"][2], "")
+ quiet = self.cards({"gpu_temp": None, "gpu_power": None, "gpus": [{"index": 0}]}, {"gpu_name": "Some GPU"})
+ self.assertEqual(quiet["temp"], ["–", "", ""], "no note: nothing invented")
+
+ def test_about_shows_the_reason_beside_a_named_gpu(self):
+ app = (WEB / "app.js").read_text(encoding="utf-8")
+ script = (STUBS + "const rows = {}; const facts = (el, r) => { rows[el.id] = r; }; const projectionText = () => null;\n"
+ "globalThis.location = {origin: 'http://127.0.0.1:8080'};\n" + function_source(app, "renderAbout") +
+ f"renderAbout({{}}, {json.dumps(self.MAC_HW)}, {json.dumps(self.MAC_ST)});\n"
+ "console.log(JSON.stringify(rows['facts-hw'].find(r => r[0] === 'GPU')[1]));")
+ self.assertEqual(run_node(script), f"Apple M5 Max, 122 GB · {MAC_NOTE}")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/serve/web/app.js b/serve/web/app.js
index 4b95920b6e..5da600a7c4 100644
--- a/serve/web/app.js
+++ b/serve/web/app.js
@@ -162,9 +162,11 @@ function spark(id, values, max) {
svg.querySelector(".line").setAttribute("d", line);
svg.querySelector(".area").setAttribute("d", `${line}L100,32L0,32Z`);
}
-function setMetric(key, value, unit, sub) {
+function setMetric(key, value, unit, sub, why) {
$(`mv-${key}`).innerHTML = value == null ? "–" : `${esc(value)}${unit ? `${esc(unit)}` : ""}`;
$(`ms-${key}`).textContent = sub || "";
+ // why a card has no reading (the server's gpu_note), on its line and as its tooltip (#5457)
+ $(`ms-${key}`).title = why || "";
}
let lastMetrics = null, metricsFailures = 0, keyWarned = false, mcpTick = 0;
@@ -488,15 +490,22 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) {
multi ? per((g) => (g.mem_used == null ? "–" : `${gb(g.mem_used)} GB`))
: eng.expert_slots ? `${fmt(eng.expert_slots)} experts cached` : (st.gpu_note ? "not available on Windows AMD yet" : ""));
spark("sp-vram", h.gpu_mem_used, hw.gpu_mem_total);
+ // #5457: a card the server cannot read (a Mac has no temperature or power without root and no PCIe link; a Windows AMD card)
+ // says so, with the server's own reason, whether or not the GPU has a name
+ const unread = (v) => v == null && !multi && !!st.gpu_note;
setMetric("temp", hw.gpu_temp == null ? null : fmt(hw.gpu_temp), "°C",
- multi ? per((g) => (g.temp == null ? "–" : `${fmt(g.temp)}°`)) : "");
+ multi ? per((g) => (g.temp == null ? "–" : `${fmt(g.temp)}°`)) : unread(hw.gpu_temp) ? "not available" : "",
+ unread(hw.gpu_temp) ? st.gpu_note : "");
spark("sp-temp", h.gpu_temp, 90);
- setMetric("power", hw.gpu_power == null ? null : fmt(hw.gpu_power), "W", hw.gpu_power_limit ? `of ${fmt(hw.gpu_power_limit)} W limit` : "");
+ setMetric("power", hw.gpu_power == null ? null : fmt(hw.gpu_power), "W",
+ hw.gpu_power_limit ? `of ${fmt(hw.gpu_power_limit)} W limit` : unread(hw.gpu_power) ? "not available" : "",
+ unread(hw.gpu_power) ? st.gpu_note : "");
spark("sp-power", h.gpu_power, hw.gpu_power_limit);
const gen = hw.gpu_pcie_gen_max || hw.gpu_pcie_gen;
setMetric("pcie", gen ? `Gen${gen}` : null, hw.gpu_pcie_width ? `x${hw.gpu_pcie_width}` : "",
- hw.gpu_pcie_rx_mb == null ? "" : `to GPU ${fmt(hw.gpu_pcie_rx_mb, hw.gpu_pcie_rx_mb < 10 ? 1 : 0)} MB/s` +
- (hw.gpu_pcie_gen && gen && hw.gpu_pcie_gen < gen ? ` · idle Gen${hw.gpu_pcie_gen}` : ""));
+ hw.gpu_pcie_rx_mb == null ? (unread(gen || null) ? "not available" : "") : `to GPU ${fmt(hw.gpu_pcie_rx_mb, hw.gpu_pcie_rx_mb < 10 ? 1 : 0)} MB/s` +
+ (hw.gpu_pcie_gen && gen && hw.gpu_pcie_gen < gen ? ` · idle Gen${hw.gpu_pcie_gen}` : ""),
+ unread(gen || null) ? st.gpu_note : "");
spark("sp-pcie", h.gpu_pcie_rx_mb);
setMetric("cpu", hw.cpu == null ? null : fmt(hw.cpu), "%", st.threads ? `${st.cores ? `${st.cores} cores · ` : ""}${st.threads} threads` : "");
spark("sp-cpu", h.cpu, 100);
@@ -587,7 +596,8 @@ function renderAbout(eng, hw, st) {
["Experimental speed projection", projectionText(eng.cvec)],
]);
facts($("facts-hw"), [
- ["GPU", st.gpu_name ? `${st.gpu_name}${hw.gpu_mem_total ? `, ${gb(hw.gpu_mem_total, 0)} GB` : ""}` : (st.gpu_note || "not readable (NVML)")],
+ // #5457: the server's reason for the readings it lacks is shown beside a named GPU too (a Mac always has a name)
+ ["GPU", st.gpu_name ? `${st.gpu_name}${hw.gpu_mem_total ? `, ${gb(hw.gpu_mem_total, 0)} GB` : ""}${st.gpu_note ? ` · ${st.gpu_note}` : ""}` : (st.gpu_note || "not readable (NVML)")],
["CPU", st.cpu_name ? `${st.cpu_name}${st.threads ? `, ${st.threads} threads` : ""}` : null],
["RAM", hw.ram_total ? `${gb(hw.ram_total, 0)} GB` : null],
]);