From 57868948c3fc806cd4bc88fd0e76607eedc1bf47 Mon Sep 17 00:00:00 2001 From: Jie Ren Date: Wed, 11 Nov 2026 09:24:40 -0800 Subject: [PATCH] Monitor: each card gets its own PCIe ceiling and power limit, so a card that runs narrower than it could is visible The server's per-card list carried util, memory, temperature and power only, so neither monitor could name the card a hardware number came from for the link ceiling or for power. It shows on a real two-card PC: the Overview's Power tile sums the per-card limits (overview.py:169) and the per-card list never sent them, so its "of 1,050 W limit" line vanished with two or more cards while one card kept it. Each card now also reports its own ceiling - NVML nvmlDeviceGetMaxPcieLinkWidth, and max_link_width from the AMD sysfs - and its own power limit, and both monitors show both numbers when a card runs below its own ceiling ("Gen5 x8 of x16"): that is what a card capped to x8 in a x16 slot, or trained down by the board, looks like. The tile's pair belongs to the card that gave the narrowest width, never to the widest card in the run, so one card's gap is never put on another card's link. The Power tile says whose power the big number adds ("all 2 cards of 360 W"), and a narrow terminal drops the ceiling whole instead of cropping mid-line. Nothing reported, nothing invented: a driver or server that answers no ceiling keeps the single number, and one card draws exactly as before. Co-Authored-By: Claude Code --- docs/TERMINAL_LAUNCH.md | 9 ++- serve/telemetry.py | 43 ++++++++++-- serve/test_server.py | 57 ++++++++++++++- serve/web/app.js | 24 +++++-- strata_cli/client.py | 38 +++++++++- strata_cli/detail_dashboard.py | 11 ++- strata_cli/overview.py | 62 ++++++++++++++--- strata_cli/render.py | 17 ++++- tests/terminal/test_monitor_classic.py | 96 +++++++++++++++++++++++++- tests/terminal/test_terminal.py | 41 ++++++++++- tests/terminal/test_visual_detail.py | 16 ++++- 11 files changed, 382 insertions(+), 32 deletions(-) diff --git a/docs/TERMINAL_LAUNCH.md b/docs/TERMINAL_LAUNCH.md index 485258a1b0..ae6527ac0c 100644 --- a/docs/TERMINAL_LAUNCH.md +++ b/docs/TERMINAL_LAUNCH.md @@ -172,8 +172,13 @@ app sends them. The list keeps two columns apart. **Vendor tested** is the app v `q` asks whether to keep serving in the background or stop. Stopping unloads the model and frees graphics memory. -With two or more cards the Overview shows the busiest card's load, all cards' memory, the hottest card and the total power, and a -"Cards" strip lists up to 4 cards (`5` opens Hardware). The CPU tile shows sockets and cores. +With two or more cards the Overview shows the busiest card's load, all cards' memory, the hottest card, the total power and the +weakest card's PCIe link, and a "Cards" strip lists up to 4 cards with the link each one trained (`5` opens Hardware). Each card +trains its own link, so a card in an x4 slot reads `Gen5 x4` beside a card at `Gen5 x8`. A card that runs narrower than its own +card could go shows both numbers (`Gen5 x8 of x16`): that is what a card capped to x8 in a x16 slot, or trained down by the board, +looks like. The Power tile says whose power the number is (`all 2 cards of 360 W`); the Hardware page gives each card its own +ceiling (`Power 180 W of 300 W`). +The CPU tile shows sockets and cores. **Windows console.** In the classic Windows 10 console the monitor switches that window's font to Cascadia Mono when it is installed and draws the full look. Otherwise it draws a solid-block look and shows one line suggesting Windows Terminal. Nothing is saved and diff --git a/serve/telemetry.py b/serve/telemetry.py index 81abf268e6..1fa8d9f766 100644 --- a/serve/telemetry.py +++ b/serve/telemetry.py @@ -101,6 +101,9 @@ class _Nvml: out["pcie_gen"] = self._uint("nvmlDeviceGetCurrPcieLinkGeneration") # drops at idle (power saving) out["pcie_gen_max"] = self._uint("nvmlDeviceGetMaxPcieLinkGeneration") out["pcie_width"] = self._uint("nvmlDeviceGetCurrPcieLinkWidth") + # the widest the card itself can go: read beside the negotiated width, so a card capped to x8 in a x16 + # slot, or trained down to x4 by the board, is visible as the gap instead of looking like an x8 card by choice + out["pcie_width_max"] = self._uint("nvmlDeviceGetMaxPcieLinkWidth") rx = self._uint("nvmlDeviceGetPcieThroughput", ctypes.c_uint(1)) # NVML_PCIE_UTIL_RX_BYTES, KB/s tx = self._uint("nvmlDeviceGetPcieThroughput", ctypes.c_uint(0)) out["pcie_rx_mb"] = rx / 1024.0 if rx is not None else None @@ -207,7 +210,8 @@ class _Amd: from each hop's `max_link_speed` / `max_link_width` (the capability, so a power-saving downgrade or a Gen3 slot cannot make it read low). A card that is Gen4 on its own hop but sits behind a Gen3 root port really runs at Gen3, and that is the number a PCIe bandwidth budget needs. - `pcie_own_gen` keeps the card's own hop aside: the gap between the two is what a user has to see. + `pcie_own_gen` and `pcie_width_max` keep the card's own capability aside: the gap between the two numbers is + what a user has to see (a x16 card that only reaches x8). The bottleneck is only claimed when **every** hop of the path could be read; `pcie_path` reports how many of them were ("4/4"). A kernel or a container that hides part of /sys/devices would otherwise drop the @@ -229,8 +233,14 @@ class _Amd: whole = bool(hops) and read == len(hops) gen = min(gens) if (whole and gens) else own_gen width = min(widths) if (whole and widths) else self._int(os.path.join(own, "current_link_width")) + # `pcie_width_max` is the card's own cap (its own hop, kept last by `_hops()`), where `pcie_width` above is + # the narrowest hop of the whole path: a card that runs at x8 behind a x8 bridge, or in a slot the board + # trained down, reads as the gap instead of looking like an x8 card by choice. Same split as `pcie_own_gen`. + cap = self._int(os.path.join(own, "max_link_width")) if own else None + if cap is None and hops: + cap = self._int(os.path.join(hops[-1], "max_link_width")) return {"pcie_gen": gen, "pcie_gen_max": gen, "pcie_own_gen": own_gen, "pcie_width": width, - "pcie_path": "%d/%d" % (read, len(hops))} + "pcie_width_max": cap, "pcie_path": "%d/%d" % (read, len(hops))} def read(self): @@ -537,8 +547,9 @@ class Telemetry: """`extra()` -> dict of more series to record each second (the server's tok/s). `gpu_index`: the card the engine runs on, numbered as nvidia-smi and NVML number them (by PCI bus); `gpu_indices`: all of them when the model is split across several (issue #112) - the gpu_* readings are then their total (memory, power, - PCIe traffic), mean (load) or hottest (temperature), and "gpus" has each card's own. `amd`: the AMD backend's - cards, numbered as HIP numbers them, read from sysfs (#301).""" + PCIe traffic), mean (load), hottest (temperature) or weakest (the PCIe link, so a card trained to x4 is not + hidden behind an x8 card), and "gpus" has each card's own, its link and its power limit included. `amd`: the + AMD backend's cards, numbered as HIP numbers them, read from sysfs (#301).""" self.extra = extra self.lock = threading.Lock() self.now: dict = {} @@ -619,8 +630,30 @@ class Telemetry: g["util"] = sum(u) / len(u) if u else None t = vals("temp") g["temp"] = max(t) if t else None + # A link is not additive. These four used to stay card 0's reading, so a card the board had trained + # down to x4 hid behind the other card's "Gen5 x8" while the traffic under the tile was already the + # two cards' total. The tile shows the slowest generation and the narrowest width among the cards, + # each field on its own: the rule `_Amd.link()` already uses for the hops of one card's path, and the + # worst link a token has to cross when the layers sit on both cards. Each card's own link goes in + # "gpus" below, which is what the Monitor and the Terminal name card by card. + for k in ("pcie_gen", "pcie_gen_max", "pcie_width"): + v = vals(k) + g[k] = min(v) if v else None + # "runs at x8, could do x16" is one card's gap, so the cap goes with the card that gave the width + # above, not with the smallest cap in the run (that can be a different card). Each card's own pair + # is in "gpus" below. + narrow = [(r.get("pcie_width"), p) for p, (_, r) in enumerate(reads) if r.get("pcie_width") is not None] + if narrow: + g["pcie_width_max"] = reads[min(narrow)[1]][1].get("pcie_width_max") + else: + g["pcie_width_max"] = None s["gpus"] = [{"index": i, "name": reader.name(), "util": r.get("util"), "mem_used": r.get("mem_used"), - "mem_total": r.get("mem_total"), "temp": r.get("temp"), "power": r.get("power")} + "mem_total": r.get("mem_total"), "temp": r.get("temp"), "power": r.get("power"), + "power_limit": r.get("power_limit"), + "pcie_gen": r.get("pcie_gen"), "pcie_gen_max": r.get("pcie_gen_max"), + "pcie_width": r.get("pcie_width"), "pcie_width_max": r.get("pcie_width_max"), + "pcie_rx_mb": r.get("pcie_rx_mb"), "pcie_tx_mb": r.get("pcie_tx_mb"), + "pcie_own_gen": r.get("pcie_own_gen"), "pcie_path": r.get("pcie_path")} for (i, r), (_, reader) in zip(reads, self.gpus)] s.update({f"gpu_{k}": v for k, v in g.items()}) if self.ps: diff --git a/serve/test_server.py b/serve/test_server.py index 233a51ba44..2f56139511 100644 --- a/serve/test_server.py +++ b/serve/test_server.py @@ -5204,7 +5204,8 @@ class AmdTelemetry(unittest.TestCase): def test_pcie_link_is_the_narrowest_slowest_hop(self): """#1733: the link is the slowest/narrowest hop between the root port and the card; the bottleneck is only - claimed when every hop could be read (pcie_path says how many were).""" + claimed when every hop could be read (pcie_path says how many were). The card's own width is kept beside it + (`pcie_width_max`), because a x16 card behind a x8 bridge has to read as the gap, not as an x8 card.""" from serve import telemetry with tempfile.TemporaryDirectory() as d: hops = [] @@ -5220,10 +5221,12 @@ class AmdTelemetry(unittest.TestCase): a.dev = hops[-1] with mock.patch.object(telemetry._Amd, "_hops", lambda self: hops): self.assertEqual(a.link(), {"pcie_gen": 3, "pcie_gen_max": 3, "pcie_own_gen": 4, "pcie_width": 8, + "pcie_width_max": 16, # the bridge narrows it to x8, the card could do x16 "pcie_path": "3/3"}) with mock.patch.object(telemetry._Amd, "_hops", lambda self: hops[:2] + [str(Path(d) / "hidden")]): got = a.link() # an unreadable hop: fall back to the card's own negotiated link - self.assertEqual((got["pcie_gen"], got["pcie_width"], got["pcie_path"]), (4, 16, "2/3")) + self.assertEqual((got["pcie_gen"], got["pcie_width"], got["pcie_width_max"], got["pcie_path"]), + (4, 16, 16, "2/3")) self.assertEqual(telemetry._Amd._gen("32.0 GT/s PCIe"), 5) self.assertIsNone(telemetry._Amd._gen("unknown")) self.assertTrue(telemetry._Amd._bdf("0000:03:00.0")) @@ -5243,6 +5246,7 @@ class AmdTelemetry(unittest.TestCase): self.assertEqual(g.read(), {"util": 37, "mem_used": 2 << 30, "mem_total": 32 << 30, "temp": 51.0, "power": 85.0, "power_limit": 300.0, "pcie_gen": None, "pcie_gen_max": None, "pcie_own_gen": None, "pcie_width": None, + "pcie_width_max": None, "pcie_path": "0/0"}) # #1733: no PCIe files in this fake tree r = telemetry.gpu_reader(1, amd=True).read() self.assertEqual((r["util"], r["temp"], r["power"]), (99, 64.0, 120.0)) # power1_input @@ -5258,6 +5262,55 @@ class AmdTelemetry(unittest.TestCase): self.assertFalse(telemetry.gpu_reader(0, amd=True).ok()) self.assertIsNone(telemetry.free_vram_mib(0, amd=True)) + def test_two_cards_keep_their_own_pcie_links(self): + """Two cards trained to different widths: each row carries its own link, and the aggregate is the weakest + card's. Card 0's reading used to be the only one anyone could see, so an x4 card hid behind x8.""" + from serve import telemetry + with tempfile.TemporaryDirectory() as d: + self.tree(d) + for minor, width in (("renderD129", "8"), ("renderD128", "4")): + dev = Path(d) / "class/drm" / minor / "device" + (dev / "current_link_speed").write_text("16.0 GT/s PCIe\n") # both cards at Gen4 + (dev / "current_link_width").write_text(width + "\n") + with mock.patch.object(telemetry, "SYSFS", d): + s = telemetry.Telemetry(gpu_index=0, gpu_indices=[0, 1], amd=True).sample() + self.assertEqual([(c["pcie_gen"], c["pcie_width"]) for c in s["gpus"]], [(4, 8), (4, 4)]) + self.assertEqual((s["gpu_pcie_gen"], s["gpu_pcie_width"]), (4, 4)) # the weakest card, not card 0's x8 + + def test_a_card_with_no_link_reading_stays_missing(self): + """A card whose sysfs hides its link (the fake tree has no PCIe files) reports nothing: no 0, no invented + width, and the aggregate is the other card's link rather than a made-up one.""" + from serve import telemetry + with tempfile.TemporaryDirectory() as d: + self.tree(d) + dev = Path(d) / "class/drm/renderD128/device" + (dev / "current_link_speed").write_text("8.0 GT/s PCIe\n") + (dev / "current_link_width").write_text("16\n") + with mock.patch.object(telemetry, "SYSFS", d): + s = telemetry.Telemetry(gpu_index=0, gpu_indices=[0, 1], amd=True).sample() + self.assertEqual([(c["pcie_gen"], c["pcie_width"]) for c in s["gpus"]], [(None, None), (3, 16)]) + self.assertEqual((s["gpu_pcie_gen"], s["gpu_pcie_width"]), (3, 16)) + + def test_a_card_narrower_than_it_could_be_shows_the_gap(self): + """A card the board trained down to x4 in a slot the card could do x16, beside a card that is x8 by nature: + the gap is one card's, so the aggregate's cap comes from the card that gave the narrowest width (the smallest + cap in the run would blame the other card). Each row also carries its own power ceiling, which the summary + adds up - without it the Overview loses "of N W limit" on a split run.""" + from serve import telemetry + with tempfile.TemporaryDirectory() as d: + self.tree(d) + for minor, (cur, cap) in (("renderD129", ("8", "8")), ("renderD128", ("4", "16"))): + dev = Path(d) / "class/drm" / minor / "device" + (dev / "current_link_speed").write_text("16.0 GT/s PCIe\n") + (dev / "current_link_width").write_text(cur + "\n") + (dev / "max_link_width").write_text(cap + "\n") + with mock.patch.object(telemetry, "SYSFS", d): + s = telemetry.Telemetry(gpu_index=0, gpu_indices=[0, 1], amd=True).sample() + self.assertEqual([(c["pcie_width"], c["pcie_width_max"]) for c in s["gpus"]], [(8, 8), (4, 16)]) + self.assertEqual((s["gpu_pcie_width"], s["gpu_pcie_width_max"]), (4, 16)) # x4 that could do x16 + self.assertEqual([c["power_limit"] for c in s["gpus"]], [300.0, 300.0]) # each card's own ceiling + self.assertEqual(s["gpu_power_limit"], 600.0) # the run's limit + def test_free_vram_on_hip(self): from serve import telemetry tok = ByteTokenizer() diff --git a/serve/web/app.js b/serve/web/app.js index 020970db47..6cacd1d484 100644 --- a/serve/web/app.js +++ b/serve/web/app.js @@ -491,12 +491,28 @@ function renderMonitor(live, hw, st, eng, h, last, requests, totals, kept) { setMetric("temp", hw.gpu_temp == null ? null : fmt(hw.gpu_temp), "°C", multi ? per((g) => (g.temp == null ? "–" : `${fmt(g.temp)}°`)) : ""); 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", + multi ? per((g) => (g.power == null ? "–" : `${fmt(g.power)} W` + + (g.power_limit ? ` of ${fmt(g.power_limit)} W ceiling` : ""))) + : hw.gpu_power_limit ? `of ${fmt(hw.gpu_power_limit)} W limit` : ""); spark("sp-power", h.gpu_power, hw.gpu_power_limit); + // each card trains its own link: with several cards the big number is the weakest card's and the line under it + // names every card, because one card's "Gen5 x8" said nothing about a second card trained down to x4 + // (the per-card words follow the big number's rule: the link the card trained, not the lower one it idles at) + // a card that runs narrower than it could - capped to x8 in a x16 slot, or trained down by the board - says both, + // because the narrow number alone reads as a link someone chose + const link = (g) => { const v = g.pcie_gen_max || g.pcie_gen; + return v ? `Gen${v}${g.pcie_width ? ` x${g.pcie_width}` + + (g.pcie_width_max > g.pcie_width ? ` of x${g.pcie_width_max}` : "") : ""}` : "–"; }; 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}` : "")); + const width = hw.gpu_pcie_width ? `x${hw.gpu_pcie_width}` + + (hw.gpu_pcie_width_max > hw.gpu_pcie_width ? ` of x${hw.gpu_pcie_width_max}` : "") : ""; + const rx = hw.gpu_pcie_rx_mb == null ? "" + : `${fmt(hw.gpu_pcie_rx_mb, hw.gpu_pcie_rx_mb < 10 ? 1 : 0)} MB/s`; + setMetric("pcie", gen ? `Gen${gen}` : null, width, + multi ? `${per(link)}${rx ? ` · ${rx} total` : ""}` + : rx === "" ? "" : `to GPU ${rx}` + + (hw.gpu_pcie_gen && gen && hw.gpu_pcie_gen < gen ? ` · idle Gen${hw.gpu_pcie_gen}` : "")); 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); diff --git a/strata_cli/client.py b/strata_cli/client.py index 90c9a7c4fe..f75e3fae55 100644 --- a/strata_cli/client.py +++ b/strata_cli/client.py @@ -181,6 +181,25 @@ def _rows(value: Any, fields: tuple[str, ...], limit: int) -> list[dict]: return out +def card_link(row: Any, gap: bool = True) -> str: + """One graphics card's own PCIe link as the Terminal words it ("Gen5 x8"); "" when the server does not report it. + The generation is the one the card runs at now, or the highest it can reach when it reports no current one (NVML + reports a lower link while the card is idle). A card that runs narrower than it could - capped to x8 in a x16 + slot, or trained down to x4 by the board - gets both numbers ("Gen5 x8 of x16"), because the narrow one alone + reads as a card someone chose; `gap=False` leaves the second number out for a column too narrow for it. An old + server, or a card whose link is not readable, gives "".""" + if not isinstance(row, dict): + return "" + gen = _number(row.get("pcie_gen")) + if gen is None: + gen = _number(row.get("pcie_gen_max")) + if gen is None: + return "" + width, cap = _number(row.get("pcie_width")), _number(row.get("pcie_width_max")) + return (f"Gen{int(gen)}" + (f" x{int(width)}" if width else "") + + (f" of x{int(cap)}" if gap and width and cap and cap > width else "")) + + def _selected_devices(value: Any) -> list[int]: """Preserve the declared serving order without accepting ambiguous indices.""" if not isinstance(value, list): @@ -426,7 +445,9 @@ def sanitize_telemetry(raw: dict[str, Any]) -> dict[str, Any]: "replica_devices": replica_devices, "replica_stages": replica_stages, "resolved": placement_resolved, "stages": stages, "source": _short(topology.get("source"), 40)}, - "devices": _rows(raw.get("devices"), ("index", "name", "mem_used", "mem_total", "util", "temp", "power"), 16), + "devices": _rows(raw.get("devices"), ("index", "name", "mem_used", "mem_total", "util", "temp", "power", + "power_limit", "pcie_gen", "pcie_gen_max", "pcie_width", "pcie_width_max"), + 16), "ram": {"used": _number(ram.get("used")), "total": _number(ram.get("total"))}, "recent": _rows(raw.get("recent"), ("id", "time", "duration_s", "finish", "prompt_tokens", "reused", "output_tokens", "prompt_ms", "decode_ms", @@ -482,7 +503,14 @@ def normalize_legacy(metrics: dict[str, Any], status: dict[str, Any]) -> dict[st "mem_used": _number(row.get("mem_used")), "mem_total": _number(row.get("mem_total")), "util": _number(row.get("util")), "temp": _number(row.get("temp")), - "power": _number(row.get("power"))}) + "power": _number(row.get("power")), "power_limit": _number(row.get("power_limit")), + # each card trains its own PCIe link: dropping these left the detail page with no + # way to say that one card runs at x8 and the other at x4, or that one of them is + # capped below the width its own card could reach + "pcie_gen": _number(row.get("pcie_gen")), + "pcie_gen_max": _number(row.get("pcie_gen_max")), + "pcie_width": _number(row.get("pcie_width")), + "pcie_width_max": _number(row.get("pcie_width_max"))}) # Old single-GPU servers report only aggregate GPU fields. It is one device only # when the static sampler says so; never duplicate an aggregate into four rows. if not safe_devices and static.get("gpu_count") == 1 and static.get("gpu_name"): @@ -490,7 +518,11 @@ def normalize_legacy(metrics: dict[str, Any], status: dict[str, Any]) -> dict[st "mem_used": _number(hardware.get("gpu_mem_used")), "mem_total": _number(hardware.get("gpu_mem_total")), "util": _number(hardware.get("gpu_util")), "temp": _number(hardware.get("gpu_temp")), - "power": _number(hardware.get("gpu_power"))}] + "power": _number(hardware.get("gpu_power")), "power_limit": _number(hardware.get("gpu_power_limit")), + "pcie_gen": _number(hardware.get("gpu_pcie_gen")), + "pcie_gen_max": _number(hardware.get("gpu_pcie_gen_max")), + "pcie_width": _number(hardware.get("gpu_pcie_width")), + "pcie_width_max": _number(hardware.get("gpu_pcie_width_max"))}] recent = [] for row in (metrics.get("requests") if isinstance(metrics.get("requests"), list) else [])[:50]: if isinstance(row, dict): diff --git a/strata_cli/detail_dashboard.py b/strata_cli/detail_dashboard.py index 67fd99ffe1..223ad60a9d 100644 --- a/strata_cli/detail_dashboard.py +++ b/strata_cli/detail_dashboard.py @@ -13,7 +13,7 @@ from rich.panel import Panel from rich.text import Text from strata_cli import nav -from strata_cli.client import complete_slots +from strata_cli.client import card_link, complete_slots from strata_cli.dashboard import (set_ascii_boxes, _rounded, _age, _current_batch_value, _current_sample, _device_role, _gib, _meter, _rate_spark, _spark, _state, _visual_pair, _visual_panel, MonitorHistory) @@ -108,7 +108,14 @@ def _detail_lines(kind: str, row: dict, snapshot: dict, width: int, f"VRAM {_gib(row.get('mem_used') if live else None)}/" f"{_gib(row.get('mem_total') if live else None)} GiB", f"Temp {number(row.get('temp') if live else None, 'C')} " - f"Power {number(row.get('power') if live else None, 'W')}", + f"Power {number(row.get('power') if live else None, 'W')}" + # the card's own ceiling (NVML's enforced limit, sysfs power1_cap); the tile adds the cards together, + # so the card you selected needs its own + + (f" of {number(row.get('power_limit') if live else None, 'W')}" + if live and row.get("power_limit") is not None else "") + # the link this card trained, not one card's link for the whole run (an x4 card was hidden behind + # an x8 card's "Gen5 x8"); "" when the server reports no link for this card + + (f" Link {card_link(row)}" if card_link(row) else ""), _device_stage(topology, row.get("index"), width)] elif kind == "slot": lines = _slot_detail(row if live else {**row, "tok_s": None}, width)[1:] diff --git a/strata_cli/overview.py b/strata_cli/overview.py index 38ee2682bf..a316b7aeff 100644 --- a/strata_cli/overview.py +++ b/strata_cli/overview.py @@ -22,6 +22,7 @@ from rich.table import Table from rich.text import Text from strata_cli import nav +from strata_cli.client import card_link GIB = 2 ** 30 BLUE = "#5aa9ff" @@ -77,7 +78,12 @@ def _cards(hw: dict, static: dict) -> list[dict]: raw = hw.get("gpus") if isinstance(hw.get("gpus"), list) else [] cards = [{"index": c.get("index"), "name": c.get("name"), "util": _num(c.get("util")), "mem_used": _gib(c.get("mem_used")), "mem_total": _gib(c.get("mem_total")), "temp": _num(c.get("temp")), "power": _num(c.get("power")), - "power_limit": _num(c.get("power_limit"))} for c in raw[:16] if isinstance(c, dict)] + "power_limit": _num(c.get("power_limit")), + # each card trains its own PCIe link, and can be capped below what the card itself can do: the tile shows + # the weakest one, the strip names them all + "pcie_gen": _num(c.get("pcie_gen")), "pcie_gen_max": _num(c.get("pcie_gen_max")), + "pcie_width": _num(c.get("pcie_width")), "pcie_width_max": _num(c.get("pcie_width_max"))} + for c in raw[:16] if isinstance(c, dict)] return cards if len(cards) >= 2 else [] @@ -91,6 +97,13 @@ def _most(values: list) -> float | None: return max(present) if present else None +def _weakest(values: list) -> float | None: + """The smallest reading that came in. A PCIe link is not a total or a mean: every token crosses the weakest + card's link too, so that is the one the tile shows.""" + present = [v for v in values if v is not None] + return min(present) if present else None + + def build(metrics: dict | None) -> dict | None: """The numbers the Overview draws, or None when the server does not serve /metrics (an old server: the caller falls back).""" if not isinstance(metrics, dict) or not isinstance(metrics.get("live"), dict): @@ -142,6 +155,7 @@ def build(metrics: dict | None) -> dict | None: slots, total_slots = _num(engine.get("expert_slots")), _num(engine.get("experts")) cache_mib = _num(engine.get("expert_cache_mib")) gen, genmax, width = _num(hw.get("gpu_pcie_gen")), _num(hw.get("gpu_pcie_gen_max")), _num(hw.get("gpu_pcie_width")) + width_cap = _num(hw.get("gpu_pcie_width_max")) # how wide this card could go: x8 under x16 means the slot or the board capped it model = { "model": engine.get("model"), "max_context": max_ctx, "state": state, "state_raw": state_raw, "queued": int(queued), "progress": (done, total), "phase_text": {"Idle": "Waiting for a request", "Reading": "Reading prompt", "Generating": "Generating a reply", @@ -156,7 +170,8 @@ def build(metrics: dict | None) -> dict | None: "vram_hist": _series(history, "gpu_mem_used", GIB), "temp": _num(hw.get("gpu_temp")), "temp_hist": _series(history, "gpu_temp"), "power": _num(hw.get("gpu_power")), "power_limit": _num(hw.get("gpu_power_limit")), "power_hist": _series(history, "gpu_power"), "pcie_rx": _num(hw.get("gpu_pcie_rx_mb")), "pcie_hist": _series(history, "gpu_pcie_rx_mb"), - "pcie_gen": gen if gen is not None else genmax, "pcie_width": width, "count": _num(static.get("gpu_count"))}, + "pcie_gen": gen if gen is not None else genmax, "pcie_width": width, "pcie_width_max": width_cap, + "count": _num(static.get("gpu_count"))}, "cpu": {"load": _num(hw.get("cpu_pct") if hw.get("cpu_pct") is not None else hw.get("cpu")), "hist": _series(history, "cpu"), "cores": _num(static.get("cores")), "threads": _num(static.get("threads")), "sockets": _num(static.get("sockets")), "numa": _num(static.get("numa_nodes"))}, @@ -181,6 +196,20 @@ def build(metrics: dict | None) -> dict | None: g["power"] = _total([c["power"] for c in cards]) g["power_limit"] = _total([c["power_limit"] for c in cards]) g["count"] = float(len(cards)) + # A link is not a total. These used to be the aggregate fields, which on a split run are card 0's reading: + # a "Gen5 x8" tile said nothing about a second card the board had trained down to x4. The tile shows the + # weakest card's link (the same rule as the server's own, and as `_Amd.link()`'s slowest/narrowest hop); + # the Cards strip under it names every card's own. + gen = _weakest([c["pcie_gen"] if c["pcie_gen"] is not None else c["pcie_gen_max"] for c in cards]) + width = _weakest([c["pcie_width"] for c in cards]) + if gen is not None: + g["pcie_gen"] = gen + if width is not None: + g["pcie_width"] = width + # "x8 of x16" is one card's gap, so it is taken from the card that gave the width above rather than from the + # smallest cap in the run (which can be another card's); the Cards strip still names every card's own. + narrow = min((c for c in cards if c["pcie_width"] is not None), key=lambda c: c["pcie_width"], default=None) + g["pcie_width_max"] = narrow["pcie_width_max"] if narrow else None return model @@ -293,20 +322,24 @@ def _tile(title: str, big: str, sub: str, series: str, width: int, *, accent: st def _cards_strip(cards: list[dict], glyphs: str, accent: str, ascii_mode: bool) -> Text: - """One line per card (up to 4): a small load bar, load %, memory, temperature and power; "+ N more cards" beyond that.""" + """One line per card (up to 4): a small load bar, load %, memory, temperature, power and that card's own PCIe link + (the server reports it per card; the tile above shows only the weakest); "+ N more cards" beyond that.""" t = Text(no_wrap=True, overflow="crop") t.append("Cards" + chr(10), style=f"bold {accent}") shown = cards[:4] names = [short_gpu(c.get("name")) for c in shown] pad = min(16, max(len(n) for n in names)) - for c, name in zip(shown, names): + links = [card_link(c) for c in shown] # "" for a card whose link the server does not report + col = max((len(x) for x in links), default=0) # no column at all when no server reports one: the line stays as it was + for c, name, link in zip(shown, names, links): util = c["util"] used, total = c["mem_used"], c["mem_total"] t.append(f"GPU {c['index'] if c['index'] is not None else '?'} {name[:pad]:<{pad}} ") t.append_text(bar((util / 100.0) if util is not None else None, 10, glyphs, accent)) mem = f"{fmt(used, 1)} / {fmt(total, 0)} GB" if used is not None and total is not None else "-- GB" temp = f"{fmt(c['temp'])} {'C' if ascii_mode else '°C'}" - t.append(f" {fmt(util):>3} % {mem:<14} {temp:>6} {fmt(c['power']):>4} W" + chr(10)) + t.append(f" {fmt(util):>3} % {mem:<14} {temp:>6} {fmt(c['power']):>4} W" + + (f" {link:>{col}}" if col else "") + chr(10)) if len(cards) > 4: t.append(f"+ {len(cards) - 4} more cards: press 5" + chr(10), style="dim") return t @@ -393,14 +426,27 @@ def render(model: dict, *, width: int, height: int, connection: str, connection_ c, d = model["cpu"], model["disk"] gen = f"Gen{int(g['pcie_gen'])}" if g["pcie_gen"] else "PCIe" link = f"{gen} x{int(g['pcie_width'])}" if g["pcie_width"] else gen + # a card that runs narrower than it could - capped to x8 in a x16 slot, or trained down by the board - shows both + # numbers, because the narrow one alone reads as a link someone chose; with several cards it is the weakest + # card's pair (the Cards strip names each card's own) + if g["pcie_width"] and g.get("pcie_width_max") and g["pcie_width_max"] > g["pcie_width"]: + link += f" of x{int(g['pcie_width_max'])}" cpu_sub = (f"{int(c['sockets'])} CPUs {dot} {int(c['cores'])} cores" if c.get("sockets") and c["sockets"] > 1 and c["cores"] else f"{int(c['cores'])} cores {dot} {int(c['threads'])} threads" if c["cores"] and c["threads"] else f"{int(c['threads'])} threads" if c["threads"] else "") + # the Power tile is a sum over the cards, and so is its ceiling, so with two or more cards the tile says whose + # power it is, like every other tile says which card its number comes from: a bare "15 W" reads as one card's. + # A narrow terminal has no room for the label and the ceiling together; the label wins and the tile stays whole + # (the box crops, so a too-long line would lose its end), and each card's own ceiling is on the Hardware page. + alone = f"of {fmt(g['power_limit'])} W limit" if g["power_limit"] else "" # one card: exactly as before + together = f"all {ncards} cards of {fmt(g['power_limit'])} W" if g["power_limit"] else f"all {ncards} cards" + power_sub = alone if not ncards else (together if len(together) <= inner else f"all {ncards} cards") tiles2 = [ - _tile("Power", f"{fmt(g['power'])} W", f"of {fmt(g['power_limit'])} W limit" if g["power_limit"] else "", spark(g["power_hist"], inner, glyphs, lo=0), + _tile("Power", f"{fmt(g['power'])} W", power_sub, spark(g["power_hist"], inner, glyphs, lo=0), tile_w, accent=accent, box_style=box_style), - _tile("PCIe", link, f"to GPU {fmt(g['pcie_rx'])} MB/s" if g["pcie_rx"] is not None else "to GPU --", spark(g["pcie_hist"], inner, glyphs, lo=0), tile_w, - accent=accent, box_style=box_style), + _tile("PCIe", link, f"weakest of {ncards} cards" if ncards else + (f"to GPU {fmt(g['pcie_rx'])} MB/s" if g["pcie_rx"] is not None else "to GPU --"), + spark(g["pcie_hist"], inner, glyphs, lo=0), tile_w, accent=accent, box_style=box_style), _tile("CPU", f"{fmt(c['load'])} %", cpu_sub, spark(c["hist"], inner, glyphs, lo=0, hi=100), tile_w, accent=accent, box_style=box_style), _tile("Disk read", f"{fmt(d['read'], 1)} MB/s", f"write {fmt(d['write'], 1)} MB/s" if d["write"] is not None else "write --", spark(d["hist"], inner, glyphs, lo=0), tile_w, accent=accent, box_style=box_style), diff --git a/strata_cli/render.py b/strata_cli/render.py index df0fa8164a..0a800ea356 100644 --- a/strata_cli/render.py +++ b/strata_cli/render.py @@ -8,7 +8,7 @@ import unicodedata from typing import Any from strata_cli import nav -from strata_cli.client import complete_slots +from strata_cli.client import card_link, complete_slots VIEWS = ("overview", "serving", "requests", "engine", "hardware", "logs") @@ -235,7 +235,14 @@ def _device(row: dict, width: int) -> str: return _line(f"{label:<7} {mem:<17} util {number(row.get('util'), '%')}", width) from strata_cli.overview import short_gpu # "NVIDIA GeForce RTX 3090" -> "RTX 3090": the maker's prefix used to cut the model off name = short_gpu(row.get("name")) if row.get("name") else None - return _line(f"{label:<7} {field(name, 20)} {mem:<17} {number(row.get('util'), '%'):>5} {number(row.get('temp'), ' C'):>6} {number(row.get('power'), ' W'):>7}", width) + link = card_link(row) # each card trains its own PCIe link: show that card's, not one card's for the run + base = (f"{label:<7} {field(name, 20)} {mem:<17} {number(row.get('util'), '%'):>5} {number(row.get('temp'), ' C'):>6}" + f" {number(row.get('power'), ' W'):>7}") + # an 80-column terminal has no room for a capped card's second number: the width the card runs at is the one that + # matters there, and dropping "of x16" beats the line's own crop cutting it mid-word (the detail pane below keeps both) + if link and len(link) > width - len(base) - 2: + link = card_link(row, gap=False) + return _line(base + (f" {link:>8}" if link else ""), width) def _device_stage(topology: dict, index: Any, width: int) -> str: @@ -320,7 +327,11 @@ def _device_detail(row: dict, topology: dict, width: int) -> list[str]: return ["DEVICE DETAIL (read only)", _line(f"GPU {number(row.get('index'))} {safe(row.get('name'), 30)}", width), _line(f"VRAM {number(used_gib, ' GiB', 1)} / {number(total_gib, ' GiB', 1)} Util {number(row.get('util'), '%')}", width), - _line(f"Temperature {number(row.get('temp'), ' C')} Power {number(row.get('power'), ' W')}", width), + _line(f"Temperature {number(row.get('temp'), ' C')} Power {number(row.get('power'), ' W')}" + + # this card's own ceiling (NVML's enforced limit, sysfs power1_cap): the tile above shows the two + # cards' limits added together, so the card you picked needs its own + (f" of {number(row.get('power_limit'), ' W')}" if row.get("power_limit") is not None else "") + + (f" Link {card_link(row)}" if card_link(row) else ""), width), _line(f"Placement {safe(topology.get('mode'), 24)}; split {safe(topology.get('configured_split'), 24)}", width), _device_stage(topology, row.get("index"), width)] diff --git a/tests/terminal/test_monitor_classic.py b/tests/terminal/test_monitor_classic.py index 39057d64de..db241871e0 100644 --- a/tests/terminal/test_monitor_classic.py +++ b/tests/terminal/test_monitor_classic.py @@ -144,10 +144,39 @@ class SeveralCards(unittest.TestCase): self.assertEqual(g["vram_total"], 72.0) # all cards self.assertEqual((g["power"], g["power_limit"]), (625.0, 1050.0)) text = draw(m) - for want in ("busiest of 3 cards", "all 3 cards", "hottest card", "64.3 / 72 GB", "625 W", "of 1,050 W limit", "61 °C"): + for want in ("busiest of 3 cards", "all 3 cards", "hottest card", "64.3 / 72 GB", "625 W", "all 3 cards of 1,050 W", "61 °C"): self.assertIn(want, text, want) self.assertNotIn("+2", text) # no more "RTX 3090 +2" + def power_sub(self, model, width=110) -> str: + """The Power tile's small line: the one that says where the big number comes from.""" + lines = draw(overview.build(model), width=width).splitlines() + top = next(i for i, ln in enumerate(lines) if "─ Power ─" in ln) + return lines[top + 2].split("│")[1].strip() + + def test_the_power_tile_says_which_cards_it_added(self): + """A bare "625 W" over three cards reads as one card's, because the other tiles all say which card they come + from and this one said nothing. The small line names the cards and keeps the added-together ceiling beside it + while both fit; a narrow terminal keeps the label and drops the ceiling whole, since a line the box crops + mid-sentence is worse than one less number (each card's own ceiling is on the Hardware page).""" + self.assertEqual(self.power_sub(three_cards()), "all 3 cards of 1,050 W") # width 110: room + self.assertEqual(self.power_sub(three_cards(), 90), "all 3 cards") # no room: whole + text = draw(overview.build(three_cards()), width=90) + self.assertNotIn("of 1,050", text) + self.assertNotIn("W limit", text) # never "…of 1,0" + two = three_cards() + two["hardware"]["gpus"] = two["hardware"]["gpus"][:2] + two["hardware_static"]["gpu_count"] = 2 + self.assertEqual(self.power_sub(two, 100), "all 2 cards of 700 W") # the pair, not the pair's biggest card + no_limit = three_cards() + for c in no_limit["hardware"]["gpus"]: + c["power_limit"] = None + self.assertEqual(self.power_sub(no_limit), "all 3 cards") # no ceiling reported: still says whose power + one = metrics("generating") + one["hardware"]["gpus"] = [{"index": 0, "name": "NVIDIA GeForce RTX 5070", "util": 88, "mem_used": 11.2 * GIB, + "mem_total": 12 * GIB, "temp": 54, "power": 114, "power_limit": 250}] + self.assertEqual(self.power_sub(one), "of 250 W limit") # one card: the old line, unchanged + def test_the_cards_strip_one_line_per_card(self): text = draw(overview.build(three_cards())) lines = [ln for ln in text.splitlines() if ln.startswith("GPU ")] @@ -160,6 +189,33 @@ class SeveralCards(unittest.TestCase): self.assertIn("236 W", lines[0]) self.assertIn("RTX 3090", lines[0]) + def test_each_card_shows_its_own_pcie_link(self): + """Every card trains its own link, so the strip names the three different ones and the tile shows the + weakest card's: an x4 card used to hide behind card 0's number.""" + m = three_cards() + for c, (gen, width) in zip(m["hardware"]["gpus"], ((5, 8), (5, 4), (5, 16))): + c["pcie_gen"] = gen + c["pcie_gen_max"] = gen + c["pcie_width"] = width + g = overview.build(m)["gpu"] + self.assertEqual((g["pcie_gen"], g["pcie_width"]), (5.0, 4.0)) # the weakest card + text = draw(overview.build(m)) + self.assertIn("weakest of 3 cards", text) + lines = [ln for ln in text.splitlines() if ln.startswith("GPU ")] + for want, line in zip(("Gen5 x8", "Gen5 x4", "Gen5 x16"), lines): + self.assertIn(want, line, want) + + def test_a_card_that_reports_no_link_falls_back_to_its_max_and_then_to_the_old_layout(self): + m = three_cards() + m["hardware"]["gpus"][0].update({"pcie_gen": None, "pcie_gen_max": 5, "pcie_width": 8}) # NVML reports no + m["hardware"]["gpus"][1].update({"pcie_gen": 3, "pcie_gen_max": 3, "pcie_width": 16}) # link when idle + g = overview.build(m)["gpu"] + self.assertEqual((g["pcie_gen"], g["pcie_width"]), (3.0, 8.0)) # min of what came in + lines = [ln for ln in draw(overview.build(m)).splitlines() if ln.startswith("GPU ")] + self.assertIn("Gen5 x8", lines[0]) + self.assertIn("Gen3 x16", lines[1]) + self.assertNotIn("Gen", lines[2]) # nothing reported: as before + def test_up_to_four_cards_then_a_pointer_to_view_5(self): m = three_cards() m["hardware"]["gpus"] += [dict(m["hardware"]["gpus"][0], index=i) for i in (3, 4, 5)] @@ -174,6 +230,38 @@ class SeveralCards(unittest.TestCase): self.assertNotIn("CPUs", one) self.assertIn("6 cores · 12 threads", draw(overview.build(metrics("generating")))) # no socket count reported: as before + def test_a_card_narrower_than_it_could_be_says_both_numbers(self): + """A card capped to x8 in a x16 slot, or trained down by the board: the narrow number alone reads as a card + someone chose, so that card gets both. The tile's pair comes from the card that gave the narrowest width, + never from the widest cap in the run (that would put one card's gap on another card's link).""" + m = three_cards() + for c, (width, cap) in zip(m["hardware"]["gpus"], ((8, 16), (4, 4), (16, 16))): + c.update({"pcie_gen": 5, "pcie_gen_max": 5, "pcie_width": width, "pcie_width_max": cap}) + lines = [ln for ln in draw(overview.build(m)).splitlines() if ln.startswith("GPU ")] + self.assertIn("Gen5 x8 of x16", lines[0]) # capped in the slot: the gap is the point + self.assertIn("Gen5 x4", lines[1]) # at its own cap: one number, as before + self.assertIn("Gen5 x16", lines[2]) + g = overview.build(m)["gpu"] + self.assertEqual((g["pcie_width"], g["pcie_width_max"]), (4.0, 4.0)) # the x4 card's own pair, not x16 + self.assertNotIn("x4 of x16", draw(overview.build(m))) + m["hardware"]["gpus"][1]["pcie_width_max"] = 16 # the weakest card could do x16 + self.assertEqual(overview.build(m)["gpu"]["pcie_width_max"], 16.0) + self.assertIn("Gen5 x4 of x16", draw(overview.build(m))) # the tile says the gap too + + def test_a_card_with_no_cap_reported_stays_one_number(self): + """An old server, or a driver that answers only the negotiated width: the strip and the tile say exactly what + they said before, with no invented cap.""" + m = three_cards() + for c, width in zip(m["hardware"]["gpus"], (8, 4, 16)): + c.update({"pcie_gen": 5, "pcie_gen_max": 5, "pcie_width": width}) + g = overview.build(m)["gpu"] + self.assertIsNone(g["pcie_width_max"]) + text = draw(overview.build(m)) + self.assertNotIn(" of x", text) + lines = [ln for ln in text.splitlines() if ln.startswith("GPU ")] + for want, line in zip(("Gen5 x8", "Gen5 x4", "Gen5 x16"), lines): + self.assertIn(want, line, want) + def test_a_missing_reading_stays_missing(self): m = three_cards() for c in m["hardware"]["gpus"]: @@ -226,6 +314,12 @@ class FooterAndViews(unittest.TestCase): line = _device(row, 100) self.assertIn("RTX 3090", line) self.assertNotIn("NVIDIA", line) + row.update({"pcie_gen": 5, "pcie_gen_max": 5, "pcie_width": 8, "pcie_width_max": 16}) # capped to x8 in a x16 slot + self.assertIn("Gen5 x8 of x16", _device(row, 100)) + narrow = _device(row, 80) # no room for the second number: dropped whole, not cut mid-word + self.assertIn("Gen5 x8", narrow) + self.assertNotIn("of x16", narrow) + self.assertLessEqual(len(narrow), 80) if __name__ == "__main__": diff --git a/tests/terminal/test_terminal.py b/tests/terminal/test_terminal.py index 5f4c74ed35..e9719f9a0a 100644 --- a/tests/terminal/test_terminal.py +++ b/tests/terminal/test_terminal.py @@ -14,7 +14,7 @@ from pathlib import Path from unittest import mock from strata_cli.cli import main -from strata_cli.client import (ClientError, Endpoint, normalize_legacy, normalize_status_only, +from strata_cli.client import (ClientError, Endpoint, card_link, normalize_legacy, normalize_status_only, sanitize_telemetry, server_url) from strata_cli.render import display_width, field, render_view, safe from serve.server import (configure_batch_telemetry_env, parse_batch_window_sample, @@ -514,6 +514,45 @@ class ContractTests(unittest.TestCase): self.assertIn("Request request-7", slot) self.assertIn("not a GPU assignment", slot) + def test_each_card_keeps_its_own_pcie_link_into_the_snapshot(self): + """The detail page names the link of the card you selected, so a row's own link has to survive both ways in: + it used to be dropped, so an x4 card could only ever read as one card's number.""" + links = ((5, 8), (5, 4), (None, None), (None, None)) + sample = four_gpu_snapshot() + for row, (gen, width) in zip(sample["devices"], links): + row["pcie_gen"] = row["pcie_gen_max"] = gen + row["pcie_width"] = width + self.assertEqual([card_link(row) for row in sanitize_telemetry(sample)["devices"]], + ["Gen5 x8", "Gen5 x4", "", ""]) + raw = {"hardware": {"gpus": [{"index": i, "name": f"GPU-{i}", "pcie_gen": g, "pcie_gen_max": g, + "pcie_width": w} for i, (g, w) in enumerate(links)]}} + self.assertEqual([card_link(row) for row in normalize_legacy(raw, {})["devices"]], + ["Gen5 x8", "Gen5 x4", "", ""]) + + def test_a_capped_card_and_its_own_power_ceiling_survive_the_snapshot(self): + """A card running at x8 under one at x16 needs its own pair, and the card you selected needs its own power + ceiling: the tile above the cards adds the two ceilings together, so a row that loses `power_limit` leaves the + detail page with no number to compare the card's watts against.""" + capped = ((5, 8, 16, 180.0), (5, 4, 4, 170.0), (None, None, None, None), (None, None, None, None)) + sample = four_gpu_snapshot() + for row, (gen, width, cap, limit) in zip(sample["devices"], capped): + row["pcie_gen"] = row["pcie_gen_max"] = gen + row["pcie_width"], row["pcie_width_max"], row["power_limit"] = width, cap, limit + rows = sanitize_telemetry(sample)["devices"] + self.assertEqual([card_link(r) for r in rows], ["Gen5 x8 of x16", "Gen5 x4", "", ""]) + self.assertEqual([r["power_limit"] for r in rows], [180.0, 170.0, None, None]) + raw = {"hardware": {"gpus": [{"index": i, "name": f"GPU-{i}", "pcie_gen": g, "pcie_width": w, + "pcie_width_max": c, "power_limit": p} + for i, (g, w, c, p) in enumerate(capped[:2])]}} + rows = normalize_legacy(raw, {})["devices"] + self.assertEqual([card_link(r) for r in rows], ["Gen5 x8 of x16", "Gen5 x4"]) + self.assertEqual([r["power_limit"] for r in rows], [180.0, 170.0]) + old = normalize_legacy({"hardware_static": {"gpu_count": 1, "gpu_name": "NVIDIA GeForce RTX 5060 Ti"}, + "hardware": {"gpu_pcie_gen": 5, "gpu_pcie_width": 8, "gpu_pcie_width_max": 16, + "gpu_power_limit": 180.0}}, {}) + self.assertEqual(card_link(old["devices"][0]), "Gen5 x8 of x16") # an old server: one row, both numbers + self.assertEqual(old["devices"][0]["power_limit"], 180.0) + def test_wide_serving_scrolls_to_selected_device(self): s = four_gpu_snapshot() s["devices"] = [{"index": i, "name": f"Card-{i}", "mem_used": 8 * 2**30, diff --git a/tests/terminal/test_visual_detail.py b/tests/terminal/test_visual_detail.py index 0e6195bafa..94fc7aeaf7 100644 --- a/tests/terminal/test_visual_detail.py +++ b/tests/terminal/test_visual_detail.py @@ -43,7 +43,11 @@ def snapshot(): for i in range(2)]}, "devices": [{"index": i, "name": f"GPU-{i}", "util": 70 + i, "mem_used": (10 + i) * 2**30, "mem_total": 24 * 2**30, - "temp": 60 + i, "power": 180 + i} for i in range(2)], + "temp": 60 + i, "power": 180 + i, "power_limit": (300, 220)[i], + # each card trains its own link, and the first one runs narrower than its own card could go: + # a page that printed one card's link, or the run's added-together ceiling, cannot pass + "pcie_gen": 5, "pcie_gen_max": 5, "pcie_width": (8, 4)[i], "pcie_width_max": (16, 4)[i]} + for i in range(2)], "ram": {"used": 20 * 2**30, "total": 64 * 2**30}, "recent": [{"id": "done-0", "finish": "stop", "prompt_tokens": 100, "reused": 20, "output_tokens": 40, "duration_s": 3.2, @@ -83,6 +87,16 @@ class VisualDetailTests(unittest.TestCase): self.assertIn("HOST SPAN", self.render(sample, "engine")) self.assertIn("req-0", self.render(sample, "logs")) + def test_the_hardware_page_names_the_link_of_the_card_you_selected(self): + """Two cards trained to different widths: the page says which card runs at which width, instead of one + card's link for the whole run. The card you selected gets its own power ceiling too - the tile above the + cards adds the two ceilings together.""" + for selected, (link, watts) in ((0, ("Link Gen5 x8 of x16", "Power 180W of 300W")), + (1, ("Link Gen5 x4", "Power 181W of 220W"))): + shown = self.render(snapshot(), "hardware", selected=selected) + self.assertIn(link, shown, link) + self.assertIn(watts, shown, watts) + def test_selection_detail_and_stale_readings(self): sample = snapshot() summary = self.render(sample, "requests", selected=0)