@simplexai/localmodels-linux-arm64 0.1.0-dev.64 → 0.1.0-dev.66
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 +125 -121
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +2 -2
- package/modules/localmodels/approval.py +5 -3
- package/modules/localmodels/auth_proxy.py +34 -2
- package/modules/localmodels/bifrost_checks.py +2 -1
- package/modules/localmodels/catalog.json +504 -18
- package/modules/localmodels/catalog.py +2 -1
- package/modules/localmodels/catalog_recipes.py +3 -0
- package/modules/localmodels/component.py +1 -1
- package/modules/localmodels/context_policy.py +1 -1
- package/modules/localmodels/custom_hub.py +54 -6
- package/modules/localmodels/custom_probe.py +33 -5
- package/modules/localmodels/debug_stub_server.py +34 -1
- package/modules/localmodels/deploy.py +45 -285
- package/modules/localmodels/deployment_lifecycle.py +167 -0
- package/modules/localmodels/download-mirrors.json +43 -3
- package/modules/localmodels/draft_spec.py +43 -1
- package/modules/localmodels/engine_adapters/__init__.py +4 -2
- package/modules/localmodels/engine_adapters/auxiliary.py +4 -1
- package/modules/localmodels/engine_adapters/llama_cpp.py +539 -0
- package/modules/localmodels/engines-b11583.json +9 -5
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +85 -1
- package/modules/localmodels/engines.json +9 -5
- package/modules/localmodels/gateway.py +124 -13
- package/modules/localmodels/gateway_accept.py +1 -6
- package/modules/localmodels/gateway_cli.py +13 -24
- package/modules/localmodels/gateway_ops.py +185 -0
- package/modules/localmodels/gateway_server.py +3 -2
- package/modules/localmodels/harness.py +13 -16
- package/modules/localmodels/harness_core.py +4 -9
- package/modules/localmodels/harness_gateway.py +18 -6
- package/modules/localmodels/harness_probe.py +64 -3
- package/modules/localmodels/hosts.py +22 -34
- package/modules/localmodels/library_convert.py +3 -3
- package/modules/localmodels/library_custom.py +15 -13
- package/modules/localmodels/library_elastic.py +27 -13
- package/modules/localmodels/library_jobs.py +151 -28
- package/modules/localmodels/library_model.py +22 -2
- package/modules/localmodels/library_order.py +5 -4
- package/modules/localmodels/library_poly.py +2 -2
- package/modules/localmodels/library_pricing.py +34 -318
- package/modules/localmodels/library_serve.py +20 -12
- package/modules/localmodels/library_smoke.py +8 -1
- package/modules/localmodels/library_state.py +12 -0
- package/modules/localmodels/library_status.py +26 -16
- package/modules/localmodels/llm_rank.py +1 -1
- package/modules/localmodels/magpie_legacy.py +160 -0
- package/modules/localmodels/magpie_setup.py +6 -1
- package/modules/localmodels/pi_profile.py +3 -7
- package/modules/localmodels/plan_envelope.py +1 -1
- package/modules/localmodels/{budget.py → planning/budget.py} +56 -33
- package/modules/localmodels/{stack_llm_ram.py → planning/llm_ram.py} +11 -1
- package/modules/localmodels/planning/memory_pools.py +403 -0
- package/modules/localmodels/recommend.py +1 -1
- package/modules/localmodels/recommend_cli.py +3 -4
- package/modules/localmodels/remote_ops_mirrors.py +55 -19
- package/modules/localmodels/residency_host.py +1 -1
- package/modules/localmodels/service_control.py +4 -4
- package/modules/localmodels/service_deployment.py +4 -4
- package/modules/localmodels/service_wiring.py +17 -19
- package/modules/localmodels/setup_inspection.py +29 -2
- package/modules/localmodels/setup_inspection_harness.py +5 -2
- package/modules/localmodels/setup_text.py +6 -0
- package/modules/localmodels/setup_upgrade.py +3 -12
- package/modules/localmodels/slot_cache.py +1 -3
- package/modules/localmodels/speech_admission.py +17 -5
- package/modules/localmodels/speech_catalog.py +5 -1
- package/modules/localmodels/speech_cli.py +5 -5
- package/modules/localmodels/speech_jobs.py +103 -20
- package/modules/localmodels/speech_model.py +2 -0
- package/modules/localmodels/speech_server.py +132 -9
- package/modules/localmodels/speech_state.py +11 -0
- package/modules/localmodels/speech_worker_sensevoice.py +215 -19
- package/modules/localmodels/speech_workers.py +79 -7
- package/modules/localmodels/stack.py +15 -6
- package/modules/localmodels/stack_auto.py +10 -4
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_binding.py +24 -143
- package/modules/localmodels/stack_capacity.py +4 -4
- package/modules/localmodels/stack_card.py +1 -1
- package/modules/localmodels/stack_cleanup.py +3 -3
- package/modules/localmodels/stack_cli.py +3 -0
- package/modules/localmodels/stack_client_settings.py +9 -2
- package/modules/localmodels/stack_compose.py +42 -9
- package/modules/localmodels/stack_console.py +2 -2
- package/modules/localmodels/stack_debug.py +1 -1
- package/modules/localmodels/stack_decision.py +1 -1
- package/modules/localmodels/stack_doctor.py +10 -7
- package/modules/localmodels/stack_down.py +3 -3
- package/modules/localmodels/stack_gpu_memory.py +1 -1
- package/modules/localmodels/stack_hardware.py +3 -3
- package/modules/localmodels/stack_hardware_text.py +1 -1
- package/modules/localmodels/stack_lifecycle.py +7 -7
- package/modules/localmodels/stack_memory.py +1 -1
- package/modules/localmodels/stack_mlx.py +1 -1
- package/modules/localmodels/stack_plan.py +18 -13
- package/modules/localmodels/stack_ports.py +60 -29
- package/modules/localmodels/stack_preflight.py +4 -3
- package/modules/localmodels/stack_remove.py +13 -6
- package/modules/localmodels/stack_review.py +3 -5
- package/modules/localmodels/stack_rollback.py +1 -1
- package/modules/localmodels/stack_route.py +5 -4
- package/modules/localmodels/stack_suite.py +17 -4
- package/modules/localmodels/stack_summary.py +1 -1
- package/modules/localmodels/stack_try.py +8 -13
- package/modules/localmodels/stack_up.py +10 -9
- package/modules/localmodels/stack_update.py +2 -1
- package/modules/localmodels/stack_verify.py +4 -30
- package/modules/localmodels/stack_view.py +6 -4
- package/modules/localmodels/stack_view_apply.py +2 -2
- package/modules/localmodels/stack_view_text.py +2 -6
- package/modules/localmodels/stack_view_tick.py +2 -2
- package/modules/localmodels/stack_view_words.py +5 -2
- package/modules/localmodels/stack_warm.py +1 -1
- package/modules/localmodels/suite.py +1 -1
- package/modules/localmodels/tui_views.py +11 -5
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/RECORD +122 -118
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/NOTICE +3 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/library_vram.py +0 -123
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -152,6 +152,8 @@ class _JobSince20261113(TypedDict, total=False):
|
|
|
152
152
|
connections: int # active parallel download connections
|
|
153
153
|
shard_index: int # 1-based active shard index for multi-shard downloads
|
|
154
154
|
shard_count: int # total shard count for multi-shard downloads
|
|
155
|
+
engine_done: int # engine archive bytes inside done while the engine downloads too
|
|
156
|
+
engine_total: int # engine archive bytes inside total (first install only)
|
|
155
157
|
load_step: str # load sub-step: prepare | start | load | warm
|
|
156
158
|
error: Problem # a download that stopped cleanly: status shows why; cancel discards it
|
|
157
159
|
custom: CustomMeta # custom hub metadata while download is in progress
|
|
@@ -350,6 +352,8 @@ class JobHandle:
|
|
|
350
352
|
load_step: str | None = None,
|
|
351
353
|
shard_index: int | None = None,
|
|
352
354
|
shard_count: int | None = None,
|
|
355
|
+
engine_done: int | None = None,
|
|
356
|
+
engine_total: int | None = None,
|
|
353
357
|
) -> None:
|
|
354
358
|
import time
|
|
355
359
|
|
|
@@ -360,6 +364,7 @@ class JobHandle:
|
|
|
360
364
|
self.job.get("total"),
|
|
361
365
|
self.job.get("shard_index"),
|
|
362
366
|
self.job.get("shard_count"),
|
|
367
|
+
self.job.get("done", 0) > 0, # the first bytes moving: status leaves 0 at once
|
|
363
368
|
)
|
|
364
369
|
self.job["phase"], self.job["done"], self.job["total"] = phase, done, total
|
|
365
370
|
self.job["bytes_per_second"] = bytes_per_second
|
|
@@ -385,6 +390,12 @@ class JobHandle:
|
|
|
385
390
|
self.job.pop("connections", None)
|
|
386
391
|
self.job.pop("shard_index", None)
|
|
387
392
|
self.job.pop("shard_count", None)
|
|
393
|
+
if phase in ("download", "verify") and engine_total is not None and engine_total > 0:
|
|
394
|
+
self.job["engine_total"] = engine_total
|
|
395
|
+
self.job["engine_done"] = max(0, min(engine_done or 0, engine_total))
|
|
396
|
+
else:
|
|
397
|
+
self.job.pop("engine_total", None)
|
|
398
|
+
self.job.pop("engine_done", None)
|
|
388
399
|
if phase in ("load", "warm") and load_step is not None:
|
|
389
400
|
self.job["load_step"] = load_step
|
|
390
401
|
else:
|
|
@@ -396,6 +407,7 @@ class JobHandle:
|
|
|
396
407
|
self.job.get("total"),
|
|
397
408
|
self.job.get("shard_index"),
|
|
398
409
|
self.job.get("shard_count"),
|
|
410
|
+
self.job.get("done", 0) > 0,
|
|
399
411
|
) != prev
|
|
400
412
|
now = time.monotonic()
|
|
401
413
|
if changed or now - self._written >= JOB_WRITE_EVERY_S or done >= total:
|
|
@@ -14,15 +14,14 @@ from typing import Any, cast
|
|
|
14
14
|
|
|
15
15
|
from localmodels import (
|
|
16
16
|
__version__,
|
|
17
|
-
budget,
|
|
18
17
|
debug_mode,
|
|
18
|
+
deployment_lifecycle,
|
|
19
19
|
hosts,
|
|
20
20
|
library_elastic,
|
|
21
21
|
library_gateway,
|
|
22
22
|
library_order,
|
|
23
23
|
library_pricing,
|
|
24
24
|
library_state,
|
|
25
|
-
library_vram,
|
|
26
25
|
metal,
|
|
27
26
|
plan_envelope,
|
|
28
27
|
remote_ops_common,
|
|
@@ -68,6 +67,7 @@ from localmodels.library_model import (
|
|
|
68
67
|
)
|
|
69
68
|
from localmodels.library_pricing import Model, Priced
|
|
70
69
|
from localmodels.library_state import Job, Record
|
|
70
|
+
from localmodels.planning import budget, memory_pools
|
|
71
71
|
from localmodels.probe import HostFacts
|
|
72
72
|
from localmodels.records import Plan
|
|
73
73
|
|
|
@@ -147,7 +147,7 @@ def _index_owned_deployments(
|
|
|
147
147
|
except (OSError, ValueError):
|
|
148
148
|
return
|
|
149
149
|
for name, owned in owned_deployments.items():
|
|
150
|
-
if name in library_names or
|
|
150
|
+
if name in library_names or deployment_lifecycle.is_removed(owned):
|
|
151
151
|
continue
|
|
152
152
|
owner = f"deployment:{name}"
|
|
153
153
|
for dest in _extract_dests(owned.get("files") or ()):
|
|
@@ -249,7 +249,7 @@ class Library:
|
|
|
249
249
|
if not self.healthy(str(record["plan"]["endpoint"]["base_url"])):
|
|
250
250
|
continue
|
|
251
251
|
pool = record["pool"]
|
|
252
|
-
found[pool] = found.get(pool, 0) +
|
|
252
|
+
found[pool] = found.get(pool, 0) + memory_pools.memory_bytes(record["plan"])
|
|
253
253
|
return found
|
|
254
254
|
|
|
255
255
|
def models(self) -> list[Model]:
|
|
@@ -337,7 +337,7 @@ def _plan_of(
|
|
|
337
337
|
if job is not None and alive and job["pool"] != priced.pool:
|
|
338
338
|
try:
|
|
339
339
|
return library_pricing.price(
|
|
340
|
-
|
|
340
|
+
memory_pools.capacity(lib.facts, reclaimable=lib.reclaimable()),
|
|
341
341
|
model,
|
|
342
342
|
job["pool"],
|
|
343
343
|
lib.base_dir,
|
|
@@ -432,6 +432,16 @@ def _downloading(job: Job) -> Download:
|
|
|
432
432
|
s_cnt = job.get("shard_count")
|
|
433
433
|
if isinstance(s_cnt, int) and not isinstance(s_cnt, bool) and s_cnt >= 1:
|
|
434
434
|
dl["shard_count"] = s_cnt
|
|
435
|
+
e_total, e_done = job.get("engine_total"), job.get("engine_done")
|
|
436
|
+
if (
|
|
437
|
+
isinstance(e_total, int)
|
|
438
|
+
and not isinstance(e_total, bool)
|
|
439
|
+
and e_total > 0
|
|
440
|
+
and isinstance(e_done, int)
|
|
441
|
+
and not isinstance(e_done, bool)
|
|
442
|
+
):
|
|
443
|
+
dl["engine_total_bytes"] = min(e_total, dl["total_bytes"])
|
|
444
|
+
dl["engine_done_bytes"] = max(0, min(e_done, dl["engine_total_bytes"]))
|
|
435
445
|
return dl
|
|
436
446
|
|
|
437
447
|
|
|
@@ -894,7 +904,7 @@ def row(lib: Library, model: Model) -> Row:
|
|
|
894
904
|
if plan is None
|
|
895
905
|
else (0, 0, False, 0)
|
|
896
906
|
)
|
|
897
|
-
memory =
|
|
907
|
+
memory = memory_pools.memory_bytes(plan) if plan is not None else fallback_memory
|
|
898
908
|
if record is None and job is not None and alive:
|
|
899
909
|
memory = job["memory_bytes"] or memory
|
|
900
910
|
if record is not None and record["state"] != "loaded" and record.get("memory_bytes"):
|
|
@@ -951,7 +961,7 @@ def row(lib: Library, model: Model) -> Row:
|
|
|
951
961
|
def _component_bytes(plan: Plan, pool: str) -> int:
|
|
952
962
|
launch = plan.get("launch") or {}
|
|
953
963
|
if pool != "system":
|
|
954
|
-
return
|
|
964
|
+
return memory_pools.memory_bytes(plan)
|
|
955
965
|
try:
|
|
956
966
|
return suite.bounded_ram(plan)
|
|
957
967
|
except (KeyError, ValueError, IndexError):
|
|
@@ -961,7 +971,7 @@ def _component_bytes(plan: Plan, pool: str) -> int:
|
|
|
961
971
|
def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
962
972
|
"""Every pool with what holds it: loaded and loading library models, and the services this
|
|
963
973
|
tool runs that are not library models (foundation components)."""
|
|
964
|
-
holders: dict[str, list[Holder]] = {p: [] for p in
|
|
974
|
+
holders: dict[str, list[Holder]] = {p: [] for p in memory_pools.pools(lib.facts)}
|
|
965
975
|
library_names = {r["plan"]["name"] for r in lib.records.values() if r["state"] != "idle"}
|
|
966
976
|
for row_ in rows:
|
|
967
977
|
if row_["state"] in ("loaded", "loading") and row_["pool"] in holders:
|
|
@@ -977,7 +987,7 @@ def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
|
977
987
|
plan = record["plan"]
|
|
978
988
|
if plan["name"] in library_names or not record.get("ok"):
|
|
979
989
|
continue
|
|
980
|
-
pool =
|
|
990
|
+
pool = memory_pools.pool_of(plan)
|
|
981
991
|
if pool not in holders:
|
|
982
992
|
if pool.startswith("gpu:"):
|
|
983
993
|
continue # a card hidden from the library (CUDA_VISIBLE_DEVICES)
|
|
@@ -990,19 +1000,19 @@ def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
|
990
1000
|
"bytes": _component_bytes(plan, pool),
|
|
991
1001
|
}
|
|
992
1002
|
)
|
|
993
|
-
now =
|
|
1003
|
+
now = memory_pools.live(lib.facts, lib.reserved())
|
|
994
1004
|
gpu_pool_count = sum(1 for p in holders if p.startswith("gpu:"))
|
|
995
1005
|
found: list[Pool] = []
|
|
996
1006
|
for pool, held in holders.items():
|
|
997
|
-
total =
|
|
998
|
-
free =
|
|
1007
|
+
total = memory_pools.pool_total(lib.facts, pool)
|
|
1008
|
+
free = memory_pools.pool_free(now, pool)
|
|
999
1009
|
used = min(total, max(0, total - free))
|
|
1000
1010
|
entry: Pool = {
|
|
1001
1011
|
"id": pool,
|
|
1002
1012
|
"total_bytes": total,
|
|
1003
1013
|
"used_bytes": used,
|
|
1004
1014
|
"holders": held,
|
|
1005
|
-
"reserve_bytes":
|
|
1015
|
+
"reserve_bytes": memory_pools.pool_reserve(now, pool),
|
|
1006
1016
|
}
|
|
1007
1017
|
if pool == "unified" and metal.supported(now):
|
|
1008
1018
|
adm = budget.admission_budget(now, "unified")
|
|
@@ -1011,7 +1021,7 @@ def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
|
1011
1021
|
entry["hard_ceiling_bytes"] = adm.hard_ceiling_bytes
|
|
1012
1022
|
if adm.wired_headroom_bytes is not None:
|
|
1013
1023
|
entry["wired_headroom_bytes"] = adm.wired_headroom_bytes
|
|
1014
|
-
if ext :=
|
|
1024
|
+
if ext := memory_pools.pool_external_holders(lib.facts, pool, gpu_pool_count):
|
|
1015
1025
|
entry["external_holders"] = ext
|
|
1016
1026
|
found.append(entry)
|
|
1017
1027
|
return found
|
|
@@ -1064,7 +1074,7 @@ def _fallback_engine_label(model: Model) -> str:
|
|
|
1064
1074
|
|
|
1065
1075
|
def host(lib: Library) -> Host:
|
|
1066
1076
|
facts = lib.facts
|
|
1067
|
-
shown =
|
|
1077
|
+
shown = memory_pools.visible(facts) # the cards the pools may use
|
|
1068
1078
|
os_info = facts.get("os") or {}
|
|
1069
1079
|
os_label = str(
|
|
1070
1080
|
os_info.get("distro")
|
|
@@ -1120,7 +1130,7 @@ def host(lib: Library) -> Host:
|
|
|
1120
1130
|
def build(lib: Library) -> Status:
|
|
1121
1131
|
models = lib.models()
|
|
1122
1132
|
rows = [row(lib, m) for m in models]
|
|
1123
|
-
now =
|
|
1133
|
+
now = memory_pools.live(lib.facts, lib.reserved())
|
|
1124
1134
|
candidates = [
|
|
1125
1135
|
m
|
|
1126
1136
|
for m, r in zip(models, rows, strict=True)
|
|
@@ -14,7 +14,6 @@ from collections.abc import Iterable, Mapping
|
|
|
14
14
|
from dataclasses import dataclass
|
|
15
15
|
|
|
16
16
|
from localmodels import engines, metal, vision
|
|
17
|
-
from localmodels.budget import HARNESS_RAM, RAM_FLOOR, host_ram
|
|
18
17
|
from localmodels.catalog import (
|
|
19
18
|
USABLE_FLOOR_TOK_S,
|
|
20
19
|
CatalogEntry,
|
|
@@ -29,6 +28,7 @@ from localmodels.catalog import (
|
|
|
29
28
|
from localmodels.context_policy import AGENT, AgentPosture
|
|
30
29
|
from localmodels.estimator import HardwareBudget, PhysicsRefusal, llama_host_bytes
|
|
31
30
|
from localmodels.plan_envelope import PlanError
|
|
31
|
+
from localmodels.planning.budget import HARNESS_RAM, RAM_FLOOR, host_ram
|
|
32
32
|
from localmodels.probe import HostFacts
|
|
33
33
|
|
|
34
34
|
# Installed SimplexAI scores closer than this are a tie (model-scoring.md; AIHOT: 3 points or more
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"""The legacy Magpie gateway behind one adapter.
|
|
2
|
+
|
|
3
|
+
A stack plan's ``harness.gateway``, its ``options.gateway`` and an app gateway's
|
|
4
|
+
``gateway.json`` name their gateway by kind: ``bifrost``, the gateway this tool installs, or
|
|
5
|
+
``magpie``, the legacy gateway that a plan or record without a kind still means (as does any
|
|
6
|
+
kind that is not ``bifrost``: plans were always read that way).
|
|
7
|
+
|
|
8
|
+
``of`` turns any of those records into a ``GatewayAdapter``: Bifrost, or ``MagpieLegacyAdapter``
|
|
9
|
+
where Magpie differs. What callers need to tell the two apart (the name shown, the model id a
|
|
10
|
+
client sends, the pinned tool, what the gateway can do) is an attribute or method here, so the
|
|
11
|
+
rest of localmodels asks what the gateway does rather than which one it is. What each gateway
|
|
12
|
+
does once installed lives in the implementation layer (``gateway._gateway``, ``gateway_ops.of``).
|
|
13
|
+
The few places that still decide on the kind read ``legacy``; scripts/architecture_gateway_kind.py
|
|
14
|
+
counts every such decision outside this module (``architecture_baselines.GATEWAY_KIND_BRANCHES``)
|
|
15
|
+
and the count can only go down. Removing Magpie removes ``MagpieLegacyAdapter`` and those
|
|
16
|
+
branches.
|
|
17
|
+
|
|
18
|
+
Standard library only (layer 0), so every layer can ask.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from collections.abc import Mapping
|
|
24
|
+
from typing import Any, Final, Literal
|
|
25
|
+
|
|
26
|
+
BIFROST: Final = "bifrost"
|
|
27
|
+
MAGPIE: Final = "magpie"
|
|
28
|
+
KINDS: Final = (BIFROST, MAGPIE)
|
|
29
|
+
GatewayTool = Literal["bifrost", "magpie"] # the tool lock's entry for each gateway
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GatewayAdapter:
|
|
33
|
+
"""Bifrost, the gateway this tool installs. ``MagpieLegacyAdapter`` overrides what differs."""
|
|
34
|
+
|
|
35
|
+
kind: str = BIFROST
|
|
36
|
+
label: str = "Bifrost" # the name plans, reports and dialogs show
|
|
37
|
+
tool: GatewayTool = BIFROST # the tool lock entry and the plan tool that installs the binary
|
|
38
|
+
legacy: bool = False # Magpie: only for the branches architecture_checks still counts
|
|
39
|
+
# An app gateway's startup budget; None: gateway_bifrost.HEALTH_TIMEOUT_S.
|
|
40
|
+
health_timeout_s: float | None = None
|
|
41
|
+
# Bifrost keeps a request log: stack try names the LLM that answered a routed chat from it.
|
|
42
|
+
request_log: bool = True
|
|
43
|
+
# --route fastest: a decision model tiers requests between two LLMs.
|
|
44
|
+
routes_fastest: bool = True
|
|
45
|
+
# A stack plan carries gateway_keys' caller key: Magpie asks callers for one, this tool's
|
|
46
|
+
# Bifrost checks no key on loopback.
|
|
47
|
+
plan_caller_key: bool = False
|
|
48
|
+
# Magpie's usage CSV: stack view lists it as request events.
|
|
49
|
+
usage_events: bool = False
|
|
50
|
+
# Its private config under an app gateway root, removed when the root changes gateway.
|
|
51
|
+
app_config: tuple[str, ...] = ("bifrost",)
|
|
52
|
+
# What a stack plan warns about this gateway.
|
|
53
|
+
plan_warning: str | None = None
|
|
54
|
+
# Where the gateway serves the decision API, when not at the service API's own path: Bifrost
|
|
55
|
+
# serves the typesafe decision API under its own prefix.
|
|
56
|
+
decision_path: str | None = "/typesafe/v1/systemone"
|
|
57
|
+
# The model library also writes this gateway's config: changes to it take the library's
|
|
58
|
+
# lock (library_gateway.gateway_locked), and recheck the stack once they hold it.
|
|
59
|
+
shares_config: bool = True
|
|
60
|
+
# The provider name pi knows this gateway by, when it is not the stack's own: legacy
|
|
61
|
+
# Magpie's ``magpie`` provider, whose models are ``magpie/<id>``.
|
|
62
|
+
pi_provider: str | None = None
|
|
63
|
+
# File names of the gateway's binary among the tools this tool installed.
|
|
64
|
+
executables: frozenset[str] = frozenset({"bifrost-http", "bifrost-http.exe"})
|
|
65
|
+
|
|
66
|
+
def selected_in_pi(self, provider: object, model: object) -> bool:
|
|
67
|
+
"""pi's default (``defaultProvider``, ``defaultModel``) is this gateway's provider."""
|
|
68
|
+
if self.pi_provider is None:
|
|
69
|
+
return False
|
|
70
|
+
return provider == self.pi_provider or (
|
|
71
|
+
not provider and isinstance(model, str) and model.startswith(self.pi_provider + "/")
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def model(self, group: str) -> str:
|
|
75
|
+
"""The model id a client sends to reach the stack's routing group."""
|
|
76
|
+
return group
|
|
77
|
+
|
|
78
|
+
def routing(self, group: str, *, tiered: bool) -> str:
|
|
79
|
+
"""How a plan summary names the stack's routing group (``tiered``: a decision model
|
|
80
|
+
picks the effort or LLM)."""
|
|
81
|
+
return f", routed model {group}" + (" (tiered by the decision model)" if tiered else "")
|
|
82
|
+
|
|
83
|
+
def binding(self, addr: str, caller_key: str) -> dict[str, str]:
|
|
84
|
+
"""The gateway binding the service worker forwards through (``caller_key``:
|
|
85
|
+
gateway_keys.CALLER_KEY). This tool's Bifrost checks no key on loopback inference."""
|
|
86
|
+
return {"baseUrl": f"http://{addr}/v1", "key": caller_key, "kind": self.kind}
|
|
87
|
+
|
|
88
|
+
def executable(self, platform: str) -> str:
|
|
89
|
+
"""The binary's file name in an app gateway root (``platform``: the lock's name)."""
|
|
90
|
+
return "bifrost-http"
|
|
91
|
+
|
|
92
|
+
def __repr__(self) -> str:
|
|
93
|
+
return f"{type(self).__name__}()"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class MagpieLegacyAdapter(GatewayAdapter):
|
|
97
|
+
"""Magpie, the legacy gateway: every way it differs from Bifrost."""
|
|
98
|
+
|
|
99
|
+
kind = MAGPIE
|
|
100
|
+
label = "Magpie"
|
|
101
|
+
tool = MAGPIE
|
|
102
|
+
legacy = True
|
|
103
|
+
health_timeout_s = 30.0
|
|
104
|
+
request_log = False
|
|
105
|
+
routes_fastest = False
|
|
106
|
+
plan_caller_key = True
|
|
107
|
+
decision_path = None
|
|
108
|
+
shares_config = False
|
|
109
|
+
pi_provider = "magpie"
|
|
110
|
+
executables = frozenset({"magpie", "magpie.exe"})
|
|
111
|
+
usage_events = True
|
|
112
|
+
app_config = ("home", ".config", "magpie")
|
|
113
|
+
plan_warning = (
|
|
114
|
+
"to register the local service keys, the control side uses Magpie's local"
|
|
115
|
+
" authenticated admin API; keys stay out of command-line arguments, diagnostic output"
|
|
116
|
+
" and temporary files, and are then kept in Magpie's providers.json (0600)"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def model(self, group: str) -> str:
|
|
120
|
+
return f"group/{group}"
|
|
121
|
+
|
|
122
|
+
def routing(self, group: str, *, tiered: bool) -> str:
|
|
123
|
+
return f", routing group {self.model(group)}"
|
|
124
|
+
|
|
125
|
+
def binding(self, addr: str, caller_key: str) -> dict[str, str]:
|
|
126
|
+
# Magpie's documented local client key is an app identity, not a remote gateway secret;
|
|
127
|
+
# the binding names no kind, as bindings did before there was a choice.
|
|
128
|
+
return {"baseUrl": f"http://{addr}/v1", "key": "magpie-simplex"}
|
|
129
|
+
|
|
130
|
+
def executable(self, platform: str) -> str:
|
|
131
|
+
return "magpie.exe" if platform == "windows" else "magpie"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
BIFROST_ADAPTER: Final = GatewayAdapter()
|
|
135
|
+
MAGPIE_LEGACY: Final = MagpieLegacyAdapter()
|
|
136
|
+
|
|
137
|
+
# Tools that update themselves after install: the copy at the path it was installed to stays
|
|
138
|
+
# this tool's whatever version it has become.
|
|
139
|
+
SELF_UPDATING_TOOLS: Final = frozenset({MAGPIE_LEGACY.tool})
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def for_kind(kind: object) -> GatewayAdapter:
|
|
143
|
+
"""The adapter for a recorded kind: Bifrost for ``bifrost``, Magpie for anything else."""
|
|
144
|
+
return BIFROST_ADAPTER if kind == BIFROST else MAGPIE_LEGACY
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def of(gateway: Mapping[str, Any] | None) -> GatewayAdapter:
|
|
148
|
+
"""The adapter for a record with a ``kind``: a plan's ``harness.gateway``, a gateway view,
|
|
149
|
+
a service binding or ``gateway.json``. None or no kind: Magpie."""
|
|
150
|
+
return for_kind((gateway or {}).get("kind"))
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def of_options(options: Mapping[str, Any]) -> GatewayAdapter:
|
|
154
|
+
"""The adapter a plan's ``options`` chose; a plan from before the choice used Magpie."""
|
|
155
|
+
return for_kind(options.get("gateway"))
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def known(kind: object) -> bool:
|
|
159
|
+
"""Whether ``kind`` names a gateway."""
|
|
160
|
+
return kind in KINDS
|
|
@@ -27,6 +27,7 @@ from typing import TypedDict
|
|
|
27
27
|
from localmodels import (
|
|
28
28
|
approval,
|
|
29
29
|
cli_help,
|
|
30
|
+
deployment_lifecycle,
|
|
30
31
|
gateway,
|
|
31
32
|
gateway_clients,
|
|
32
33
|
harness,
|
|
@@ -502,7 +503,11 @@ def remove(purge: bool, yes: bool) -> int:
|
|
|
502
503
|
refused while a stack deployment still uses the gateway."""
|
|
503
504
|
owned = hosts.load_owned()
|
|
504
505
|
members = lifecycle.stack_members()
|
|
505
|
-
live = sorted(
|
|
506
|
+
live = sorted(
|
|
507
|
+
n
|
|
508
|
+
for n, d in owned["deployments"].items()
|
|
509
|
+
if n in members and deployment_lifecycle.holds_service(d)
|
|
510
|
+
)
|
|
506
511
|
if live:
|
|
507
512
|
print(
|
|
508
513
|
f"magpie:本机还有 stack 部署({'、'.join(live)})在用这个网关;"
|
|
@@ -15,7 +15,7 @@ from collections.abc import Mapping
|
|
|
15
15
|
from pathlib import Path
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
|
-
from localmodels import hosts, runtime_auth, runtime_discovery, runtime_io
|
|
18
|
+
from localmodels import hosts, magpie_legacy, runtime_auth, runtime_discovery, runtime_io
|
|
19
19
|
|
|
20
20
|
RUNTIMES = ("codex", "claude", "pi")
|
|
21
21
|
PROFILE_KEYS = {
|
|
@@ -360,17 +360,13 @@ class PiProfileStore:
|
|
|
360
360
|
return
|
|
361
361
|
current_provider = settings.get("defaultProvider")
|
|
362
362
|
current_model = settings.get("defaultModel")
|
|
363
|
-
was_magpie = current_provider
|
|
364
|
-
not current_provider
|
|
365
|
-
and isinstance(current_model, str)
|
|
366
|
-
and current_model.startswith("magpie/")
|
|
367
|
-
)
|
|
363
|
+
was_magpie = magpie_legacy.MAGPIE_LEGACY.selected_in_pi(current_provider, current_model)
|
|
368
364
|
if was_magpie or (stack_provider is not None and not current_model):
|
|
369
365
|
settings["defaultProvider"] = pi_provider
|
|
370
366
|
settings["defaultModel"] = gateway_model
|
|
371
367
|
self.write_settings(settings)
|
|
372
368
|
if was_magpie or retired_magpie:
|
|
373
|
-
self.drop_provider(
|
|
369
|
+
self.drop_provider(str(magpie_legacy.MAGPIE_LEGACY.pi_provider))
|
|
374
370
|
|
|
375
371
|
def write_isolated_profile(
|
|
376
372
|
self, provider: str, provider_entry: dict[str, Any], default_model: str
|
|
@@ -24,8 +24,8 @@ from typing import TypedDict
|
|
|
24
24
|
|
|
25
25
|
from localmodels import catalog as cat
|
|
26
26
|
from localmodels import region
|
|
27
|
-
from localmodels.budget import gib
|
|
28
27
|
from localmodels.contracts import decode
|
|
28
|
+
from localmodels.planning.budget import gib
|
|
29
29
|
from localmodels.probe import HostFacts
|
|
30
30
|
from localmodels.records import (
|
|
31
31
|
Launch,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Hardware budgets from probe facts.
|
|
1
|
+
"""Hardware budgets from probe facts: the placements a host offers and what each may hold.
|
|
2
2
|
|
|
3
3
|
Hermes' probe_budget() reads the machine it runs on and prices only CUDA device 0. Here the same
|
|
4
4
|
rules run on the controller over a host-facts document (localmodels.probe), so local and remote
|
|
@@ -22,6 +22,7 @@ from __future__ import annotations
|
|
|
22
22
|
|
|
23
23
|
import re
|
|
24
24
|
from dataclasses import dataclass, replace
|
|
25
|
+
from typing import Literal
|
|
25
26
|
|
|
26
27
|
from localmodels import gpu_specs, metal
|
|
27
28
|
from localmodels.context_policy import RUNTIME_OVERHEAD_BYTES
|
|
@@ -34,7 +35,8 @@ HARNESS_RAM = 1 * _GIB
|
|
|
34
35
|
_MARGIN_FLOOR = 2 << 30
|
|
35
36
|
_MARGIN_FRACTION = 0.09
|
|
36
37
|
_LAUNCH_HEADROOM = 1 << 30
|
|
37
|
-
|
|
38
|
+
# Unified memory (a Mac, an integrated CUDA device, CPU RAM) keeps this share back from models.
|
|
39
|
+
UMA_HEADROOM_FRACTION = 0.20
|
|
38
40
|
_POOL_DISAGREEMENT_FACTOR = 1.5
|
|
39
41
|
_POOL_RAM_FRACTION = 0.75
|
|
40
42
|
# A card whose free memory is below this share of its total holds someone else's work.
|
|
@@ -60,6 +62,10 @@ _SERVING_PROCESS_RE = re.compile(
|
|
|
60
62
|
)
|
|
61
63
|
|
|
62
64
|
|
|
65
|
+
# The device a placement runs on; engine_adapters.llama_cpp.backend_for keys its hooks on it.
|
|
66
|
+
Backend = Literal["cuda", "metal", "cpu"]
|
|
67
|
+
|
|
68
|
+
|
|
63
69
|
@dataclass(frozen=True)
|
|
64
70
|
class Placement:
|
|
65
71
|
"""Where one model would run: one card, every card split by layer, or the host's unified pool."""
|
|
@@ -68,7 +74,7 @@ class Placement:
|
|
|
68
74
|
label: str
|
|
69
75
|
gpu_indices: tuple[int, ...]
|
|
70
76
|
budget: HardwareBudget
|
|
71
|
-
backend:
|
|
77
|
+
backend: Backend
|
|
72
78
|
pooled: bool = False # multi-card split: our extension, not calibrated
|
|
73
79
|
busy: bool = False # another process already holds part of a selected card
|
|
74
80
|
conflicts: tuple[str, ...] = () # foreign serving work on the selected cards (gpu_conflicts)
|
|
@@ -78,6 +84,41 @@ def _margin(total: int) -> int:
|
|
|
78
84
|
return max(_MARGIN_FLOOR, int(total * _MARGIN_FRACTION))
|
|
79
85
|
|
|
80
86
|
|
|
87
|
+
def uma_usable(base: int) -> int:
|
|
88
|
+
"""What a unified-memory pool of ``base`` bytes may give models: less UMA_HEADROOM_FRACTION."""
|
|
89
|
+
return int(base * (1 - UMA_HEADROOM_FRACTION))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def cuda_uma_agent_bytes(base: int) -> int:
|
|
93
|
+
"""What an agent-posture model may take of a CUDA unified-memory pool of ``base`` bytes: the
|
|
94
|
+
usable share less the agent safety and display reserve."""
|
|
95
|
+
return max(0, uma_usable(base) - AGENT_VRAM_RESERVE_BYTES)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def nvidia_cards(facts: HostFacts) -> list[GPU]:
|
|
99
|
+
"""The NVIDIA cards CUDA can place on, in probe order: every one not in MIG mode (CUDA sees
|
|
100
|
+
only a MIG card's instances)."""
|
|
101
|
+
return [
|
|
102
|
+
g
|
|
103
|
+
for g in facts.get("gpus") or []
|
|
104
|
+
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def cuda_uma_live_bytes(facts: HostFacts, unified: int) -> int:
|
|
109
|
+
"""A CUDA unified-memory pool of ``unified`` bytes as free now: device 0's free memory plus
|
|
110
|
+
the RAM available to a service, never more than the pool."""
|
|
111
|
+
cards = nvidia_cards(facts)
|
|
112
|
+
first_free = cards[0]["free_bytes"] if cards else 0
|
|
113
|
+
return min(unified, first_free + host_ram(facts)[1])
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def metal_reserve_bytes(facts: HostFacts) -> int:
|
|
117
|
+
"""What a Mac keeps back from models in unified memory: the host's soft keep (scaled by its
|
|
118
|
+
RAM) plus the Metal VRAM reserve."""
|
|
119
|
+
return metal.soft_host_keep_bytes(facts) + METAL_VRAM_RESERVE_BYTES
|
|
120
|
+
|
|
121
|
+
|
|
81
122
|
def unified_pool_bytes(facts: HostFacts) -> int | None:
|
|
82
123
|
"""The allocator pool when the NVIDIA device is unified memory behind a carve-out, else None.
|
|
83
124
|
The driver's INTEGRATED attribute decides when readable; otherwise both numeric gates hold."""
|
|
@@ -111,7 +152,7 @@ def _uma(
|
|
|
111
152
|
lazy_reads: bool = True,
|
|
112
153
|
) -> HardwareBudget:
|
|
113
154
|
return HardwareBudget(
|
|
114
|
-
usable_vram_bytes=max(0,
|
|
155
|
+
usable_vram_bytes=max(0, uma_usable(base)),
|
|
115
156
|
total_device_bytes=total,
|
|
116
157
|
ram_available_bytes=0,
|
|
117
158
|
uma=True,
|
|
@@ -327,20 +368,15 @@ def placements(facts: HostFacts, *, planning: bool = True) -> list[Placement]:
|
|
|
327
368
|
recommendation); ``planning=False`` prices free memory now (a launch)."""
|
|
328
369
|
ram_total, ram_avail = host_ram(facts)
|
|
329
370
|
ram_budget = ram_total if planning else ram_avail
|
|
330
|
-
gpus =
|
|
331
|
-
g
|
|
332
|
-
for g in facts.get("gpus") or []
|
|
333
|
-
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
334
|
-
]
|
|
371
|
+
gpus = nvidia_cards(facts)
|
|
335
372
|
conflicts = gpu_conflicts(facts)
|
|
336
373
|
|
|
337
374
|
result: list[Placement] = []
|
|
338
375
|
unified = unified_pool_bytes(facts)
|
|
339
376
|
if unified is not None:
|
|
340
377
|
first = gpus[0] if gpus else None
|
|
341
|
-
live = first["free_bytes"] + ram_avail if first else ram_avail
|
|
342
378
|
uma_budget = _uma(
|
|
343
|
-
unified if planning else
|
|
379
|
+
unified if planning else cuda_uma_live_bytes(facts, unified),
|
|
344
380
|
unified,
|
|
345
381
|
facts,
|
|
346
382
|
gpu_name=first["name"] if first else "",
|
|
@@ -360,7 +396,7 @@ def placements(facts: HostFacts, *, planning: bool = True) -> list[Placement]:
|
|
|
360
396
|
# Metal, integrated or unknown GPUs, CPU: RAM as unified memory. AMD/Intel discrete cards
|
|
361
397
|
# need the engine's device probe, which runs only after an engine is installed.
|
|
362
398
|
cls = facts.get("gpu_vendor_class", "unknown")
|
|
363
|
-
backend = "metal" if facts.get("platform") == "darwin" else "cpu"
|
|
399
|
+
backend: Backend = "metal" if facts.get("platform") == "darwin" else "cpu"
|
|
364
400
|
metal_info = metal.reading(facts) if backend == "metal" else None
|
|
365
401
|
metal_name = str(metal_info.get("name") or "") if metal_info else ""
|
|
366
402
|
budget = _uma(
|
|
@@ -451,7 +487,7 @@ def launch_budget(capacity: Placement, facts: HostFacts, *, own_bytes: int = 0)
|
|
|
451
487
|
total, available = host_ram(facts)
|
|
452
488
|
return replace(
|
|
453
489
|
capacity.budget,
|
|
454
|
-
usable_vram_bytes=max(0,
|
|
490
|
+
usable_vram_bytes=max(0, uma_usable(available)),
|
|
455
491
|
total_device_bytes=total,
|
|
456
492
|
ram_available_bytes=0,
|
|
457
493
|
)
|
|
@@ -531,7 +567,7 @@ class AdmissionBudget:
|
|
|
531
567
|
"""
|
|
532
568
|
|
|
533
569
|
pool: str
|
|
534
|
-
backend:
|
|
570
|
+
backend: Backend
|
|
535
571
|
soft_budget_bytes: int
|
|
536
572
|
hard_ceiling_bytes: int
|
|
537
573
|
reserve_bytes: int
|
|
@@ -559,7 +595,7 @@ def admission_budget(
|
|
|
559
595
|
if metal.supported(facts):
|
|
560
596
|
level = facts["ram"].get("pressure_level")
|
|
561
597
|
critical = metal.is_critical_pressure(facts)
|
|
562
|
-
base_reserve =
|
|
598
|
+
base_reserve = metal_reserve_bytes(facts)
|
|
563
599
|
pressured_facts, _ = metal.pressured(facts)
|
|
564
600
|
kept = int(pressured_facts["ram"].get("pressure_kept_bytes") or 0)
|
|
565
601
|
reserve = base_reserve + kept
|
|
@@ -603,22 +639,9 @@ def admission_budget(
|
|
|
603
639
|
unified = unified_pool_bytes(facts)
|
|
604
640
|
if unified is None:
|
|
605
641
|
return None
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
610
|
-
]
|
|
611
|
-
first_free = nvidia[0]["free_bytes"] if nvidia else 0
|
|
612
|
-
_, ram_avail = host_ram(facts)
|
|
613
|
-
usable_total = max(
|
|
614
|
-
0, int(unified * (1 - _UMA_HEADROOM_FRACTION)) - AGENT_VRAM_RESERVE_BYTES
|
|
615
|
-
)
|
|
616
|
-
raw_live = max(
|
|
617
|
-
0,
|
|
618
|
-
int(min(unified, first_free + ram_avail) * (1 - _UMA_HEADROOM_FRACTION))
|
|
619
|
-
- AGENT_VRAM_RESERVE_BYTES,
|
|
620
|
-
)
|
|
621
|
-
live_budget = max(0, min(usable_total, raw_live - delta_bytes))
|
|
642
|
+
live = cuda_uma_live_bytes(facts, unified)
|
|
643
|
+
usable_total = cuda_uma_agent_bytes(unified)
|
|
644
|
+
live_budget = max(0, min(usable_total, cuda_uma_agent_bytes(live) - delta_bytes))
|
|
622
645
|
return AdmissionBudget(
|
|
623
646
|
pool="unified",
|
|
624
647
|
backend="cuda",
|
|
@@ -626,7 +649,7 @@ def admission_budget(
|
|
|
626
649
|
hard_ceiling_bytes=live_budget,
|
|
627
650
|
reserve_bytes=max(0, unified - usable_total),
|
|
628
651
|
allows_soft_overcommit=False,
|
|
629
|
-
physical_limit_bytes=max(0,
|
|
652
|
+
physical_limit_bytes=max(0, live - delta_bytes),
|
|
630
653
|
)
|
|
631
654
|
if pool.startswith("gpu:"):
|
|
632
655
|
try:
|
|
@@ -656,7 +679,7 @@ def admission_budget(
|
|
|
656
679
|
)
|
|
657
680
|
if pool == "system":
|
|
658
681
|
total, avail = host_ram(facts)
|
|
659
|
-
pool_cap =
|
|
682
|
+
pool_cap = uma_usable(total)
|
|
660
683
|
used = total - avail
|
|
661
684
|
usable = max(0, min(pool_cap, pool_cap - used - delta_bytes))
|
|
662
685
|
return AdmissionBudget(
|
|
@@ -16,9 +16,10 @@ from collections.abc import Sequence
|
|
|
16
16
|
from typing import cast
|
|
17
17
|
|
|
18
18
|
from localmodels import catalog as cat
|
|
19
|
-
from localmodels
|
|
19
|
+
from localmodels import draft_spec
|
|
20
20
|
from localmodels.context_policy import AgentPosture
|
|
21
21
|
from localmodels.estimator import llama_host_bytes
|
|
22
|
+
from localmodels.planning.budget import gib
|
|
22
23
|
from localmodels.records import Plan
|
|
23
24
|
|
|
24
25
|
|
|
@@ -61,6 +62,15 @@ def prompt_cache_bytes(llm: Plan) -> int:
|
|
|
61
62
|
return max(0, int(argv[argv.index("--cache-ram") + 1])) << 20
|
|
62
63
|
|
|
63
64
|
|
|
65
|
+
def drafter_costs_cache(llm: Plan, posture: AgentPosture) -> bool:
|
|
66
|
+
"""Whether a unified-memory LLM carries an optional external drafter (DSpark) while its prompt
|
|
67
|
+
cache came out below the posture's full ``--cache-ram``. The drafter and the cache share one
|
|
68
|
+
pool there, so the plan without the drafter holds the larger cache; an optional speed-up never
|
|
69
|
+
outranks the prompt cache, and the caller re-plans with ``draft="off"``."""
|
|
70
|
+
full = posture.prompt_cache_mib << 20
|
|
71
|
+
return draft_spec.active(llm["launch"]) and 0 < prompt_cache_bytes(llm) < full
|
|
72
|
+
|
|
73
|
+
|
|
64
74
|
# What a cache grown into the RAM left leaves free, so the RAM may fall this far between plan
|
|
65
75
|
# and apply and the approved plan still fits: a desktop's free RAM moves by tens of MiB a minute,
|
|
66
76
|
# and a cache sized to the last megabyte made every apply on one fail its RAM check (WINSTK1).
|