@simplexai/localmodels-darwin-x64 0.1.0-dev.59 → 0.1.0-dev.61
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.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +126 -107
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +107 -44
- package/modules/localmodels/apple_sensors.py +431 -0
- package/modules/localmodels/auth_proxy.py +185 -19
- package/modules/localmodels/bifrost_admin.py +30 -0
- package/modules/localmodels/bifrost_checks.py +2 -2
- package/modules/localmodels/bifrost_config.py +132 -9
- package/modules/localmodels/bifrost_models.py +1 -1
- package/modules/localmodels/catalog.json +509 -54
- package/modules/localmodels/catalog.py +21 -4
- package/modules/localmodels/catalog_add.py +42 -11
- package/modules/localmodels/catalog_license.py +2 -0
- package/modules/localmodels/catalog_recipes.py +2 -0
- package/modules/localmodels/cli_parser.py +6 -2
- package/modules/localmodels/context_policy.py +40 -4
- package/modules/localmodels/custom_hub.py +983 -0
- package/modules/localmodels/custom_hub_http.py +579 -0
- package/modules/localmodels/custom_probe.py +451 -0
- package/modules/localmodels/debug_mode.py +13 -0
- package/modules/localmodels/debug_stub_server.py +156 -1
- package/modules/localmodels/deploy.py +38 -7
- package/modules/localmodels/deploy_steps.py +5 -0
- package/modules/localmodels/download-mirrors.json +20 -0
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +26 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
- package/modules/localmodels/engines-whisper-b5454.json +120 -1
- package/modules/localmodels/engines.py +38 -8
- package/modules/localmodels/estimator.py +60 -7
- package/modules/localmodels/gateway.py +48 -3
- package/modules/localmodels/gateway_app_bifrost.py +18 -18
- package/modules/localmodels/gateway_bifrost.py +102 -16
- package/modules/localmodels/gateway_cli.py +14 -80
- package/modules/localmodels/gateway_server.py +88 -16
- package/modules/localmodels/gguf.py +6 -0
- package/modules/localmodels/gpu_specs.py +35 -1
- package/modules/localmodels/harness.py +1 -2
- package/modules/localmodels/hf_repo.py +12 -4
- package/modules/localmodels/host_sensors.py +704 -0
- package/modules/localmodels/install.py +4 -4
- package/modules/localmodels/library_cli.py +181 -3
- package/modules/localmodels/library_custom.py +831 -0
- package/modules/localmodels/library_elastic.py +35 -7
- package/modules/localmodels/library_gateway.py +94 -32
- package/modules/localmodels/library_jobs.py +76 -11
- package/modules/localmodels/library_kept.py +50 -6
- package/modules/localmodels/library_model.py +254 -2
- package/modules/localmodels/library_pricing.py +83 -4
- package/modules/localmodels/library_serve.py +178 -60
- package/modules/localmodels/library_smoke.py +315 -0
- package/modules/localmodels/library_state.py +77 -1
- package/modules/localmodels/library_status.py +126 -4
- package/modules/localmodels/npm_transport.py +4 -58
- package/modules/localmodels/nvml_ctypes.py +431 -0
- package/modules/localmodels/plan_envelope.py +14 -6
- package/modules/localmodels/recommend_cli.py +2 -1
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +120 -665
- package/modules/localmodels/remote_ops_common.py +729 -0
- package/modules/localmodels/remote_ops_download.py +396 -241
- package/modules/localmodels/remote_ops_mirrors.py +26 -65
- package/modules/localmodels/remote_ops_prepare.py +43 -35
- package/modules/localmodels/remote_ops_ranges.py +98 -65
- package/modules/localmodels/remote_ops_remove.py +30 -22
- package/modules/localmodels/remote_ops_service.py +103 -95
- package/modules/localmodels/remote_ops_verify.py +113 -65
- package/modules/localmodels/runtime-lock.json +19 -19
- package/modules/localmodels/runtime_cli.py +15 -5
- package/modules/localmodels/runtime_io.py +54 -1
- package/modules/localmodels/service_control.py +32 -1
- package/modules/localmodels/service_wiring.py +2 -3
- package/modules/localmodels/service_worker.py +6 -2
- package/modules/localmodels/services_cli.py +35 -27
- package/modules/localmodels/source_byok.py +3 -5
- package/modules/localmodels/speech-sv.txt +93 -0
- package/modules/localmodels/speech_admission.py +437 -0
- package/modules/localmodels/speech_catalog.py +170 -0
- package/modules/localmodels/speech_cli.py +273 -0
- package/modules/localmodels/speech_jobs.py +772 -0
- package/modules/localmodels/speech_model.py +404 -0
- package/modules/localmodels/speech_serve.py +287 -0
- package/modules/localmodels/speech_server.py +837 -0
- package/modules/localmodels/speech_state.py +697 -0
- package/modules/localmodels/speech_worker_sensevoice.py +255 -0
- package/modules/localmodels/speech_workers.py +783 -0
- package/modules/localmodels/stack.py +0 -33
- package/modules/localmodels/stack_auto.py +5 -3
- package/modules/localmodels/stack_aux_gpu.py +45 -4
- package/modules/localmodels/stack_capacity.py +77 -8
- package/modules/localmodels/stack_cli.py +16 -1
- package/modules/localmodels/stack_compose.py +1 -1
- package/modules/localmodels/stack_down.py +24 -1
- package/modules/localmodels/stack_hardware.py +57 -88
- package/modules/localmodels/stack_hardware_text.py +4 -59
- package/modules/localmodels/stack_lifecycle.py +2 -2
- package/modules/localmodels/stack_memory.py +14 -3
- package/modules/localmodels/stack_suite.py +9 -10
- package/modules/localmodels/stack_summary.py +4 -4
- package/modules/localmodels/stack_view.py +77 -53
- package/modules/localmodels/stack_view_demo.py +36 -5
- package/modules/localmodels/stack_view_events.py +147 -12
- package/modules/localmodels/stack_view_gpu.py +97 -17
- package/modules/localmodels/stack_view_llm.py +16 -1
- package/modules/localmodels/stack_view_measure.py +4 -1
- package/modules/localmodels/stack_view_schema.py +54 -8
- package/modules/localmodels/stack_view_serve.py +40 -3
- package/modules/localmodels/stack_view_slots.py +89 -10
- package/modules/localmodels/stack_view_telemetry.py +163 -0
- package/modules/localmodels/stack_view_text.py +5 -2
- package/modules/localmodels/stack_view_tick.py +658 -0
- package/modules/localmodels/stack_view_words.py +4 -0
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.5.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
- package/modules/localmodels/suite.py +3 -1
- package/modules/localmodels/telemetry_math.py +538 -0
- package/modules/localmodels/transport.py +3 -2
- package/modules/localmodels/tui_views.py +2 -2
- package/modules/localmodels/web/view/view.js +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/RECORD +123 -104
- package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/NOTICE +9 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/bifrost_datasheet.py +0 -53
- package/modules/localmodels/bifrost_provider.py +0 -88
- package/modules/localmodels/bifrost_unit.py +0 -99
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +0 -94
- package/modules/localmodels/gateway_switch.py +0 -51
- package/modules/localmodels/library_floor.py +0 -78
- package/modules/localmodels/service_stop.py +0 -52
- /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev59.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -387,6 +387,7 @@ class _PriceCtx:
|
|
|
387
387
|
base_dir: str
|
|
388
388
|
catalog: tuple[cat.CatalogEntry, ...]
|
|
389
389
|
port: int
|
|
390
|
+
use_jinja: bool = True
|
|
390
391
|
|
|
391
392
|
|
|
392
393
|
def _price_rung(
|
|
@@ -418,6 +419,7 @@ def _price_rung(
|
|
|
418
419
|
hf_api_endpoint=deploy.hf_endpoint(),
|
|
419
420
|
agent=rung_posture,
|
|
420
421
|
quant=ctx.model.variant.quant,
|
|
422
|
+
use_jinja=ctx.use_jinja,
|
|
421
423
|
),
|
|
422
424
|
entries=ctx.catalog,
|
|
423
425
|
resolver=deploy.catalog_pins,
|
|
@@ -621,6 +623,22 @@ def _try_floor_admission(
|
|
|
621
623
|
return None
|
|
622
624
|
|
|
623
625
|
|
|
626
|
+
def _custom_ctx_ladder(
|
|
627
|
+
base: AgentPosture, backend: str, ctx_tokens: int
|
|
628
|
+
) -> tuple[PostureRung, ...]:
|
|
629
|
+
requested = context_policy.posture_for(base, backend)
|
|
630
|
+
pinned = replace(
|
|
631
|
+
requested,
|
|
632
|
+
slots=1,
|
|
633
|
+
floor=ctx_tokens,
|
|
634
|
+
preferred=ctx_tokens,
|
|
635
|
+
target=ctx_tokens,
|
|
636
|
+
prompt_cache_mib=min(requested.prompt_cache_mib, 512),
|
|
637
|
+
prompt_cache_min_mib=min(requested.prompt_cache_min_mib, 512),
|
|
638
|
+
)
|
|
639
|
+
return (PostureRung(pinned, degraded=False, reason=None),)
|
|
640
|
+
|
|
641
|
+
|
|
624
642
|
def price_elastic(
|
|
625
643
|
facts: HostFacts,
|
|
626
644
|
model: Model,
|
|
@@ -632,8 +650,13 @@ def price_elastic(
|
|
|
632
650
|
allow_overcommit: bool = True,
|
|
633
651
|
force: bool = False,
|
|
634
652
|
min_rung_index: int = 0,
|
|
653
|
+
ctx_override: int | None = None,
|
|
654
|
+
use_jinja: bool = True,
|
|
635
655
|
) -> ElasticPlan:
|
|
636
656
|
"""Dual-tier memory admission + elastic posture ladder for loading ``model`` on ``pool``."""
|
|
657
|
+
effective_catalog = (
|
|
658
|
+
catalog if any(e.id == model.entry.id for e in catalog) else (*catalog, model.entry)
|
|
659
|
+
)
|
|
637
660
|
placement = library_pricing.pools(facts).get(pool)
|
|
638
661
|
if placement is None:
|
|
639
662
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -654,12 +677,15 @@ def price_elastic(
|
|
|
654
677
|
)
|
|
655
678
|
eff = _plan_posture(poly_plan)
|
|
656
679
|
return ElasticPlan(poly_plan, 0, (), eff, eff, False, None, None, False, adm)
|
|
657
|
-
|
|
658
|
-
library_pricing.posture(),
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
680
|
+
if ctx_override is not None and ctx_override > 0:
|
|
681
|
+
ladder = _custom_ctx_ladder(library_pricing.posture(), adm.backend, ctx_override)
|
|
682
|
+
else:
|
|
683
|
+
ladder = elastic_posture_ladder(
|
|
684
|
+
library_pricing.posture(),
|
|
685
|
+
backend=adm.backend,
|
|
686
|
+
native_ctx=model.entry.n_ctx_train,
|
|
687
|
+
max_agent_window=model.entry.max_agent_window,
|
|
688
|
+
)
|
|
663
689
|
floor_rung = ladder[-1]
|
|
664
690
|
compact_floor = replace(
|
|
665
691
|
floor_rung.posture, kv_types=(floor_rung.posture.kv_types[-1],), kv_pinned=True
|
|
@@ -688,7 +714,9 @@ def price_elastic(
|
|
|
688
714
|
context_tokens=req_window, slots=req_p.slots, kv_types=req_p.kv_types[0]
|
|
689
715
|
)
|
|
690
716
|
|
|
691
|
-
ctx = _PriceCtx(
|
|
717
|
+
ctx = _PriceCtx(
|
|
718
|
+
facts, model, pool, placement, base_dir, effective_catalog, port, use_jinja=use_jinja
|
|
719
|
+
)
|
|
692
720
|
admitted, ram_shortfall = _try_tier1_ladder(ctx, ladder, requested_spec, adm, min_rung_index)
|
|
693
721
|
if admitted is not None:
|
|
694
722
|
return admitted
|
|
@@ -25,10 +25,8 @@ from typing import Any
|
|
|
25
25
|
from localmodels import (
|
|
26
26
|
bifrost_admin,
|
|
27
27
|
bifrost_config,
|
|
28
|
-
bifrost_datasheet,
|
|
29
28
|
bifrost_log,
|
|
30
29
|
bifrost_models,
|
|
31
|
-
bifrost_unit,
|
|
32
30
|
gateway_bifrost,
|
|
33
31
|
gateway_home,
|
|
34
32
|
harness,
|
|
@@ -137,9 +135,9 @@ def _install(facts: HostFacts, event: runtime_io.Event = lambda _: None) -> host
|
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
config = gateway_bifrost.render_config({}, governance, app)
|
|
140
|
-
config["framework"] =
|
|
138
|
+
config["framework"] = bifrost_config.framework(app)
|
|
141
139
|
gateway_bifrost._write_config(
|
|
142
|
-
app, config, {
|
|
140
|
+
app, config, {bifrost_config.DATASHEET: {}, bifrost_config.PARAMETERS: {}}
|
|
143
141
|
)
|
|
144
142
|
return record
|
|
145
143
|
|
|
@@ -158,12 +156,85 @@ def ensure_instance(
|
|
|
158
156
|
def read_sheet(app: Path) -> dict[str, Any]:
|
|
159
157
|
"""Read the current model datasheet of ``app``, or an empty mapping when absent."""
|
|
160
158
|
try:
|
|
161
|
-
value = json.loads((app /
|
|
159
|
+
value = json.loads((app / bifrost_config.DATASHEET).read_text(encoding="utf-8"))
|
|
162
160
|
except (OSError, ValueError):
|
|
163
161
|
return {}
|
|
164
162
|
return value if isinstance(value, dict) else {}
|
|
165
163
|
|
|
166
164
|
|
|
165
|
+
def _is_healthy(record: hosts.OwnedBifrost) -> bool:
|
|
166
|
+
return gateway_bifrost._healthy_owned(record)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _stop_for_store_change(record: hosts.OwnedBifrost, app: Path) -> None:
|
|
170
|
+
# A change drops the config store, which Windows cannot delete while Bifrost holds it
|
|
171
|
+
# open (WinError 32 on unload, homewin): stop it first; it restarts on the change.
|
|
172
|
+
if STOP_BEFORE_CONFIG_CHANGE and record["how"] != "unit":
|
|
173
|
+
gateway_bifrost._stop_serve(app)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _start_and_await(record: hosts.OwnedBifrost, app: Path, *, restart: bool) -> None:
|
|
177
|
+
log_offset = bifrost_log.log_size(app)
|
|
178
|
+
gateway_bifrost._start(record, restart=restart)
|
|
179
|
+
gateway_bifrost._await(record["addr"], record=record, log_offset=log_offset)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _reconcile_store_cold(record: hosts.OwnedBifrost, config: dict[str, Any]) -> None:
|
|
183
|
+
"""Converge a running Bifrost's derived SQLite store with ``config.json`` via cold restart
|
|
184
|
+
(or stop it when ``config.json`` has no providers left)."""
|
|
185
|
+
app = Path(record["app_dir"])
|
|
186
|
+
if not config.get("providers"):
|
|
187
|
+
_stop(record)
|
|
188
|
+
bifrost_config.clear_store(app)
|
|
189
|
+
return
|
|
190
|
+
_stop_for_store_change(record, app)
|
|
191
|
+
bifrost_config.clear_store(app)
|
|
192
|
+
_start_and_await(record, app, restart=True)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _cleanup_orphaned_provider(
|
|
196
|
+
record: hosts.OwnedBifrost,
|
|
197
|
+
config: dict[str, Any],
|
|
198
|
+
pid: str,
|
|
199
|
+
*,
|
|
200
|
+
sync_rules: bool = False,
|
|
201
|
+
) -> None:
|
|
202
|
+
"""Remove a provider left in live Bifrost or ``config.db`` by a hot-reload that failed, was
|
|
203
|
+
interrupted, or was killed before ``config.json`` was written."""
|
|
204
|
+
app = Path(record["app_dir"])
|
|
205
|
+
prefix = pid + "/"
|
|
206
|
+
before_sheet = read_sheet(app)
|
|
207
|
+
sheet = {k: v for k, v in before_sheet.items() if not k.startswith(prefix)}
|
|
208
|
+
sheet_pruned = sheet != before_sheet
|
|
209
|
+
params = {bifrost_config.DATASHEET: sheet, bifrost_config.PARAMETERS: {}}
|
|
210
|
+
if _is_healthy(record):
|
|
211
|
+
desired_rules: list[dict[str, Any]] | None = None
|
|
212
|
+
if sync_rules:
|
|
213
|
+
gov = config.get("governance")
|
|
214
|
+
raw_rules = gov.get("routing_rules") if isinstance(gov, dict) else None
|
|
215
|
+
desired_rules = (
|
|
216
|
+
[r for r in raw_rules if isinstance(r, dict)] if isinstance(raw_rules, list) else []
|
|
217
|
+
)
|
|
218
|
+
try:
|
|
219
|
+
removed = bifrost_admin.drop_live_provider(record, pid, desired_rules=desired_rules)
|
|
220
|
+
except bifrost_admin.AdminError:
|
|
221
|
+
if sheet_pruned:
|
|
222
|
+
bifrost_config.write_config(app, config, params, drop_store=False)
|
|
223
|
+
_reconcile_store_cold(record, config)
|
|
224
|
+
return
|
|
225
|
+
if sheet_pruned:
|
|
226
|
+
bifrost_config.write_config(app, config, params, drop_store=False)
|
|
227
|
+
if removed and not config.get("providers"):
|
|
228
|
+
_stop(record)
|
|
229
|
+
bifrost_config.clear_store(app)
|
|
230
|
+
return
|
|
231
|
+
if gateway_bifrost.owned_listener(record):
|
|
232
|
+
_stop(record)
|
|
233
|
+
if sheet_pruned:
|
|
234
|
+
bifrost_config.write_config(app, config, params)
|
|
235
|
+
bifrost_config.clear_store(app)
|
|
236
|
+
|
|
237
|
+
|
|
167
238
|
def apply_config(record: hosts.OwnedBifrost, config: dict[str, Any], sheet: dict[str, Any]) -> None:
|
|
168
239
|
"""Apply updated config and datasheet to the gateway.
|
|
169
240
|
|
|
@@ -176,7 +247,7 @@ def apply_config(record: hosts.OwnedBifrost, config: dict[str, Any], sheet: dict
|
|
|
176
247
|
its LLM, decision model or foundation services) serves nobody: it is stopped instead, its
|
|
177
248
|
record and config kept, and the next load starts it again."""
|
|
178
249
|
app = Path(record["app_dir"])
|
|
179
|
-
params = {
|
|
250
|
+
params = {bifrost_config.DATASHEET: sheet, bifrost_config.PARAMETERS: {}}
|
|
180
251
|
if config.get("providers") and bifrost_config.differs(app, config, params):
|
|
181
252
|
before = gateway_bifrost.read_config(app)
|
|
182
253
|
before_sheet = read_sheet(app)
|
|
@@ -192,29 +263,21 @@ def apply_config(record: hosts.OwnedBifrost, config: dict[str, Any], sheet: dict
|
|
|
192
263
|
return
|
|
193
264
|
except bifrost_admin.AdminError:
|
|
194
265
|
pass # fall back to cold restart so config.json and config.db converge cleanly
|
|
195
|
-
if (
|
|
196
|
-
|
|
197
|
-
and record["how"] != "unit"
|
|
198
|
-
and bifrost_config.differs(app, config, params)
|
|
199
|
-
):
|
|
200
|
-
# A change drops the config store, which Windows cannot delete while Bifrost holds it
|
|
201
|
-
# open (WinError 32 on unload, homewin): stop it first; it restarts on the change.
|
|
202
|
-
gateway_bifrost._stop_serve(app)
|
|
266
|
+
if bifrost_config.differs(app, config, params):
|
|
267
|
+
_stop_for_store_change(record, app)
|
|
203
268
|
changed = gateway_bifrost._write_config(app, config, params)
|
|
204
269
|
if not config.get("providers"):
|
|
205
270
|
_stop(record)
|
|
206
271
|
return
|
|
207
|
-
if changed or not
|
|
208
|
-
|
|
209
|
-
gateway_bifrost._start(record, restart=changed)
|
|
210
|
-
gateway_bifrost._await(record["addr"], record=record, log_offset=log_offset)
|
|
272
|
+
if changed or not _is_healthy(record):
|
|
273
|
+
_start_and_await(record, app, restart=changed)
|
|
211
274
|
|
|
212
275
|
|
|
213
276
|
def _stop(record: hosts.OwnedBifrost) -> None:
|
|
214
277
|
"""Stop the instance through what proves it ours: its systemd --user unit (disabled too, so
|
|
215
278
|
an empty gateway does not come back at login) or its process identity receipt."""
|
|
216
279
|
if record["how"] == "unit":
|
|
217
|
-
name =
|
|
280
|
+
name = gateway_bifrost.unit(record)
|
|
218
281
|
if gateway_bifrost._systemctl("disable", "--now", f"{name}.service").returncode != 0:
|
|
219
282
|
raise _fail(f"stopping {name} failed")
|
|
220
283
|
return
|
|
@@ -222,9 +285,7 @@ def _stop(record: hosts.OwnedBifrost) -> None:
|
|
|
222
285
|
|
|
223
286
|
|
|
224
287
|
def _provider(base_url: str, model: str, key: str, pid: str) -> dict[str, Any]:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
entry = bifrost_provider.render("llm", base_url, model, key, pid)
|
|
288
|
+
entry = bifrost_config.render_provider("llm", base_url, model, key, pid)
|
|
228
289
|
first = entry["keys"][0]
|
|
229
290
|
first["models"] = [model] # no alias for the stack's agent group: only this model
|
|
230
291
|
first.pop("aliases", None)
|
|
@@ -543,7 +604,7 @@ def _retire_legacy_magpie(tools_dir: str) -> bool:
|
|
|
543
604
|
is unavailable, ``leave_magpie`` cannot invoke the Magpie CLI; we still proceed so Bifrost
|
|
544
605
|
registration and pi recovery succeed rather than leaving the user stuck on a dead port.
|
|
545
606
|
"""
|
|
546
|
-
from localmodels import bifrost_clients,
|
|
607
|
+
from localmodels import bifrost_clients, gateway
|
|
547
608
|
|
|
548
609
|
doc = hosts.load_owned(tools_dir)
|
|
549
610
|
had_magpie = bool(
|
|
@@ -554,7 +615,7 @@ def _retire_legacy_magpie(tools_dir: str) -> bool:
|
|
|
554
615
|
if not had_magpie:
|
|
555
616
|
return False
|
|
556
617
|
try:
|
|
557
|
-
|
|
618
|
+
gateway.leave_magpie(tools_dir)
|
|
558
619
|
except (harness.HarnessError, OSError, ValueError):
|
|
559
620
|
_clear_legacy_magpie_pi_record(tools_dir)
|
|
560
621
|
return True
|
|
@@ -625,8 +686,6 @@ def _register(
|
|
|
625
686
|
facts: HostFacts,
|
|
626
687
|
stack_provider: str | None,
|
|
627
688
|
) -> Registration:
|
|
628
|
-
from localmodels import bifrost_provider
|
|
629
|
-
|
|
630
689
|
added = planned(model, plan, stack_provider=stack_provider)
|
|
631
690
|
pid, gateway_model, pi_provider = added["provider"], added["model"], added["pi_provider"]
|
|
632
691
|
name = str(plan["endpoint"]["model"])
|
|
@@ -642,7 +701,7 @@ def _register(
|
|
|
642
701
|
before, before_sheet = copy.deepcopy(config), read_sheet(app)
|
|
643
702
|
providers = config.setdefault("providers", {})
|
|
644
703
|
if stack_provider is not None:
|
|
645
|
-
providers[pid] =
|
|
704
|
+
providers[pid] = bifrost_config.render_provider("llm", url, name, key, pid)
|
|
646
705
|
_route_agent(config)
|
|
647
706
|
listed_as, names = f"{pid}/{gateway_model}", [name, gateway_model]
|
|
648
707
|
else:
|
|
@@ -650,10 +709,7 @@ def _register(
|
|
|
650
709
|
_normalize_existing_rules(config)
|
|
651
710
|
listed_as, names = gateway_model, [name]
|
|
652
711
|
context = int(str(plan["launch"].get("window") or 0)) or None
|
|
653
|
-
sheet = (
|
|
654
|
-
before_sheet
|
|
655
|
-
| bifrost_datasheet.sheets(pid, names, context)[bifrost_datasheet.DATASHEET]
|
|
656
|
-
)
|
|
712
|
+
sheet = before_sheet | bifrost_config.sheets(pid, names, context)[bifrost_config.DATASHEET]
|
|
657
713
|
apply_config(record, config, sheet)
|
|
658
714
|
try:
|
|
659
715
|
if listed_as not in bifrost_models.listed(record["addr"]):
|
|
@@ -697,6 +753,7 @@ def _unregister(registration: Registration) -> None:
|
|
|
697
753
|
config = gateway_bifrost.read_config(app)
|
|
698
754
|
providers = config.get("providers")
|
|
699
755
|
if not isinstance(providers, dict) or registration["provider"] not in providers:
|
|
756
|
+
_cleanup_orphaned_provider(record, config, registration["provider"])
|
|
700
757
|
return
|
|
701
758
|
del providers[registration["provider"]]
|
|
702
759
|
_normalize_existing_rules(config)
|
|
@@ -724,6 +781,7 @@ def _unwire_member(registration: Registration) -> None:
|
|
|
724
781
|
app = Path(record["app_dir"]) if record else None
|
|
725
782
|
config = gateway_bifrost.read_config(app) if app else {}
|
|
726
783
|
providers = config.get("providers") or {}
|
|
784
|
+
was_on_disk = isinstance(providers, dict) and registration["provider"] in providers
|
|
727
785
|
providers.pop(registration["provider"], None)
|
|
728
786
|
if not any(p in providers for p in STACK_PROVIDERS): # the last stack LLM
|
|
729
787
|
tools_root = hosts.tools_dir()
|
|
@@ -740,7 +798,11 @@ def _unwire_member(registration: Registration) -> None:
|
|
|
740
798
|
_route_agent(config)
|
|
741
799
|
prefix = registration["provider"] + "/"
|
|
742
800
|
sheet = {k: v for k, v in read_sheet(app).items() if not k.startswith(prefix)}
|
|
743
|
-
|
|
801
|
+
params = {bifrost_config.DATASHEET: sheet, bifrost_config.PARAMETERS: {}}
|
|
802
|
+
if was_on_disk or bifrost_config.differs(app, config, params):
|
|
803
|
+
apply_config(record, config, sheet)
|
|
804
|
+
else:
|
|
805
|
+
_cleanup_orphaned_provider(record, config, registration["provider"], sync_rules=True)
|
|
744
806
|
if (target := _agent_target(config)) and (ctx := _sheet_context(sheet, target)):
|
|
745
807
|
_pi_sync_shared(
|
|
746
808
|
gateway_bifrost.PI_PROVIDER,
|
|
@@ -30,6 +30,7 @@ from localmodels import (
|
|
|
30
30
|
metal,
|
|
31
31
|
plan_envelope,
|
|
32
32
|
process_identity,
|
|
33
|
+
remote_ops,
|
|
33
34
|
remote_ops_download,
|
|
34
35
|
reuse,
|
|
35
36
|
)
|
|
@@ -150,6 +151,25 @@ def delete_weights(files: list[str], keep: set[str]) -> list[str]:
|
|
|
150
151
|
return deleted
|
|
151
152
|
|
|
152
153
|
|
|
154
|
+
def prune_empty_custom_dirs(files: list[str], base_dir: str) -> None:
|
|
155
|
+
"""Remove empty parent directories strictly under ``<base_dir>/models/custom``."""
|
|
156
|
+
custom_root = (Path(os.path.expanduser(base_dir)) / "models" / "custom").resolve()
|
|
157
|
+
if not custom_root.is_dir():
|
|
158
|
+
return
|
|
159
|
+
for raw in files:
|
|
160
|
+
parent = Path(os.path.expanduser(raw)).resolve().parent
|
|
161
|
+
while parent != custom_root:
|
|
162
|
+
try:
|
|
163
|
+
parent.relative_to(custom_root)
|
|
164
|
+
except ValueError:
|
|
165
|
+
break
|
|
166
|
+
try:
|
|
167
|
+
parent.rmdir()
|
|
168
|
+
except OSError:
|
|
169
|
+
break
|
|
170
|
+
parent = parent.parent
|
|
171
|
+
|
|
172
|
+
|
|
153
173
|
KEEP_FAILED_DOWNLOAD_CODES = frozenset(
|
|
154
174
|
("DOWNLOAD_FAILED", "NETWORK_UNAVAILABLE", "DISK_INSUFFICIENT")
|
|
155
175
|
)
|
|
@@ -185,8 +205,19 @@ class _Counter:
|
|
|
185
205
|
the files already verified (or partially downloaded on disk) count as done; each progress
|
|
186
206
|
event moves its file's counter for the phase it reports."""
|
|
187
207
|
|
|
188
|
-
def __init__(
|
|
208
|
+
def __init__(
|
|
209
|
+
self,
|
|
210
|
+
model: str,
|
|
211
|
+
plan: Plan,
|
|
212
|
+
handle: JobHandle,
|
|
213
|
+
*,
|
|
214
|
+
shard_count: int | None = None,
|
|
215
|
+
) -> None:
|
|
189
216
|
self.model, self.handle = model, handle
|
|
217
|
+
self.shard_count = shard_count if shard_count and shard_count >= 1 else None
|
|
218
|
+
self.file_order = {
|
|
219
|
+
os.path.basename(f["dest"]): idx + 1 for idx, f in enumerate(plan["files"])
|
|
220
|
+
}
|
|
190
221
|
self.sizes = {os.path.basename(f["dest"]): f["size_bytes"] for f in plan["files"]}
|
|
191
222
|
self.done = {
|
|
192
223
|
os.path.basename(f["dest"]): (
|
|
@@ -252,8 +283,20 @@ class _Counter:
|
|
|
252
283
|
finished += sum(min(n, self.engine_sizes[k]) for k, n in self.engine_done.items())
|
|
253
284
|
rate = int(speed) if isinstance(speed, int) and phase == "download" else 0
|
|
254
285
|
source, connections = _download_telemetry(phase, event)
|
|
286
|
+
shard_index: int | None = None
|
|
287
|
+
shard_count: int | None = None
|
|
288
|
+
if phase == "download" and self.shard_count is not None and label in self.file_order:
|
|
289
|
+
shard_count = self.shard_count
|
|
290
|
+
shard_index = min(self.file_order[label], self.shard_count)
|
|
255
291
|
self.handle.update(
|
|
256
|
-
phase,
|
|
292
|
+
phase,
|
|
293
|
+
finished,
|
|
294
|
+
self.total,
|
|
295
|
+
rate,
|
|
296
|
+
source=source,
|
|
297
|
+
connections=connections,
|
|
298
|
+
shard_index=shard_index,
|
|
299
|
+
shard_count=shard_count,
|
|
257
300
|
)
|
|
258
301
|
progress(
|
|
259
302
|
self.model,
|
|
@@ -263,6 +306,8 @@ class _Counter:
|
|
|
263
306
|
rate,
|
|
264
307
|
source=source,
|
|
265
308
|
connections=connections,
|
|
309
|
+
shard_index=shard_index,
|
|
310
|
+
shard_count=shard_count,
|
|
266
311
|
)
|
|
267
312
|
|
|
268
313
|
|
|
@@ -298,13 +343,29 @@ def fetch(
|
|
|
298
343
|
only: set[str] | None = None,
|
|
299
344
|
*,
|
|
300
345
|
engine: bool = True,
|
|
346
|
+
auth_headers: dict[str, str] | None = None,
|
|
347
|
+
shard_count: int | None = None,
|
|
301
348
|
) -> None:
|
|
302
349
|
"""The plan's engine (when it is a pinned release) and weights, as stack apply fetches them;
|
|
303
350
|
``only`` limits the weights to the files this job claims. Progress counts the whole model."""
|
|
304
|
-
counter = _Counter(model, plan, handle)
|
|
351
|
+
counter = _Counter(model, plan, handle, shard_count=shard_count)
|
|
305
352
|
initial_done = sum(counter.done.values())
|
|
306
|
-
|
|
307
|
-
|
|
353
|
+
init_shard_idx = 1 if counter.shard_count is not None else None
|
|
354
|
+
handle.update(
|
|
355
|
+
"download",
|
|
356
|
+
initial_done,
|
|
357
|
+
counter.total,
|
|
358
|
+
shard_index=init_shard_idx,
|
|
359
|
+
shard_count=counter.shard_count,
|
|
360
|
+
)
|
|
361
|
+
progress(
|
|
362
|
+
model,
|
|
363
|
+
"download",
|
|
364
|
+
initial_done,
|
|
365
|
+
counter.total,
|
|
366
|
+
shard_index=init_shard_idx,
|
|
367
|
+
shard_count=counter.shard_count,
|
|
368
|
+
)
|
|
308
369
|
files = [f for f in plan["files"] if only is None or os.path.expanduser(f["dest"]) in only]
|
|
309
370
|
steps: tuple[Action, ...] = ("download",) if files else ()
|
|
310
371
|
if engine and plan["engine"]["source"] == "release":
|
|
@@ -312,11 +373,13 @@ def fetch(
|
|
|
312
373
|
mine: Plan = {**plan, "files": _with_reuse(files) if files else files}
|
|
313
374
|
for step in steps:
|
|
314
375
|
on_event = counter if step in ("engine", "download") else None
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
376
|
+
params = deploy_steps.step_params(mine, step, "")
|
|
377
|
+
if step == "download" and auth_headers:
|
|
378
|
+
params = {**params, "auth_headers": dict(auth_headers)} # type: ignore[assignment]
|
|
379
|
+
outcome, result = run.run_action(step, params, on_event=on_event or (lambda _e: None))
|
|
318
380
|
if result.returncode != 0 or outcome.get("event") != "result":
|
|
319
|
-
|
|
381
|
+
raw_msg = str(outcome.get("message") or result.stderr.strip()[-500:] or "failed")
|
|
382
|
+
message = remote_ops.redact_text(raw_msg)
|
|
320
383
|
raise LibraryError(_code(message), message, failed=True)
|
|
321
384
|
if step == "engine":
|
|
322
385
|
counter.finish_engine()
|
|
@@ -559,9 +622,11 @@ def cancel(model_id: str, base_dir: str) -> Row:
|
|
|
559
622
|
with library_state.locked(): # it ended without cleaning up after itself (killed)
|
|
560
623
|
committed = library_state.load(model.id) is not None
|
|
561
624
|
if library_state.current(job) and not library_state.job_alive(model.id) and not committed:
|
|
562
|
-
|
|
625
|
+
gone = leftovers(job)
|
|
626
|
+
delete_weights(gone, in_use(model.id))
|
|
627
|
+
prune_empty_custom_dirs(gone, job.get("base_dir") or base_dir)
|
|
563
628
|
library_state.clear_job(model.id)
|
|
564
|
-
return library_status.
|
|
629
|
+
return library_status.row(library_status.Library.read(probe(), base_dir), model)
|
|
565
630
|
|
|
566
631
|
|
|
567
632
|
def files_missing(plan: Plan) -> list[str]:
|
|
@@ -99,17 +99,61 @@ def _retired(record: Record) -> tuple[cat.CatalogEntry, cat.QuantVariant]:
|
|
|
99
99
|
return entry, variant
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
def _entry_from_snapshot(
|
|
103
|
+
raw: dict[str, object], quant: str
|
|
104
|
+
) -> tuple[cat.CatalogEntry, cat.QuantVariant] | None:
|
|
105
|
+
try:
|
|
106
|
+
loaded = cat.load_catalog({"schema_version": 3, "models": [raw]})
|
|
107
|
+
except ValueError:
|
|
108
|
+
return None
|
|
109
|
+
if not loaded:
|
|
110
|
+
return None
|
|
111
|
+
entry = loaded[0]
|
|
112
|
+
variant = next((v for v in entry.variants if v.quant == quant), entry.variants[0])
|
|
113
|
+
return entry, variant
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _custom_from_record(record: Record) -> tuple[cat.CatalogEntry, cat.QuantVariant]:
|
|
117
|
+
raw_entry = record.get("catalog_entry")
|
|
118
|
+
if isinstance(raw_entry, dict):
|
|
119
|
+
if found := _entry_from_snapshot(raw_entry, record["quant"]):
|
|
120
|
+
return found
|
|
121
|
+
entry, variant = _retired(record)
|
|
122
|
+
return (
|
|
123
|
+
dataclasses.replace(
|
|
124
|
+
entry,
|
|
125
|
+
status="candidate",
|
|
126
|
+
engine=entry.engine or "b12588-mix-c0c3de8",
|
|
127
|
+
),
|
|
128
|
+
variant,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _custom_from_job(model_id: str) -> tuple[cat.CatalogEntry, cat.QuantVariant] | None:
|
|
133
|
+
job = library_state.read_job(model_id)
|
|
134
|
+
if job is None or job.get("custom") is None:
|
|
135
|
+
return None
|
|
136
|
+
raw_entry = job.get("catalog_entry")
|
|
137
|
+
if isinstance(raw_entry, dict):
|
|
138
|
+
quant = str(job["custom"].get("variant_id") or "")
|
|
139
|
+
if found := _entry_from_snapshot(raw_entry, quant):
|
|
140
|
+
return found
|
|
141
|
+
return None
|
|
142
|
+
|
|
143
|
+
|
|
102
144
|
def find_entry(
|
|
103
145
|
model_id: str, catalog: Iterable[cat.CatalogEntry]
|
|
104
146
|
) -> tuple[cat.CatalogEntry, cat.QuantVariant] | None:
|
|
105
147
|
"""The model a library record on disk names by its full ``id:QUANT``, or None."""
|
|
106
148
|
record = library_state.load(model_id)
|
|
107
|
-
if record is None
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
149
|
+
if record is not None and record["id"] == model_id:
|
|
150
|
+
if record.get("custom") is not None:
|
|
151
|
+
return _custom_from_record(record)
|
|
152
|
+
if (recipe := _recipe(record)) is not None:
|
|
153
|
+
entry, variant = library_poly.as_entry(recipe)
|
|
154
|
+
return (entry if recipe.get("display_name") else _named(entry, catalog)), variant
|
|
155
|
+
return _retired(record)
|
|
156
|
+
return _custom_from_job(model_id)
|
|
113
157
|
|
|
114
158
|
|
|
115
159
|
def retired(entry: cat.CatalogEntry) -> bool:
|