@simplexai/localmodels-win32-x64 0.1.0-dev.59 → 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 (87) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +79 -73
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +104 -43
  5. package/modules/localmodels/apple_sensors.py +431 -0
  6. package/modules/localmodels/bifrost_admin.py +30 -0
  7. package/modules/localmodels/bifrost_checks.py +2 -2
  8. package/modules/localmodels/bifrost_config.py +132 -9
  9. package/modules/localmodels/bifrost_models.py +1 -1
  10. package/modules/localmodels/catalog.json +146 -54
  11. package/modules/localmodels/catalog.py +20 -3
  12. package/modules/localmodels/catalog_add.py +42 -11
  13. package/modules/localmodels/custom_hub.py +983 -0
  14. package/modules/localmodels/custom_hub_http.py +579 -0
  15. package/modules/localmodels/custom_probe.py +451 -0
  16. package/modules/localmodels/deploy.py +27 -5
  17. package/modules/localmodels/deploy_steps.py +5 -0
  18. package/modules/localmodels/download-mirrors.json +8 -0
  19. package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
  20. package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
  21. package/modules/localmodels/engines.py +38 -8
  22. package/modules/localmodels/estimator.py +60 -7
  23. package/modules/localmodels/gateway.py +48 -3
  24. package/modules/localmodels/gateway_app_bifrost.py +4 -4
  25. package/modules/localmodels/gateway_bifrost.py +98 -15
  26. package/modules/localmodels/gguf.py +6 -0
  27. package/modules/localmodels/host_sensors.py +704 -0
  28. package/modules/localmodels/library_cli.py +181 -3
  29. package/modules/localmodels/library_custom.py +831 -0
  30. package/modules/localmodels/library_elastic.py +35 -7
  31. package/modules/localmodels/library_gateway.py +94 -32
  32. package/modules/localmodels/library_jobs.py +76 -11
  33. package/modules/localmodels/library_kept.py +50 -6
  34. package/modules/localmodels/library_model.py +254 -2
  35. package/modules/localmodels/library_pricing.py +83 -4
  36. package/modules/localmodels/library_serve.py +112 -50
  37. package/modules/localmodels/library_smoke.py +315 -0
  38. package/modules/localmodels/library_state.py +77 -1
  39. package/modules/localmodels/library_status.py +126 -4
  40. package/modules/localmodels/nvml_ctypes.py +431 -0
  41. package/modules/localmodels/plan_envelope.py +14 -6
  42. package/modules/localmodels/records.py +1 -0
  43. package/modules/localmodels/remote_ops.py +53 -5
  44. package/modules/localmodels/remote_ops_download.py +168 -29
  45. package/modules/localmodels/remote_ops_ranges.py +2 -5
  46. package/modules/localmodels/remote_ops_service.py +2 -1
  47. package/modules/localmodels/remote_ops_verify.py +22 -5
  48. package/modules/localmodels/runtime-lock.json +19 -19
  49. package/modules/localmodels/service_control.py +32 -1
  50. package/modules/localmodels/service_wiring.py +2 -3
  51. package/modules/localmodels/service_worker.py +6 -2
  52. package/modules/localmodels/services_cli.py +35 -27
  53. package/modules/localmodels/source_byok.py +3 -5
  54. package/modules/localmodels/stack_lifecycle.py +2 -2
  55. package/modules/localmodels/stack_memory.py +1 -0
  56. package/modules/localmodels/stack_view.py +77 -53
  57. package/modules/localmodels/stack_view_demo.py +36 -5
  58. package/modules/localmodels/stack_view_events.py +147 -12
  59. package/modules/localmodels/stack_view_gpu.py +97 -17
  60. package/modules/localmodels/stack_view_llm.py +15 -0
  61. package/modules/localmodels/stack_view_measure.py +4 -1
  62. package/modules/localmodels/stack_view_schema.py +54 -8
  63. package/modules/localmodels/stack_view_serve.py +40 -3
  64. package/modules/localmodels/stack_view_slots.py +89 -10
  65. package/modules/localmodels/stack_view_telemetry.py +163 -0
  66. package/modules/localmodels/stack_view_text.py +5 -2
  67. package/modules/localmodels/stack_view_tick.py +658 -0
  68. package/modules/localmodels/stack_view_words.py +4 -0
  69. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.5.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
  70. package/modules/localmodels/suite.py +3 -1
  71. package/modules/localmodels/telemetry_math.py +538 -0
  72. package/modules/localmodels/web/view/view.js +1 -1
  73. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
  74. package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +76 -70
  75. package/package.json +1 -1
  76. package/tool.json +1 -1
  77. package/modules/localmodels/bifrost_datasheet.py +0 -53
  78. package/modules/localmodels/bifrost_provider.py +0 -88
  79. package/modules/localmodels/bifrost_unit.py +0 -99
  80. package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +0 -94
  81. package/modules/localmodels/gateway_switch.py +0 -51
  82. package/modules/localmodels/library_floor.py +0 -78
  83. package/modules/localmodels/service_stop.py +0 -52
  84. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
  85. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
  86. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
  87. /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -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")
@@ -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