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

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 (85) hide show
  1. package/README.md +1 -1
  2. package/bootstrap.identity +1 -1
  3. package/bootstrap.sha256 +84 -82
  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/sidecar_http.py +6 -2
  40. package/modules/localmodels/speech_cli.py +23 -17
  41. package/modules/localmodels/speech_jobs.py +4 -0
  42. package/modules/localmodels/speech_model.py +1 -1
  43. package/modules/localmodels/speech_serve.py +9 -2
  44. package/modules/localmodels/speech_server.py +3 -0
  45. package/modules/localmodels/stack_args.py +270 -139
  46. package/modules/localmodels/stack_auto.py +90 -5
  47. package/modules/localmodels/stack_cli.py +117 -116
  48. package/modules/localmodels/stack_compose.py +5 -1
  49. package/modules/localmodels/stack_debug.py +14 -4
  50. package/modules/localmodels/stack_down.py +2 -0
  51. package/modules/localmodels/stack_hardware.py +14 -12
  52. package/modules/localmodels/stack_mlx.py +8 -1
  53. package/modules/localmodels/stack_picks.py +19 -20
  54. package/modules/localmodels/stack_plan.py +3 -2
  55. package/modules/localmodels/stack_review.py +28 -7
  56. package/modules/localmodels/stack_suite.py +11 -9
  57. package/modules/localmodels/stack_up.py +2 -0
  58. package/modules/localmodels/stack_view.py +180 -35
  59. package/modules/localmodels/stack_view_demo.py +2 -0
  60. package/modules/localmodels/stack_view_gpu.py +36 -2
  61. package/modules/localmodels/stack_view_schema.py +26 -3
  62. package/modules/localmodels/stack_view_slots.py +3 -1
  63. package/modules/localmodels/stack_view_telemetry.py +90 -4
  64. package/modules/localmodels/stack_view_tick.py +246 -40
  65. package/modules/localmodels/stack_view_words.py +7 -0
  66. package/modules/localmodels/stack_whatif_html.py +9 -12
  67. package/modules/localmodels/suite.py +129 -2
  68. package/modules/localmodels/telemetry_math.py +458 -18
  69. package/modules/localmodels/transport.py +8 -1
  70. package/modules/localmodels/tts_cli.py +29 -25
  71. package/modules/localmodels/tts_jobs.py +5 -0
  72. package/modules/localmodels/tts_serve.py +9 -2
  73. package/modules/localmodels/tts_sidecar.py +3 -0
  74. package/modules/localmodels/web/whatif/app.js +1 -1
  75. package/modules/localmodels/web/whatif/sim.js +8 -14
  76. package/modules/localmodels/win_probe.py +89 -16
  77. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/METADATA +1 -1
  78. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/RECORD +80 -78
  79. package/package.json +1 -1
  80. package/tool.json +1 -1
  81. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/WHEEL +0 -0
  82. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/entry_points.txt +0 -0
  83. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/licenses/LICENSE +0 -0
  84. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/licenses/NOTICE +0 -0
  85. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev106.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -288,9 +288,10 @@ def prefix_hit_pct(
288
288
  waterfall: Sequence[WaterfallEntry],
289
289
  slots: Sequence[Mapping[str, Any]] | None = None,
290
290
  *,
291
+ counters: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
291
292
  source: str = "live",
292
293
  ) -> TelemetryFigure:
293
- """Prefix cache hit % from recent waterfall requests or live engine ``/slots`` counters."""
294
+ """Prefix cache hit % from recent waterfall requests, live ``/metrics``, or ``/slots``."""
294
295
  wf_hits: list[float] = []
295
296
  for entry in waterfall:
296
297
  raw_hit = entry.get("cached_prefix_pct")
@@ -305,6 +306,42 @@ def prefix_hit_pct(
305
306
  if source == "demo"
306
307
  else "Mean cached prefix share across recent requests",
307
308
  }
309
+ counter_list: Sequence[Mapping[str, Any]] = (
310
+ [counters] if isinstance(counters, Mapping) else (counters or ())
311
+ )
312
+ m_processed = 0.0
313
+ m_cached = 0.0
314
+ has_metric_cache = False
315
+ for counter in counter_list:
316
+ raw_cached = counter.get("prompt_tokens_cached")
317
+ if (
318
+ isinstance(raw_cached, int | float)
319
+ and not isinstance(raw_cached, bool)
320
+ and math.isfinite(raw_cached)
321
+ and raw_cached >= 0
322
+ ):
323
+ raw_proc = counter.get("prompt_tokens", 0.0)
324
+ proc = (
325
+ float(raw_proc)
326
+ if isinstance(raw_proc, int | float)
327
+ and not isinstance(raw_proc, bool)
328
+ and math.isfinite(raw_proc)
329
+ and raw_proc >= 0
330
+ else 0.0
331
+ )
332
+ has_metric_cache = True
333
+ m_cached += float(raw_cached)
334
+ m_processed += proc
335
+ if has_metric_cache and (m_processed + m_cached) > 0:
336
+ basis = "demo" if source == "demo" else "live"
337
+ pct = min(100.0, max(0.0, (m_cached / (m_processed + m_cached)) * 100.0))
338
+ return {
339
+ "value": round(pct, 1),
340
+ "basis": basis,
341
+ "note": "Demo data, not a measurement"
342
+ if source == "demo"
343
+ else "Cached prompt token ratio from live /metrics",
344
+ }
308
345
  prompt_total = 0
309
346
  cached_total = 0
310
347
  for slot in slots or ():
@@ -329,6 +366,194 @@ def prefix_hit_pct(
329
366
  }
330
367
 
331
368
 
369
+ def kv_cache_usage_ratio_from_slots(
370
+ slots: Sequence[Mapping[str, Any]] | None,
371
+ *,
372
+ pool_capacity: int | None = None,
373
+ ) -> float | None:
374
+ """Derive live KV cache usage ratio (0..1) from ``/slots`` when ``/metrics`` omits it.
375
+
376
+ Under ``--kv-unified`` every slot reports the unified pool capacity as ``n_ctx``; total live
377
+ KV occupancy is ``sum(prompt_tokens + decoded)`` across slots divided by the unified capacity.
378
+ """
379
+ if not slots:
380
+ return None
381
+ used = 0
382
+ max_n_ctx = 0
383
+ for slot in slots:
384
+ ctx = slot.get("n_ctx")
385
+ if isinstance(ctx, int) and not isinstance(ctx, bool) and ctx > max_n_ctx:
386
+ max_n_ctx = ctx
387
+ p = slot.get("prompt_tokens")
388
+ d = slot.get("decoded")
389
+ if isinstance(p, int) and not isinstance(p, bool) and p > 0:
390
+ used += p
391
+ if isinstance(d, int) and not isinstance(d, bool) and d > 0:
392
+ used += d
393
+ cap_override = (
394
+ pool_capacity
395
+ if isinstance(pool_capacity, int)
396
+ and not isinstance(pool_capacity, bool)
397
+ and pool_capacity > 0
398
+ else 0
399
+ )
400
+ capacity = max(max_n_ctx, cap_override)
401
+ if capacity <= 0:
402
+ return None
403
+ return round(min(1.0, max(0.0, used / capacity)), 3)
404
+
405
+
406
+ def _finite_nonneg(value: object) -> float | None:
407
+ if isinstance(value, int | float) and not isinstance(value, bool):
408
+ f = float(value)
409
+ if math.isfinite(f) and f >= 0:
410
+ return f
411
+ return None
412
+
413
+
414
+ def _pct_ratio(numerator: float | None, denominator: float | None) -> float | None:
415
+ if numerator is None or denominator is None or denominator <= 0 or numerator < 0:
416
+ return None
417
+ return round(min(100.0, max(0.0, (numerator / denominator) * 100.0)), 1)
418
+
419
+
420
+ def spec_decode_acceptance_pct(
421
+ curr: Mapping[str, Any] | None,
422
+ prev: Mapping[str, Any] | None = None,
423
+ ) -> float | None:
424
+ """Speculative draft acceptance % (0..100), preferring two-frame counter delta when active."""
425
+ if curr is None:
426
+ return None
427
+ c_draft = _finite_nonneg(curr.get("spec_decode_draft_tokens"))
428
+ c_acc = _finite_nonneg(curr.get("spec_decode_accepted_tokens"))
429
+ if prev is not None and c_draft is not None and c_acc is not None:
430
+ p_draft = _finite_nonneg(prev.get("spec_decode_draft_tokens"))
431
+ p_acc = _finite_nonneg(prev.get("spec_decode_accepted_tokens"))
432
+ if p_draft is not None and p_acc is not None:
433
+ d_draft = c_draft - p_draft
434
+ d_acc = c_acc - p_acc
435
+ if d_draft > 0 and d_acc >= 0:
436
+ return _pct_ratio(d_acc, d_draft)
437
+ cum = _pct_ratio(c_acc, c_draft)
438
+ if cum is not None:
439
+ return cum
440
+ explicit = _finite_nonneg(curr.get("spec_decode_acceptance_pct"))
441
+ return round(min(100.0, explicit), 1) if explicit is not None else None
442
+
443
+
444
+ def counter_delta_rates(
445
+ prev: Mapping[str, Any] | None,
446
+ curr: Mapping[str, Any],
447
+ ) -> tuple[float | None, float | None, bool]:
448
+ """Compute ``(prefill_tok_s, decode_tok_s, active_tick_delta)`` from two consecutive frames.
449
+
450
+ Uses instantaneous ``Δtokens / Δseconds`` whenever both counters advance monotonically;
451
+ falls back cleanly on first frame, counter reset (negative delta), or idle ticks.
452
+ """
453
+ p_tok = _finite_nonneg(curr.get("prompt_tokens")) or 0.0
454
+ p_sec = _finite_nonneg(curr.get("prompt_seconds")) or 0.0
455
+ d_tok = _finite_nonneg(curr.get("predicted_tokens")) or 0.0
456
+ d_sec = _finite_nonneg(curr.get("predicted_seconds")) or 0.0
457
+ pre_rate: float | None = None
458
+ dec_rate: float | None = None
459
+ active = False
460
+
461
+ if prev is not None:
462
+ prev_p_tok = _finite_nonneg(prev.get("prompt_tokens"))
463
+ prev_p_sec = _finite_nonneg(prev.get("prompt_seconds"))
464
+ if prev_p_tok is not None and prev_p_sec is not None:
465
+ dp_tok = p_tok - prev_p_tok
466
+ dp_sec = p_sec - prev_p_sec
467
+ if dp_tok > 0 and dp_sec > 0:
468
+ pre_rate = dp_tok / dp_sec
469
+ active = True
470
+
471
+ prev_d_tok = _finite_nonneg(prev.get("predicted_tokens"))
472
+ prev_d_sec = _finite_nonneg(prev.get("predicted_seconds"))
473
+ if prev_d_tok is not None and prev_d_sec is not None:
474
+ dd_tok = d_tok - prev_d_tok
475
+ dd_sec = d_sec - prev_d_sec
476
+ if dd_tok > 0 and dd_sec > 0:
477
+ dec_rate = dd_tok / dd_sec
478
+ active = True
479
+
480
+ if pre_rate is None:
481
+ gauge_p = _finite_nonneg(curr.get("prompt_tokens_seconds"))
482
+ if p_tok > 0 and p_sec > 0:
483
+ pre_rate = p_tok / p_sec
484
+ elif gauge_p and gauge_p > 0:
485
+ pre_rate = gauge_p
486
+ if dec_rate is None:
487
+ gauge_d = _finite_nonneg(curr.get("predicted_tokens_seconds"))
488
+ if d_tok > 0 and d_sec > 0:
489
+ dec_rate = d_tok / d_sec
490
+ elif gauge_d and gauge_d > 0:
491
+ dec_rate = gauge_d
492
+ return pre_rate, dec_rate, active
493
+
494
+
495
+ def apply_slot_deltas(
496
+ slots: Sequence[Mapping[str, Any]],
497
+ prev_state: Mapping[str, Any] | None,
498
+ now_mono: float,
499
+ ) -> tuple[list[dict[str, Any]], dict[str, Any], bool]:
500
+ """Populate per-slot instantaneous ``tok_s`` via ``Δn_decoded / Δt`` keyed by ``(id, id_task)``.
501
+
502
+ Safely ignores counter resets, task switches, idle slots, and ``Δt <= 0``. Stores only numeric
503
+ slot identity and counters in ``next_state`` (never prompt or generated text).
504
+ """
505
+ prev_map = prev_state if isinstance(prev_state, Mapping) else {}
506
+ updated: list[dict[str, Any]] = []
507
+ next_state: dict[str, Any] = {}
508
+ any_delta = False
509
+
510
+ for raw in slots:
511
+ slot = dict(raw)
512
+ slot_key = str(slot.get("id"))
513
+ busy = slot.get("busy") is True
514
+ curr_task = slot.get("id_task")
515
+ if not isinstance(curr_task, int) or isinstance(curr_task, bool):
516
+ curr_task = None
517
+ curr_dec = slot.get("decoded")
518
+ if not isinstance(curr_dec, int) or isinstance(curr_dec, bool) or curr_dec < 0:
519
+ curr_dec = None
520
+
521
+ prev = prev_map.get(slot_key)
522
+ if busy and curr_dec is not None and isinstance(prev, Mapping):
523
+ prev_at = prev.get("at")
524
+ prev_dec = prev.get("n_decoded")
525
+ prev_task = prev.get("id_task")
526
+ prev_busy = prev.get("busy") is True
527
+ same_task = (
528
+ curr_task == prev_task
529
+ if curr_task is not None and prev_task is not None
530
+ else (curr_task is None and prev_task is None and prev_busy)
531
+ )
532
+ if (
533
+ same_task
534
+ and isinstance(prev_at, int | float)
535
+ and not isinstance(prev_at, bool)
536
+ and isinstance(prev_dec, int)
537
+ and not isinstance(prev_dec, bool)
538
+ ):
539
+ dt_s = now_mono - float(prev_at)
540
+ d_dec = curr_dec - prev_dec
541
+ if dt_s > 0 and math.isfinite(dt_s) and d_dec > 0:
542
+ rate = d_dec / dt_s
543
+ if math.isfinite(rate) and rate > 0:
544
+ slot["tok_s"] = round(rate, 1)
545
+ any_delta = True
546
+
547
+ next_state[slot_key] = {
548
+ "id_task": curr_task,
549
+ "n_decoded": curr_dec,
550
+ "busy": busy,
551
+ "at": now_mono,
552
+ }
553
+ updated.append(slot)
554
+ return updated, next_state, any_delta
555
+
556
+
332
557
  class RequestWaterfallBuffer:
333
558
  """Thread-safe bounded ring buffer tracking in-flight & recent gateway requests (last 20)."""
334
559
 
@@ -448,37 +673,221 @@ class RequestWaterfallBuffer:
448
673
  return p50_ttft_ms(self.entries(), now=now, window_s=window_s)
449
674
 
450
675
 
676
+ def _num_from(mapping: Mapping[str, Any] | None, *keys: str) -> float | None:
677
+ if not isinstance(mapping, Mapping):
678
+ return None
679
+ for key in keys:
680
+ val = mapping.get(key)
681
+ if isinstance(val, int | float) and not isinstance(val, bool) and math.isfinite(val):
682
+ return float(val)
683
+ return None
684
+
685
+
686
+ def _clamp_pct(value: float | None, *, fraction: bool = False) -> float | None:
687
+ if value is None or not math.isfinite(value) or value < 0:
688
+ return None
689
+ pct = value * 100.0 if fraction else value
690
+ return round(min(100.0, max(0.0, pct)), 1)
691
+
692
+
693
+ def _latest_request_metric(requests: object, key: str) -> float | None:
694
+ if not isinstance(requests, list):
695
+ return None
696
+ for row in requests:
697
+ if not isinstance(row, Mapping):
698
+ continue
699
+ val = _num_from(row, key)
700
+ if val is not None and val >= 0:
701
+ return val
702
+ return None
703
+
704
+
705
+ def _polystrata_nested_metrics(raw: Mapping[str, Any]) -> dict[str, Any] | None:
706
+ """Parse real PolyStrata nested JSON ``/metrics`` (totals/live/requests/conversation_cache/hardware)."""
707
+ totals = raw.get("totals") if isinstance(raw.get("totals"), Mapping) else None
708
+ live = raw.get("live") if isinstance(raw.get("live"), Mapping) else None
709
+ conv = (
710
+ raw.get("conversation_cache")
711
+ if isinstance(raw.get("conversation_cache"), Mapping)
712
+ else None
713
+ )
714
+ hardware = raw.get("hardware") if isinstance(raw.get("hardware"), Mapping) else None
715
+ requests = raw.get("requests") if isinstance(raw.get("requests"), list) else None
716
+ if totals is None and live is None and conv is None and hardware is None and requests is None:
717
+ return None
718
+
719
+ total_prompt = _num_from(totals, "prompt_tokens")
720
+ if total_prompt is None:
721
+ total_prompt = _num_from(conv, "prompt_tokens", "last_prompt")
722
+ reused = _num_from(totals, "reused", "prompt_tokens_cached")
723
+ if reused is None:
724
+ reused = _num_from(conv, "reused_tokens", "last_reused")
725
+ if total_prompt is not None and reused is not None:
726
+ prompt_tok: float | None = max(0.0, total_prompt - reused)
727
+ else:
728
+ prompt_tok = total_prompt
729
+
730
+ prompt_ms = _num_from(totals, "prompt_ms")
731
+ prompt_sec = (
732
+ prompt_ms / 1000.0 if prompt_ms is not None else _num_from(totals, "prompt_seconds")
733
+ )
734
+ pred_tok = _num_from(totals, "output_tokens", "predicted_tokens", "tokens_predicted")
735
+ decode_ms = _num_from(totals, "decode_ms")
736
+ pred_sec = (
737
+ decode_ms / 1000.0
738
+ if decode_ms is not None
739
+ else _num_from(totals, "decode_seconds", "predicted_seconds")
740
+ )
741
+
742
+ processing = _num_from(live, "running", "requests_processing", "in_flight")
743
+ if processing is None and isinstance(live, Mapping):
744
+ state = str(live.get("state") or "").lower()
745
+ if state in ("reading", "generating", "decoding", "prefill"):
746
+ processing = 1.0
747
+ elif state in ("idle", "unloaded"):
748
+ processing = 0.0
749
+
750
+ queued = _num_from(live, "queued", "requests_deferred")
751
+ waiting = _num_from(live, "waiting")
752
+ deferred = (
753
+ max(queued, waiting)
754
+ if queued is not None and waiting is not None
755
+ else (queued if queued is not None else waiting)
756
+ )
757
+
758
+ prompt_rate = _num_from(live, "prefill_tok_s_mean", "prompt_tokens_seconds", "prefill_tok_s")
759
+ pred_rate = _num_from(live, "tok_s", "tok_s_mean", "predicted_tokens_seconds", "decode_tok_s")
760
+ if pred_rate is None:
761
+ pred_rate = _latest_request_metric(requests, "decode_tok_s")
762
+
763
+ kv_ratio = _num_from(live, "kv_cache_usage_ratio", "kv_usage_ratio")
764
+ if kv_ratio is None:
765
+ kv_ratio = _num_from(hardware, "kv_cache_usage_ratio", "kv_usage_ratio")
766
+
767
+ draft_tokens = _num_from(totals, "drafts_offered", "spec_decode_num_draft_tokens_total")
768
+ accepted_tokens = _num_from(totals, "drafts_accepted", "spec_decode_num_accepted_tokens_total")
769
+ if draft_tokens is None:
770
+ draft_tokens = _latest_request_metric(requests, "drafts_offered")
771
+ if accepted_tokens is None:
772
+ accepted_tokens = _latest_request_metric(requests, "drafts_accepted")
773
+ spec_accept = _pct_ratio(accepted_tokens, draft_tokens)
774
+
775
+ hit_rate = _latest_request_metric(requests, "hit_rate")
776
+ expert_hit_pct = (
777
+ _clamp_pct(hit_rate, fraction=True)
778
+ if hit_rate is not None
779
+ else _clamp_pct(_num_from(totals, "expert_cache_hit_pct"))
780
+ or _clamp_pct(_num_from(live, "expert_cache_hit_pct"))
781
+ )
782
+ pcie_share = _latest_request_metric(requests, "pcie_share")
783
+ pcie_share_pct = (
784
+ _clamp_pct(pcie_share, fraction=True)
785
+ if pcie_share is not None
786
+ else _clamp_pct(_num_from(totals, "pcie_share_pct"))
787
+ or _clamp_pct(_num_from(live, "pcie_share_pct"))
788
+ )
789
+
790
+ if all(
791
+ v is None
792
+ for v in (
793
+ prompt_tok,
794
+ reused,
795
+ pred_tok,
796
+ processing,
797
+ deferred,
798
+ kv_ratio,
799
+ prompt_rate,
800
+ pred_rate,
801
+ expert_hit_pct,
802
+ pcie_share_pct,
803
+ spec_accept,
804
+ )
805
+ ):
806
+ return None
807
+ return {
808
+ "prompt_tokens": prompt_tok or 0.0,
809
+ "prompt_seconds": prompt_sec or 0.0,
810
+ "predicted_tokens": pred_tok or 0.0,
811
+ "predicted_seconds": pred_sec or 0.0,
812
+ "processing": processing or 0.0,
813
+ "requests_deferred": deferred,
814
+ "kv_cache_usage_ratio": kv_ratio,
815
+ "prompt_tokens_seconds": prompt_rate,
816
+ "predicted_tokens_seconds": pred_rate,
817
+ "prompt_tokens_cached": reused,
818
+ "n_tokens_max": None,
819
+ "n_busy_slots_per_decode": None,
820
+ "spec_decode_drafts": None,
821
+ "spec_decode_draft_tokens": draft_tokens,
822
+ "spec_decode_accepted_tokens": accepted_tokens,
823
+ "spec_decode_acceptance_pct": spec_accept,
824
+ "expert_cache_hit_pct": expert_hit_pct,
825
+ "pcie_share_pct": pcie_share_pct,
826
+ }
827
+
828
+
451
829
  def _parse_polystrata_json_metrics(text: str) -> dict[str, Any] | None:
452
- """Parse PolyStrata JSON ``/metrics`` when it carries live numeric engine counters."""
830
+ """Parse PolyStrata JSON ``/metrics`` (nested real format or legacy flat keys)."""
453
831
  try:
454
832
  raw = json.loads(text)
455
833
  except ValueError:
456
834
  return None
457
835
  if not isinstance(raw, dict):
458
836
  return None
837
+ if (nested := _polystrata_nested_metrics(raw)) is not None:
838
+ return nested
839
+
459
840
  src = raw.get("metrics") if isinstance(raw.get("metrics"), dict) else raw
460
841
  if not isinstance(src, dict):
461
842
  return None
462
843
 
463
- def num(*keys: str) -> float | None:
464
- for key in keys:
465
- val = src.get(key)
466
- if isinstance(val, int | float) and not isinstance(val, bool) and math.isfinite(val):
467
- return float(val)
468
- return None
844
+ prompt_tok = _num_from(src, "prompt_tokens_total", "prompt_tokens")
845
+ prompt_sec = _num_from(src, "prompt_seconds_total", "prompt_seconds")
846
+ pred_tok = _num_from(src, "tokens_predicted_total", "predicted_tokens", "decode_tokens_total")
847
+ pred_sec = _num_from(
848
+ src, "tokens_predicted_seconds_total", "predicted_seconds", "decode_seconds_total"
849
+ )
850
+ processing = _num_from(src, "requests_processing", "in_flight", "active_requests")
851
+ deferred = _num_from(src, "requests_deferred", "queued_requests")
852
+ kv_ratio = _num_from(src, "kv_cache_usage_ratio", "kv_usage_ratio")
853
+ prompt_rate = _num_from(src, "prompt_tokens_seconds", "prefill_tok_s")
854
+ pred_rate = _num_from(src, "predicted_tokens_seconds", "decode_tok_s")
855
+ prompt_cached = _num_from(src, "prompt_tokens_cached_total", "prompt_tokens_cached", "reused")
856
+ draft_tokens = _num_from(
857
+ src, "spec_decode_num_draft_tokens_total", "spec_decode_draft_tokens", "drafts_offered"
858
+ )
859
+ accepted_tokens = _num_from(
860
+ src,
861
+ "spec_decode_num_accepted_tokens_total",
862
+ "spec_decode_accepted_tokens",
863
+ "drafts_accepted",
864
+ )
865
+ spec_accept = _pct_ratio(accepted_tokens, draft_tokens) or _clamp_pct(
866
+ _num_from(src, "spec_decode_acceptance_pct")
867
+ )
868
+ expert_hit_pct = _clamp_pct(_num_from(src, "expert_cache_hit_pct"))
869
+ if expert_hit_pct is None:
870
+ expert_hit_pct = _clamp_pct(
871
+ _num_from(src, "expert_cache_hit_rate", "hit_rate"), fraction=True
872
+ )
873
+ pcie_share_pct = _clamp_pct(_num_from(src, "pcie_share_pct"))
874
+ if pcie_share_pct is None:
875
+ pcie_share_pct = _clamp_pct(_num_from(src, "pcie_share"), fraction=True)
469
876
 
470
- prompt_tok = num("prompt_tokens_total", "prompt_tokens")
471
- prompt_sec = num("prompt_seconds_total", "prompt_seconds")
472
- pred_tok = num("tokens_predicted_total", "predicted_tokens", "decode_tokens_total")
473
- pred_sec = num("tokens_predicted_seconds_total", "predicted_seconds", "decode_seconds_total")
474
- processing = num("requests_processing", "in_flight", "active_requests")
475
- deferred = num("requests_deferred", "queued_requests")
476
- kv_ratio = num("kv_cache_usage_ratio", "kv_usage_ratio")
477
- prompt_rate = num("prompt_tokens_seconds", "prefill_tok_s")
478
- pred_rate = num("predicted_tokens_seconds", "decode_tok_s")
479
877
  if all(
480
878
  v is None
481
- for v in (prompt_tok, pred_tok, processing, deferred, kv_ratio, prompt_rate, pred_rate)
879
+ for v in (
880
+ prompt_tok,
881
+ pred_tok,
882
+ processing,
883
+ deferred,
884
+ kv_ratio,
885
+ prompt_rate,
886
+ pred_rate,
887
+ expert_hit_pct,
888
+ pcie_share_pct,
889
+ spec_accept,
890
+ )
482
891
  ):
483
892
  return None
484
893
  return {
@@ -491,6 +900,15 @@ def _parse_polystrata_json_metrics(text: str) -> dict[str, Any] | None:
491
900
  "kv_cache_usage_ratio": kv_ratio,
492
901
  "prompt_tokens_seconds": prompt_rate,
493
902
  "predicted_tokens_seconds": pred_rate,
903
+ "prompt_tokens_cached": prompt_cached,
904
+ "n_tokens_max": _num_from(src, "n_tokens_max"),
905
+ "n_busy_slots_per_decode": _num_from(src, "n_busy_slots_per_decode"),
906
+ "spec_decode_drafts": _num_from(src, "spec_decode_num_drafts_total", "spec_decode_drafts"),
907
+ "spec_decode_draft_tokens": draft_tokens,
908
+ "spec_decode_accepted_tokens": accepted_tokens,
909
+ "spec_decode_acceptance_pct": spec_accept,
910
+ "expert_cache_hit_pct": expert_hit_pct,
911
+ "pcie_share_pct": pcie_share_pct,
494
912
  }
495
913
 
496
914
 
@@ -525,6 +943,19 @@ def parse_engine_metrics(text: str) -> dict[str, Any] | None:
525
943
  totals[key] = totals.get(key, 0.0) + value
526
944
  if not totals:
527
945
  return None
946
+ draft_tokens = totals.get("spec_decode_num_draft_tokens_total")
947
+ if draft_tokens is None:
948
+ draft_tokens = totals.get("drafts_offered_total")
949
+ accepted_tokens = totals.get("spec_decode_num_accepted_tokens_total")
950
+ if accepted_tokens is None:
951
+ accepted_tokens = totals.get("drafts_accepted_total")
952
+ spec_accept = _pct_ratio(accepted_tokens, draft_tokens)
953
+ expert_hit_pct = _clamp_pct(totals.get("expert_cache_hit_pct"))
954
+ if expert_hit_pct is None:
955
+ expert_hit_pct = _clamp_pct(totals.get("expert_cache_hit_rate"), fraction=True)
956
+ pcie_share_pct = _clamp_pct(totals.get("pcie_share_pct"))
957
+ if pcie_share_pct is None:
958
+ pcie_share_pct = _clamp_pct(totals.get("pcie_share"), fraction=True)
528
959
  return {
529
960
  "prompt_tokens": totals.get("prompt_tokens_total", 0.0),
530
961
  "prompt_seconds": totals.get("prompt_seconds_total", 0.0),
@@ -535,4 +966,13 @@ def parse_engine_metrics(text: str) -> dict[str, Any] | None:
535
966
  "kv_cache_usage_ratio": totals.get("kv_cache_usage_ratio"),
536
967
  "prompt_tokens_seconds": totals.get("prompt_tokens_seconds"),
537
968
  "predicted_tokens_seconds": totals.get("predicted_tokens_seconds"),
969
+ "prompt_tokens_cached": totals.get("prompt_tokens_cached_total"),
970
+ "n_tokens_max": totals.get("n_tokens_max"),
971
+ "n_busy_slots_per_decode": totals.get("n_busy_slots_per_decode"),
972
+ "spec_decode_drafts": totals.get("spec_decode_num_drafts_total"),
973
+ "spec_decode_draft_tokens": draft_tokens,
974
+ "spec_decode_accepted_tokens": accepted_tokens,
975
+ "spec_decode_acceptance_pct": spec_accept,
976
+ "expert_cache_hit_pct": expert_hit_pct,
977
+ "pcie_share_pct": pcie_share_pct,
538
978
  }
@@ -36,7 +36,14 @@ SSH_OPTIONS = (
36
36
  # one stdin payload, and an in-memory loader resolves each part as ``localmodels.<stem>`` on the
37
37
  # target — the same name it imports as a member of this package.
38
38
  BUNDLES = {
39
- "probe.py": ("metal_probe.py", "win_probe.py"),
39
+ "probe.py": (
40
+ "metal_probe.py",
41
+ "win_probe.py",
42
+ "process_identity.py",
43
+ "process_identity_darwin.py",
44
+ "process_identity_linux.py",
45
+ "process_windows.py",
46
+ ),
40
47
  "service_probe.py": (
41
48
  "process_identity.py",
42
49
  "process_identity_darwin.py",
@@ -10,7 +10,7 @@ import argparse
10
10
  import sys
11
11
  from pathlib import Path
12
12
 
13
- from localmodels import cli_help, deploy, tts_jobs, tts_serve
13
+ from localmodels import cli_help
14
14
  from localmodels.tts_model import (
15
15
  EXIT_FAILED,
16
16
  TtsError,
@@ -48,7 +48,7 @@ _FALLBACK_CODE = {
48
48
  def _add_base_dir(parser: argparse.ArgumentParser) -> None:
49
49
  parser.add_argument(
50
50
  "--base-dir",
51
- default=deploy.DEFAULT_BASE_DIR,
51
+ default=cli_help.DEFAULT_BASE_DIR,
52
52
  metavar="DIR",
53
53
  help="directory holding TTS model weights and runtimes",
54
54
  )
@@ -78,10 +78,10 @@ def _add_manage_parsers(verbs: argparse._SubParsersAction[argparse.ArgumentParse
78
78
  cli_help.document(
79
79
  status_p,
80
80
  "Print one localmodels.tts-status/v1 JSON document describing configuration, live "
81
- "sidecar status, and visible v1 TTS models with license disclosures. Absent GPU "
82
- "Qwen3-TTS models are hidden by default unless --all or LOCALMODELS_VOICE_INCLUDE_GPU=1 "
83
- "(or LOCALMODELS_TTS_INCLUDE_GPU=1) is set; already-installed or active models remain "
84
- "visible until removed. Read-only.",
81
+ "sidecar status, and visible v1 TTS models with license disclosures. Qwen3-TTS models "
82
+ "are hidden in every state unless --all or LOCALMODELS_VOICE_INCLUDE_GPU=1 (or "
83
+ "LOCALMODELS_TTS_INCLUDE_GPU=1) is set, and a saved hidden model_id is reported as the "
84
+ "default model and voice. Read-only.",
85
85
  examples=[("%(prog)s --base-dir /srv/models --json", "")],
86
86
  )
87
87
 
@@ -93,7 +93,7 @@ def _add_manage_parsers(verbs: argparse._SubParsersAction[argparse.ArgumentParse
93
93
  list_p,
94
94
  "Print one localmodels.tts-list/v1 JSON document listing visible v1 TTS models and "
95
95
  "install states. Pass --all or set LOCALMODELS_VOICE_INCLUDE_GPU=1 (or "
96
- "LOCALMODELS_TTS_INCLUDE_GPU=1) to include absent GPU Qwen3-TTS models.",
96
+ "LOCALMODELS_TTS_INCLUDE_GPU=1) to include hidden Qwen3-TTS models.",
97
97
  examples=[("%(prog)s --json", "")],
98
98
  )
99
99
 
@@ -250,24 +250,26 @@ def _include_hidden(args: argparse.Namespace) -> bool | None:
250
250
  def _dispatch(args: argparse.Namespace) -> dict[str, object]:
251
251
  verb = str(args.tts_command)
252
252
  base_dir = str(args.base_dir)
253
- if verb == "status":
254
- return dict(tts_jobs.status(base_dir, include_hidden=_include_hidden(args)))
255
- if verb == "list":
256
- return dict(tts_jobs.list_models(base_dir, include_hidden=_include_hidden(args)))
257
- if verb == "download":
258
- row = tts_jobs.download(
259
- str(args.model),
260
- base_dir,
261
- include_gpu_engine=bool(getattr(args, "include_gpu_engine", False)),
262
- )
263
- return result_event(ok=True, model_id=str(args.model), detail="downloaded", row=row)
264
- if verb == "cancel":
265
- row = tts_jobs.cancel(str(args.model), base_dir)
266
- return result_event(ok=True, model_id=str(args.model), detail="cancelled", row=row)
267
- if verb == "remove":
268
- row = tts_jobs.remove(str(args.model), base_dir)
269
- return result_event(ok=True, model_id=str(args.model), detail="removed", row=row)
270
- if verb == "configure":
253
+ if verb in ("status", "list", "download", "cancel", "remove", "configure"):
254
+ from localmodels import tts_jobs
255
+
256
+ if verb == "status":
257
+ return dict(tts_jobs.status(base_dir, include_hidden=_include_hidden(args)))
258
+ if verb == "list":
259
+ return dict(tts_jobs.list_models(base_dir, include_hidden=_include_hidden(args)))
260
+ if verb == "download":
261
+ row = tts_jobs.download(
262
+ str(args.model),
263
+ base_dir,
264
+ include_gpu_engine=bool(getattr(args, "include_gpu_engine", False)),
265
+ )
266
+ return result_event(ok=True, model_id=str(args.model), detail="downloaded", row=row)
267
+ if verb == "cancel":
268
+ row = tts_jobs.cancel(str(args.model), base_dir)
269
+ return result_event(ok=True, model_id=str(args.model), detail="cancelled", row=row)
270
+ if verb == "remove":
271
+ row = tts_jobs.remove(str(args.model), base_dir)
272
+ return result_event(ok=True, model_id=str(args.model), detail="removed", row=row)
271
273
  use_gpu = (
272
274
  parse_bool_flag(args.use_gpu, flag="--use-gpu") if args.use_gpu is not None else None
273
275
  )
@@ -283,6 +285,8 @@ def _dispatch(args: argparse.Namespace) -> dict[str, object]:
283
285
  language=args.language,
284
286
  )
285
287
  )
288
+ from localmodels import tts_serve
289
+
286
290
  if verb == "start":
287
291
  return dict(
288
292
  tts_serve.start(
@@ -46,6 +46,7 @@ from localmodels.tts_model import (
46
46
  TtsModelState,
47
47
  TtsRuntime,
48
48
  TtsStatusDocument,
49
+ default_config,
49
50
  emit_progress,
50
51
  )
51
52
  from localmodels.tts_state import TtsJob, TtsJobHandle, TtsModelRecord
@@ -233,6 +234,10 @@ def status(
233
234
  tts_catalog.HIDDEN_TTS_MODEL_IDS,
234
235
  show_hidden=show_hidden,
235
236
  )
237
+ if not show_hidden and cfg["model_id"] in tts_catalog.HIDDEN_TTS_MODEL_IDS:
238
+ # A saved voice belongs to its model, so a retired selection reports the default pair.
239
+ default = default_config()
240
+ cfg["model_id"], cfg["voice"] = default["model_id"], default["voice"]
236
241
  return {
237
242
  "schema": STATUS_SCHEMA,
238
243
  "tool_version": __version__,