@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 0.1.0-dev.38

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 (134) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +132 -110
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_checks.py +9 -6
  7. package/modules/localmodels/bifrost_config.py +203 -0
  8. package/modules/localmodels/bifrost_datasheet.py +12 -2
  9. package/modules/localmodels/budget.py +13 -2
  10. package/modules/localmodels/catalog.json +137 -2
  11. package/modules/localmodels/catalog.py +70 -321
  12. package/modules/localmodels/catalog_add.py +2 -8
  13. package/modules/localmodels/catalog_recipes.py +352 -0
  14. package/modules/localmodels/cli_parser.py +4 -1
  15. package/modules/localmodels/console.py +5 -4
  16. package/modules/localmodels/contracts.py +13 -3
  17. package/modules/localmodels/debug_cli.py +158 -0
  18. package/modules/localmodels/debug_mode.py +727 -0
  19. package/modules/localmodels/debug_stub_server.py +192 -0
  20. package/modules/localmodels/decode_calibration.json +1 -1
  21. package/modules/localmodels/decode_calibration.py +34 -17
  22. package/modules/localmodels/gateway.py +21 -155
  23. package/modules/localmodels/gateway_accept.py +201 -0
  24. package/modules/localmodels/gateway_bifrost.py +30 -193
  25. package/modules/localmodels/gateway_cli.py +15 -6
  26. package/modules/localmodels/gateway_foundations.py +2 -4
  27. package/modules/localmodels/gateway_probe.py +0 -1
  28. package/modules/localmodels/gateway_server.py +2 -3
  29. package/modules/localmodels/gpu_specs.py +12 -0
  30. package/modules/localmodels/guard.py +2 -7
  31. package/modules/localmodels/harness.py +16 -129
  32. package/modules/localmodels/harness_cleanup.py +135 -0
  33. package/modules/localmodels/harness_gateway.py +16 -14
  34. package/modules/localmodels/harness_probe.py +12 -4
  35. package/modules/localmodels/hosts.py +25 -2
  36. package/modules/localmodels/http_local.py +59 -0
  37. package/modules/localmodels/install.py +23 -8
  38. package/modules/localmodels/library_gateway.py +20 -9
  39. package/modules/localmodels/library_jobs.py +125 -28
  40. package/modules/localmodels/library_model.py +10 -0
  41. package/modules/localmodels/library_pricing.py +29 -22
  42. package/modules/localmodels/library_serve.py +17 -1
  43. package/modules/localmodels/library_state.py +15 -2
  44. package/modules/localmodels/library_status.py +30 -0
  45. package/modules/localmodels/llm_rank.py +185 -39
  46. package/modules/localmodels/probe.py +108 -174
  47. package/modules/localmodels/process_identity.py +120 -154
  48. package/modules/localmodels/process_windows.py +86 -0
  49. package/modules/localmodels/recommend.py +6 -3
  50. package/modules/localmodels/recommend_cli.py +14 -6
  51. package/modules/localmodels/remote_ops.py +65 -0
  52. package/modules/localmodels/remote_ops_service.py +14 -2
  53. package/modules/localmodels/runtime_args.py +10 -3
  54. package/modules/localmodels/runtime_auth.py +5 -9
  55. package/modules/localmodels/runtime_cli.py +128 -129
  56. package/modules/localmodels/runtime_discovery.py +84 -0
  57. package/modules/localmodels/runtime_install.py +101 -0
  58. package/modules/localmodels/runtime_releases.py +302 -0
  59. package/modules/localmodels/search_server.py +5 -1
  60. package/modules/localmodels/service_stop.py +8 -108
  61. package/modules/localmodels/service_upgrade.py +394 -63
  62. package/modules/localmodels/services_cli.py +24 -14
  63. package/modules/localmodels/setup_inspection.py +97 -9
  64. package/modules/localmodels/setup_text.py +7 -0
  65. package/modules/localmodels/sizecalc.py +0 -1
  66. package/modules/localmodels/stack.py +45 -235
  67. package/modules/localmodels/stack_arena.py +732 -0
  68. package/modules/localmodels/stack_args.py +21 -12
  69. package/modules/localmodels/stack_auto.py +384 -3
  70. package/modules/localmodels/stack_aux_gpu.py +4 -3
  71. package/modules/localmodels/stack_capacity.py +138 -0
  72. package/modules/localmodels/stack_cleanup.py +9 -4
  73. package/modules/localmodels/stack_cli.py +288 -0
  74. package/modules/localmodels/stack_compose.py +63 -30
  75. package/modules/localmodels/stack_console.py +9 -6
  76. package/modules/localmodels/stack_hardware.py +95 -265
  77. package/modules/localmodels/stack_hardware_text.py +263 -0
  78. package/modules/localmodels/stack_journal.py +3 -9
  79. package/modules/localmodels/stack_ledger.py +48 -18
  80. package/modules/localmodels/stack_lifecycle.py +33 -312
  81. package/modules/localmodels/stack_llm_ram.py +16 -6
  82. package/modules/localmodels/stack_mcp.py +729 -0
  83. package/modules/localmodels/stack_memory.py +0 -2
  84. package/modules/localmodels/stack_picks.py +62 -15
  85. package/modules/localmodels/stack_plan.py +19 -1
  86. package/modules/localmodels/stack_preflight.py +11 -19
  87. package/modules/localmodels/stack_progress.py +9 -1
  88. package/modules/localmodels/stack_remove.py +373 -0
  89. package/modules/localmodels/stack_route.py +101 -17
  90. package/modules/localmodels/stack_run.py +29 -0
  91. package/modules/localmodels/stack_suite.py +21 -10
  92. package/modules/localmodels/stack_summary.py +14 -0
  93. package/modules/localmodels/stack_try.py +238 -24
  94. package/modules/localmodels/stack_try_client.py +53 -15
  95. package/modules/localmodels/stack_try_docs.py +2 -2
  96. package/modules/localmodels/stack_view.py +24 -171
  97. package/modules/localmodels/stack_view_access.py +114 -1
  98. package/modules/localmodels/stack_view_agent.py +3 -13
  99. package/modules/localmodels/stack_view_hub.py +9 -10
  100. package/modules/localmodels/stack_view_llm.py +1 -1
  101. package/modules/localmodels/stack_view_sandbox.py +2 -2
  102. package/modules/localmodels/stack_view_schema.py +183 -0
  103. package/modules/localmodels/stack_view_serve.py +7 -1
  104. package/modules/localmodels/stack_view_service.py +1 -2
  105. package/modules/localmodels/stack_view_text.py +13 -9
  106. package/modules/localmodels/stack_warm.py +48 -4
  107. package/modules/localmodels/stack_warm_store.py +517 -0
  108. package/modules/localmodels/tools.json +32 -18
  109. package/modules/localmodels/transport.py +38 -13
  110. package/modules/localmodels/tui.py +28 -4
  111. package/modules/localmodels/tui_dialogs.py +136 -0
  112. package/modules/localmodels/tui_modals.py +279 -0
  113. package/modules/localmodels/tui_screen.py +113 -154
  114. package/modules/localmodels/tui_views.py +134 -203
  115. package/modules/localmodels/web/index.html +510 -101
  116. package/modules/localmodels/web/sizecalc/app.js +363 -10
  117. package/modules/localmodels/web/sizecalc/page.html +27 -3
  118. package/modules/localmodels/web/view/fleet.html +11 -2
  119. package/modules/localmodels/web/view/fleet.js +191 -17
  120. package/modules/localmodels/web/view/i18n.js +3 -2
  121. package/modules/localmodels/web/view/index.html +1 -1
  122. package/modules/localmodels/web/view/nav.js +22 -3
  123. package/modules/localmodels/web/view/view.css +63 -18
  124. package/modules/localmodels/web/view/view.js +169 -32
  125. package/modules/localmodels/windows_job.py +69 -0
  126. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
  127. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
  128. package/package.json +1 -1
  129. package/tool.json +1 -1
  130. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  131. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
  132. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
  133. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
  134. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,517 @@
1
+ """Private per-device decode measurements persisted from ``stack warm``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import datetime as dt
6
+ import json
7
+ import math
8
+ import os
9
+ import threading
10
+ from collections.abc import Mapping, Sequence
11
+ from pathlib import Path
12
+ from typing import Any, Literal, TypedDict, TypeGuard
13
+
14
+ from localmodels import gpu_specs, hosts, metal, probe
15
+ from localmodels.probe import GPU, HostFacts
16
+ from localmodels.records import Plan
17
+
18
+ SCHEMA: Literal["localmodels.warm-speeds/v1"] = "localmodels.warm-speeds/v1"
19
+ _LOCK = threading.Lock()
20
+
21
+
22
+ class WarmSpeedEntry(TypedDict):
23
+ hostname: str
24
+ platform: str
25
+ ram_total_bytes: int
26
+ gpu_name: str
27
+ model_id: str
28
+ quant: str
29
+ decode_tok_s: float
30
+ measured_at: str
31
+
32
+
33
+ class WarmSpeedStore(TypedDict):
34
+ schema: Literal["localmodels.warm-speeds/v1"]
35
+ entries: dict[str, WarmSpeedEntry]
36
+
37
+
38
+ KeyTuple = tuple[str, str, int, str, str, str]
39
+
40
+
41
+ def store_path() -> Path:
42
+ """Private store of measured decode speeds under the controller state directory."""
43
+ return hosts.state_dir() / "warm_speeds.json"
44
+
45
+
46
+ def _is_positive_int(value: object) -> TypeGuard[int]:
47
+ return isinstance(value, int) and not isinstance(value, bool) and value > 0
48
+
49
+
50
+ def _is_positive_speed(value: object) -> TypeGuard[int | float]:
51
+ if not isinstance(value, int | float) or isinstance(value, bool):
52
+ return False
53
+ try:
54
+ as_float = float(value)
55
+ except OverflowError:
56
+ return False
57
+ return math.isfinite(as_float) and as_float > 0
58
+
59
+
60
+ def _total_ram_bytes(facts: HostFacts) -> int | None:
61
+ ram = facts.get("ram")
62
+ total = ram.get("total_bytes") if isinstance(ram, Mapping) else None
63
+ if not _is_positive_int(total):
64
+ return None
65
+ cgroup = facts.get("cgroup_memory")
66
+ if facts.get("environment") == "container" and isinstance(cgroup, Mapping):
67
+ limit = cgroup.get("limit_bytes")
68
+ if _is_positive_int(limit):
69
+ total = min(total, limit)
70
+ return total
71
+
72
+
73
+ def _gpu_name(facts: HostFacts, gpu_index: int | None) -> str | None:
74
+ if gpu_index is None:
75
+ return ""
76
+ if not isinstance(gpu_index, int) or isinstance(gpu_index, bool):
77
+ return None
78
+ mac = metal.device(facts) if gpu_index == 0 else None
79
+ if mac is not None:
80
+ raw_gpu = str(mac.get("name") or "")
81
+ else:
82
+ card = next(
83
+ (
84
+ g
85
+ for g in (facts.get("gpus") or [])
86
+ if isinstance(g, Mapping) and g.get("index") == gpu_index
87
+ ),
88
+ None,
89
+ )
90
+ if card is None:
91
+ return None
92
+ raw_gpu = str(card.get("name") or "")
93
+ normalized = gpu_specs.normalized(raw_gpu)
94
+ return normalized or None
95
+
96
+
97
+ def _key_tuple(
98
+ facts: HostFacts, gpu_index: int | None, model_id: str, quant: str
99
+ ) -> KeyTuple | None:
100
+ hostname = str(facts.get("hostname") or "").strip()
101
+ if not hostname or hostname == "simulated":
102
+ return None
103
+ platform = str(facts.get("platform") or "").strip()
104
+ if not platform:
105
+ return None
106
+ ram_total = _total_ram_bytes(facts)
107
+ if ram_total is None:
108
+ return None
109
+ gpu_name = _gpu_name(facts, gpu_index)
110
+ if gpu_name is None:
111
+ return None
112
+ mid = model_id.strip()
113
+ q = quant.strip()
114
+ if not mid or not q:
115
+ return None
116
+ return (hostname, platform, ram_total, gpu_name, mid, q)
117
+
118
+
119
+ def _encode_key(key: KeyTuple) -> str:
120
+ return json.dumps(list(key), ensure_ascii=False, separators=(",", ":"))
121
+
122
+
123
+ def _valid_entry(key: object, raw: object) -> WarmSpeedEntry | None:
124
+ if not isinstance(key, str) or not isinstance(raw, Mapping):
125
+ return None
126
+ hostname = raw.get("hostname")
127
+ platform = raw.get("platform")
128
+ ram_total = raw.get("ram_total_bytes")
129
+ gpu_name = raw.get("gpu_name")
130
+ model_id = raw.get("model_id")
131
+ quant = raw.get("quant")
132
+ decode_tok_s = raw.get("decode_tok_s")
133
+ measured_at = raw.get("measured_at")
134
+ if not (
135
+ isinstance(hostname, str)
136
+ and hostname
137
+ and hostname != "simulated"
138
+ and isinstance(platform, str)
139
+ and platform
140
+ and _is_positive_int(ram_total)
141
+ and isinstance(gpu_name, str)
142
+ and isinstance(model_id, str)
143
+ and model_id
144
+ and isinstance(quant, str)
145
+ and quant
146
+ and _is_positive_speed(decode_tok_s)
147
+ and isinstance(measured_at, str)
148
+ ):
149
+ return None
150
+ expected = _encode_key((hostname, platform, ram_total, gpu_name, model_id, quant))
151
+ if key != expected:
152
+ return None
153
+ return {
154
+ "hostname": hostname,
155
+ "platform": platform,
156
+ "ram_total_bytes": ram_total,
157
+ "gpu_name": gpu_name,
158
+ "model_id": model_id,
159
+ "quant": quant,
160
+ "decode_tok_s": float(decode_tok_s),
161
+ "measured_at": measured_at,
162
+ }
163
+
164
+
165
+ def _load_entries() -> dict[str, WarmSpeedEntry]:
166
+ try:
167
+ raw = json.loads(store_path().read_text(encoding="utf-8"))
168
+ except (OSError, UnicodeError, ValueError):
169
+ return {}
170
+ if not isinstance(raw, dict) or raw.get("schema") != SCHEMA:
171
+ return {}
172
+ entries = raw.get("entries")
173
+ if not isinstance(entries, dict):
174
+ return {}
175
+ loaded: dict[str, WarmSpeedEntry] = {}
176
+ for key, value in entries.items():
177
+ valid = _valid_entry(key, value)
178
+ if valid is not None:
179
+ loaded[key] = valid
180
+ return loaded
181
+
182
+
183
+ def record(
184
+ facts: HostFacts,
185
+ gpu_index: int | None,
186
+ model_id: str,
187
+ quant: str,
188
+ decode_tok_s: float,
189
+ ) -> bool:
190
+ """Persist a positive same-device decode measurement atomically as 0600 JSON."""
191
+ if not _is_positive_speed(decode_tok_s):
192
+ return False
193
+ key = _key_tuple(facts, gpu_index, model_id, quant)
194
+ if key is None:
195
+ return False
196
+ encoded = _encode_key(key)
197
+ entry: WarmSpeedEntry = {
198
+ "hostname": key[0],
199
+ "platform": key[1],
200
+ "ram_total_bytes": key[2],
201
+ "gpu_name": key[3],
202
+ "model_id": key[4],
203
+ "quant": key[5],
204
+ "decode_tok_s": float(decode_tok_s),
205
+ "measured_at": dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds"),
206
+ }
207
+ with _LOCK:
208
+ entries = _load_entries()
209
+ entries[encoded] = entry
210
+ doc: WarmSpeedStore = {"schema": SCHEMA, "entries": entries}
211
+ hosts.save_private(store_path(), doc)
212
+ return True
213
+
214
+
215
+ def lookup(facts: HostFacts, gpu_index: int, model_id: str, quant: str) -> float | None:
216
+ """Return a positive measured decode speed matching this device and model, else None."""
217
+ key = _key_tuple(facts, gpu_index, model_id, quant)
218
+ if key is None:
219
+ return None
220
+ entry = _load_entries().get(_encode_key(key))
221
+ return float(entry["decode_tok_s"]) if entry is not None else None
222
+
223
+
224
+ def apply_fit_measurement(facts: HostFacts, gpu_index: int, fit: Any) -> None:
225
+ """Overlay a same-device warm measurement onto a ``stack_hardware.llm_fits`` entry."""
226
+ model_id = fit.get("id")
227
+ quant = fit.get("quant")
228
+ if not isinstance(model_id, str) or not isinstance(quant, str):
229
+ return
230
+ measured = lookup(facts, gpu_index, model_id, quant)
231
+ if measured is not None:
232
+ fit["decode_tok_s"] = round(measured, 1)
233
+ fit["decode_basis"] = "measured-decode"
234
+
235
+
236
+ def _resolve_legacy_gpu(
237
+ card_spec: Mapping[str, Any], host_gpus: Sequence[Mapping[str, Any]]
238
+ ) -> tuple[bool, int | None]:
239
+ idx = card_spec.get("index")
240
+ spec_name = gpu_specs.normalized(str(card_spec.get("name") or ""))
241
+ if not isinstance(idx, int) or isinstance(idx, bool) or not spec_name:
242
+ return False, None
243
+ matched = next((g for g in host_gpus if g.get("index") == idx), None)
244
+ if matched is None or str(matched.get("uuid") or "").strip():
245
+ return False, None
246
+ if gpu_specs.normalized(str(matched.get("name") or "")) != spec_name:
247
+ return False, None
248
+ return True, idx
249
+
250
+
251
+ def _cuda_env(part: Plan) -> str:
252
+ env = part.get("service", {}).get("env")
253
+ raw_cuda = env.get("CUDA_VISIBLE_DEVICES") if isinstance(env, Mapping) else None
254
+ return raw_cuda.strip() if isinstance(raw_cuda, str) else ""
255
+
256
+
257
+ def _resolve_part_gpu(part: Plan, facts: HostFacts) -> tuple[bool, int | None]:
258
+ placement = part["placement"]
259
+ if placement.get("pooled"):
260
+ return False, None
261
+ raw_gpus = placement.get("gpus")
262
+ if isinstance(raw_gpus, list) and len(raw_gpus) > 1:
263
+ return False, None
264
+ cuda_dev = _cuda_env(part)
265
+ if "," in cuda_dev:
266
+ return False, None
267
+ if metal.on_device(placement):
268
+ return (True, 0) if metal.device(facts) is not None else (False, None)
269
+ if raw_gpus in (None, []) and not cuda_dev:
270
+ return True, None
271
+ if not (isinstance(raw_gpus, list) and len(raw_gpus) == 1 and isinstance(raw_gpus[0], Mapping)):
272
+ if raw_gpus not in (None, []):
273
+ return False, None
274
+ card_spec: Mapping[str, Any] = {}
275
+ else:
276
+ card_spec = raw_gpus[0]
277
+ place_uuid = str(card_spec.get("uuid") or "").strip()
278
+ if cuda_dev and place_uuid and cuda_dev != place_uuid:
279
+ return False, None
280
+ target_uuid = cuda_dev or place_uuid
281
+ host_gpus = [g for g in (facts.get("gpus") or []) if isinstance(g, Mapping)]
282
+ if not target_uuid:
283
+ return _resolve_legacy_gpu(card_spec, host_gpus)
284
+ matched = next(
285
+ (g for g in host_gpus if str(g.get("uuid") or "").strip() == target_uuid),
286
+ None,
287
+ )
288
+ if matched is None:
289
+ return False, None
290
+ idx = matched.get("index")
291
+ if not isinstance(idx, int) or isinstance(idx, bool):
292
+ return False, None
293
+ return True, idx
294
+
295
+
296
+ def _gpu_card(
297
+ index: int, uuid: str, name: str, total: int = 0, free: int = 0, used: int = 0
298
+ ) -> GPU:
299
+ return {
300
+ "index": index,
301
+ "uuid": uuid,
302
+ "name": name,
303
+ "vendor": "nvidia",
304
+ "pci_bus_id": "",
305
+ "pci_device_id": None,
306
+ "total_bytes": total,
307
+ "free_bytes": free,
308
+ "used_bytes": used,
309
+ "util_percent": None,
310
+ "driver_version": "",
311
+ }
312
+
313
+
314
+ def _single_placed_card(part: Plan) -> tuple[int, str, str] | None:
315
+ raw_gpus = part["placement"].get("gpus")
316
+ if not (isinstance(raw_gpus, list) and len(raw_gpus) == 1 and isinstance(raw_gpus[0], Mapping)):
317
+ return None
318
+ card = raw_gpus[0]
319
+ idx = card.get("index")
320
+ if not isinstance(idx, int) or isinstance(idx, bool):
321
+ return None
322
+ name = str(card.get("name") or "")
323
+ cuda_dev = _cuda_env(part)
324
+ uuid = str(card.get("uuid") or "").strip() or ("" if "," in cuda_dev else cuda_dev)
325
+ return idx, name, uuid
326
+
327
+
328
+ def _part_uuid_by_card(parts: Sequence[tuple[str, Plan]]) -> dict[tuple[int, str], str]:
329
+ found: dict[tuple[int, str], str] = {}
330
+ for _, part in parts:
331
+ placed = _single_placed_card(part)
332
+ if placed is None:
333
+ continue
334
+ idx, name, uuid = placed
335
+ norm = gpu_specs.normalized(name)
336
+ if norm and uuid:
337
+ found.setdefault((idx, norm), uuid)
338
+ return found
339
+
340
+
341
+ def _cards_from_parts(
342
+ parts: Sequence[tuple[str, Plan]],
343
+ ) -> tuple[list[GPU], dict[str, object] | None]:
344
+ gpus: list[GPU] = []
345
+ metal_doc: dict[str, object] | None = None
346
+ for _, part in parts:
347
+ placed = _single_placed_card(part)
348
+ if placed is None:
349
+ continue
350
+ idx, name, uuid = placed
351
+ if uuid == metal.METAL_UUID and metal_doc is None:
352
+ metal_doc = {"name": name, "unified_memory": True}
353
+ elif name and not any(g["index"] == idx for g in gpus):
354
+ gpus.append(_gpu_card(idx, uuid, name))
355
+ return gpus, metal_doc
356
+
357
+
358
+ def _cards_from_hardware(
359
+ hardware: Mapping[str, Any],
360
+ parts: Sequence[tuple[str, Plan]],
361
+ ) -> tuple[list[GPU], dict[str, object] | None, str]:
362
+ cards = hardware.get("cards") or []
363
+ part_uuids = _part_uuid_by_card(parts)
364
+ metal_card = next(
365
+ (c for c in cards if isinstance(c, Mapping) and c.get("uuid") == metal.METAL_UUID), None
366
+ )
367
+ gpus: list[GPU] = []
368
+ for c in cards:
369
+ if not isinstance(c, Mapping) or c.get("uuid") == metal.METAL_UUID:
370
+ continue
371
+ idx = int(c["index"])
372
+ name = str(c["name"])
373
+ uuid = str(c.get("uuid") or "") or part_uuids.get((idx, gpu_specs.normalized(name)), "")
374
+ gpus.append(
375
+ _gpu_card(
376
+ idx,
377
+ uuid,
378
+ name,
379
+ int(c["total_bytes"]),
380
+ int(c["free_bytes"]),
381
+ int(c["used_bytes"]),
382
+ )
383
+ )
384
+ metal_doc: dict[str, object] | None = (
385
+ {
386
+ "name": str(metal_card["name"]),
387
+ "unified_memory": True,
388
+ "recommended_max_working_set_bytes": int(metal_card["total_bytes"]),
389
+ }
390
+ if metal_card is not None
391
+ else None
392
+ )
393
+ arch = str(hardware.get("arch") or "") or ("arm64" if metal_doc is not None else "")
394
+ return gpus, metal_doc, arch
395
+
396
+
397
+ def _live_ram_basis(
398
+ platform: str, raw_total_ram: int
399
+ ) -> tuple[int, str, probe.CgroupMemory | None]:
400
+ if platform.startswith("linux"):
401
+ env_kind = probe.environment()
402
+ if env_kind == "container":
403
+ live_cg = probe.cgroup_memory()
404
+ limit = live_cg.get("limit_bytes") if live_cg is not None else None
405
+ effective = min(raw_total_ram, limit) if _is_positive_int(limit) else raw_total_ram
406
+ return effective, "container", live_cg
407
+ return raw_total_ram, env_kind, None
408
+ return raw_total_ram, "bare", None
409
+
410
+
411
+ def _warm_facts(
412
+ plan: Mapping[str, Any],
413
+ report: Mapping[str, Any],
414
+ parts: Sequence[tuple[str, Plan]],
415
+ ) -> HostFacts | None:
416
+ hostname = str(report.get("hostname") or "")
417
+ platform = str(report.get("platform") or "")
418
+ if not hostname or hostname == "simulated" or plan.get("hostname") != hostname:
419
+ return None
420
+ mem_before, mem_after = report["memory_before"], report["memory_after"]
421
+ raw_total_ram = mem_before.get("total_bytes")
422
+ if not _is_positive_int(raw_total_ram):
423
+ return None
424
+ hardware = plan.get("hardware")
425
+ hw_ram: int | None = None
426
+ if isinstance(hardware, Mapping):
427
+ if hardware.get("platform") and hardware["platform"] != platform:
428
+ return None
429
+ if hardware.get("assumed_unified_bytes") is None:
430
+ cand = hardware.get("ram_total_bytes")
431
+ if not _is_positive_int(cand):
432
+ return None
433
+ hw_ram = cand
434
+ live_effective_ram, env_kind, cgroup_doc = _live_ram_basis(platform, raw_total_ram)
435
+ if hw_ram is not None and hw_ram != live_effective_ram:
436
+ return None
437
+ cached = hosts.load_facts(hosts.LOCAL_ID)
438
+ if (
439
+ cached is not None
440
+ and cached.get("hostname") == hostname
441
+ and cached.get("platform") == platform
442
+ and cached.get("ram", {}).get("total_bytes") == raw_total_ram
443
+ and _total_ram_bytes(cached) == live_effective_ram
444
+ ):
445
+ return cached
446
+ if isinstance(hardware, Mapping):
447
+ gpus, metal_doc, arch = _cards_from_hardware(hardware, parts)
448
+ else:
449
+ gpus, metal_doc = _cards_from_parts(parts)
450
+ arch = "arm64" if metal_doc is not None else ""
451
+ return {
452
+ "schema": probe.SCHEMA,
453
+ "collected_at": "",
454
+ "hostname": hostname,
455
+ "user": "",
456
+ "platform": platform,
457
+ "arch": arch,
458
+ "os": {},
459
+ "python": "",
460
+ "cpu": {},
461
+ "ram": {
462
+ "total_bytes": raw_total_ram,
463
+ "available_bytes": int(mem_after["available_bytes"]),
464
+ },
465
+ "gpu_vendor_class": "apple_silicon" if metal_doc is not None else "nvidia",
466
+ "nvidia": None,
467
+ "gpus": gpus,
468
+ "cuda_pool": None,
469
+ "llama_servers": [],
470
+ "engines": [],
471
+ "disk": {"path": "", "free_bytes": None, "total_bytes": None},
472
+ "service_manager": {"kind": "nohup", "linger": False},
473
+ "errors": [],
474
+ "environment": env_kind,
475
+ "cgroup_memory": cgroup_doc,
476
+ "metal": metal_doc,
477
+ }
478
+
479
+
480
+ def persist_warm(
481
+ plan: Mapping[str, Any],
482
+ report: Mapping[str, Any],
483
+ parts: Sequence[tuple[str, Plan]],
484
+ warmed: Mapping[str, Mapping[str, Any]],
485
+ ) -> None:
486
+ """Persist ``warm.json`` in the LLM deployment directory and update ``warm_speeds.json``."""
487
+ llm_report = report.get("llm")
488
+ if isinstance(llm_report, Mapping) and llm_report.get("ok") is True:
489
+ deploy_dir = Path(os.path.expanduser(str(plan["llm"]["service"]["deploy_dir"])))
490
+ if deploy_dir.is_dir():
491
+ try:
492
+ hosts.save_private(deploy_dir / "warm.json", report)
493
+ except OSError:
494
+ pass
495
+ facts = _warm_facts(plan, report, parts)
496
+ if facts is None:
497
+ return
498
+ for role, part in parts:
499
+ item = warmed.get(role)
500
+ if item is None or item.get("ok") is not True:
501
+ continue
502
+ speed = item.get("decode_tok_s")
503
+ if not _is_positive_speed(speed):
504
+ continue
505
+ ok_gpu, gpu_index = _resolve_part_gpu(part, facts)
506
+ if not ok_gpu:
507
+ continue
508
+ try:
509
+ record(
510
+ facts,
511
+ gpu_index,
512
+ str(part["model"]["id"]),
513
+ str(part["model"]["quant"]),
514
+ float(speed),
515
+ )
516
+ except OSError:
517
+ pass
@@ -101,7 +101,7 @@
101
101
  ]
102
102
  },
103
103
  "bifrost": {
104
- "version": "v2.3.0-localmodels.5",
104
+ "version": "v2.3.0-localmodels.6",
105
105
  "source": "maximhq/bifrost tag transports/v2.3.0 (9237ec06672406e437b3cb33fc793ffd0403b3ae) with scripts/bifrost/patches applied",
106
106
  "license": "Apache-2.0",
107
107
  "note": "Binary SHA256 and size are always verified. Release CI reuses verified published npm tarballs, or packs unpublished versions, and adds their exact archive SHA256 and bytes before building wheels and kits. Source checkouts without archive pins use a bounded download and verify the extracted binary against these pins. macOS requires 13 or later.",
@@ -109,44 +109,58 @@
109
109
  {
110
110
  "platform": "linux",
111
111
  "arch": "x64",
112
- "name": "bifrost-http-v2.3.0-localmodels.5-linux-amd64",
113
- "url": "https://registry.npmjs.org/@simplexai/bifrost-linux-x64/-/bifrost-linux-x64-2.3.0-localmodels.5.tgz",
114
- "sha256": "9b7092361e98e9336052e76edd9e7b961d703f48b031bda2a1ba30ed89c31ba9",
112
+ "name": "bifrost-http-v2.3.0-localmodels.6-linux-amd64",
113
+ "url": "https://registry.npmjs.org/@simplexai/bifrost-linux-x64/-/bifrost-linux-x64-2.3.0-localmodels.6.tgz",
114
+ "sha256": "cc150e8c1e2a79d1510b6f9e16a1a3a8ce8c4155f9d09e198331223109d98299",
115
115
  "size_bytes": 134369352,
116
116
  "npm": {
117
117
  "package": "@simplexai/bifrost-linux-x64",
118
- "version": "2.3.0-localmodels.5",
119
- "sha256": "38e9f1bb1642df5e1119264067ae48bf152d919e181d118349ab524adbc9c562",
120
- "bytes": 44527062
118
+ "version": "2.3.0-localmodels.6",
119
+ "sha256": "c0ca5c46367257f42c9459473bf060c7f0543d56bd61f1a0aa47bcd88e86d4ba",
120
+ "bytes": 44526898
121
121
  }
122
122
  },
123
123
  {
124
124
  "platform": "linux",
125
125
  "arch": "arm64",
126
- "name": "bifrost-http-v2.3.0-localmodels.5-linux-arm64",
127
- "url": "https://registry.npmjs.org/@simplexai/bifrost-linux-arm64/-/bifrost-linux-arm64-2.3.0-localmodels.5.tgz",
128
- "sha256": "7ebed6aee1b3a0484d18666313f485b937161dea8097f67aed94ee7ae89154d6",
126
+ "name": "bifrost-http-v2.3.0-localmodels.6-linux-arm64",
127
+ "url": "https://registry.npmjs.org/@simplexai/bifrost-linux-arm64/-/bifrost-linux-arm64-2.3.0-localmodels.6.tgz",
128
+ "sha256": "2271017c90aa82039a4b1053d8de724e9d790dbedd8688c7cc6293e3295b4803",
129
129
  "size_bytes": 121320696,
130
130
  "npm": {
131
131
  "package": "@simplexai/bifrost-linux-arm64",
132
- "version": "2.3.0-localmodels.5",
133
- "sha256": "65b68909a6f6661f9641018ad52b4040b0351c97bf824b56fc96611c469b7efa",
134
- "bytes": 39350802
132
+ "version": "2.3.0-localmodels.6",
133
+ "sha256": "1de39559b85d38ad1999415a26ca609d307fe8a1a748e8d97881d2ba21b5aab8",
134
+ "bytes": 39350803
135
135
  }
136
136
  },
137
137
  {
138
138
  "platform": "darwin",
139
139
  "arch": "arm64",
140
- "name": "bifrost-http-v2.3.0-localmodels.5-darwin-arm64",
141
- "url": "https://registry.npmjs.org/@simplexai/bifrost-darwin-arm64/-/bifrost-darwin-arm64-2.3.0-localmodels.5.tgz",
142
- "sha256": "888ca565268e196839a5ac26678b180a7df7d378b7f60f8ceaffb160934fc2f6",
140
+ "name": "bifrost-http-v2.3.0-localmodels.6-darwin-arm64",
141
+ "url": "https://registry.npmjs.org/@simplexai/bifrost-darwin-arm64/-/bifrost-darwin-arm64-2.3.0-localmodels.6.tgz",
142
+ "sha256": "ea79619e1aea87bac1000df09306c11cd75ffc15e7da78c52806a88d27da0c13",
143
143
  "size_bytes": 129721778,
144
144
  "npm": {
145
145
  "package": "@simplexai/bifrost-darwin-arm64",
146
- "version": "2.3.0-localmodels.5",
147
- "sha256": "04c364f6dec3c766fc127d4aa4d17e5ef797a1b1a8fc70dc1a4dfd2e1a78f016",
146
+ "version": "2.3.0-localmodels.6",
147
+ "sha256": "b520fc349c5bab6efdf158195fe68537fd2a3d7a56eecfaedd3101d3c057f16f",
148
148
  "bytes": 42858185
149
149
  }
150
+ },
151
+ {
152
+ "platform": "win32",
153
+ "arch": "x64",
154
+ "name": "bifrost-http-v2.3.0-localmodels.6-windows-amd64",
155
+ "url": "https://registry.npmjs.org/@simplexai/bifrost-win32-x64/-/bifrost-win32-x64-2.3.0-localmodels.6.tgz",
156
+ "sha256": "6f396470e642bb5e9472aa19361bf07cd3e909658674a1506c25171f62cb8544",
157
+ "size_bytes": 128701952,
158
+ "npm": {
159
+ "package": "@simplexai/bifrost-win32-x64",
160
+ "version": "2.3.0-localmodels.6",
161
+ "sha256": "45c44a042e555dfc593d19975c15d1240ad1f57dd765558f60e57e3637e2835f",
162
+ "bytes": 42705253
163
+ }
150
164
  }
151
165
  ]
152
166
  }
@@ -55,6 +55,43 @@ class Result:
55
55
  stderr: str
56
56
 
57
57
 
58
+ REAP_S = 10.0 # how long an interrupted run waits for the killed helper to be gone
59
+
60
+
61
+ def stream(argv: list[str], source: bytes, on_line: Callable[[str], None]) -> Result:
62
+ """Run ``argv`` with ``source`` on stdin, handing each stdout line to ``on_line`` as it
63
+ arrives. Whatever ends the run early (Ctrl+C, a cancel's SIGTERM turned KeyboardInterrupt,
64
+ an error in ``on_line``) kills the helper and waits for it before it propagates: the caller
65
+ then releases what the helper was writing (a download's claim on a file), and a helper
66
+ still running would go on writing a file another download has claimed since. Popen's own
67
+ exit waits only 0.25 s after a KeyboardInterrupt and never kills."""
68
+ with subprocess.Popen(
69
+ argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
70
+ ) as proc:
71
+ assert proc.stdin and proc.stdout and proc.stderr
72
+ if sys.platform == "win32": # nothing above runs when this process is killed outright
73
+ from localmodels import windows_job
74
+
75
+ windows_job.end_with_this_process(int(proc._handle)) # type: ignore[attr-defined]
76
+ try:
77
+ proc.stdin.write(source)
78
+ proc.stdin.close()
79
+ lines = []
80
+ for raw in proc.stdout:
81
+ line = raw.decode("utf-8", "replace").rstrip("\n")
82
+ lines.append(line)
83
+ on_line(line)
84
+ stderr = proc.stderr.read().decode("utf-8", "replace")
85
+ return Result(proc.wait(), "\n".join(lines), stderr)
86
+ except BaseException:
87
+ proc.kill() # SIGKILL; TerminateProcess on Windows
88
+ try:
89
+ proc.wait(timeout=REAP_S)
90
+ except subprocess.TimeoutExpired:
91
+ pass
92
+ raise
93
+
94
+
58
95
  @dataclass(frozen=True)
59
96
  class Executor:
60
97
  """``target`` is None for this machine, else an ssh destination (alias or user@host)."""
@@ -111,19 +148,7 @@ class Executor:
111
148
  out.stdout.decode("utf-8", "replace"),
112
149
  out.stderr.decode("utf-8", "replace"),
113
150
  )
114
- with subprocess.Popen(
115
- argv, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
116
- ) as proc:
117
- assert proc.stdin and proc.stdout and proc.stderr
118
- proc.stdin.write(source)
119
- proc.stdin.close()
120
- lines = []
121
- for raw in proc.stdout:
122
- line = raw.decode("utf-8", "replace").rstrip("\n")
123
- lines.append(line)
124
- on_line(line)
125
- stderr = proc.stderr.read().decode("utf-8", "replace")
126
- return Result(proc.wait(), "\n".join(lines), stderr)
151
+ return stream(argv, source, on_line)
127
152
 
128
153
  def _bundle_source(self, script: str, entry: bytes, params: object) -> bytes:
129
154
  """The payload for a BUNDLES script: a stub ``localmodels`` package plus a meta-path