@simplexai/localmodels-linux-arm64 0.1.0-dev.104 → 0.1.0-dev.105

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 (81) hide show
  1. package/README.md +1 -1
  2. package/bootstrap.identity +1 -1
  3. package/bootstrap.sha256 +80 -78
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +204 -86
  6. package/modules/localmodels/apple_sensors.py +23 -0
  7. package/modules/localmodels/approval.py +25 -2
  8. package/modules/localmodels/catalog.json +454 -31
  9. package/modules/localmodels/catalog.py +11 -0
  10. package/modules/localmodels/catalog_recipes.py +61 -3
  11. package/modules/localmodels/cli_help.py +10 -0
  12. package/modules/localmodels/cli_parser.py +313 -230
  13. package/modules/localmodels/component.py +20 -2
  14. package/modules/localmodels/custom_probe.py +4 -2
  15. package/modules/localmodels/deploy.py +11 -1
  16. package/modules/localmodels/engine_adapters/suite_plan.py +21 -21
  17. package/modules/localmodels/host_sensors.py +25 -2
  18. package/modules/localmodels/hosts.py +26 -5
  19. package/modules/localmodels/library_cli.py +34 -16
  20. package/modules/localmodels/library_custom.py +9 -1
  21. package/modules/localmodels/library_direct.py +41 -1
  22. package/modules/localmodels/library_jobs.py +23 -4
  23. package/modules/localmodels/library_model.py +146 -1
  24. package/modules/localmodels/library_order.py +175 -69
  25. package/modules/localmodels/library_poly.py +42 -11
  26. package/modules/localmodels/library_presentation.py +485 -0
  27. package/modules/localmodels/library_pricing.py +3 -1
  28. package/modules/localmodels/library_serve.py +208 -3
  29. package/modules/localmodels/library_state.py +47 -10
  30. package/modules/localmodels/library_status.py +29 -16
  31. package/modules/localmodels/llm_rank.py +9 -3
  32. package/modules/localmodels/plan_envelope.py +11 -2
  33. package/modules/localmodels/probe.py +34 -7
  34. package/modules/localmodels/quant_formats.py +9 -2
  35. package/modules/localmodels/records.py +19 -2
  36. package/modules/localmodels/remote_ops_verify.py +91 -24
  37. package/modules/localmodels/runtime_index.py +303 -0
  38. package/modules/localmodels/setup_inspection.py +22 -3
  39. package/modules/localmodels/speech_cli.py +20 -14
  40. package/modules/localmodels/speech_serve.py +9 -2
  41. package/modules/localmodels/speech_server.py +3 -0
  42. package/modules/localmodels/stack_args.py +270 -139
  43. package/modules/localmodels/stack_auto.py +90 -5
  44. package/modules/localmodels/stack_cli.py +117 -116
  45. package/modules/localmodels/stack_compose.py +5 -1
  46. package/modules/localmodels/stack_debug.py +14 -4
  47. package/modules/localmodels/stack_down.py +2 -0
  48. package/modules/localmodels/stack_hardware.py +14 -12
  49. package/modules/localmodels/stack_mlx.py +8 -1
  50. package/modules/localmodels/stack_picks.py +19 -20
  51. package/modules/localmodels/stack_plan.py +3 -2
  52. package/modules/localmodels/stack_review.py +28 -7
  53. package/modules/localmodels/stack_suite.py +11 -9
  54. package/modules/localmodels/stack_up.py +2 -0
  55. package/modules/localmodels/stack_view.py +180 -35
  56. package/modules/localmodels/stack_view_demo.py +2 -0
  57. package/modules/localmodels/stack_view_gpu.py +36 -2
  58. package/modules/localmodels/stack_view_schema.py +26 -3
  59. package/modules/localmodels/stack_view_slots.py +3 -1
  60. package/modules/localmodels/stack_view_telemetry.py +90 -4
  61. package/modules/localmodels/stack_view_tick.py +246 -40
  62. package/modules/localmodels/stack_view_words.py +7 -0
  63. package/modules/localmodels/stack_whatif_html.py +9 -12
  64. package/modules/localmodels/suite.py +129 -2
  65. package/modules/localmodels/telemetry_math.py +458 -18
  66. package/modules/localmodels/transport.py +8 -1
  67. package/modules/localmodels/tts_cli.py +24 -20
  68. package/modules/localmodels/tts_serve.py +9 -2
  69. package/modules/localmodels/tts_sidecar.py +3 -0
  70. package/modules/localmodels/web/whatif/app.js +1 -1
  71. package/modules/localmodels/web/whatif/sim.js +8 -14
  72. package/modules/localmodels/win_probe.py +89 -16
  73. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/METADATA +1 -1
  74. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +76 -74
  75. package/package.json +1 -1
  76. package/tool.json +1 -1
  77. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
  78. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
  79. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/LICENSE +0 -0
  80. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/NOTICE +0 -0
  81. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -50,6 +50,17 @@ def _figure(value: float | None, basis: str, note: str, *, allow_zero: bool = Fa
50
50
  return {"value": round(value, 1), "basis": basis, "note": note}
51
51
 
52
52
 
53
+ def _first_counter_value(comps: list[Component], key: str) -> float | None:
54
+ for comp in comps:
55
+ counters = comp["perf"]["counters"]
56
+ if counters is None:
57
+ continue
58
+ val = counters.get(key)
59
+ if isinstance(val, int | float) and not isinstance(val, bool) and math.isfinite(val):
60
+ return float(val)
61
+ return None
62
+
63
+
53
64
  def summary(
54
65
  reading: Reading,
55
66
  comps: list[Component],
@@ -58,7 +69,9 @@ def summary(
58
69
  ) -> dict[str, Any]:
59
70
  """Derive v1.1 additive telemetry fields for ``stack_view.render``."""
60
71
  hw, plan, source = reading["hw"], reading["plan"], reading["source"]
61
- llm_comp = next((c for c in comps if c["id"] == "llm"), None)
72
+ llm_comp = next((c for c in comps if c["id"] == "llm"), None) or next(
73
+ (c for c in comps if c["id"].startswith("library:")), None
74
+ )
62
75
  all_slots = [s for slot_list in reading["slots"].values() for s in slot_list]
63
76
  waterfall: list[WaterfallEntry] = list(reading.get("waterfall") or [])
64
77
  if not waterfall and reading["events"]:
@@ -77,7 +90,9 @@ def summary(
77
90
 
78
91
  client_lanes = telemetry_math.client_lanes(waterfall, in_flight)
79
92
 
80
- active_bytes = active_weight_bytes(plan["llm"]) if plan is not None else None
93
+ lib_parts = reading.get("library_parts") or []
94
+ primary_llm_part = plan["llm"] if plan is not None else (lib_parts[0][1] if lib_parts else None)
95
+ active_bytes = active_weight_bytes(primary_llm_part) if primary_llm_part is not None else None
81
96
  decode_fig = llm_comp["perf"]["decode_tok_s"] if llm_comp is not None else None
82
97
  eff_bw = cast(Figure, telemetry_math.effective_decode_bw_gb_s(decode_fig, active_bytes))
83
98
  primary_gpu = llm_comp["gpu"] if llm_comp is not None else (gpus[0]["index"] if gpus else None)
@@ -131,11 +146,23 @@ def summary(
131
146
  if llm_comp is not None and llm_comp["perf"]["counters"] is not None
132
147
  else None
133
148
  )
149
+ kv_from_slots = False
150
+ if kv_val is None and llm_comp is not None:
151
+ llm_slots = llm_comp.get("live_slots") or all_slots
152
+ kv_val = telemetry_math.kv_cache_usage_ratio_from_slots(
153
+ llm_slots, pool_capacity=llm_comp.get("window")
154
+ )
155
+ kv_from_slots = kv_val is not None
156
+ kv_note = (
157
+ say("fig.demo")
158
+ if source == "demo"
159
+ else (say("fig.kv_ratio.slots") if kv_from_slots else say("fig.kv_ratio.live"))
160
+ )
134
161
  kv_ratio: Figure = (
135
162
  {
136
163
  "value": round(float(kv_val), 3),
137
164
  "basis": live_basis,
138
- "note": say("fig.demo") if source == "demo" else say("fig.kv_ratio.live"),
165
+ "note": kv_note,
139
166
  }
140
167
  if kv_val is not None and math.isfinite(kv_val) and kv_val >= 0
141
168
  else _figure(None, "none", say("fig.kv_ratio.none"))
@@ -145,10 +172,66 @@ def summary(
145
172
  Figure,
146
173
  telemetry_math.p50_ttft_ms(waterfall, now=reading["generated_at"], source=source),
147
174
  )
175
+ all_counters = [c["perf"]["counters"] for c in comps if c["perf"]["counters"] is not None]
148
176
  prefix_hit = cast(
149
177
  Figure,
150
- telemetry_math.prefix_hit_pct(waterfall, all_slots, source=source),
178
+ telemetry_math.prefix_hit_pct(waterfall, all_slots, counters=all_counters, source=source),
179
+ )
180
+
181
+ spec_val = (
182
+ telemetry_math.spec_decode_acceptance_pct(llm_comp["perf"]["counters"])
183
+ if llm_comp is not None and llm_comp["perf"]["counters"] is not None
184
+ else None
151
185
  )
186
+ if spec_val is None:
187
+ spec_val = _first_counter_value(comps, "spec_decode_acceptance_pct")
188
+ spec_accept = (
189
+ _figure(
190
+ spec_val,
191
+ live_basis,
192
+ say("fig.demo") if source == "demo" else say("fig.spec_accept.live"),
193
+ allow_zero=True,
194
+ )
195
+ if spec_val is not None
196
+ else _figure(None, "none", say("fig.spec_accept.none"))
197
+ )
198
+
199
+ expert_val = (
200
+ llm_comp["perf"]["counters"].get("expert_cache_hit_pct")
201
+ if llm_comp is not None and llm_comp["perf"]["counters"] is not None
202
+ else None
203
+ )
204
+ if expert_val is None:
205
+ expert_val = _first_counter_value(comps, "expert_cache_hit_pct")
206
+ expert_hit = (
207
+ _figure(
208
+ float(expert_val),
209
+ live_basis,
210
+ say("fig.demo") if source == "demo" else say("fig.expert_hit.live"),
211
+ allow_zero=True,
212
+ )
213
+ if expert_val is not None
214
+ else _figure(None, "none", say("fig.expert_hit.none"))
215
+ )
216
+
217
+ pcie_val = (
218
+ llm_comp["perf"]["counters"].get("pcie_share_pct")
219
+ if llm_comp is not None and llm_comp["perf"]["counters"] is not None
220
+ else None
221
+ )
222
+ if pcie_val is None:
223
+ pcie_val = _first_counter_value(comps, "pcie_share_pct")
224
+ pcie_share = (
225
+ _figure(
226
+ float(pcie_val),
227
+ live_basis,
228
+ say("fig.demo") if source == "demo" else say("fig.pcie_share.live"),
229
+ allow_zero=True,
230
+ )
231
+ if pcie_val is not None
232
+ else _figure(None, "none", say("fig.pcie_share.none"))
233
+ )
234
+
152
235
  return {
153
236
  "effective_decode_bw_gb_s": eff_bw,
154
237
  "memory_bw_ceiling_gb_s": bw_ceiling,
@@ -158,6 +241,9 @@ def summary(
158
241
  "prefix_hit_pct": prefix_hit,
159
242
  "requests_deferred": requests_deferred,
160
243
  "kv_cache_usage_ratio": kv_ratio,
244
+ "spec_decode_acceptance_pct": spec_accept,
245
+ "expert_cache_hit_pct": expert_hit,
246
+ "pcie_share_pct": pcie_share,
161
247
  "in_flight": in_flight,
162
248
  "client_lanes": client_lanes,
163
249
  }
@@ -127,6 +127,14 @@ def _state_stamp(state_root: Path) -> list[float]:
127
127
  stamps.append(target.stat().st_mtime)
128
128
  except OSError:
129
129
  stamps.append(0.0)
130
+ lib_dir = state_root / "library" / "models"
131
+ try:
132
+ dir_mtime = lib_dir.stat().st_mtime
133
+ files = list(lib_dir.glob("*.json"))
134
+ max_file_mtime = max((p.stat().st_mtime for p in files), default=0.0)
135
+ stamps.extend([dir_mtime, max_file_mtime, float(len(files))])
136
+ except OSError:
137
+ stamps.extend([0.0, 0.0, 0.0])
130
138
  return stamps
131
139
 
132
140
 
@@ -220,18 +228,21 @@ def _refresh_ram_segments(ram_doc: dict[str, Any], avail_bytes: int) -> None:
220
228
  seg["bytes"] = max(0, -free)
221
229
 
222
230
 
231
+ def _is_llm_endpoint(ep: dict[str, Any]) -> bool:
232
+ cid = str(ep.get("id") or "")
233
+ return bool(ep.get("is_llm")) or cid in ("llm", "llm_fast") or cid.startswith("library:")
234
+
235
+
223
236
  def _apply_component_metrics(
224
- comp: dict[str, Any], counters: dict[str, Any]
225
- ) -> tuple[int, float | None, float | None]:
237
+ comp: dict[str, Any],
238
+ counters: dict[str, Any],
239
+ *,
240
+ prev_counters: dict[str, Any] | None = None,
241
+ ) -> tuple[int, float | None, float | None, bool]:
226
242
  comp["state"] = "serving"
227
243
  comp["health"] = "ok"
228
244
  comp["perf"]["counters"] = counters
229
- p_tok = counters["prompt_tokens"] or 0.0
230
- p_sec = counters["prompt_seconds"] or 0.0
231
- d_tok = counters["predicted_tokens"] or 0.0
232
- d_sec = counters["predicted_seconds"] or 0.0
233
- p_rate = p_tok / p_sec if p_tok > 0 and p_sec > 0 else counters["prompt_tokens_seconds"]
234
- d_rate = d_tok / d_sec if d_tok > 0 and d_sec > 0 else counters["predicted_tokens_seconds"]
245
+ p_rate, d_rate, active_delta = telemetry_math.counter_delta_rates(prev_counters, counters)
235
246
  if p_rate and p_rate > 0:
236
247
  comp["perf"]["prefill_tok_s"] = {
237
248
  "value": round(p_rate, 1),
@@ -250,10 +261,11 @@ def _apply_component_metrics(
250
261
  )
251
262
  kv_ratio = (
252
263
  float(counters["kv_cache_usage_ratio"])
253
- if comp.get("id") == "llm" and counters["kv_cache_usage_ratio"] is not None
264
+ if (comp.get("id") == "llm" or str(comp.get("id") or "").startswith("library:"))
265
+ and counters["kv_cache_usage_ratio"] is not None
254
266
  else None
255
267
  )
256
- return processing, deferred, kv_ratio
268
+ return processing, deferred, kv_ratio, active_delta
257
269
 
258
270
 
259
271
  def _mark_component_unreachable(comp: dict[str, Any], ep: dict[str, Any]) -> None:
@@ -273,21 +285,55 @@ def _mark_component_unreachable(comp: dict[str, Any], ep: dict[str, Any]) -> Non
273
285
  port = int(ep.get("port") or 0)
274
286
  deploy_dir = str(ep.get("deploy_dir") or "")
275
287
  health_path = str(ep.get("health_path") or "/health")
276
- if task in _METRICS_TASKS or _loopback_get(port, deploy_dir, health_path, 4096) is None:
288
+ if (
289
+ task in _METRICS_TASKS
290
+ or _is_llm_endpoint(ep)
291
+ or _loopback_get(port, deploy_dir, health_path, 4096) is None
292
+ ):
277
293
  comp["state"] = "failed"
278
294
  comp["health"] = "unreachable"
279
295
 
280
296
 
281
297
  def _refresh_components(
282
- view: dict[str, Any], endpoints: list[dict[str, Any]]
283
- ) -> tuple[int, list[dict[str, Any]], float | None, float | None]:
298
+ view: dict[str, Any],
299
+ endpoints: list[dict[str, Any]],
300
+ telemetry_state: dict[str, Any] | None = None,
301
+ *,
302
+ now_mono: float | None = None,
303
+ ) -> tuple[
304
+ int,
305
+ list[dict[str, Any]],
306
+ float | None,
307
+ float | None,
308
+ list[dict[str, Any]],
309
+ dict[str, Any],
310
+ bool,
311
+ ]:
284
312
  by_id = {c["id"]: c for c in view.get("components", []) if isinstance(c, dict)}
313
+ prev_tel = telemetry_state if isinstance(telemetry_state, dict) else {}
314
+ raw_prev_counters = prev_tel.get("counters")
315
+ prev_counters_map: dict[str, Any] = (
316
+ raw_prev_counters if isinstance(raw_prev_counters, dict) else {}
317
+ )
318
+ same_proc = prev_tel.get("pid") == os.getpid()
319
+ raw_prev_slots = prev_tel.get("slots")
320
+ prev_slots_map: dict[str, Any] = (
321
+ raw_prev_slots if same_proc and isinstance(raw_prev_slots, dict) else {}
322
+ )
323
+ now_t = time.monotonic() if now_mono is None else now_mono
324
+
285
325
  all_slots: list[dict[str, Any]] = []
326
+ all_counters: list[dict[str, Any]] = []
327
+ next_counters_map: dict[str, Any] = {}
328
+ next_slots_map: dict[str, Any] = {}
286
329
  processing_sum = 0
287
330
  deferred_sum: float | None = None
288
331
  kv_ratio: float | None = None
332
+ active_tick_delta = False
333
+
289
334
  for ep in endpoints:
290
- comp = by_id.get(ep.get("id"))
335
+ cid = str(ep.get("id") or "")
336
+ comp = by_id.get(cid)
291
337
  if comp is None:
292
338
  continue
293
339
  port = int(ep.get("port") or 0)
@@ -300,16 +346,25 @@ def _refresh_components(
300
346
  if body is not None
301
347
  else None
302
348
  )
349
+ prev_c = (
350
+ prev_counters_map.get(cid) if isinstance(prev_counters_map.get(cid), dict) else None
351
+ )
352
+ comp_counter_delta = False
303
353
  if counters is not None:
304
- proc, deferred, comp_kv = _apply_component_metrics(comp, counters)
354
+ proc, deferred, comp_kv, comp_counter_delta = _apply_component_metrics(
355
+ comp, counters, prev_counters=prev_c
356
+ )
357
+ active_tick_delta = active_tick_delta or comp_counter_delta
358
+ next_counters_map[cid] = counters
359
+ all_counters.append(counters)
305
360
  processing_sum += proc
306
361
  if deferred is not None:
307
362
  deferred_sum = (deferred_sum or 0.0) + deferred
308
- if comp_kv is not None:
363
+ if comp_kv is not None and (cid == "llm" or kv_ratio is None):
309
364
  kv_ratio = comp_kv
310
365
  else:
311
366
  _mark_component_unreachable(comp, ep)
312
- if ep.get("id") in ("llm", "llm_fast"):
367
+ if _is_llm_endpoint(ep):
313
368
  if comp.get("state") != "serving":
314
369
  comp["live_slots"] = None
315
370
  continue
@@ -322,16 +377,54 @@ def _refresh_components(
322
377
  else None
323
378
  )
324
379
  if parsed is not None:
325
- comp["live_slots"] = parsed
326
- all_slots.extend(cast(list[dict[str, Any]], parsed))
380
+ prev_s = (
381
+ prev_slots_map.get(cid) if isinstance(prev_slots_map.get(cid), dict) else None
382
+ )
383
+ updated_slots, next_s, slot_delta = telemetry_math.apply_slot_deltas(
384
+ parsed, prev_s, now_t
385
+ )
386
+ next_slots_map[cid] = next_s
387
+ comp["live_slots"] = updated_slots
388
+ all_slots.extend(updated_slots)
389
+ if slot_delta:
390
+ active_tick_delta = True
391
+ if not comp_counter_delta:
392
+ slot_rate_sum = sum(
393
+ float(s["tok_s"])
394
+ for s in updated_slots
395
+ if s.get("busy") and isinstance(s.get("tok_s"), int | float)
396
+ )
397
+ if slot_rate_sum > 0:
398
+ comp["perf"]["decode_tok_s"] = {
399
+ "value": round(slot_rate_sum, 1),
400
+ "basis": "live",
401
+ "note": say("fig.decode.live"),
402
+ }
327
403
  else:
328
404
  comp["live_slots"] = None
329
- return processing_sum, all_slots, deferred_sum, kv_ratio
405
+ next_tel = {"pid": os.getpid(), "counters": next_counters_map, "slots": next_slots_map}
406
+ return (
407
+ processing_sum,
408
+ all_slots,
409
+ deferred_sum,
410
+ kv_ratio,
411
+ all_counters,
412
+ next_tel,
413
+ active_tick_delta,
414
+ )
415
+
416
+
417
+ def _opt_pct_figure(value: float | None, live_key: str, none_key: str) -> dict[str, Any]:
418
+ if value is not None and math.isfinite(value) and value >= 0:
419
+ return {"value": round(float(value), 1), "basis": "live", "note": say(live_key)}
420
+ return {"value": None, "basis": "none", "note": say(none_key)}
330
421
 
331
422
 
332
423
  def _apply_warm_tick(
333
- cache: dict[str, Any], sensor_state: dict[str, Any]
334
- ) -> tuple[dict[str, Any], dict[str, Any]]:
424
+ cache: dict[str, Any],
425
+ sensor_state: dict[str, Any],
426
+ telemetry_state: dict[str, Any] | None = None,
427
+ ) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
335
428
  view: dict[str, Any] = copy.deepcopy(cache["base_view"])
336
429
  view["generated_at"] = _now_iso()
337
430
  gpu_loads = stack_view_gpu.read() if view.get("gpus") else []
@@ -343,6 +436,9 @@ def _apply_warm_tick(
343
436
  used = row.get("vram_used_bytes") if row else None
344
437
  if isinstance(used, int):
345
438
  _refresh_gpu_segments(gpu_doc, used)
439
+ spill = row.get("wddm_shared_spill_bytes") if row else None
440
+ if isinstance(spill, int) and not isinstance(spill, bool) and spill >= 0:
441
+ gpu_doc["wddm_shared_spill_bytes"] = spill
346
442
 
347
443
  avail_ram = host_sensors.read_live_ram_available_bytes()
348
444
  if avail_ram is not None and isinstance(view.get("ram"), dict):
@@ -351,7 +447,20 @@ def _apply_warm_tick(
351
447
  view["what_if"]["host_ram_available_bytes"] = avail_ram
352
448
 
353
449
  endpoints = cache.get("endpoints") or []
354
- processing_sum, all_slots, deferred_sum, kv_ratio = _refresh_components(view, endpoints)
450
+ prev_tel = telemetry_state if isinstance(telemetry_state, dict) else {}
451
+ raw_prev_counters = prev_tel.get("counters")
452
+ prev_counters_map: dict[str, Any] = (
453
+ raw_prev_counters if isinstance(raw_prev_counters, dict) else {}
454
+ )
455
+ (
456
+ processing_sum,
457
+ all_slots,
458
+ deferred_sum,
459
+ kv_ratio,
460
+ all_counters,
461
+ next_tel,
462
+ active_tick_delta,
463
+ ) = _refresh_components(view, endpoints, prev_tel)
355
464
  liveness = {
356
465
  c["id"]: ("active" if c["state"] == "serving" else c["state"], c["health"])
357
466
  for c in view.get("components", [])
@@ -369,7 +478,10 @@ def _apply_warm_tick(
369
478
  view["in_flight"] = in_flight
370
479
  view["client_lanes"] = telemetry_math.client_lanes(waterfall, in_flight)
371
480
 
372
- llm_comp = next((c for c in view.get("components", []) if c.get("id") == "llm"), None)
481
+ comps = [c for c in view.get("components", []) if isinstance(c, dict)]
482
+ llm_comp = next((c for c in comps if c.get("id") == "llm"), None) or next(
483
+ (c for c in comps if str(c.get("id") or "").startswith("library:")), None
484
+ )
373
485
  decode_fig = llm_comp["perf"]["decode_tok_s"] if llm_comp else None
374
486
  active_bytes = cache.get("active_weight_bytes")
375
487
  eff_bw = telemetry_math.effective_decode_bw_gb_s(
@@ -396,6 +508,7 @@ def _apply_warm_tick(
396
508
  gpu_util_pct=gpu_row["util_pct"] if gpu_row else None,
397
509
  mem_ctrl_util_pct=gpu_row.get("mem_ctrl_util_pct") if gpu_row else None,
398
510
  disk_read_mb_s=sensors["disk"]["read_mb_s"]["value"],
511
+ active_tick_delta=active_tick_delta,
399
512
  )
400
513
  view["requests_deferred"] = (
401
514
  {
@@ -406,20 +519,94 @@ def _apply_warm_tick(
406
519
  if deferred_sum is not None
407
520
  else {"value": None, "basis": "none", "note": say("fig.deferred.none")}
408
521
  )
522
+ kv_from_slots = False
523
+ if kv_ratio is None and llm_comp is not None:
524
+ llm_slots = llm_comp.get("live_slots") or all_slots
525
+ kv_ratio = telemetry_math.kv_cache_usage_ratio_from_slots(
526
+ llm_slots, pool_capacity=llm_comp.get("window")
527
+ )
528
+ kv_from_slots = kv_ratio is not None
409
529
  view["kv_cache_usage_ratio"] = (
410
530
  {
411
531
  "value": round(kv_ratio, 3),
412
532
  "basis": "live",
413
- "note": say("fig.kv_ratio.live"),
533
+ "note": say("fig.kv_ratio.slots") if kv_from_slots else say("fig.kv_ratio.live"),
414
534
  }
415
535
  if kv_ratio is not None
416
536
  else {"value": None, "basis": "none", "note": say("fig.kv_ratio.none")}
417
537
  )
418
- view["prefix_hit_pct"] = telemetry_math.prefix_hit_pct(waterfall, all_slots)
538
+ view["prefix_hit_pct"] = telemetry_math.prefix_hit_pct(
539
+ waterfall, all_slots, counters=all_counters
540
+ )
541
+
542
+ llm_cid = str(llm_comp.get("id") or "") if llm_comp is not None else ""
543
+ llm_curr_c = llm_comp["perf"].get("counters") if llm_comp is not None else None
544
+ llm_prev_c = (
545
+ prev_counters_map.get(llm_cid)
546
+ if llm_cid and isinstance(prev_counters_map.get(llm_cid), dict)
547
+ else None
548
+ )
549
+ spec_val = telemetry_math.spec_decode_acceptance_pct(llm_curr_c, llm_prev_c)
550
+ if spec_val is None:
551
+ spec_val = next(
552
+ (
553
+ v
554
+ for c in all_counters
555
+ if (v := telemetry_math.spec_decode_acceptance_pct(c)) is not None
556
+ ),
557
+ None,
558
+ )
559
+ view["spec_decode_acceptance_pct"] = _opt_pct_figure(
560
+ spec_val, "fig.spec_accept.live", "fig.spec_accept.none"
561
+ )
562
+ expert_val = llm_curr_c.get("expert_cache_hit_pct") if isinstance(llm_curr_c, dict) else None
563
+ if expert_val is None:
564
+ expert_val = next(
565
+ (
566
+ float(c["expert_cache_hit_pct"])
567
+ for c in all_counters
568
+ if isinstance(c.get("expert_cache_hit_pct"), int | float)
569
+ ),
570
+ None,
571
+ )
572
+ view["expert_cache_hit_pct"] = _opt_pct_figure(
573
+ expert_val, "fig.expert_hit.live", "fig.expert_hit.none"
574
+ )
575
+ pcie_val = llm_curr_c.get("pcie_share_pct") if isinstance(llm_curr_c, dict) else None
576
+ if pcie_val is None:
577
+ pcie_val = next(
578
+ (
579
+ float(c["pcie_share_pct"])
580
+ for c in all_counters
581
+ if isinstance(c.get("pcie_share_pct"), int | float)
582
+ ),
583
+ None,
584
+ )
585
+ view["pcie_share_pct"] = _opt_pct_figure(pcie_val, "fig.pcie_share.live", "fig.pcie_share.none")
586
+
419
587
  if isinstance(view.get("gateway"), dict):
420
588
  view["gateway"]["in_flight"] = in_flight
421
589
  view["gateway"]["client_lanes"] = view["client_lanes"]
422
- return view, next_sensor_state
590
+ return view, next_sensor_state, next_tel
591
+
592
+
593
+ def _seed_telemetry_state(view: dict[str, Any], now_mono: float) -> dict[str, Any]:
594
+ counters_map: dict[str, Any] = {}
595
+ slots_map: dict[str, Any] = {}
596
+ for comp in view.get("components", []):
597
+ if not isinstance(comp, dict):
598
+ continue
599
+ cid = str(comp.get("id") or "")
600
+ if not cid:
601
+ continue
602
+ perf = comp.get("perf")
603
+ if isinstance(perf, dict) and isinstance(perf.get("counters"), dict):
604
+ counters_map[cid] = perf["counters"]
605
+ live_slots = comp.get("live_slots")
606
+ if isinstance(live_slots, list):
607
+ _, seeded_slots, _ = telemetry_math.apply_slot_deltas(live_slots, None, now_mono)
608
+ slots_map[cid] = seeded_slots
609
+ return {"pid": os.getpid(), "counters": counters_map, "slots": slots_map}
423
610
 
424
611
 
425
612
  def _cold_build(
@@ -429,24 +616,36 @@ def _cold_build(
429
616
 
430
617
  _, plan = stack_run.latest()
431
618
  reading = stack_view.read_live()
619
+ now_mono = time.monotonic()
432
620
  sensors, next_sensor_state = host_sensors.collect(
433
621
  liveness=reading["liveness"] or None, prev_state=prev_sensor_state
434
622
  )
435
623
  reading["sensors"] = sensors
436
624
  view = cast(dict[str, Any], stack_view.render(reading))
437
625
  endpoints: list[dict[str, Any]] = []
438
- active_bytes: int | None = None
439
- if plan is not None:
440
- active_bytes = stack_view_llm.active_weight_bytes(plan["llm"])
441
- for task, part in stack_view.parts_of(plan):
442
- endpoints.append(
443
- {
444
- "id": task,
445
- "port": part["service"]["port"],
446
- "deploy_dir": part["service"]["deploy_dir"],
447
- "health_path": part["endpoint"].get("health", "/health"),
448
- }
449
- )
626
+ lib_parts = list(reading.get("library_parts") or [])
627
+ all_parts = [*(stack_view.parts_of(plan) if plan is not None else []), *lib_parts]
628
+ primary_llm_part = plan["llm"] if plan is not None else (lib_parts[0][1] if lib_parts else None)
629
+ active_bytes = (
630
+ stack_view_llm.active_weight_bytes(primary_llm_part)
631
+ if primary_llm_part is not None
632
+ else None
633
+ )
634
+ for task, part in all_parts:
635
+ endpoints.append(
636
+ {
637
+ "id": task,
638
+ "port": part["service"]["port"],
639
+ "deploy_dir": part["service"]["deploy_dir"],
640
+ "health_path": (
641
+ part["service"].get("health_path")
642
+ or part["endpoint"].get("health_path")
643
+ or part["endpoint"].get("health")
644
+ or "/health"
645
+ ),
646
+ "is_llm": stack_view.is_llm_task(task),
647
+ }
648
+ )
450
649
  now_wall = time.time()
451
650
  cache_doc = {
452
651
  "version": CACHE_VERSION,
@@ -456,6 +655,7 @@ def _cold_build(
456
655
  "endpoints": endpoints,
457
656
  "active_weight_bytes": active_bytes,
458
657
  "sensor_state": next_sensor_state,
658
+ "telemetry_state": _seed_telemetry_state(view, now_mono),
459
659
  }
460
660
  return view, cache_doc
461
661
 
@@ -485,9 +685,15 @@ def _step_live_tick(
485
685
  prev_sensor = (
486
686
  cached["sensor_state"] if cached and isinstance(cached.get("sensor_state"), dict) else {}
487
687
  )
688
+ prev_tel = (
689
+ cached["telemetry_state"]
690
+ if cached and isinstance(cached.get("telemetry_state"), dict)
691
+ else {}
692
+ )
488
693
  if _is_cache_warm(cached, stamp, now_wall, ttl_s) and cached is not None:
489
- view, next_sensor = _apply_warm_tick(cached, prev_sensor)
694
+ view, next_sensor, next_tel = _apply_warm_tick(cached, prev_sensor, prev_tel)
490
695
  cached["sensor_state"] = next_sensor
696
+ cached["telemetry_state"] = next_tel
491
697
  if persist_warm:
492
698
  _save_cache(cache_path, cached)
493
699
  return view, cached
@@ -114,9 +114,16 @@ WORDS: dict[str, str] = {
114
114
  "fig.demo": "Demo data, not a measurement",
115
115
  "fig.gateway": "Request log: the last {n} calls",
116
116
  "fig.kv_ratio.live": "The service's /metrics: live KV cache usage ratio",
117
+ "fig.kv_ratio.slots": "Derived live from /slots token usage against unified KV capacity",
117
118
  "fig.kv_ratio.none": "KV cache usage ratio not reported by the service",
118
119
  "fig.deferred.live": "The service's /metrics: requests deferred waiting for a slot",
119
120
  "fig.deferred.none": "Deferred request count not reported by the service",
121
+ "fig.spec_accept.live": "The service's /metrics: speculative draft token acceptance rate",
122
+ "fig.spec_accept.none": "Speculative decoding counters not reported by the service",
123
+ "fig.expert_hit.live": "PolyStrata /metrics: MoE expert cache hit rate",
124
+ "fig.expert_hit.none": "Expert cache telemetry not reported by the service",
125
+ "fig.pcie_share.live": "PolyStrata /metrics: routed experts served over PCIe",
126
+ "fig.pcie_share.none": "PCIe expert share not reported by the service",
120
127
  "state.undeployed": "not deployed",
121
128
  "alert.down": "{names} is not running",
122
129
  "alert.down.many": "{names} are not running",
@@ -183,9 +183,10 @@ def _bisect_curve(
183
183
  return bands
184
184
 
185
185
 
186
- def _strata_possible(platform: str, cuda: str, vram_used: int, prefer: str) -> bool:
187
- """True only when Strata/PolyStrata can enter selection and read ``ram_total``."""
188
- if prefer != "smartest" or cuda != "13.0":
186
+ def _strata_possible(platform: str, cuda: str, vram_used: int) -> bool:
187
+ """True only when Strata/PolyStrata can enter selection and read ``ram_total`` (under every
188
+ ``--prefer``: concurrent and fastest also weigh full-VRAM-resident PolyStrata recipes)."""
189
+ if cuda != "13.0":
189
190
  return False
190
191
  if platform == "linux" and vram_used >= 1:
191
192
  return False
@@ -273,14 +274,14 @@ def _nvidia_curve_raw(
273
274
  )
274
275
 
275
276
 
276
- def _vram_used_groups(plat: str, vram: int, cuda: str, prefer: str) -> list[tuple[bool, list[int]]]:
277
+ def _vram_used_groups(plat: str, vram: int, cuda: str) -> list[tuple[bool, list[int]]]:
277
278
  """Partition ``VRAM_USED_GIB`` by ``_strata_possible`` so cards can share identical curves."""
278
279
  valid = [vu for vu in VRAM_USED_GIB if vu < vram]
279
280
  if vram < 24:
280
- return [(_strata_possible(plat, cuda, vu, prefer), [vu]) for vu in valid]
281
+ return [(_strata_possible(plat, cuda, vu), [vu]) for vu in valid]
281
282
  by_strata: dict[bool, list[int]] = {}
282
283
  for vu in valid:
283
- by_strata.setdefault(_strata_possible(plat, cuda, vu, prefer), []).append(vu)
284
+ by_strata.setdefault(_strata_possible(plat, cuda, vu), []).append(vu)
284
285
  return list(by_strata.items())
285
286
 
286
287
 
@@ -314,10 +315,6 @@ def _sweep_nvidia_eval_slice(
314
315
  ) -> dict[str, list[list[Any]]]:
315
316
  curves: dict[str, list[list[Any]]] = {}
316
317
  for prefer in SIM_PREFERS:
317
- if prefer != "smartest" and cuda == "13.0":
318
- continue
319
- if prefer == "concurrent" and decision == "auto":
320
- continue
321
318
  best_res = stack_whatif.evaluate(
322
319
  _nvidia_facts(plat, vram, RAM_TIERS_GIB[-1], RAM_TIERS_GIB[-1], cuda, 0),
323
320
  prefer=prefer,
@@ -326,7 +323,7 @@ def _sweep_nvidia_eval_slice(
326
323
  )
327
324
  all_refused = not best_res["ok"]
328
325
  refused_curve: list[list[Any]] = [[0.0, dict(best_res)]]
329
- for strata, group in _vram_used_groups(plat, vram, cuda, prefer):
326
+ for strata, group in _vram_used_groups(plat, vram, cuda):
330
327
  if not strata and cuda == "13.0":
331
328
  continue
332
329
  ram_list: list[int | None] = list(ram_reps) if strata else [None]
@@ -361,7 +358,7 @@ def _sweep_nvidia_lib_slice(
361
358
  def lib_hints(_val: Any) -> tuple[int, ...]:
362
359
  return lib_hint
363
360
 
364
- for strata, group in _vram_used_groups(plat, vram, cuda, "smartest"):
361
+ for strata, group in _vram_used_groups(plat, vram, cuda):
365
362
  if not strata and cuda == "13.0":
366
363
  continue
367
364
  lib_rams: list[int | None] = list(ram_reps) if strata else [None]