@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
@@ -1,9 +1,10 @@
1
1
  """What each llama-server slot holds right now, for ``stack view``'s live slots: the context it
2
2
  uses (prompt tokens, of them read so far and reused from the cache, and tokens written) against
3
- its window, and whether it is working. llama-server's ``GET /slots`` (deploy passes ``--slots``)
4
- answers with each slot's prompt and generated text as well; only the counters are kept, the text
5
- is dropped on arrival and never stored, shown or logged. Older builds leave some counters out:
6
- those are None, never zero.
3
+ its window, its current phase (``idle | prefill | decoding | queued``), and live timing rates
4
+ where emitted. llama-server's ``GET /slots`` (deploy passes ``--slots``) answers with each slot's
5
+ prompt and generated text as well; only allowlisted numeric/boolean/enum counters are kept — the
6
+ prompt and completion text are dropped unconditionally on arrival and never stored, shown or
7
+ logged. Older builds leave some counters out: those are None, never zero.
7
8
 
8
9
  ``owned_get`` is the one way the board asks an owned service: loopback only, no proxy, with the
9
10
  deployment's own key read from its directory (it never leaves the function), at most ``limit``
@@ -13,6 +14,7 @@ bytes. A body that does not fit is no answer.
13
14
  from __future__ import annotations
14
15
 
15
16
  import json
17
+ import math
16
18
  import os
17
19
  import urllib.error
18
20
  import urllib.request
@@ -22,16 +24,23 @@ from typing import TypedDict
22
24
  from localmodels.records import Plan
23
25
 
24
26
  SLOTS_BYTES = 8 << 20 # a slot's prompt comes along: a long session's is a few hundred KB
27
+ PHASES = ("idle", "prefill", "decoding", "queued")
25
28
 
26
29
 
27
30
  class Slot(TypedDict):
28
31
  id: int
29
32
  n_ctx: int | None
30
33
  busy: bool
34
+ phase: str # idle | prefill | decoding | queued
31
35
  prompt_tokens: int | None # the prompt this slot holds (its last task's, when idle)
32
36
  prompt_done: int | None # of them, read so far in this task
33
37
  cached: int | None # of them, reused from the cache instead of read again
34
38
  decoded: int | None # tokens written in this task
39
+ n_prompt: int | None # v1.1 alias for prompt_tokens
40
+ cached_prefix_tokens: int | None # v1.1 alias for cached
41
+ n_decoded: int | None # v1.1 alias for decoded
42
+ tok_s: float | None # live decode speed for this slot when emitted
43
+ ttft_ms: float | None # live prefill/TTFT milliseconds for this slot when emitted
35
44
 
36
45
 
37
46
  def owned_get(part: Plan, path: str, limit: int, timeout: float) -> bytes | None:
@@ -55,8 +64,43 @@ def _count(value: object) -> int | None:
55
64
  return value if isinstance(value, int) and not isinstance(value, bool) and value >= 0 else None
56
65
 
57
66
 
67
+ def _rate(value: object) -> float | None:
68
+ if isinstance(value, int | float) and not isinstance(value, bool):
69
+ f = float(value)
70
+ if math.isfinite(f) and f >= 0:
71
+ return round(f, 1)
72
+ return None
73
+
74
+
75
+ def _phase(
76
+ row: dict[str, object],
77
+ *,
78
+ busy: bool,
79
+ prompt_tokens: int | None,
80
+ prompt_done: int | None,
81
+ decoded: int | None,
82
+ ) -> str:
83
+ raw_phase = row.get("phase") or row.get("state")
84
+ if isinstance(raw_phase, str) and raw_phase.lower() in PHASES:
85
+ return raw_phase.lower()
86
+ if row.get("is_queued") is True or raw_phase == "queued":
87
+ return "queued"
88
+ if not busy:
89
+ return "idle"
90
+ if decoded is not None and decoded > 0:
91
+ return "decoding"
92
+ if prompt_tokens is not None and prompt_done is not None and prompt_done < prompt_tokens:
93
+ return "prefill"
94
+ if decoded == 0 and prompt_tokens is not None:
95
+ return "prefill"
96
+ return "decoding"
97
+
98
+
58
99
  def parse(text: str) -> list[Slot] | None:
59
- """The counters of each slot in ``GET /slots``; None when it is not that answer."""
100
+ """The counters of each slot in ``GET /slots``; None when it is not that answer.
101
+
102
+ All prompt, generated text, messages, and free-form strings are stripped unconditionally.
103
+ """
60
104
  try:
61
105
  raw = json.loads(text)
62
106
  except ValueError:
@@ -69,15 +113,50 @@ def parse(text: str) -> list[Slot] | None:
69
113
  continue
70
114
  nxt = row.get("next_token")
71
115
  first = nxt[0] if isinstance(nxt, list) and nxt and isinstance(nxt[0], dict) else {}
116
+ raw_timings = row.get("timings")
117
+ timings: dict[str, object] = raw_timings if isinstance(raw_timings, dict) else {}
118
+ busy = row.get("is_processing") is True
119
+ prompt_tokens = _count(row.get("n_prompt_tokens"))
120
+ if prompt_tokens is None:
121
+ prompt_tokens = _count(row.get("n_prompt"))
122
+ prompt_done = _count(row.get("n_prompt_tokens_processed"))
123
+ cached = _count(row.get("n_prompt_tokens_cache"))
124
+ if cached is None:
125
+ cached = _count(row.get("cached_prefix_tokens"))
126
+ decoded = _count(first.get("n_decoded"))
127
+ if decoded is None:
128
+ decoded = _count(row.get("n_decoded"))
129
+ tok_s = _rate(
130
+ timings.get("predicted_per_second")
131
+ if timings.get("predicted_per_second") is not None
132
+ else row.get("tok_s")
133
+ if row.get("tok_s") is not None
134
+ else row.get("decode_tok_s")
135
+ )
136
+ ttft_ms = _rate(
137
+ timings.get("prompt_ms") if timings.get("prompt_ms") is not None else row.get("ttft_ms")
138
+ )
72
139
  found.append(
73
140
  {
74
141
  "id": int(row["id"]),
75
142
  "n_ctx": _count(row.get("n_ctx")),
76
- "busy": row.get("is_processing") is True,
77
- "prompt_tokens": _count(row.get("n_prompt_tokens")),
78
- "prompt_done": _count(row.get("n_prompt_tokens_processed")),
79
- "cached": _count(row.get("n_prompt_tokens_cache")),
80
- "decoded": _count(first.get("n_decoded")),
143
+ "busy": busy,
144
+ "phase": _phase(
145
+ row,
146
+ busy=busy,
147
+ prompt_tokens=prompt_tokens,
148
+ prompt_done=prompt_done,
149
+ decoded=decoded,
150
+ ),
151
+ "prompt_tokens": prompt_tokens,
152
+ "prompt_done": prompt_done,
153
+ "cached": cached,
154
+ "decoded": decoded,
155
+ "n_prompt": prompt_tokens,
156
+ "cached_prefix_tokens": cached,
157
+ "n_decoded": decoded,
158
+ "tok_s": tok_s,
159
+ "ttft_ms": ttft_ms,
81
160
  }
82
161
  )
83
162
  return found
@@ -0,0 +1,163 @@
1
+ """v1.1 additive telemetry projection for ``stack view``: effective decode bandwidth, memory
2
+ bandwidth ceiling, deterministic bottleneck classification, waterfall, p50 TTFT, prefix hit %,
3
+ deferred requests, and KV cache usage ratio."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import math
8
+ from typing import Any, cast
9
+
10
+ from localmodels import host_sensors, stack_view_events, telemetry_math
11
+ from localmodels.host_sensors import HostSensors
12
+ from localmodels.stack_view_llm import active_weight_bytes
13
+ from localmodels.stack_view_schema import Component, Figure, Gpu, Reading
14
+ from localmodels.stack_view_words import say
15
+ from localmodels.telemetry_math import WaterfallEntry
16
+
17
+
18
+ def default_sensors(source: str) -> HostSensors:
19
+ if source == "demo":
20
+ return host_sensors.demo(False)
21
+ return {
22
+ "cpu": {
23
+ "overall_pct": {"value": None, "basis": "none", "note": "Host CPU sensor not read"},
24
+ "per_core": [],
25
+ "logical_cores": None,
26
+ },
27
+ "disk": {
28
+ "read_mb_s": {"value": None, "basis": "none", "note": "Disk read sensor not read"},
29
+ "write_mb_s": {"value": None, "basis": "none", "note": "Disk write sensor not read"},
30
+ },
31
+ "memory_pressure": {
32
+ "level": "unknown",
33
+ "basis": "none",
34
+ "available_ratio": None,
35
+ "psi_some_avg10": None,
36
+ "swap_used_bytes": None,
37
+ },
38
+ "watchdog": {
39
+ "status": "unknown",
40
+ "basis": "none",
41
+ "detail": "Watchdog status not read",
42
+ },
43
+ "collector": "none",
44
+ }
45
+
46
+
47
+ def _figure(value: float | None, basis: str, note: str, *, allow_zero: bool = False) -> Figure:
48
+ if value is None or not math.isfinite(value) or (value < 0 if allow_zero else value <= 0):
49
+ return {"value": None, "basis": "none", "note": note}
50
+ return {"value": round(value, 1), "basis": basis, "note": note}
51
+
52
+
53
+ def summary(
54
+ reading: Reading,
55
+ comps: list[Component],
56
+ gpus: list[Gpu],
57
+ sensors: HostSensors,
58
+ ) -> dict[str, Any]:
59
+ """Derive v1.1 additive telemetry fields for ``stack_view.render``."""
60
+ hw, plan, source = reading["hw"], reading["plan"], reading["source"]
61
+ llm_comp = next((c for c in comps if c["id"] == "llm"), None)
62
+ all_slots = [s for slot_list in reading["slots"].values() for s in slot_list]
63
+ waterfall: list[WaterfallEntry] = list(reading.get("waterfall") or [])
64
+ if not waterfall and reading["events"]:
65
+ model_map = {c["id"]: c["model"] for c in comps}
66
+ wf_basis = "demo" if source == "demo" else "live"
67
+ waterfall = stack_view_events.waterfall_from_events(
68
+ reading["events"], model_by_component=model_map, basis=wf_basis
69
+ )
70
+
71
+ processing_sum = sum(
72
+ int(c["perf"]["counters"]["processing"]) for c in comps if c["perf"]["counters"] is not None
73
+ )
74
+ busy_slots = sum(1 for s in all_slots if s["busy"])
75
+ streaming_wf = sum(1 for w in waterfall if w["status"] == "streaming")
76
+ in_flight = max(processing_sum, busy_slots, streaming_wf)
77
+
78
+ client_lanes = telemetry_math.client_lanes(waterfall, in_flight)
79
+
80
+ active_bytes = active_weight_bytes(plan["llm"]) if plan is not None else None
81
+ decode_fig = llm_comp["perf"]["decode_tok_s"] if llm_comp is not None else None
82
+ eff_bw = cast(Figure, telemetry_math.effective_decode_bw_gb_s(decode_fig, active_bytes))
83
+ primary_gpu = llm_comp["gpu"] if llm_comp is not None else (gpus[0]["index"] if gpus else None)
84
+ hw_card = (
85
+ next((c for c in hw["cards"] if c["index"] == primary_gpu), None)
86
+ if primary_gpu is not None
87
+ else None
88
+ )
89
+ bw_ceiling = cast(
90
+ Figure,
91
+ telemetry_math.memory_bw_ceiling_gb_s(
92
+ cast(dict[str, Any], hw_card) if hw_card is not None else None,
93
+ source=source,
94
+ ),
95
+ )
96
+
97
+ gpu_row = (
98
+ next((g for g in reading["gpu_load"] if g["index"] == primary_gpu), None)
99
+ if primary_gpu is not None
100
+ else (reading["gpu_load"][0] if reading["gpu_load"] else None)
101
+ )
102
+ bottleneck = telemetry_math.classify_bottleneck(
103
+ in_flight=in_flight,
104
+ decode_tok_s=decode_fig["value"] if decode_fig else None,
105
+ effective_bw_gb_s=eff_bw["value"],
106
+ bw_ceiling_gb_s=bw_ceiling["value"],
107
+ gpu_util_pct=gpu_row["util_pct"] if gpu_row else None,
108
+ mem_ctrl_util_pct=gpu_row.get("mem_ctrl_util_pct") if gpu_row else None,
109
+ disk_read_mb_s=sensors["disk"]["read_mb_s"]["value"],
110
+ )
111
+
112
+ deferred_vals = [
113
+ c["perf"]["counters"]["requests_deferred"]
114
+ for c in comps
115
+ if c["perf"]["counters"] is not None
116
+ and c["perf"]["counters"].get("requests_deferred") is not None
117
+ ]
118
+ live_basis = "demo" if source == "demo" else "live"
119
+ requests_deferred = (
120
+ _figure(
121
+ float(sum(v for v in deferred_vals if v is not None)),
122
+ live_basis,
123
+ say("fig.demo") if source == "demo" else say("fig.deferred.live"),
124
+ allow_zero=True,
125
+ )
126
+ if deferred_vals
127
+ else _figure(None, "none", say("fig.deferred.none"))
128
+ )
129
+ kv_val = (
130
+ llm_comp["perf"]["counters"].get("kv_cache_usage_ratio")
131
+ if llm_comp is not None and llm_comp["perf"]["counters"] is not None
132
+ else None
133
+ )
134
+ kv_ratio: Figure = (
135
+ {
136
+ "value": round(float(kv_val), 3),
137
+ "basis": live_basis,
138
+ "note": say("fig.demo") if source == "demo" else say("fig.kv_ratio.live"),
139
+ }
140
+ if kv_val is not None and math.isfinite(kv_val) and kv_val >= 0
141
+ else _figure(None, "none", say("fig.kv_ratio.none"))
142
+ )
143
+
144
+ p50_ttft = cast(
145
+ Figure,
146
+ telemetry_math.p50_ttft_ms(waterfall, now=reading["generated_at"], source=source),
147
+ )
148
+ prefix_hit = cast(
149
+ Figure,
150
+ telemetry_math.prefix_hit_pct(waterfall, all_slots, source=source),
151
+ )
152
+ return {
153
+ "effective_decode_bw_gb_s": eff_bw,
154
+ "memory_bw_ceiling_gb_s": bw_ceiling,
155
+ "bottleneck": bottleneck,
156
+ "waterfall": waterfall,
157
+ "p50_ttft_ms": p50_ttft,
158
+ "prefix_hit_pct": prefix_hit,
159
+ "requests_deferred": requests_deferred,
160
+ "kv_cache_usage_ratio": kv_ratio,
161
+ "in_flight": in_flight,
162
+ "client_lanes": client_lanes,
163
+ }
@@ -18,7 +18,7 @@ from collections.abc import Callable
18
18
  from typing import TextIO
19
19
 
20
20
  from localmodels import console
21
- from localmodels.stack_view import Component, Counters, Figure, Segment, StackView
21
+ from localmodels.stack_view import Component, Figure, Segment, StackView
22
22
  from localmodels.stack_view_events import Event
23
23
  from localmodels.stack_view_words import say
24
24
 
@@ -154,7 +154,10 @@ def recent_rates(before: StackView | None, after: StackView) -> dict[str, dict[s
154
154
  a, b = old.get(comp["id"]), comp["perf"]["counters"]
155
155
  if a is None or b is None:
156
156
  continue
157
- d = {key: b[key] - a[key] for key in Counters.__annotations__} # type: ignore[literal-required]
157
+ d = {
158
+ key: float(b[key]) - float(a[key]) # type: ignore[literal-required]
159
+ for key in ("prompt_tokens", "prompt_seconds", "predicted_tokens", "predicted_seconds")
160
+ }
158
161
  if d["prompt_tokens"] < 0 or d["predicted_tokens"] < 0:
159
162
  continue
160
163
  found[comp["id"]] = {