@simplexai/localmodels-win32-x64 0.1.0-dev.63 → 0.1.0-dev.65

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 (142) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +140 -130
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +2 -2
  5. package/modules/localmodels/app.py +15 -2
  6. package/modules/localmodels/approval.py +5 -3
  7. package/modules/localmodels/bifrost_checks.py +2 -1
  8. package/modules/localmodels/catalog.json +36 -0
  9. package/modules/localmodels/catalog.py +28 -5
  10. package/modules/localmodels/catalog_recipes.py +40 -1
  11. package/modules/localmodels/component.py +1 -1
  12. package/modules/localmodels/context_policy.py +7 -2
  13. package/modules/localmodels/custom_probe.py +5 -5
  14. package/modules/localmodels/debug_mode.py +85 -103
  15. package/modules/localmodels/deploy.py +129 -18
  16. package/modules/localmodels/deployment_lifecycle.py +167 -0
  17. package/modules/localmodels/download-mirrors.json +126 -6
  18. package/modules/localmodels/draft_spec.py +164 -0
  19. package/modules/localmodels/engine_adapters/__init__.py +4 -0
  20. package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
  21. package/modules/localmodels/engine_adapters/base.py +40 -0
  22. package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
  23. package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
  24. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  25. package/modules/localmodels/gateway.py +124 -13
  26. package/modules/localmodels/gateway_accept.py +1 -6
  27. package/modules/localmodels/gateway_cli.py +13 -24
  28. package/modules/localmodels/gateway_ops.py +185 -0
  29. package/modules/localmodels/gateway_server.py +3 -2
  30. package/modules/localmodels/harness.py +13 -16
  31. package/modules/localmodels/harness_core.py +4 -9
  32. package/modules/localmodels/harness_gateway.py +4 -3
  33. package/modules/localmodels/hosts.py +22 -34
  34. package/modules/localmodels/install.py +15 -0
  35. package/modules/localmodels/library_convert.py +5 -11
  36. package/modules/localmodels/library_custom.py +6 -6
  37. package/modules/localmodels/library_elastic.py +24 -127
  38. package/modules/localmodels/library_jobs.py +14 -5
  39. package/modules/localmodels/library_order.py +4 -3
  40. package/modules/localmodels/library_poly.py +5 -4
  41. package/modules/localmodels/library_pricing.py +80 -255
  42. package/modules/localmodels/library_serve.py +13 -14
  43. package/modules/localmodels/library_smoke.py +8 -1
  44. package/modules/localmodels/library_status.py +16 -16
  45. package/modules/localmodels/llm_rank.py +1 -1
  46. package/modules/localmodels/magpie_legacy.py +160 -0
  47. package/modules/localmodels/magpie_setup.py +6 -1
  48. package/modules/localmodels/memcalc_cli.py +2 -2
  49. package/modules/localmodels/pi_profile.py +3 -7
  50. package/modules/localmodels/plan_envelope.py +1 -1
  51. package/modules/localmodels/planning/__init__.py +3 -0
  52. package/modules/localmodels/{budget.py → planning/budget.py} +48 -30
  53. package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
  54. package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
  55. package/modules/localmodels/planning/memory_pools.py +403 -0
  56. package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
  57. package/modules/localmodels/recommend.py +1 -1
  58. package/modules/localmodels/recommend_cli.py +3 -4
  59. package/modules/localmodels/residency_host.py +1 -1
  60. package/modules/localmodels/service_control.py +4 -4
  61. package/modules/localmodels/service_deployment.py +3 -2
  62. package/modules/localmodels/service_wiring.py +17 -19
  63. package/modules/localmodels/setup_inspection.py +1 -1
  64. package/modules/localmodels/setup_inspection_harness.py +1 -1
  65. package/modules/localmodels/setup_upgrade.py +3 -12
  66. package/modules/localmodels/sizecalc_cli.py +10 -2
  67. package/modules/localmodels/speech_admission.py +1 -1
  68. package/modules/localmodels/speech_jobs.py +2 -1
  69. package/modules/localmodels/speech_model.py +2 -0
  70. package/modules/localmodels/speech_server.py +130 -9
  71. package/modules/localmodels/speech_state.py +11 -0
  72. package/modules/localmodels/speech_worker_sensevoice.py +38 -0
  73. package/modules/localmodels/speech_workers.py +5 -1
  74. package/modules/localmodels/stack.py +4 -9
  75. package/modules/localmodels/stack_arena.py +2 -2
  76. package/modules/localmodels/stack_auto.py +5 -5
  77. package/modules/localmodels/stack_aux_gpu.py +5 -3
  78. package/modules/localmodels/stack_binding.py +24 -143
  79. package/modules/localmodels/stack_capacity.py +1 -1
  80. package/modules/localmodels/stack_card.py +3 -3
  81. package/modules/localmodels/stack_cleanup.py +6 -5
  82. package/modules/localmodels/stack_client_settings.py +9 -2
  83. package/modules/localmodels/stack_compose.py +43 -6
  84. package/modules/localmodels/stack_console.py +2 -2
  85. package/modules/localmodels/stack_debug.py +1 -1
  86. package/modules/localmodels/stack_decision.py +1 -1
  87. package/modules/localmodels/stack_doctor.py +10 -7
  88. package/modules/localmodels/stack_down.py +3 -3
  89. package/modules/localmodels/stack_gpu_memory.py +1 -1
  90. package/modules/localmodels/stack_hardware.py +3 -3
  91. package/modules/localmodels/stack_hardware_text.py +1 -1
  92. package/modules/localmodels/stack_ledger.py +2 -1
  93. package/modules/localmodels/stack_lifecycle.py +7 -7
  94. package/modules/localmodels/stack_mcp.py +1 -1
  95. package/modules/localmodels/stack_memory.py +4 -4
  96. package/modules/localmodels/stack_mlx.py +1 -1
  97. package/modules/localmodels/stack_plan.py +18 -13
  98. package/modules/localmodels/stack_ports.py +2 -2
  99. package/modules/localmodels/stack_preflight.py +4 -3
  100. package/modules/localmodels/stack_remove.py +13 -6
  101. package/modules/localmodels/stack_review.py +3 -5
  102. package/modules/localmodels/stack_rollback.py +1 -1
  103. package/modules/localmodels/stack_route.py +5 -4
  104. package/modules/localmodels/stack_run.py +16 -0
  105. package/modules/localmodels/stack_suite.py +14 -6
  106. package/modules/localmodels/stack_summary.py +1 -1
  107. package/modules/localmodels/stack_try.py +10 -14
  108. package/modules/localmodels/stack_up.py +25 -39
  109. package/modules/localmodels/stack_update.py +2 -1
  110. package/modules/localmodels/stack_verify.py +4 -30
  111. package/modules/localmodels/stack_view.py +6 -4
  112. package/modules/localmodels/stack_view_apply.py +2 -2
  113. package/modules/localmodels/stack_view_llm.py +12 -7
  114. package/modules/localmodels/stack_view_text.py +2 -6
  115. package/modules/localmodels/stack_view_tick.py +2 -2
  116. package/modules/localmodels/stack_view_words.py +5 -2
  117. package/modules/localmodels/stack_warm.py +7 -4
  118. package/modules/localmodels/stack_whatif.py +1 -1
  119. package/modules/localmodels/suite.py +6 -334
  120. package/modules/localmodels/tui_views.py +28 -7
  121. package/modules/localmodels/web/index.html +595 -226
  122. package/modules/localmodels/web/sizecalc/app.js +34 -40
  123. package/modules/localmodels/web/sizecalc/calc.js +3 -3
  124. package/modules/localmodels/web/sizecalc/page.html +4 -3
  125. package/modules/localmodels/web/view/fleet.html +18 -3
  126. package/modules/localmodels/web/view/fleet.js +135 -14
  127. package/modules/localmodels/web/view/i18n.js +4 -0
  128. package/modules/localmodels/web/view/index.html +16 -0
  129. package/modules/localmodels/web/view/nav.js +49 -0
  130. package/modules/localmodels/web/view/theme.js +1 -1
  131. package/modules/localmodels/web/view/view.css +51 -15
  132. package/modules/localmodels/web/view/view.js +22 -4
  133. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
  134. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +137 -127
  135. package/package.json +1 -1
  136. package/tool.json +1 -1
  137. package/modules/localmodels/library_vram.py +0 -123
  138. /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/WHEEL +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
  141. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
  142. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,394 @@
1
+ """The deployment plan for one suite component (``suite.SuiteRecipe``) from its catalog
2
+ template. Everything here is shared by every runtime; where engines differ the plan asks the
3
+ runtime's adapter (``adapter_for``)."""
4
+
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ import sys
9
+ import urllib.parse
10
+ from pathlib import Path
11
+ from typing import Any, cast
12
+
13
+ from localmodels import catalog as cat
14
+ from localmodels import hosts, reuse, suite, vision
15
+ from localmodels.component import front_venv, venv_python
16
+ from localmodels.engine_adapters.auxiliary import AuxAdapter
17
+ from localmodels.engine_adapters.base import EngineAdapter
18
+ from localmodels.engine_adapters.strata_poly import PolyStrataAdapter, StrataAdapter
19
+ from localmodels.engines import engine_lock_path, release_engine, select_engine_build
20
+ from localmodels.frontend import MIN_PYTHON
21
+ from localmodels.plan_envelope import (
22
+ Deployment,
23
+ PlanError,
24
+ cpu_threads,
25
+ deployment,
26
+ plan_envelope,
27
+ verified_in_place,
28
+ )
29
+ from localmodels.probe import HostFacts
30
+ from localmodels.records import ModelSpec, Plan, ReleaseEngine, ReusableFile
31
+ from localmodels.suite import (
32
+ AUTH_PROXY,
33
+ NO_SWAP,
34
+ PACKAGE_DIR,
35
+ POLY_SERVER,
36
+ SERVERS,
37
+ SLICE,
38
+ SOURCES,
39
+ TTS_SERVER,
40
+ SuiteFile,
41
+ SuiteOptions,
42
+ SuiteRecipe,
43
+ )
44
+
45
+ ADAPTERS: dict[str, EngineAdapter] = {
46
+ "strata": StrataAdapter(),
47
+ "strata-poly": PolyStrataAdapter(),
48
+ }
49
+
50
+
51
+ def adapter_for(runtime: str) -> EngineAdapter:
52
+ """The adapter of a recipe's ``runtime``: Strata's two engines, else a plain server."""
53
+ return ADAPTERS.get(runtime) or AuxAdapter(runtime)
54
+
55
+
56
+ def _engine(r: SuiteRecipe, facts: HostFacts, base_dir: str, backend: str) -> ReleaseEngine:
57
+ build = select_engine_build(facts, backend, engine_lock_path(r["engine"]))
58
+ return release_engine(build, base_dir)
59
+
60
+
61
+ def venv_engine(r: SuiteRecipe, base_dir: str) -> ReleaseEngine:
62
+ """The Python of the recipe's hash-locked venv; the requirements file is its pin. stack is
63
+ local-only, so the venv is made from the Python planning runs on."""
64
+ if sys.version_info < MIN_PYTHON:
65
+ need = ".".join(map(str, MIN_PYTHON))
66
+ raise PlanError(
67
+ f"its Python environment needs Python {need} or newer; this host has {sys.version.split()[0]}"
68
+ )
69
+ venv = front_venv(base_dir, r["venv"])
70
+ return {"source": "venv", "binary": venv_python(venv), "build": r["venv"], "dir": venv}
71
+
72
+
73
+ def _threads(r: SuiteRecipe, facts: HostFacts) -> int:
74
+ return int(r["threads"]) if r.get("threads") else cpu_threads(facts)
75
+
76
+
77
+ def _formatted(value: object, values: dict[str, str]) -> object:
78
+ if isinstance(value, str):
79
+ return value.format(**values)
80
+ if isinstance(value, list):
81
+ return [_formatted(v, values) for v in value]
82
+ if isinstance(value, dict):
83
+ return {k: _formatted(v, values) for k, v in value.items()}
84
+ return value
85
+
86
+
87
+ def _reuse(files: list[ReusableFile], specs: list[SuiteFile], roots: tuple[str, ...]) -> None:
88
+ """Point each file at a same-size copy under a --reuse-from directory (at its catalog path)
89
+ on the destination's filesystem; the download step hard-links it only after the SHA256
90
+ matches. A copy elsewhere cannot be linked, so it is not counted as saved download."""
91
+ for f, spec in zip(files, specs, strict=True):
92
+ for root in roots:
93
+ candidate = Path(root).expanduser() / spec["path"]
94
+ if (
95
+ candidate.is_file()
96
+ and candidate.stat().st_size == f["size_bytes"]
97
+ and candidate.stat().st_dev == reuse.device(str(Path(f["dest"]).expanduser()))
98
+ ):
99
+ f["reuse"] = str(candidate)
100
+ break
101
+
102
+
103
+ def _plan_files(
104
+ r: SuiteRecipe, options: SuiteOptions, model_dir: str, reader: str
105
+ ) -> list[ReusableFile]:
106
+ template = SOURCES[r.get("source", "hf")]
107
+ files: list[ReusableFile] = []
108
+ specs = [
109
+ f for f in cast("list[SuiteFile]", r["files"]) if reader != "off" or not f.get("vision")
110
+ ]
111
+ for f in specs: # catalog files may name their own source
112
+ repo, revision = f.get("repo", r["repo"]), f.get("revision", r["revision"])
113
+ url = "" if f.get("derived") else f.get("url") or template
114
+ files.append(
115
+ {
116
+ "repo": repo,
117
+ "path": f["path"],
118
+ "revision": revision,
119
+ "size_bytes": f["size_bytes"],
120
+ "sha256": f["sha256"],
121
+ "local_name": f.get("local_name", f["path"].rsplit("/", 1)[-1]),
122
+ "dest": f"{model_dir}/{f.get('local_name', f['path'])}",
123
+ "url": url.format(
124
+ hf=options.hf_endpoint,
125
+ repo=repo,
126
+ revision=revision,
127
+ path=urllib.parse.quote(f["path"]),
128
+ catalog_dir=cat.CATALOG_PATH.parent,
129
+ ),
130
+ }
131
+ )
132
+ if f.get("derived"):
133
+ files[-1]["generated"] = True
134
+ _reuse(files, specs, options.reuse_from)
135
+ missing = [
136
+ s["path"]
137
+ for f, s in zip(files, specs, strict=True)
138
+ if s.get("derived") and not f.get("reuse") and not verified_in_place(f)
139
+ ]
140
+ if missing and not r.get("preparation"):
141
+ raise PlanError(
142
+ f"{r['id']} has no pinned preparation recipe for {len(missing)} generated files "
143
+ f"(such as {missing[0]}); point --reuse-from at an existing Strata model directory"
144
+ )
145
+ return files
146
+
147
+
148
+ def _profile_template(
149
+ facts: HostFacts,
150
+ r: SuiteRecipe,
151
+ options: SuiteOptions,
152
+ files: list[ReusableFile],
153
+ values: dict[str, str],
154
+ reader: str,
155
+ ) -> dict[str, Any]:
156
+ """Build the rendered Strata/PolyStrata ``strata-profile.json`` template."""
157
+ adapter = adapter_for(r["runtime"])
158
+ profile_template = dict(r.get("profile") or {})
159
+ if reader != "off":
160
+ projector = next(f for f in files if f["local_name"] == r["vision"]["mmproj"])
161
+ values["vision_mmproj"] = projector["dest"]
162
+ cores = int(facts.get("cpu", {}).get("logical_cores") or 2)
163
+ profile_template["vision"] = vision.strata_section(reader, cores, exe="{vision_exe}")
164
+ if extra := adapter.reader_args(reader):
165
+ profile_template["args"] = [*cast("list[str]", profile_template["args"]), *extra]
166
+ if options.gpu and r.get("card_args"):
167
+ # Under --gpu-memory the reserve also holds what the share leaves out of the real card
168
+ # (stack_gpu_memory.LEFT_OUT, stack_suite.poly_reserve_mib), so the room is counted on it.
169
+ left_out = int(cast("dict[str, int]", options.gpu).get("share_left_out_bytes", 0))
170
+ room = options.gpu["total_bytes"] + left_out - (options.vram_reserve_mib << 20)
171
+ profile_template["args"] = [
172
+ *cast("list[str]", profile_template["args"]),
173
+ *(
174
+ a
175
+ for group in r["card_args"]
176
+ if room >= group["at_least_bytes"]
177
+ and facts["platform"] in group.get("platforms", [facts["platform"]])
178
+ for a in group["args"]
179
+ ),
180
+ ]
181
+ adapter.finish_profile(profile_template, options)
182
+ return profile_template
183
+
184
+
185
+ def _values(
186
+ facts: HostFacts,
187
+ r: SuiteRecipe,
188
+ options: SuiteOptions,
189
+ engine: ReleaseEngine,
190
+ files: list[ReusableFile],
191
+ where: Deployment,
192
+ ) -> dict[str, str]:
193
+ """The placeholders the recipe's argv, env, profile and preparation are formatted with."""
194
+ base = options.base_dir.rstrip("/")
195
+ model_dir = f"{base}/models/{r['id']}"
196
+ windows = facts["platform"] == "win32"
197
+ return {
198
+ "engine": engine["binary"],
199
+ "engine_dir": engine["dir"],
200
+ "vision_exe": f"{engine['dir']}/strata-vision.exe"
201
+ if windows
202
+ else f"{engine['dir']}/strata-vision",
203
+ "model_dir": model_dir,
204
+ "hf_endpoint": options.hf_endpoint,
205
+ "model": files[0]["dest"] if files else model_dir,
206
+ "weights_sha256": files[0]["sha256"] if files else "",
207
+ "alias": r.get("alias", r["id"]),
208
+ "port": str(where.port),
209
+ "key_file": where.api_key_file,
210
+ "deploy_dir": where.deploy_dir,
211
+ "threads": str(_threads(r, facts)),
212
+ "gpu_uuid": options.gpu["uuid"] if options.gpu else "",
213
+ "vram_reserve_mib": str(options.vram_reserve_mib),
214
+ "expert_cache": options.expert_cache,
215
+ "auth_proxy": f"{where.deploy_dir}/{AUTH_PROXY}",
216
+ "tts_server": f"{where.deploy_dir}/{TTS_SERVER}",
217
+ "poly_server": f"{where.deploy_dir}/{POLY_SERVER}",
218
+ "python": venv_python(front_venv(base, r["venv"])) if r.get("venv") else "",
219
+ }
220
+
221
+
222
+ def _argv(r: SuiteRecipe, values: dict[str, str], host_id: str, device: list[str]) -> list[str]:
223
+ argv = [a.format(**values) for a in r["argv"]]
224
+ argv[0] = (
225
+ sys.executable
226
+ if host_id == hosts.LOCAL_ID and r.get("auth_proxy") and argv[0] == "python3"
227
+ else argv[0]
228
+ )
229
+ return argv + device
230
+
231
+
232
+ def _env(
233
+ r: SuiteRecipe, values: dict[str, str], library_path: str | None, apple: bool
234
+ ) -> dict[str, str]:
235
+ env = {k: v.format(**values) for k, v in r.get("env", {}).items()}
236
+ env.setdefault("CUDA_VISIBLE_DEVICES", values["gpu_uuid"])
237
+ if library_path is not None:
238
+ env.setdefault("LD_LIBRARY_PATH", library_path)
239
+ if apple:
240
+ env.pop("CUDA_VISIBLE_DEVICES", None)
241
+ env.pop("LD_LIBRARY_PATH", None)
242
+ return env
243
+
244
+
245
+ def _limits(r: SuiteRecipe, added_mib: int) -> dict[str, str]:
246
+ """The unit's ceilings, raised by what parked conversations and the picture reader add
247
+ (both live in the engine's own cgroup); swap stays off."""
248
+ return {
249
+ k: f"{(suite.size_bytes(v) >> 20) + added_mib}M"
250
+ if added_mib and k in ("MemoryHigh", "MemoryMax")
251
+ else v
252
+ for k, v in {**r.get("limits", {}), **NO_SWAP}.items()
253
+ }
254
+
255
+
256
+ def _placement(options: SuiteOptions, on_gpu: bool, threads: int) -> dict[str, object]:
257
+ gpu = options.gpu if on_gpu else None
258
+ return {
259
+ "id": "gpu" if on_gpu else "cpu",
260
+ "label": f"GPU {gpu['index']}" if gpu else f"CPU {threads} threads",
261
+ "pooled": False,
262
+ "gpus": [{"index": gpu["index"], "uuid": gpu["uuid"], "name": gpu["name"]}] if gpu else [],
263
+ }
264
+
265
+
266
+ def _launch(
267
+ r: SuiteRecipe,
268
+ options: SuiteOptions,
269
+ values: dict[str, str],
270
+ profile: dict[str, Any],
271
+ reader: str,
272
+ parking_mib: int,
273
+ added_mib: int,
274
+ ) -> dict[str, object]:
275
+ return {
276
+ "window": r.get("context", 0),
277
+ "spilled": False,
278
+ "spill_bytes": 0,
279
+ "reasons": [r.get("note", "")],
280
+ "threads": int(values["threads"]),
281
+ "memory_estimate_bytes": r["memory_estimate_bytes"] + (added_mib << 20),
282
+ "vram_bytes": r.get("vram_bytes", 0)
283
+ + (vision.strata_gpu_mib(r.get("vision") or {}, reader) << 20),
284
+ **({"preparation": _formatted(r["preparation"], values)} if r.get("preparation") else {}),
285
+ **({"conversation_cache_mib": parking_mib} if r.get("conversation_cache") else {}),
286
+ **adapter_for(r["runtime"]).launch_keys(profile),
287
+ **({"vision": reader} if reader != "off" else {}),
288
+ # The same keys as a decision front's: stack apply builds the venv before the unit.
289
+ **(
290
+ {
291
+ "frontend_requirements": r["venv"],
292
+ "frontend_base_dir": options.base_dir,
293
+ "frontend_bytes": r.get("venv_bytes", 0),
294
+ }
295
+ if r.get("venv")
296
+ else {}
297
+ ),
298
+ }
299
+
300
+
301
+ def _config_files(
302
+ r: SuiteRecipe, where: Deployment, values: dict[str, str], profile: dict[str, Any]
303
+ ) -> dict[str, str]:
304
+ """The files written beside the service: its serve profile and the Python it runs."""
305
+ config: dict[str, str] = {}
306
+ if profile:
307
+ rendered = _formatted(profile, values)
308
+ config[f"{where.deploy_dir}/strata-profile.json"] = json.dumps(rendered, indent=1) + "\n"
309
+ if r.get("auth_proxy"):
310
+ config[values["auth_proxy"]] = (PACKAGE_DIR / AUTH_PROXY).read_text(encoding="utf-8")
311
+ if server := SERVERS.get(r["runtime"]):
312
+ config[f"{where.deploy_dir}/{server}"] = (PACKAGE_DIR / server).read_text(encoding="utf-8")
313
+ return config
314
+
315
+
316
+ def _readiness(plan: Plan, r: SuiteRecipe) -> None:
317
+ """What the readiness check needs beyond the contract: its input, time and token limit."""
318
+ if r.get("fixture"):
319
+ plan["fixture"] = r["fixture"]
320
+ if r.get("verify_timeout_s"):
321
+ plan["verify_timeout_s"] = r["verify_timeout_s"]
322
+ if r.get("input_tokens"):
323
+ plan["input_tokens"] = r["input_tokens"]
324
+
325
+
326
+ def _parking_values(r: SuiteRecipe, parking_mib: int) -> dict[str, str]:
327
+ """Strata conversation parking's placeholders: the granted budget and the recipe's rest."""
328
+ parking = r.get("conversation_cache")
329
+ if not parking:
330
+ return {}
331
+ return {
332
+ "conversation_cache_mib": str(parking_mib),
333
+ "conversation_cache_slots": str(parking["slots"]),
334
+ "conversation_cache_min_free_mib": str(parking["min_free_mib"]),
335
+ "conversation_cache_min_tokens": str(parking["min_tokens"]),
336
+ }
337
+
338
+
339
+ def _model(r: SuiteRecipe) -> ModelSpec:
340
+ return {
341
+ "id": r["id"],
342
+ "display_name": r.get("display_name") or f"{r.get('alias', r['id'])} ({r['runtime']})",
343
+ "repo": r["repo"],
344
+ "quant": r["version"],
345
+ "model_id": r.get("alias", r["id"]),
346
+ "validated": r.get("status") == "validated",
347
+ }
348
+
349
+
350
+ def build_plan(host_id: str, facts: HostFacts, r: SuiteRecipe, options: SuiteOptions) -> Plan:
351
+ """The deployment plan for one suite component from its catalog template."""
352
+ adapter = adapter_for(r["runtime"])
353
+ base = options.base_dir.rstrip("/")
354
+ on_gpu = adapter.on_gpu(r)
355
+ if on_gpu and options.gpu is None:
356
+ raise PlanError(f"{r['id']} needs an idle NVIDIA GPU")
357
+ apple = facts["platform"] == "darwin" and facts["arch"] == "arm64"
358
+ adapter.check(facts, r)
359
+ backend = ("metal" if apple else "cuda") if on_gpu else "cpu"
360
+ engine = _engine(r, facts, base, backend) if r.get("engine") else venv_engine(r, base)
361
+ reader = options.vision_reader if r.get("vision") else "off"
362
+ files = _plan_files(r, options, f"{base}/models/{r['id']}", reader)
363
+ port = options.port or int(r.get("port") or 0)
364
+ where = deployment(r["id"], port, base, taken=hosts.deployment_dirs(host_id))
365
+ values = _values(facts, r, options, engine, files, where)
366
+ parking_mib = options.conversation_cache_mib if r.get("conversation_cache") else 0
367
+ profile = _profile_template(facts, r, options, files, values, reader)
368
+ values |= _parking_values(r, parking_mib)
369
+ added_mib = parking_mib + vision.strata_ram_mib(r.get("vision") or {}, reader)
370
+ plan = plan_envelope(
371
+ host_id,
372
+ facts,
373
+ where,
374
+ model=_model(r),
375
+ files=files,
376
+ engine=engine,
377
+ placement=_placement(options, on_gpu, int(values["threads"])),
378
+ launch=_launch(r, options, values, profile, reader, parking_mib, added_mib),
379
+ service={
380
+ "argv": _argv(r, values, host_id, adapter.device_args(apple=apple, on_gpu=on_gpu)),
381
+ "env": _env(r, values, adapter.library_path(engine, on_gpu=on_gpu), apple),
382
+ "limits": _limits(r, added_mib),
383
+ "slice": SLICE,
384
+ "slice_limits": {**options.slice_limits, **NO_SWAP},
385
+ },
386
+ endpoint={"model": r.get("alias", r["id"]), "contract": r.get("contract", "chat")},
387
+ warnings=[],
388
+ )
389
+ if config := _config_files(r, where, values, profile):
390
+ plan["service"]["config_files"] = config
391
+ if r.get("health_path"):
392
+ plan["service"]["health_path"] = r["health_path"]
393
+ _readiness(plan, r)
394
+ return plan
@@ -3,7 +3,7 @@
3
3
  "tag": "prism-b12178-03ec600",
4
4
  "commit": "03ec60072cdd32a03ae931969af62e57bfb0c8dc",
5
5
  "source": "https://github.com/PrismML-Eng/llama.cpp/releases/tag/prism-b12178-03ec600",
6
- "note": "Release asset digests from the GitHub release API (PrismML-Eng/llama.cpp prism-b12178-03ec600, commit 03ec60072cdd32a03ae931969af62e57bfb0c8dc, read 2026-11-26). Required for Ternary Bonsai 2.5 27B (PTQ1_0, PQ2_0, and PQ2_0M ggml tensor types 142/143/145, unsupported in upstream llama.cpp). Linux x64 CUDA 12.8 archive imports up to GLIBC_2.34 plus libgomp.so.1, libcudart.so.12, and libcublas.so.12 (verified via readelf -V -d) and pairs with the pinned CUDA 12.8 cudart companion archive from ggml-org/llama.cpp b11370. Linux and macOS tarballs unpack with a single top directory llama-prism-b12178-03ec600/ stripped by remote_ops.unpack; Windows CUDA 12.4, CUDA 13.3, and CPU zips unpack flat with llama-server.exe beside their DLLs and pair with PrismML's pinned cudart companion zips.",
6
+ "note": "Release asset digests from the GitHub release API (PrismML-Eng/llama.cpp prism-b12178-03ec600, commit 03ec60072cdd32a03ae931969af62e57bfb0c8dc, read 2026-11-26). Required for Ternary Bonsai 2.5 27B (PTQ1_0, PQ2_0, and PQ2_0M ggml tensor types 142/143/145, unsupported in upstream llama.cpp). Linux x64 CUDA 12.8 archive imports up to GLIBC_2.34 plus libgomp.so.1, libcudart.so.12, and libcublas.so.12 (verified via readelf -V -d) and pairs with the pinned CUDA 12.8 cudart companion archive from ggml-org/llama.cpp b11370. Linux and macOS tarballs unpack with a single top directory llama-prism-b12178-03ec600/ stripped by remote_ops.unpack; Windows CUDA 12.4, CUDA 13.3, and CPU zips unpack flat with llama-server.exe beside their DLLs and pair with PrismML's pinned cudart companion zips. Archives over 200 MiB (the Linux CUDA 12.8 build, the Windows CUDA 12.4 and 13.3 builds and their cudart companions) are fetched from byte-identical copies on the project CloudFront under cli/localmodels/engines/prism/, uploaded 2026-11-28 with S3 sha256 metadata and read back: GitHub release downloads crawl from mainland China (home-win 2026-11-27: 48.6 KB/s GitHub against ~8 MB/s CloudFront) and npm copies stop at 200 MiB. The originals keep the same file names in the GitHub release above (the Linux cudart companion in ggml-org/llama.cpp b11370).",
7
7
  "builds": [
8
8
  {
9
9
  "platform": "linux",
@@ -17,13 +17,13 @@
17
17
  "assets": [
18
18
  {
19
19
  "name": "llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
20
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
20
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
21
21
  "sha256": "a50997fb29bb0684c00cdf21bb1382923c6bc70085a74c9c3d913dcf76af1899",
22
22
  "size_bytes": 225887048
23
23
  },
24
24
  {
25
25
  "name": "cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
26
- "url": "https://github.com/ggml-org/llama.cpp/releases/download/b11370/cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
26
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
27
27
  "sha256": "7807b4fc01958fc11db9894b2ab791e664b4da999017e70f7b5a7147f6c770e3",
28
28
  "size_bytes": 594375807
29
29
  }
@@ -76,13 +76,13 @@
76
76
  "assets": [
77
77
  {
78
78
  "name": "llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
79
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
79
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
80
80
  "sha256": "f1bef85254012f0e6f25502ee86696c7de6ccc76a922f05c3f23ab2e5719c531",
81
81
  "size_bytes": 341653677
82
82
  },
83
83
  {
84
84
  "name": "cudart-llama-bin-win-cuda-12.4-x64.zip",
85
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/cudart-llama-bin-win-cuda-12.4-x64.zip",
85
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-bin-win-cuda-12.4-x64.zip",
86
86
  "sha256": "8c79a9b226de4b3cacfd1f83d24f962d0773be79f1e7b75c6af4ded7e32ae1d6",
87
87
  "size_bytes": 391443627
88
88
  }
@@ -97,13 +97,13 @@
97
97
  "assets": [
98
98
  {
99
99
  "name": "llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
100
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
100
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
101
101
  "sha256": "a34bdb817e797243f86c5e2dd1bdf118d17ea32b6eaa4e6f32c41533b13bc2d8",
102
102
  "size_bytes": 216516289
103
103
  },
104
104
  {
105
105
  "name": "cudart-llama-bin-win-cuda-13.3-x64.zip",
106
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/cudart-llama-bin-win-cuda-13.3-x64.zip",
106
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-bin-win-cuda-13.3-x64.zip",
107
107
  "sha256": "1462a050eb4c684921ba51dcc4cc488a036674c3e73e9945ee705b854808d03e",
108
108
  "size_bytes": 390970417
109
109
  }
@@ -19,6 +19,7 @@ from pathlib import Path
19
19
  from typing import Literal, TypedDict
20
20
 
21
21
  from localmodels import (
22
+ bifrost_checks,
22
23
  bifrost_clients,
23
24
  gateway_accept,
24
25
  gateway_admin,
@@ -30,6 +31,7 @@ from localmodels import (
30
31
  harness_gateway,
31
32
  harness_probe,
32
33
  hosts,
34
+ magpie_legacy,
33
35
  pi_profile,
34
36
  process_identity,
35
37
  runtime_io,
@@ -91,14 +93,12 @@ def require_magpie(out: subprocess.CompletedProcess[str], what: str) -> None:
91
93
  raise HarnessError(f"magpie {what} failed (exit {out.returncode})")
92
94
 
93
95
 
94
- def _bifrost(plan: ToolPlan) -> bool:
95
- return harness_core.gateway_kind(plan.get("gateway")) == "bifrost" # type: ignore[arg-type]
96
-
97
-
98
96
  def ensure_gateway(plan: ToolPlan) -> str:
99
97
  """Reuse a gateway that answers; otherwise start the one the plan names."""
100
- if _bifrost(plan):
101
- return gateway_bifrost.ensure(plan)
98
+ return _gateway(plan).ensure(plan)
99
+
100
+
101
+ def _ensure_magpie(plan: ToolPlan) -> str:
102
102
  action = next(t for t in plan["tools"] if t["tool"] == "gateway")
103
103
  if run_magpie(plan, "healthcheck", timeout=20).returncode == 0:
104
104
  return "reused"
@@ -112,10 +112,29 @@ def ensure_gateway(plan: ToolPlan) -> str:
112
112
  return "started"
113
113
 
114
114
 
115
+ def answers(plan: HarnessPlan) -> bool:
116
+ """The plan's gateway is the one this tool runs there, and it answers its health check."""
117
+ return _gateway(plan).answers(plan)
118
+
119
+
120
+ def _answers_magpie(plan: HarnessPlan) -> bool:
121
+ try:
122
+ env = harness_gateway.checked_gateway_environment(plan)
123
+ except HarnessError:
124
+ return False
125
+ magpie = tool_path(plan, "magpie")
126
+ return harness_core.run_tool([magpie, "healthcheck"], timeout=20, env=env).returncode == 0
127
+
128
+
129
+ def wired_providers(plan: HarnessPlan, doc: hosts.Owned) -> set[str]:
130
+ """The provider ids the plan's gateway holds now: its Bifrost config, or the ones this tool
131
+ added to Magpie (the owned manifest)."""
132
+ return _gateway(plan).wired_providers(doc)
133
+
134
+
115
135
  def revive(plan: HarnessPlan, started: str | None) -> str:
116
- if _bifrost(plan):
117
- return gateway_bifrost.revive(plan)
118
- return _revive_magpie(plan, started)
136
+ """``stack up``: start the plan's gateway again if it does not answer."""
137
+ return _gateway(plan).revive(plan, started)
119
138
 
120
139
 
121
140
  def _revive_magpie(plan: HarnessPlan, started: str | None) -> str:
@@ -427,10 +446,17 @@ def wire(
427
446
  point pi at it. Idempotent: providers are updated by id, and adding a group by its name
428
447
  replaces it with its rules. A re-sync (``select_pi=False``) leaves the gateway keys alone, so a
429
448
  key the user removed stays removed. A Bifrost plan goes to ``gateway_bifrost.wire``."""
449
+ return _gateway(plan).wire(plan, llm_key, decision_key, aux, select_pi)
450
+
451
+
452
+ def _wire_magpie(
453
+ plan: HarnessPlan,
454
+ llm_key: str,
455
+ decision_key: str | None,
456
+ aux: list[AuxEndpoint],
457
+ select_pi: bool,
458
+ ) -> list[str]:
430
459
  tools_dir = plan["tools_dir"]
431
- if _bifrost(plan):
432
- done = leave_magpie(tools_dir) if select_pi else []
433
- return done + gateway_bifrost.wire(plan, llm_key, decision_key, aux, select_pi=select_pi)
434
460
  done = leave(tools_dir) if select_pi else []
435
461
  if select_pi and (key := gateway_keys.ensure(plan)):
436
462
  done.append(key)
@@ -692,13 +718,18 @@ def accept(
692
718
  gateway (the decision model must be consulted), one embedding, rerank or transcription request
693
719
  per wired auxiliary (Magpie's usage log must gain its row), and one pi prompt with the stack's model.
694
720
  A Bifrost plan is accepted by ``bifrost_checks.accept``."""
721
+ return _gateway(plan).accept(plan, decision_key, aux, timeout)
722
+
723
+
724
+ def _accept_magpie(
725
+ plan: HarnessPlan, decision_key: str | None, aux: list[AuxEndpoint], timeout: float
726
+ ) -> list[Check]:
695
727
  return gateway_accept.accept(
696
728
  plan,
697
729
  decision_key,
698
730
  aux,
699
731
  timeout,
700
732
  aux_providers=AUX_PROVIDERS,
701
- is_bifrost=_bifrost(plan),
702
733
  post_fn=_post,
703
734
  magpie=run_magpie,
704
735
  run_tool=run_tool,
@@ -706,3 +737,83 @@ def accept(
706
737
  calls_fn=logged_calls,
707
738
  after_fn=logged_after,
708
739
  )
740
+
741
+
742
+ class _BifrostGateway:
743
+ """This tool's Bifrost, which ``gateway_bifrost`` runs and ``bifrost_checks`` accepts."""
744
+
745
+ def ensure(self, plan: ToolPlan) -> str:
746
+ return gateway_bifrost.ensure(plan)
747
+
748
+ def revive(self, plan: HarnessPlan, started: str | None) -> str:
749
+ return gateway_bifrost.revive(plan)
750
+
751
+ def answers(self, plan: HarnessPlan) -> bool:
752
+ try:
753
+ record = gateway_bifrost.require_target(plan)
754
+ except HarnessError:
755
+ return False
756
+ return bool(
757
+ record
758
+ and gateway_bifrost.owned_listener(record)
759
+ and gateway_bifrost.healthy(plan["gateway"]["addr"])
760
+ )
761
+
762
+ def wired_providers(self, doc: hosts.Owned) -> set[str]:
763
+ return bifrost_checks.wired_providers(doc)
764
+
765
+ def wire(
766
+ self,
767
+ plan: HarnessPlan,
768
+ llm_key: str,
769
+ decision_key: str | None,
770
+ aux: list[AuxEndpoint],
771
+ select_pi: bool,
772
+ ) -> list[str]:
773
+ done = leave_magpie(plan["tools_dir"]) if select_pi else []
774
+ return done + gateway_bifrost.wire(plan, llm_key, decision_key, aux, select_pi=select_pi)
775
+
776
+ def accept(
777
+ self, plan: HarnessPlan, decision_key: str | None, aux: list[AuxEndpoint], timeout: float
778
+ ) -> list[Check]:
779
+ return bifrost_checks.accept(plan, decision_key, aux, timeout)
780
+
781
+
782
+ class _MagpieGateway(_BifrostGateway):
783
+ """Legacy Magpie, which this module runs through the ``magpie`` CLI."""
784
+
785
+ def ensure(self, plan: ToolPlan) -> str:
786
+ return _ensure_magpie(plan)
787
+
788
+ def revive(self, plan: HarnessPlan, started: str | None) -> str:
789
+ return _revive_magpie(plan, started)
790
+
791
+ def answers(self, plan: HarnessPlan) -> bool:
792
+ return _answers_magpie(plan)
793
+
794
+ def wired_providers(self, doc: hosts.Owned) -> set[str]:
795
+ return set(doc["gateway"]["providers"])
796
+
797
+ def wire(
798
+ self,
799
+ plan: HarnessPlan,
800
+ llm_key: str,
801
+ decision_key: str | None,
802
+ aux: list[AuxEndpoint],
803
+ select_pi: bool,
804
+ ) -> list[str]:
805
+ return _wire_magpie(plan, llm_key, decision_key, aux, select_pi)
806
+
807
+ def accept(
808
+ self, plan: HarnessPlan, decision_key: str | None, aux: list[AuxEndpoint], timeout: float
809
+ ) -> list[Check]:
810
+ return _accept_magpie(plan, decision_key, aux, timeout)
811
+
812
+
813
+ _BIFROST = _BifrostGateway()
814
+ _MAGPIE = _MagpieGateway()
815
+
816
+
817
+ def _gateway(plan: ToolPlan) -> _BifrostGateway:
818
+ """The implementation of the gateway the plan names: the one place this module asks."""
819
+ return _MAGPIE if magpie_legacy.of(plan.get("gateway")).legacy else _BIFROST # type: ignore[arg-type]
@@ -101,7 +101,6 @@ def accept(
101
101
  timeout: float = 600,
102
102
  *,
103
103
  aux_providers: dict[str, str],
104
- is_bifrost: bool,
105
104
  post_fn: PostFn = post,
106
105
  magpie: MagpieFn,
107
106
  run_tool: Callable[..., subprocess.CompletedProcess[str]],
@@ -112,11 +111,7 @@ def accept(
112
111
  """Each claim needs a request: provider tests through Magpie, one routed turn through the
113
112
  gateway (the decision model must be consulted), one embedding, rerank or transcription request
114
113
  per wired auxiliary (Magpie's usage log must gain its row), and one pi prompt with the stack's model.
115
- A Bifrost plan is accepted by ``bifrost_checks.accept``."""
116
- if is_bifrost:
117
- from localmodels import bifrost_checks
118
-
119
- return bifrost_checks.accept(plan, decision_key, aux, timeout)
114
+ Magpie only: a Bifrost plan is accepted by ``bifrost_checks.accept``."""
120
115
  gw = plan["gateway"]
121
116
  checks: list[Check] = []
122
117