@simplexai/localmodels-darwin-x64 0.1.0-dev.58 → 0.1.0-dev.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +105 -98
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +104 -43
  5. package/modules/localmodels/app.py +1 -1
  6. package/modules/localmodels/apple_sensors.py +431 -0
  7. package/modules/localmodels/bifrost_admin.py +83 -8
  8. package/modules/localmodels/bifrost_checks.py +2 -2
  9. package/modules/localmodels/bifrost_config.py +235 -13
  10. package/modules/localmodels/bifrost_log.py +166 -0
  11. package/modules/localmodels/bifrost_models.py +1 -1
  12. package/modules/localmodels/budget.py +1 -1
  13. package/modules/localmodels/catalog.json +192 -77
  14. package/modules/localmodels/catalog.py +20 -3
  15. package/modules/localmodels/catalog_add.py +42 -11
  16. package/modules/localmodels/custom_hub.py +983 -0
  17. package/modules/localmodels/custom_hub_http.py +579 -0
  18. package/modules/localmodels/custom_probe.py +451 -0
  19. package/modules/localmodels/deploy.py +27 -5
  20. package/modules/localmodels/deploy_steps.py +5 -0
  21. package/modules/localmodels/download-mirrors.json +8 -0
  22. package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
  23. package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
  24. package/modules/localmodels/engines.py +38 -8
  25. package/modules/localmodels/estimator.py +60 -7
  26. package/modules/localmodels/frontend.py +26 -21
  27. package/modules/localmodels/gateway.py +48 -3
  28. package/modules/localmodels/gateway_app_bifrost.py +4 -4
  29. package/modules/localmodels/gateway_bifrost.py +128 -21
  30. package/modules/localmodels/gguf.py +6 -0
  31. package/modules/localmodels/host_sensors.py +704 -0
  32. package/modules/localmodels/hosts.py +99 -12
  33. package/modules/localmodels/library_cli.py +181 -3
  34. package/modules/localmodels/library_convert.py +34 -0
  35. package/modules/localmodels/library_custom.py +831 -0
  36. package/modules/localmodels/library_elastic.py +182 -127
  37. package/modules/localmodels/library_gateway.py +193 -40
  38. package/modules/localmodels/library_jobs.py +92 -18
  39. package/modules/localmodels/library_kept.py +50 -6
  40. package/modules/localmodels/library_model.py +254 -2
  41. package/modules/localmodels/library_pricing.py +97 -8
  42. package/modules/localmodels/library_serve.py +196 -66
  43. package/modules/localmodels/library_smoke.py +315 -0
  44. package/modules/localmodels/library_state.py +81 -2
  45. package/modules/localmodels/library_status.py +144 -8
  46. package/modules/localmodels/metal.py +1 -1
  47. package/modules/localmodels/metal_probe.py +4 -4
  48. package/modules/localmodels/nvml_ctypes.py +431 -0
  49. package/modules/localmodels/plan_envelope.py +18 -7
  50. package/modules/localmodels/process_identity_linux.py +39 -0
  51. package/modules/localmodels/records.py +1 -0
  52. package/modules/localmodels/remote_ops.py +57 -8
  53. package/modules/localmodels/remote_ops_download.py +205 -53
  54. package/modules/localmodels/remote_ops_mirrors.py +43 -2
  55. package/modules/localmodels/remote_ops_ranges.py +2 -5
  56. package/modules/localmodels/remote_ops_service.py +95 -37
  57. package/modules/localmodels/remote_ops_verify.py +22 -5
  58. package/modules/localmodels/runtime-lock.json +19 -19
  59. package/modules/localmodels/runtime_auth.py +4 -1
  60. package/modules/localmodels/service_control.py +32 -1
  61. package/modules/localmodels/service_wiring.py +237 -12
  62. package/modules/localmodels/service_worker.py +6 -2
  63. package/modules/localmodels/services_cli.py +35 -27
  64. package/modules/localmodels/setup_inspection.py +47 -70
  65. package/modules/localmodels/setup_inspection_harness.py +159 -15
  66. package/modules/localmodels/setup_text.py +14 -0
  67. package/modules/localmodels/setup_upgrade.py +1 -1
  68. package/modules/localmodels/source_byok.py +9 -7
  69. package/modules/localmodels/source_byok_probe.py +6 -1
  70. package/modules/localmodels/stack.py +9 -1
  71. package/modules/localmodels/stack_binding.py +3 -35
  72. package/modules/localmodels/stack_cleanup.py +4 -0
  73. package/modules/localmodels/stack_compose.py +18 -2
  74. package/modules/localmodels/stack_lifecycle.py +26 -3
  75. package/modules/localmodels/stack_memory.py +1 -0
  76. package/modules/localmodels/stack_plan.py +6 -2
  77. package/modules/localmodels/stack_ports.py +2 -0
  78. package/modules/localmodels/stack_remove.py +10 -1
  79. package/modules/localmodels/stack_up.py +33 -7
  80. package/modules/localmodels/stack_update.py +3 -1
  81. package/modules/localmodels/stack_view.py +77 -53
  82. package/modules/localmodels/stack_view_demo.py +36 -5
  83. package/modules/localmodels/stack_view_events.py +147 -12
  84. package/modules/localmodels/stack_view_gpu.py +97 -17
  85. package/modules/localmodels/stack_view_llm.py +15 -0
  86. package/modules/localmodels/stack_view_measure.py +4 -1
  87. package/modules/localmodels/stack_view_schema.py +54 -8
  88. package/modules/localmodels/stack_view_serve.py +40 -3
  89. package/modules/localmodels/stack_view_slots.py +89 -10
  90. package/modules/localmodels/stack_view_telemetry.py +163 -0
  91. package/modules/localmodels/stack_view_text.py +5 -2
  92. package/modules/localmodels/stack_view_tick.py +658 -0
  93. package/modules/localmodels/stack_view_words.py +4 -0
  94. package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
  95. package/modules/localmodels/suite.py +45 -27
  96. package/modules/localmodels/telemetry_math.py +538 -0
  97. package/modules/localmodels/transport.py +13 -2
  98. package/modules/localmodels/web/view/view.js +1 -1
  99. package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
  100. package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +102 -95
  101. package/package.json +1 -1
  102. package/tool.json +1 -1
  103. package/modules/localmodels/bifrost_datasheet.py +0 -53
  104. package/modules/localmodels/bifrost_provider.py +0 -88
  105. package/modules/localmodels/bifrost_unit.py +0 -99
  106. package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
  107. package/modules/localmodels/gateway_switch.py +0 -51
  108. package/modules/localmodels/library_floor.py +0 -78
  109. package/modules/localmodels/service_stop.py +0 -52
  110. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
  111. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
  112. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
  113. /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -27,6 +27,7 @@ from typing import Any, TypedDict
27
27
  from localmodels import bifrost_checks, gateway, harness, hosts
28
28
  from localmodels.gateway_bifrost import FAST_PROVIDER, owned_listener
29
29
  from localmodels.stack_view_words import say
30
+ from localmodels.telemetry_math import WATERFALL_LIMIT, WaterfallEntry
30
31
 
31
32
  LIMIT = 40 # the last calls a page needs to animate and to average
32
33
  KINDS = {
@@ -188,18 +189,8 @@ def read(doc: hosts.Owned, magpie_addr: str | None = None, limit: int = LIMIT) -
188
189
  """The last ``limit`` calls of this tool's gateway, newest-ended first: its Bifrost's log
189
190
  (which picks the last ``limit`` by start time), else, for a stack wired into Magpie
190
191
  (``magpie_addr``), Magpie's usage log; empty when neither."""
191
- bifrost = doc["gateway"].get("bifrost")
192
- if bifrost:
193
- try:
194
- if not owned_listener(bifrost):
195
- return []
196
- rows = bifrost_checks.logs(bifrost["addr"], limit=str(limit))
197
- except (OSError, ValueError, KeyError):
198
- return []
199
- return newest_first([event(row) for row in rows if isinstance(row, dict)])
200
- if magpie_addr and doc["gateway"]["providers"]:
201
- return read_magpie(doc, magpie_addr, limit)
202
- return []
192
+ events, _ = read_with_waterfall(doc, magpie_addr, limit)
193
+ return events
203
194
 
204
195
 
205
196
  # What the board says about the calls above: per-component figures and the alerts.
@@ -258,3 +249,147 @@ def alerts(comps: list[Any]) -> list[str]:
258
249
  )
259
250
  )
260
251
  return found
252
+
253
+
254
+ _CLIENT_TAGS = ("pi", "claude", "codex", "linger", "local")
255
+
256
+
257
+ def _client_id(row: dict[str, Any], default: str = "unknown") -> str:
258
+ """Safe, allowlisted client attribution from gateway metadata (never copies arbitrary headers)."""
259
+ for key in ("client_id", "client", "source_client", "user_agent", "routing_rule_id"):
260
+ raw = row.get(key)
261
+ if not isinstance(raw, str):
262
+ continue
263
+ lower = raw.lower()
264
+ for tag in _CLIENT_TAGS:
265
+ if tag in lower:
266
+ return tag
267
+ return default
268
+
269
+
270
+ def _waterfall_status(raw_status: object) -> str:
271
+ text = str(raw_status or "").strip().lower()
272
+ if text in ("streaming", "in_progress", "processing", "running"):
273
+ return "streaming"
274
+ if text in ("deferred", "queued", "pending", "rate_limited"):
275
+ return "deferred"
276
+ if text in ("failed", "error", "errored", "timeout", "cancelled", "canceled") or (
277
+ text.isdigit() and int(text) >= 400
278
+ ):
279
+ return "failed"
280
+ return "completed"
281
+
282
+
283
+ def waterfall_from_bifrost_row(row: dict[str, Any], *, basis: str = "live") -> WaterfallEntry:
284
+ """Convert one Bifrost log row into a sanitized ``WaterfallEntry`` (no prompt/answer text)."""
285
+ usage = row.get("token_usage")
286
+ prompt_tokens = _count(usage, "prompt_tokens")
287
+ completion_tokens = _count(usage, "completion_tokens")
288
+ cached_tokens = _count(usage, "cached_tokens")
289
+ if cached_tokens is None and isinstance(usage, dict):
290
+ details = usage.get("prompt_tokens_details")
291
+ if isinstance(details, dict):
292
+ cached_tokens = _count(details, "cached_tokens")
293
+ cached_pct: float | None = None
294
+ if cached_tokens is not None and prompt_tokens is not None and prompt_tokens > 0:
295
+ cached_pct = round(min(100.0, max(0.0, (cached_tokens / prompt_tokens) * 100.0)), 1)
296
+ latency_ms = _number(row.get("latency"))
297
+ gateway_ms = _number(row.get("overhead_latency"))
298
+ ttft_ms = _number(row.get("ttft_ms"))
299
+ if ttft_ms is None:
300
+ ttft_ms = _number(row.get("time_to_first_token_ms"))
301
+ decode_ms: float | None = None
302
+ if latency_ms is not None:
303
+ head = (ttft_ms or 0.0) + (gateway_ms or 0.0 if ttft_ms is None else 0.0)
304
+ decode_ms = round(max(0.0, latency_ms - head), 1)
305
+ decode_tok_s: float | None = None
306
+ if completion_tokens and decode_ms and decode_ms > 0:
307
+ decode_tok_s = round(completion_tokens / (decode_ms / 1000.0), 1)
308
+ model_raw = str(row.get("model") or row.get("provider") or "local-llm")[:128]
309
+ return {
310
+ "request_id": str(row.get("id") or ""),
311
+ "at": str(row.get("timestamp") or ""),
312
+ "client_id": _client_id(row),
313
+ "model_id": model_raw,
314
+ "status": _waterfall_status(row.get("status")),
315
+ "gateway_ms": round(gateway_ms, 1) if gateway_ms is not None else None,
316
+ "ttft_ms": round(ttft_ms, 1) if ttft_ms is not None else None,
317
+ "decode_ms": decode_ms,
318
+ "prompt_tokens": prompt_tokens,
319
+ "completion_tokens": completion_tokens,
320
+ "cached_prefix_pct": cached_pct,
321
+ "decode_tok_s": decode_tok_s,
322
+ "basis": basis,
323
+ }
324
+
325
+
326
+ def waterfall_from_events(
327
+ events: list[Event],
328
+ *,
329
+ default_client: str = "unknown",
330
+ model_by_component: dict[str, str] | None = None,
331
+ basis: str = "live",
332
+ limit: int = WATERFALL_LIMIT,
333
+ ) -> list[WaterfallEntry]:
334
+ """Project sanitized ``Event`` rows into bounded rolling ``WaterfallEntry`` items."""
335
+ models = model_by_component or {}
336
+ found: list[WaterfallEntry] = []
337
+ for ev in newest_first(events)[:limit]:
338
+ latency = ev["latency_ms"]
339
+ gw = ev["gateway_ms"]
340
+ ttft = ev["ttft_ms"]
341
+ decode_ms: float | None = None
342
+ if latency is not None:
343
+ head = ttft if ttft is not None else (gw or 0.0)
344
+ decode_ms = round(max(0.0, latency - head), 1)
345
+ out_tok = ev["tokens_out"]
346
+ tok_s = (
347
+ round(out_tok / (decode_ms / 1000.0), 1)
348
+ if out_tok and decode_ms and decode_ms > 0
349
+ else None
350
+ )
351
+ comp = ev["component"] or ev["kind"]
352
+ found.append(
353
+ {
354
+ "request_id": ev["id"],
355
+ "at": ev["at"],
356
+ "client_id": default_client,
357
+ "model_id": models.get(comp, comp),
358
+ "status": "completed" if ev["ok"] else "failed",
359
+ "gateway_ms": round(gw, 1) if gw is not None else None,
360
+ "ttft_ms": round(ttft, 1) if ttft is not None else None,
361
+ "decode_ms": decode_ms,
362
+ "prompt_tokens": ev["tokens_in"],
363
+ "completion_tokens": out_tok,
364
+ "cached_prefix_pct": None,
365
+ "decode_tok_s": tok_s,
366
+ "basis": basis,
367
+ }
368
+ )
369
+ return found
370
+
371
+
372
+ def read_with_waterfall(
373
+ doc: hosts.Owned, magpie_addr: str | None = None, limit: int = LIMIT
374
+ ) -> tuple[list[Event], list[WaterfallEntry]]:
375
+ """Read gateway events and bounded rolling waterfall entries in a single gateway call."""
376
+ bifrost = doc["gateway"].get("bifrost")
377
+ if bifrost:
378
+ try:
379
+ if not owned_listener(bifrost):
380
+ return [], []
381
+ rows = bifrost_checks.logs(bifrost["addr"], limit=str(limit))
382
+ except (OSError, ValueError, KeyError):
383
+ return [], []
384
+ dict_rows = [row for row in rows if isinstance(row, dict)]
385
+ paired = [(event(row), row) for row in dict_rows]
386
+ paired.sort(key=lambda item: ended(item[0]), reverse=True)
387
+ ev = [item[0] for item in paired]
388
+ wf = [
389
+ waterfall_from_bifrost_row(item[1], basis="live") for item in paired[:WATERFALL_LIMIT]
390
+ ]
391
+ return ev, wf
392
+ if magpie_addr and doc["gateway"]["providers"]:
393
+ ev = read_magpie(doc, magpie_addr, limit)
394
+ return ev, waterfall_from_events(ev, basis="live")
395
+ return [], []
@@ -1,26 +1,40 @@
1
- """Each NVIDIA card's load now, for ``stack view``: utilization, power draw against its limit and
2
- temperature, from one light ``nvidia-smi --query-gpu`` per reading (the full hardware probe runs
3
- only every half minute). The page lets a card glow with it. Nothing is read beyond these five
4
- columns, and a missing, slow or failing ``nvidia-smi`` is no reading, never an error.
1
+ """Each card's load now, for ``stack view``: utilization, memory controller %, VRAM usage, power
2
+ draw against its limit and temperature.
3
+
4
+ On NVIDIA (Linux & Windows), queries ``libnvidia-ml.so.1`` / ``nvml.dll`` persistently via
5
+ ``nvml_ctypes`` with zero subprocess fork; falls back to ``nvidia-smi --query-gpu`` when NVML is
6
+ absent. On Apple Silicon (macOS), reads non-sudo ``apple_sensors`` (IOReport / AppleSMC) and
7
+ degrades unavailable sensors to ``None`` rather than fabricating numbers.
5
8
  """
6
9
 
7
10
  from __future__ import annotations
8
11
 
9
12
  import shutil
10
13
  import subprocess
14
+ import sys
11
15
  from typing import TypedDict
12
16
 
13
- COLUMNS = "index,utilization.gpu,power.draw,power.limit,temperature.gpu"
17
+ from localmodels import nvml_ctypes
18
+
19
+ COLUMNS = "index,utilization.gpu,power.draw,power.limit,temperature.gpu,utilization.memory"
14
20
  TIMEOUT_S = 2.0
15
21
 
16
22
 
17
- class GpuLoad(TypedDict):
23
+ class _GpuLoadOptional(TypedDict, total=False):
24
+ mem_ctrl_util_pct: float | None
25
+ vram_total_bytes: int | None
26
+ vram_used_bytes: int | None
27
+ vram_free_bytes: int | None
28
+ source: str # nvml | nvidia-smi | apple_sensors | demo
29
+
30
+
31
+ class GpuLoad(_GpuLoadOptional):
18
32
  index: int
19
33
  util_pct: float | None
20
34
  power_w: float | None
21
35
  power_limit_w: float | None
22
36
  temp_c: float | None
23
- basis: str # live | demo
37
+ basis: str # live | demo | none
24
38
 
25
39
 
26
40
  def _number(text: str) -> float | None:
@@ -32,27 +46,53 @@ def _number(text: str) -> float | None:
32
46
 
33
47
 
34
48
  def parse(text: str, basis: str = "live") -> list[GpuLoad]:
35
- """``nvidia-smi --query-gpu=COLUMNS --format=csv,noheader,nounits`` as one load per card."""
49
+ """Parse ``nvidia-smi --query-gpu=... --format=csv,noheader,nounits`` (5 or 6 columns)."""
36
50
  found: list[GpuLoad] = []
37
51
  for line in text.splitlines():
38
52
  cells = [c.strip() for c in line.split(",")]
39
- if len(cells) != 5 or not cells[0].isdigit():
53
+ if len(cells) not in (5, 6) or not cells[0].isdigit():
40
54
  continue
41
- util, power, limit, temp = (_number(c) for c in cells[1:])
55
+ util, power, limit, temp = (_number(c) for c in cells[1:5])
56
+ row: GpuLoad = {
57
+ "index": int(cells[0]),
58
+ "util_pct": util,
59
+ "power_w": power,
60
+ "power_limit_w": limit,
61
+ "temp_c": temp,
62
+ "basis": basis,
63
+ }
64
+ if len(cells) == 6:
65
+ row["mem_ctrl_util_pct"] = _number(cells[5])
66
+ row["source"] = "nvidia-smi"
67
+ found.append(row)
68
+ return found
69
+
70
+
71
+ def _read_nvml() -> list[GpuLoad] | None:
72
+ devices = nvml_ctypes.read_devices(include_processes=False)
73
+ if devices is None:
74
+ return None
75
+ found: list[GpuLoad] = []
76
+ for dev in devices:
42
77
  found.append(
43
78
  {
44
- "index": int(cells[0]),
45
- "util_pct": util,
46
- "power_w": power,
47
- "power_limit_w": limit,
48
- "temp_c": temp,
49
- "basis": basis,
79
+ "index": dev["index"],
80
+ "util_pct": dev["util_pct"],
81
+ "mem_ctrl_util_pct": dev["mem_ctrl_util_pct"],
82
+ "vram_total_bytes": dev["vram_total_bytes"],
83
+ "vram_used_bytes": dev["vram_used_bytes"],
84
+ "vram_free_bytes": dev["vram_free_bytes"],
85
+ "power_w": dev["power_w"],
86
+ "power_limit_w": dev["power_limit_w"],
87
+ "temp_c": dev["temp_c"],
88
+ "basis": dev["basis"],
89
+ "source": "nvml",
50
90
  }
51
91
  )
52
92
  return found
53
93
 
54
94
 
55
- def read() -> list[GpuLoad]:
95
+ def _read_nvidia_smi() -> list[GpuLoad]:
56
96
  smi = shutil.which("nvidia-smi")
57
97
  if smi is None:
58
98
  return []
@@ -69,6 +109,44 @@ def read() -> list[GpuLoad]:
69
109
  return parse(done.stdout) if done.returncode == 0 else []
70
110
 
71
111
 
112
+ def _read_apple() -> list[GpuLoad]:
113
+ from localmodels import apple_sensors
114
+
115
+ tel = apple_sensors.read_telemetry()
116
+ util = tel["gpu_util_pct"]["value"]
117
+ power = tel["power_w"]["value"]
118
+ temp = tel["temp_c"]["value"]
119
+ has_live = any(
120
+ s["basis"] == "live" for s in (tel["gpu_util_pct"], tel["power_w"], tel["temp_c"])
121
+ )
122
+ return [
123
+ {
124
+ "index": 0,
125
+ "util_pct": util,
126
+ "mem_ctrl_util_pct": None,
127
+ "vram_used_bytes": tel["gpu_in_use_bytes"],
128
+ "power_w": power,
129
+ "power_limit_w": None,
130
+ "temp_c": temp,
131
+ "basis": "live" if has_live else "none",
132
+ "source": "apple_sensors",
133
+ }
134
+ ]
135
+
136
+
137
+ def read() -> list[GpuLoad]:
138
+ """Read live per-GPU load: NVML ctypes -> nvidia-smi fallback -> macOS Apple sensors."""
139
+ nvml_rows = _read_nvml()
140
+ if nvml_rows is not None:
141
+ return nvml_rows
142
+ smi_rows = _read_nvidia_smi()
143
+ if smi_rows:
144
+ return smi_rows
145
+ if sys.platform == "darwin":
146
+ return _read_apple()
147
+ return []
148
+
149
+
72
150
  def demo(busy: bool) -> list[GpuLoad]:
73
151
  """The demo card: busy while the made-up turn runs on it, labelled demo."""
74
152
  util = 91.0 if busy else 4.0
@@ -76,9 +154,11 @@ def demo(busy: bool) -> list[GpuLoad]:
76
154
  {
77
155
  "index": 0,
78
156
  "util_pct": util,
157
+ "mem_ctrl_util_pct": 82.0 if busy else 3.0,
79
158
  "power_w": round(38 + util * 3.6, 1),
80
159
  "power_limit_w": 450.0,
81
160
  "temp_c": round(41 + util * 0.24, 1),
82
161
  "basis": "demo",
162
+ "source": "demo",
83
163
  }
84
164
  ]
@@ -43,3 +43,18 @@ def llm_parts(part: Plan, window: int | None = None) -> dict[str, int]:
43
43
  ubatch=entry.agent_posture(AGENT).ubatch,
44
44
  mtp=_int(launch.get("mtp_draft_depth")) > 0,
45
45
  )
46
+
47
+
48
+ def active_weight_bytes(part: Plan) -> int | None:
49
+ """Bytes of resident weights read per decoded token (accounts for MoE ``decode_fraction``)."""
50
+ entry = catalog_entry(part["model"]["id"])
51
+ if entry is not None:
52
+ variant = next((v for v in entry.variants if v.quant == part["model"]["quant"]), None)
53
+ if variant is not None and variant.weights_bytes > 0:
54
+ fraction = entry.decode_fraction if 0 < entry.decode_fraction <= 1.0 else 1.0
55
+ return int(variant.weights_bytes * fraction)
56
+ parts = llm_parts(part)
57
+ if parts.get("weights", 0) > 0:
58
+ return parts["weights"]
59
+ downloaded = _int(part["model"].get("download_bytes"))
60
+ return downloaded if downloaded > 0 else None
@@ -16,7 +16,7 @@ from collections.abc import Mapping, Sequence
16
16
  from pathlib import Path
17
17
  from typing import Any, TypedDict
18
18
 
19
- from localmodels import stack_lifecycle
19
+ from localmodels import nvml_ctypes, stack_lifecycle
20
20
  from localmodels.records import Plan
21
21
 
22
22
  PROC = Path("/proc")
@@ -77,6 +77,9 @@ def parse_smi(text: str) -> dict[int, int]:
77
77
 
78
78
 
79
79
  def gpu_by_pid() -> dict[int, int] | None:
80
+ nvml_map = nvml_ctypes.read_process_vram()
81
+ if nvml_map is not None:
82
+ return nvml_map
80
83
  smi = shutil.which("nvidia-smi")
81
84
  if smi is None:
82
85
  return None
@@ -7,14 +7,17 @@ from typing import TypedDict
7
7
  from localmodels import hosts
8
8
  from localmodels import stack_journal as journal
9
9
  from localmodels import stack_view_apply as running
10
+ from localmodels.host_sensors import HostSensors
10
11
  from localmodels.stack_plan import Hardware, StackPlan, command
11
12
  from localmodels.stack_view_events import Event
12
13
  from localmodels.stack_view_gpu import GpuLoad
13
14
  from localmodels.stack_view_measure import Measured, MeasuredRow
14
15
  from localmodels.stack_view_slots import Slot
15
16
  from localmodels.stack_view_words import say
17
+ from localmodels.telemetry_math import WaterfallEntry
16
18
 
17
19
  SCHEMA = "localmodels.stack-view/v1"
20
+ SCHEMA_VERSION = "1.1"
18
21
  GIB = 1 << 30
19
22
  METRICS_BYTES = 256 * 1024 # a llama-server /metrics page is a few KiB
20
23
  TASKS = ("llm", "llm_fast", "decision", "embedding", "rerank", "stt", "tts")
@@ -60,8 +63,15 @@ class Memory(TypedDict):
60
63
  segments: list[Segment]
61
64
 
62
65
 
63
- class Counters(TypedDict):
64
- """llama-server's own counters since it started; a client diffs two to get a rate."""
66
+ class _CountersV11(TypedDict, total=False):
67
+ requests_deferred: float | None
68
+ kv_cache_usage_ratio: float | None
69
+ prompt_tokens_seconds: float | None
70
+ predicted_tokens_seconds: float | None
71
+
72
+
73
+ class Counters(_CountersV11):
74
+ """llama-server / PolyStrata counters since start; a client diffs two to get a rate."""
65
75
 
66
76
  prompt_tokens: float
67
77
  prompt_seconds: float
@@ -108,15 +118,31 @@ class Client(TypedDict):
108
118
  model: str
109
119
 
110
120
 
111
- class Gateway(TypedDict):
121
+ class _GatewayV11(TypedDict, total=False):
122
+ in_flight: int
123
+ client_lanes: dict[str, int]
124
+ p50_ttft_ms: Figure
125
+
126
+
127
+ class Gateway(_GatewayV11):
112
128
  kind: str # bifrost | magpie
113
129
  addr: str
114
130
  route: str # the routed model the clients pick
115
131
 
116
132
 
117
- class WhatIf(TypedDict):
118
- """Enough for a slider to reprice the LLM's card at another window: linear in the window,
119
- without the sliding-window cap, so it never under-prices (an upper bound)."""
133
+ class _WhatIfV11(TypedDict, total=False):
134
+ active_weight_bytes: int
135
+ weights_bytes: int
136
+ memory_bw_ceiling_gb_s: float | None
137
+ pcie_bandwidth_gb_s: float | None
138
+ kv_dtype_factors: dict[str, float]
139
+ pool_kind: str # unified | discrete
140
+ host_ram_available_bytes: int
141
+
142
+
143
+ class WhatIf(_WhatIfV11):
144
+ """Enough for a slider and local What-If roofline sandbox to reprice the LLM's card at another
145
+ window/concurrency/KV quant with zero extra round-trips."""
120
146
 
121
147
  gpu: int
122
148
  window: int
@@ -145,7 +171,22 @@ def next_steps() -> list[Step]:
145
171
  return [{"command": f"{command()} {sub}", "why": say(f"next.{key}")} for sub, key in steps]
146
172
 
147
173
 
148
- class StackView(TypedDict):
174
+ class _StackViewV11(TypedDict, total=False):
175
+ schema_version: str # "1.1"
176
+ sensors: HostSensors
177
+ effective_decode_bw_gb_s: Figure
178
+ memory_bw_ceiling_gb_s: Figure
179
+ bottleneck: str # memory_bw_bound | compute_bound | io_bound | balanced | idle
180
+ waterfall: list[WaterfallEntry]
181
+ p50_ttft_ms: Figure
182
+ prefix_hit_pct: Figure
183
+ requests_deferred: Figure
184
+ kv_cache_usage_ratio: Figure
185
+ in_flight: int
186
+ client_lanes: dict[str, int]
187
+
188
+
189
+ class StackView(_StackViewV11):
149
190
  schema: str
150
191
  generated_at: str
151
192
  source: str # live | demo | empty
@@ -166,7 +207,12 @@ class StackView(TypedDict):
166
207
  gpu_load: list[GpuLoad] # each card's utilization, power and temperature now
167
208
 
168
209
 
169
- class Reading(TypedDict):
210
+ class _ReadingV11(TypedDict, total=False):
211
+ sensors: HostSensors | None
212
+ waterfall: list[WaterfallEntry]
213
+
214
+
215
+ class Reading(_ReadingV11):
170
216
  """What one look at the computer found; ``render`` draws it."""
171
217
 
172
218
  hw: Hardware
@@ -33,7 +33,14 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
33
33
  from pathlib import Path
34
34
  from urllib.parse import parse_qs, urlsplit
35
35
 
36
- from localmodels import hosts, stack_view, stack_view_demo, stack_view_sandbox, stack_view_text
36
+ from localmodels import (
37
+ hosts,
38
+ stack_view,
39
+ stack_view_demo,
40
+ stack_view_sandbox,
41
+ stack_view_text,
42
+ stack_view_tick,
43
+ )
37
44
  from localmodels.stack_plan import Hardware
38
45
  from localmodels.stack_view import Reading
39
46
  from localmodels.stack_view_access import (
@@ -453,6 +460,22 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
453
460
  view.add_argument(
454
461
  "--demo", action="store_true", help="draw a synthetic 24GB + 64GB stack; reads nothing"
455
462
  )
463
+ view.add_argument(
464
+ "--live-tick",
465
+ action="store_true",
466
+ help="with --json: fast single-tick telemetry snapshot using cached static hardware specs",
467
+ )
468
+ view.add_argument(
469
+ "--stream",
470
+ action="store_true",
471
+ help="with --json --live-tick: emit newline-delimited JSON ticks keeping sensors persistent",
472
+ )
473
+ view.add_argument(
474
+ "--ticks",
475
+ type=int,
476
+ default=None,
477
+ help="with --json --live-tick --stream: stop after N ticks (default: run until interrupted)",
478
+ )
456
479
  view.add_argument(
457
480
  "--interval", type=float, default=None, help="seconds between readings (2; demo 0.5)"
458
481
  )
@@ -465,7 +488,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
465
488
 
466
489
 
467
490
  def cli(args: argparse.Namespace) -> int:
468
- interval = args.interval or (0.5 if args.demo else 2.0)
491
+ interval = args.interval if args.interval is not None else (0.5 if args.demo else 2.0)
469
492
  if interval <= 0:
470
493
  raise ValueError("--interval must be greater than 0")
471
494
  read: Callable[[], Reading] = stack_view_demo.reading if args.demo else LiveReader()
@@ -477,7 +500,21 @@ def cli(args: argparse.Namespace) -> int:
477
500
  raise ValueError("--lan and --embed-from only go with --web or --app")
478
501
  if args.watch:
479
502
  return stack_view_text.watch(lambda: stack_view.render(read()), interval)
480
- view = stack_view.render(read())
503
+ if getattr(args, "live_tick", False):
504
+ tick_argv = ["--json", "--live-tick"]
505
+ if args.demo:
506
+ tick_argv.append("--demo")
507
+ if getattr(args, "stream", False):
508
+ tick_argv.append("--stream")
509
+ if args.interval is not None:
510
+ tick_argv.extend(["--interval", str(args.interval)])
511
+ if getattr(args, "ticks", None) is not None:
512
+ tick_argv.extend(["--ticks", str(args.ticks)])
513
+ if args.json:
514
+ return stack_view_tick.cli(tick_argv)
515
+ view = stack_view_demo.view() if args.demo else stack_view_tick.collect_live_tick()
516
+ else:
517
+ view = stack_view.render(read())
481
518
  if args.json:
482
519
  json.dump(view, sys.stdout, ensure_ascii=False, indent=1)
483
520
  sys.stdout.write("\n")