@simplexai/localmodels-linux-arm64 0.1.0-dev.57 → 0.1.0-dev.59
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 +66 -64
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +1 -1
- package/modules/localmodels/bifrost_admin.py +53 -8
- package/modules/localmodels/bifrost_config.py +103 -4
- package/modules/localmodels/bifrost_log.py +166 -0
- package/modules/localmodels/budget.py +161 -1
- package/modules/localmodels/catalog.json +55 -32
- package/modules/localmodels/catalog.py +5 -2
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.5.json +94 -0
- package/modules/localmodels/frontend.py +26 -21
- package/modules/localmodels/gateway_bifrost.py +30 -6
- package/modules/localmodels/gpu_specs.py +38 -13
- package/modules/localmodels/hosts.py +99 -12
- package/modules/localmodels/library_cli.py +8 -1
- package/modules/localmodels/library_convert.py +34 -0
- package/modules/localmodels/library_elastic.py +747 -0
- package/modules/localmodels/library_gateway.py +101 -10
- package/modules/localmodels/library_jobs.py +16 -7
- package/modules/localmodels/library_model.py +101 -4
- package/modules/localmodels/library_pricing.py +41 -39
- package/modules/localmodels/library_serve.py +322 -58
- package/modules/localmodels/library_state.py +35 -1
- package/modules/localmodels/library_status.py +113 -6
- package/modules/localmodels/llm_rank.py +16 -5
- package/modules/localmodels/metal.py +141 -0
- package/modules/localmodels/metal_probe.py +167 -0
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/probe.py +2 -2
- package/modules/localmodels/process_identity_linux.py +39 -0
- package/modules/localmodels/recommend.py +6 -1
- package/modules/localmodels/remote_ops.py +4 -3
- package/modules/localmodels/remote_ops_download.py +37 -24
- package/modules/localmodels/remote_ops_mirrors.py +43 -2
- package/modules/localmodels/remote_ops_service.py +93 -36
- package/modules/localmodels/runtime_auth.py +4 -1
- package/modules/localmodels/service_wiring.py +238 -12
- package/modules/localmodels/setup_inspection.py +47 -70
- package/modules/localmodels/setup_inspection_harness.py +159 -15
- package/modules/localmodels/setup_text.py +14 -0
- package/modules/localmodels/setup_upgrade.py +1 -1
- package/modules/localmodels/source_byok.py +6 -2
- package/modules/localmodels/source_byok_probe.py +6 -1
- package/modules/localmodels/stack.py +9 -1
- package/modules/localmodels/stack_binding.py +3 -35
- package/modules/localmodels/stack_cleanup.py +4 -0
- package/modules/localmodels/stack_compose.py +24 -3
- package/modules/localmodels/stack_hardware.py +3 -1
- package/modules/localmodels/stack_lifecycle.py +24 -1
- package/modules/localmodels/stack_picks.py +16 -2
- package/modules/localmodels/stack_plan.py +6 -2
- package/modules/localmodels/stack_ports.py +2 -0
- package/modules/localmodels/stack_remove.py +10 -1
- package/modules/localmodels/stack_up.py +33 -7
- package/modules/localmodels/stack_update.py +3 -1
- package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.5.txt} +1 -1
- package/modules/localmodels/suite.py +43 -27
- package/modules/localmodels/transport.py +13 -2
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/RECORD +63 -61
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev59.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -26,6 +26,7 @@ from localmodels import (
|
|
|
26
26
|
bifrost_admin,
|
|
27
27
|
bifrost_config,
|
|
28
28
|
bifrost_datasheet,
|
|
29
|
+
bifrost_log,
|
|
29
30
|
bifrost_models,
|
|
30
31
|
bifrost_unit,
|
|
31
32
|
gateway_bifrost,
|
|
@@ -204,8 +205,9 @@ def apply_config(record: hosts.OwnedBifrost, config: dict[str, Any], sheet: dict
|
|
|
204
205
|
_stop(record)
|
|
205
206
|
return
|
|
206
207
|
if changed or not gateway_bifrost._healthy_owned(record):
|
|
208
|
+
log_offset = bifrost_log.log_size(app)
|
|
207
209
|
gateway_bifrost._start(record, restart=changed)
|
|
208
|
-
gateway_bifrost._await(record["addr"], record=record)
|
|
210
|
+
gateway_bifrost._await(record["addr"], record=record, log_offset=log_offset)
|
|
209
211
|
|
|
210
212
|
|
|
211
213
|
def _stop(record: hosts.OwnedBifrost) -> None:
|
|
@@ -257,6 +259,15 @@ def _ours_marker(provider: str) -> Path:
|
|
|
257
259
|
return library_state.root() / f"pi-provider{suffix}"
|
|
258
260
|
|
|
259
261
|
|
|
262
|
+
def _pi_provider_doc(base: str, models: list[dict[str, Any]]) -> dict[str, Any]:
|
|
263
|
+
return {
|
|
264
|
+
"baseUrl": f"{base}/v1",
|
|
265
|
+
"api": "openai-completions",
|
|
266
|
+
"apiKey": gateway_bifrost.CALLER_KEY,
|
|
267
|
+
"models": models,
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
260
271
|
def _pi_add(provider: str, entry: dict[str, Any], base: str) -> None:
|
|
261
272
|
path = pi_profile() / "models.json"
|
|
262
273
|
models = _read(path)
|
|
@@ -270,12 +281,7 @@ def _pi_add(provider: str, entry: dict[str, Any], base: str) -> None:
|
|
|
270
281
|
marker.parent.mkdir(parents=True, exist_ok=True)
|
|
271
282
|
marker.write_text(str(path) + "\n", encoding="utf-8")
|
|
272
283
|
kept = [m for m in (current or {}).get("models", []) if m.get("id") != entry["id"]]
|
|
273
|
-
providers[provider] =
|
|
274
|
-
"baseUrl": f"{base}/v1",
|
|
275
|
-
"api": "openai-completions",
|
|
276
|
-
"apiKey": gateway_bifrost.CALLER_KEY,
|
|
277
|
-
"models": [*kept, entry],
|
|
278
|
-
}
|
|
284
|
+
providers[provider] = _pi_provider_doc(base, [*kept, entry])
|
|
279
285
|
_write(path, models)
|
|
280
286
|
|
|
281
287
|
|
|
@@ -294,6 +300,74 @@ def _marker_for_other_file(marker: Path, path: Path) -> bool:
|
|
|
294
300
|
return False
|
|
295
301
|
|
|
296
302
|
|
|
303
|
+
def _agent_target(config: dict[str, Any]) -> str | None:
|
|
304
|
+
rules = (config.get("governance") or {}).get("routing_rules") or []
|
|
305
|
+
agent = next(
|
|
306
|
+
(r for r in rules if isinstance(r, dict) and r.get("id") == gateway_bifrost.AGENT_RULE),
|
|
307
|
+
None,
|
|
308
|
+
)
|
|
309
|
+
targets = (agent or {}).get("targets") or []
|
|
310
|
+
target = targets[0].get("provider") if targets and isinstance(targets[0], dict) else None
|
|
311
|
+
return str(target) if isinstance(target, str) and target else None
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _pi_sync_shared(
|
|
315
|
+
provider: str, model_id: str, context: int, base: str, *, entry: dict[str, Any] | None = None
|
|
316
|
+
) -> None:
|
|
317
|
+
"""Sync ``contextWindow``/``maxTokens`` on an owned pi provider entry without changing
|
|
318
|
+
stack ownership or clobbering a user-defined provider (different ``baseUrl``)."""
|
|
319
|
+
if context <= 0:
|
|
320
|
+
return
|
|
321
|
+
path = pi_profile() / "models.json"
|
|
322
|
+
try:
|
|
323
|
+
models = _read(path)
|
|
324
|
+
except LibraryError:
|
|
325
|
+
if entry is not None:
|
|
326
|
+
raise
|
|
327
|
+
return
|
|
328
|
+
providers = models.setdefault("providers", {})
|
|
329
|
+
if not isinstance(providers, dict):
|
|
330
|
+
if entry is not None:
|
|
331
|
+
raise _fail("providers in pi's models.json is not an object; left as is")
|
|
332
|
+
return
|
|
333
|
+
current = providers.get(provider)
|
|
334
|
+
if current is None:
|
|
335
|
+
if entry is not None:
|
|
336
|
+
providers[provider] = _pi_provider_doc(base, [entry])
|
|
337
|
+
_write(path, models)
|
|
338
|
+
return
|
|
339
|
+
if not isinstance(current, dict) or not str(current.get("baseUrl", "")).startswith(f"{base}/"):
|
|
340
|
+
return
|
|
341
|
+
items = current.get("models")
|
|
342
|
+
if not isinstance(items, list):
|
|
343
|
+
return
|
|
344
|
+
max_tokens = min(32768, max(4096, context // 4))
|
|
345
|
+
matched = [m for m in items if isinstance(m, dict) and m.get("id") == model_id]
|
|
346
|
+
changed = False
|
|
347
|
+
for item in matched:
|
|
348
|
+
if item.get("contextWindow") != context or item.get("maxTokens") != max_tokens:
|
|
349
|
+
item["contextWindow"], item["maxTokens"] = context, max_tokens
|
|
350
|
+
changed = True
|
|
351
|
+
if not matched and entry is not None:
|
|
352
|
+
items.append(entry)
|
|
353
|
+
changed = True
|
|
354
|
+
if changed:
|
|
355
|
+
_write(path, models)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _sheet_context(sheet: dict[str, Any], provider: str) -> int | None:
|
|
359
|
+
prefix = provider + "/"
|
|
360
|
+
for key in (
|
|
361
|
+
f"{prefix}{gateway_bifrost.AGENT_MODEL}",
|
|
362
|
+
*(k for k in sheet if k.startswith(prefix)),
|
|
363
|
+
):
|
|
364
|
+
doc = sheet.get(key)
|
|
365
|
+
ctx = doc.get("context_length") if isinstance(doc, dict) else None
|
|
366
|
+
if isinstance(ctx, int) and not isinstance(ctx, bool) and ctx > 0:
|
|
367
|
+
return ctx
|
|
368
|
+
return None
|
|
369
|
+
|
|
370
|
+
|
|
297
371
|
def _pi_drop(provider: str, model_id: str) -> None:
|
|
298
372
|
marker = _ours_marker(provider)
|
|
299
373
|
if not marker.is_file():
|
|
@@ -360,7 +434,7 @@ def _agent_rule(provider: str, served: str) -> dict[str, Any]:
|
|
|
360
434
|
"description": "local agent turns sent to the local LLM",
|
|
361
435
|
"cel_expression": f"model == '{gateway_bifrost.AGENT_MODEL}'",
|
|
362
436
|
"targets": [{"provider": provider, "model": served, "weight": 1}],
|
|
363
|
-
"priority":
|
|
437
|
+
"priority": bifrost_config.AGENT_RULE_PRIORITY,
|
|
364
438
|
}
|
|
365
439
|
|
|
366
440
|
|
|
@@ -376,7 +450,7 @@ def _route_agent(config: dict[str, Any]) -> None:
|
|
|
376
450
|
rules = [
|
|
377
451
|
r
|
|
378
452
|
for r in governance.get("routing_rules") or []
|
|
379
|
-
if r.get("id") != gateway_bifrost.COMPLEX_RULE
|
|
453
|
+
if isinstance(r, dict) and r.get("id") != gateway_bifrost.COMPLEX_RULE
|
|
380
454
|
]
|
|
381
455
|
governance.pop("complexity_analyzer_config", None)
|
|
382
456
|
left = [p for p in STACK_PROVIDERS if p in providers]
|
|
@@ -390,6 +464,11 @@ def _route_agent(config: dict[str, Any]) -> None:
|
|
|
390
464
|
served = (keys[0].get("models") or [gateway_bifrost.AGENT_MODEL])[0]
|
|
391
465
|
rules.append(_agent_rule(left[0], served))
|
|
392
466
|
governance["routing_rules"] = rules
|
|
467
|
+
bifrost_config.sanitize_governance(config)
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
def _normalize_existing_rules(config: dict[str, Any]) -> None:
|
|
471
|
+
bifrost_config.sanitize_governance(config)
|
|
393
472
|
|
|
394
473
|
|
|
395
474
|
def planned(model: str, plan: Plan, *, stack_provider: str | None = None) -> Registration:
|
|
@@ -568,6 +647,7 @@ def _register(
|
|
|
568
647
|
listed_as, names = f"{pid}/{gateway_model}", [name, gateway_model]
|
|
569
648
|
else:
|
|
570
649
|
providers[pid] = _provider(url, name, key, pid)
|
|
650
|
+
_normalize_existing_rules(config)
|
|
571
651
|
listed_as, names = gateway_model, [name]
|
|
572
652
|
context = int(str(plan["launch"].get("window") or 0)) or None
|
|
573
653
|
sheet = (
|
|
@@ -584,6 +664,8 @@ def _register(
|
|
|
584
664
|
pi_entry = bifrost_models.pi_provider(facts_, gateway_model, base)["models"][0]
|
|
585
665
|
if not shared: # the stack's own pi entry already names localmodels-agent
|
|
586
666
|
_pi_add(pi_provider, pi_entry, base)
|
|
667
|
+
elif _agent_target(config) == pid:
|
|
668
|
+
_pi_sync_shared(pi_provider, gateway_model, facts_["context"], base, entry=pi_entry)
|
|
587
669
|
_sync_pi_default(
|
|
588
670
|
pi_profile(),
|
|
589
671
|
pi_provider,
|
|
@@ -617,6 +699,7 @@ def _unregister(registration: Registration) -> None:
|
|
|
617
699
|
if not isinstance(providers, dict) or registration["provider"] not in providers:
|
|
618
700
|
return
|
|
619
701
|
del providers[registration["provider"]]
|
|
702
|
+
_normalize_existing_rules(config)
|
|
620
703
|
prefix = registration["provider"] + "/"
|
|
621
704
|
sheet = {k: v for k, v in read_sheet(app).items() if not k.startswith(prefix)}
|
|
622
705
|
apply_config(record, config, sheet)
|
|
@@ -645,8 +728,9 @@ def _unwire_member(registration: Registration) -> None:
|
|
|
645
728
|
if not any(p in providers for p in STACK_PROVIDERS): # the last stack LLM
|
|
646
729
|
tools_root = hosts.tools_dir()
|
|
647
730
|
environment = {**os.environ, **harness_probe.client_environment(tools_root)}
|
|
731
|
+
pi_environment = {**environment, "PI_CODING_AGENT_DIR": str(pi_profile())}
|
|
648
732
|
checks = bifrost_clients.unwire(tools_root, environment=environment)
|
|
649
|
-
checks += bifrost_pi.unpoint_pi(tools_root, environment=
|
|
733
|
+
checks += bifrost_pi.unpoint_pi(tools_root, environment=pi_environment)
|
|
650
734
|
failed = [c["detail"] for c in checks if not c["ok"]]
|
|
651
735
|
if failed:
|
|
652
736
|
raise _fail("; ".join(failed))
|
|
@@ -657,3 +741,10 @@ def _unwire_member(registration: Registration) -> None:
|
|
|
657
741
|
prefix = registration["provider"] + "/"
|
|
658
742
|
sheet = {k: v for k, v in read_sheet(app).items() if not k.startswith(prefix)}
|
|
659
743
|
apply_config(record, config, sheet)
|
|
744
|
+
if (target := _agent_target(config)) and (ctx := _sheet_context(sheet, target)):
|
|
745
|
+
_pi_sync_shared(
|
|
746
|
+
gateway_bifrost.PI_PROVIDER,
|
|
747
|
+
gateway_bifrost.AGENT_MODEL,
|
|
748
|
+
ctx,
|
|
749
|
+
f"http://{record['addr']}",
|
|
750
|
+
)
|
|
@@ -142,9 +142,11 @@ def delete_weights(files: list[str], keep: set[str]) -> list[str]:
|
|
|
142
142
|
continue
|
|
143
143
|
remote_ops_download.discard(path + ".part")
|
|
144
144
|
for name in (path, path + ".sha256"):
|
|
145
|
-
|
|
145
|
+
try:
|
|
146
146
|
os.remove(name)
|
|
147
147
|
deleted.append(name)
|
|
148
|
+
except FileNotFoundError:
|
|
149
|
+
pass
|
|
148
150
|
return deleted
|
|
149
151
|
|
|
150
152
|
|
|
@@ -498,14 +500,21 @@ def download(
|
|
|
498
500
|
_give_up(model.id, job, handle)
|
|
499
501
|
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
500
502
|
except LibraryError as exc:
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if library_state.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
503
|
+
with library_state.locked():
|
|
504
|
+
if library_state.load(model.id) is None and library_state.current(job):
|
|
505
|
+
if library_state.cancelled(job):
|
|
506
|
+
_give_up(model.id, job, handle)
|
|
507
|
+
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
508
|
+
if exc.code in KEEP_FAILED_DOWNLOAD_CODES:
|
|
507
509
|
library_state.fail_job(handle.job, {"code": exc.code, "detail": exc.detail})
|
|
508
510
|
claims.clear()
|
|
511
|
+
else:
|
|
512
|
+
_give_up(model.id, job, handle)
|
|
513
|
+
raise
|
|
514
|
+
except Exception:
|
|
515
|
+
with library_state.locked():
|
|
516
|
+
if library_state.load(model.id) is None and library_state.current(job):
|
|
517
|
+
_give_up(model.id, job, handle)
|
|
509
518
|
raise
|
|
510
519
|
if not autoload:
|
|
511
520
|
return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import json
|
|
11
11
|
import sys
|
|
12
|
+
from collections.abc import Mapping
|
|
12
13
|
from typing import Literal, TypedDict
|
|
13
14
|
|
|
14
15
|
STATUS_SCHEMA = "localmodels.library-status/v1"
|
|
@@ -69,11 +70,12 @@ DETAIL_LIMIT = 500 # diagnostic text only; consumers never match on it
|
|
|
69
70
|
|
|
70
71
|
class LibraryError(Exception):
|
|
71
72
|
"""One contract error: its code, a diagnostic detail and the structured fields it carries
|
|
72
|
-
(``pool``, ``need_bytes``, ``free_bytes``, ``have_bytes
|
|
73
|
-
after the command changed something:
|
|
73
|
+
(``pool``, ``need_bytes``, ``free_bytes``, ``have_bytes``, plus optional admission headroom
|
|
74
|
+
fields on ``LOAD_NO_ROOM``). ``failed`` marks one raised after the command changed something:
|
|
75
|
+
it exits 1 whatever its code."""
|
|
74
76
|
|
|
75
77
|
def __init__(
|
|
76
|
-
self, code: str, detail: str, *, failed: bool = False, **fields: str | int
|
|
78
|
+
self, code: str, detail: str, *, failed: bool = False, **fields: str | int | bool
|
|
77
79
|
) -> None:
|
|
78
80
|
if code not in ERROR_CODES:
|
|
79
81
|
raise ValueError(f"unknown library error code {code}")
|
|
@@ -112,6 +114,10 @@ class Host(_Host, total=False):
|
|
|
112
114
|
ram_available_bytes: int
|
|
113
115
|
metal_working_set_bytes: int
|
|
114
116
|
memory_pressure: MemoryPressure
|
|
117
|
+
wired_limit_bytes: int
|
|
118
|
+
gpu_in_use_bytes: int
|
|
119
|
+
wired_headroom_bytes: int
|
|
120
|
+
inactive_anon_bytes: int
|
|
115
121
|
|
|
116
122
|
|
|
117
123
|
class Holder(TypedDict):
|
|
@@ -137,6 +143,37 @@ class _Pool(TypedDict):
|
|
|
137
143
|
class Pool(_Pool, total=False):
|
|
138
144
|
reserve_bytes: int
|
|
139
145
|
external_holders: list[ExternalHolder]
|
|
146
|
+
soft_budget_bytes: int
|
|
147
|
+
hard_ceiling_bytes: int
|
|
148
|
+
wired_headroom_bytes: int
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
KvCacheQuant = Literal["f16", "q8_0", "q4_0"]
|
|
152
|
+
KV_CACHE_QUANTS = ("f16", "q8_0", "q4_0")
|
|
153
|
+
MemoryPressureWarningLevel = Literal["soft", "high"]
|
|
154
|
+
DegradationReason = Literal[
|
|
155
|
+
"reduced_slots",
|
|
156
|
+
"reduced_context",
|
|
157
|
+
"above_soft_budget",
|
|
158
|
+
"oom_retry",
|
|
159
|
+
"forced_overcommit",
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class _PostureSummaryRequired(TypedDict):
|
|
164
|
+
context_tokens: int
|
|
165
|
+
slots: int
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class PostureSummary(_PostureSummaryRequired, total=False):
|
|
169
|
+
kv_cache_quant: KvCacheQuant
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class MemoryPressureWarning(TypedDict):
|
|
173
|
+
level: MemoryPressureWarningLevel
|
|
174
|
+
pool: str
|
|
175
|
+
free_bytes: int
|
|
176
|
+
budget_bytes: int
|
|
140
177
|
|
|
141
178
|
|
|
142
179
|
class _Reason(TypedDict):
|
|
@@ -190,11 +227,23 @@ class Endpoint(TypedDict):
|
|
|
190
227
|
gateway_model: str
|
|
191
228
|
|
|
192
229
|
|
|
193
|
-
class
|
|
230
|
+
class _ProblemRequired(TypedDict):
|
|
194
231
|
code: str
|
|
195
232
|
detail: str
|
|
196
233
|
|
|
197
234
|
|
|
235
|
+
class Problem(_ProblemRequired, total=False):
|
|
236
|
+
pool: str
|
|
237
|
+
need_bytes: int
|
|
238
|
+
free_bytes: int
|
|
239
|
+
shortfall_bytes: int
|
|
240
|
+
can_force: bool
|
|
241
|
+
min_need_bytes: int
|
|
242
|
+
wired_headroom_bytes: int
|
|
243
|
+
soft_available_bytes: int
|
|
244
|
+
memory_pressure: str
|
|
245
|
+
|
|
246
|
+
|
|
198
247
|
class Note(TypedDict):
|
|
199
248
|
code: str
|
|
200
249
|
|
|
@@ -238,6 +287,14 @@ class Row(_Row, total=False):
|
|
|
238
287
|
fits_now: bool # live pool currently has enough free memory to load
|
|
239
288
|
load_need_bytes: int # pool-aligned memory needed to load when fits_now is False
|
|
240
289
|
load_free_bytes: int # pool-aligned free memory when fits_now is False
|
|
290
|
+
minimum_memory_bytes: int # estimated footprint at the lowest elastic posture rung
|
|
291
|
+
degraded: bool # True when effective posture stepped down from requested posture
|
|
292
|
+
requested_posture: PostureSummary # requested/target agent posture
|
|
293
|
+
effective_posture: PostureSummary # applied/planned agent posture
|
|
294
|
+
degradation_reason: DegradationReason # why the effective posture stepped down
|
|
295
|
+
memory_pressure_warning: MemoryPressureWarning # present when loaded above soft budget / forced
|
|
296
|
+
oom_retries: int # count of runtime OOM self-healing step-downs performed
|
|
297
|
+
forced: bool # True when loaded via --force override
|
|
241
298
|
error: Problem # failed only
|
|
242
299
|
note: Note # idle only, when autoload was skipped
|
|
243
300
|
|
|
@@ -321,6 +378,46 @@ def result_doc(row: Row) -> dict[str, object]:
|
|
|
321
378
|
return {"schema": EVENT_SCHEMA, "event": "result", "ok": True, "model": row}
|
|
322
379
|
|
|
323
380
|
|
|
381
|
+
def problem_from_error(error: LibraryError) -> Problem:
|
|
382
|
+
"""Persistable ``model.error`` document; retains structured headroom fields on LOAD_NO_ROOM."""
|
|
383
|
+
raw: dict[str, object] = {"code": error.code, "detail": error.detail}
|
|
384
|
+
if error.code == "LOAD_NO_ROOM":
|
|
385
|
+
raw.update(error.fields)
|
|
386
|
+
return sanitize_problem(raw)
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def sanitize_problem(raw: Mapping[str, object]) -> Problem:
|
|
390
|
+
"""Validate and copy a persisted ``Problem`` dict for ``library status``."""
|
|
391
|
+
out: Problem = {
|
|
392
|
+
"code": str(raw.get("code") or "ENGINE_START_FAILED"),
|
|
393
|
+
"detail": str(raw.get("detail") or ""),
|
|
394
|
+
}
|
|
395
|
+
if out["code"] != "LOAD_NO_ROOM":
|
|
396
|
+
return out
|
|
397
|
+
if isinstance(pool := raw.get("pool"), str) and pool:
|
|
398
|
+
out["pool"] = pool
|
|
399
|
+
for key in (
|
|
400
|
+
"need_bytes",
|
|
401
|
+
"free_bytes",
|
|
402
|
+
"shortfall_bytes",
|
|
403
|
+
"min_need_bytes",
|
|
404
|
+
"wired_headroom_bytes",
|
|
405
|
+
"soft_available_bytes",
|
|
406
|
+
):
|
|
407
|
+
val = raw.get(key)
|
|
408
|
+
if isinstance(val, int) and not isinstance(val, bool) and val >= 0:
|
|
409
|
+
out[key] = val
|
|
410
|
+
if isinstance(can_force := raw.get("can_force"), bool):
|
|
411
|
+
out["can_force"] = can_force
|
|
412
|
+
if isinstance(pressure := raw.get("memory_pressure"), str) and pressure in (
|
|
413
|
+
"normal",
|
|
414
|
+
"warn",
|
|
415
|
+
"critical",
|
|
416
|
+
):
|
|
417
|
+
out["memory_pressure"] = pressure
|
|
418
|
+
return out
|
|
419
|
+
|
|
420
|
+
|
|
324
421
|
def error_doc(error: LibraryError, model: str | None = None) -> dict[str, object]:
|
|
325
422
|
doc: dict[str, object] = {
|
|
326
423
|
"schema": EVENT_SCHEMA,
|
|
@@ -43,7 +43,6 @@ from localmodels.context_policy import AgentPosture
|
|
|
43
43
|
from localmodels.estimator import (
|
|
44
44
|
AGENT_VRAM_RESERVE_BYTES,
|
|
45
45
|
METAL_VRAM_RESERVE_BYTES,
|
|
46
|
-
PhysicsRefusal,
|
|
47
46
|
)
|
|
48
47
|
from localmodels.library_model import LibraryError, Reason, display_name, split_id
|
|
49
48
|
from localmodels.probe import HostFacts
|
|
@@ -203,22 +202,21 @@ def pool_total(facts: HostFacts, pool: str) -> int:
|
|
|
203
202
|
if pool == "unified":
|
|
204
203
|
if (unified := _cuda_uma(facts)) is not None:
|
|
205
204
|
return _cuda_uma_budget_bytes(unified)
|
|
206
|
-
return max(
|
|
205
|
+
return max(
|
|
206
|
+
0,
|
|
207
|
+
facts["ram"]["total_bytes"]
|
|
208
|
+
- (metal.soft_host_keep_bytes(facts) + METAL_VRAM_RESERVE_BYTES),
|
|
209
|
+
)
|
|
207
210
|
return int(facts["ram"]["total_bytes"] * POOL_RAM_FRACTION)
|
|
208
211
|
|
|
209
212
|
|
|
210
213
|
def _unified_live(facts: HostFacts) -> tuple[int, int]:
|
|
211
|
-
"""(free_bytes, reserve_bytes) on a unified pool (Metal or CUDA UMA)."""
|
|
214
|
+
"""(free_bytes, reserve_bytes) on a unified pool (Metal soft budget or CUDA UMA)."""
|
|
212
215
|
if _cuda_uma(facts) is not None:
|
|
213
216
|
return _cuda_uma_live(facts)
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
reserve = UNIFIED_RESERVE_BYTES + kept
|
|
218
|
-
if level is not None and level not in (1, metal.PRESSURE_WARN):
|
|
219
|
-
return 0, reserve
|
|
220
|
-
free = max(0, pressured["ram"]["available_bytes"] - UNIFIED_RESERVE_BYTES)
|
|
221
|
-
return free, reserve
|
|
217
|
+
adm = budget.admission_budget(facts, "unified")
|
|
218
|
+
base_reserve = metal.soft_host_keep_bytes(facts) + METAL_VRAM_RESERVE_BYTES
|
|
219
|
+
return (adm.soft_budget_bytes, adm.reserve_bytes) if adm is not None else (0, base_reserve)
|
|
222
220
|
|
|
223
221
|
|
|
224
222
|
def pool_free(facts: HostFacts, pool: str) -> int:
|
|
@@ -318,6 +316,20 @@ def live(
|
|
|
318
316
|
else:
|
|
319
317
|
delta = unified_delta + system_delta
|
|
320
318
|
ram["available_bytes"] = max(0, min(ram["total_bytes"], ram["available_bytes"] - delta))
|
|
319
|
+
if metal.supported(seen) and unified_delta:
|
|
320
|
+
gpu_reading = metal.gpu_in_use_reading(seen)
|
|
321
|
+
metal_doc = seen.get("metal")
|
|
322
|
+
if isinstance(metal_doc, dict):
|
|
323
|
+
cur_in_use = metal.gpu_in_use_bytes(seen)
|
|
324
|
+
metal_doc["gpu_in_use_bytes"] = max(0, cur_in_use + unified_delta)
|
|
325
|
+
wired_ram = ram.get("wired_bytes")
|
|
326
|
+
if isinstance(wired_ram, int) and not isinstance(wired_ram, bool) and wired_ram >= 0:
|
|
327
|
+
wired_delta = (
|
|
328
|
+
max(unified_delta, -gpu_reading)
|
|
329
|
+
if unified_delta < 0 and gpu_reading is not None
|
|
330
|
+
else unified_delta
|
|
331
|
+
)
|
|
332
|
+
ram["wired_bytes"] = max(0, min(ram["total_bytes"], wired_ram + wired_delta))
|
|
321
333
|
seen["llama_servers"] = []
|
|
322
334
|
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
323
335
|
return seen
|
|
@@ -355,6 +367,8 @@ def price(
|
|
|
355
367
|
require_live: bool = False,
|
|
356
368
|
) -> Plan:
|
|
357
369
|
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there."""
|
|
370
|
+
from localmodels import library_elastic
|
|
371
|
+
|
|
358
372
|
placement = pools(facts).get(pool)
|
|
359
373
|
if placement is None:
|
|
360
374
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -367,7 +381,13 @@ def price(
|
|
|
367
381
|
if require_live and pool == "unified" and metal.supported(facts):
|
|
368
382
|
if problem := metal.problem(facts):
|
|
369
383
|
raise LiveMemoryUnavailable(problem)
|
|
370
|
-
|
|
384
|
+
adm = budget.admission_budget(facts, "unified")
|
|
385
|
+
if adm is not None:
|
|
386
|
+
facts = library_elastic.facts_for_budget(
|
|
387
|
+
facts, "unified", adm.soft_budget_bytes, wired_cap_bytes=adm.wired_headroom_bytes
|
|
388
|
+
)
|
|
389
|
+
else:
|
|
390
|
+
facts, _ = metal.pressured(facts)
|
|
371
391
|
plan = deploy.build_plan(
|
|
372
392
|
hosts.LOCAL_ID,
|
|
373
393
|
facts,
|
|
@@ -384,32 +404,7 @@ def price(
|
|
|
384
404
|
entries=catalog,
|
|
385
405
|
resolver=deploy.catalog_pins,
|
|
386
406
|
)
|
|
387
|
-
|
|
388
|
-
used = memory_bytes(plan)
|
|
389
|
-
if used > total:
|
|
390
|
-
refused = PhysicsRefusal(
|
|
391
|
-
needed_bytes=used,
|
|
392
|
-
available_bytes=total,
|
|
393
|
-
message=f"{model.id} needs {used} bytes, exceeding pool {pool} total {total} bytes",
|
|
394
|
-
)
|
|
395
|
-
raise deploy.AgentMemoryError(
|
|
396
|
-
refused.message,
|
|
397
|
-
refused,
|
|
398
|
-
"unified memory" if pool == "unified" else "GPU memory",
|
|
399
|
-
)
|
|
400
|
-
if gpu_index(pool) is not None:
|
|
401
|
-
needed_ram = _required_host_ram(plan, catalog)
|
|
402
|
-
_, avail_ram = budget.host_ram(facts)
|
|
403
|
-
if needed_ram > avail_ram:
|
|
404
|
-
refused = PhysicsRefusal(
|
|
405
|
-
needed_bytes=needed_ram,
|
|
406
|
-
available_bytes=avail_ram,
|
|
407
|
-
message=(
|
|
408
|
-
f"{model.id} needs {needed_ram} bytes of system memory, "
|
|
409
|
-
f"exceeding {avail_ram} bytes available"
|
|
410
|
-
),
|
|
411
|
-
)
|
|
412
|
-
raise deploy.AgentMemoryError(refused.message, refused, "system memory")
|
|
407
|
+
library_elastic.validate_plan_bounds(facts, model, pool, plan, catalog)
|
|
413
408
|
return plan
|
|
414
409
|
|
|
415
410
|
|
|
@@ -690,8 +685,15 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
|
|
|
690
685
|
break
|
|
691
686
|
if not ranked:
|
|
692
687
|
return None
|
|
688
|
+
slow_ids = {
|
|
689
|
+
entry_id for (_, tok_s), entry_id, _ in ranked if 0 < tok_s < cat.USABLE_FLOOR_TOK_S
|
|
690
|
+
}
|
|
693
691
|
chosen_id, _ = llm_rank.choose(
|
|
694
|
-
ranked,
|
|
692
|
+
ranked,
|
|
693
|
+
"smartest",
|
|
694
|
+
llm_rank.mac_ladder(facts),
|
|
695
|
+
fallback_ids=fallback_ids,
|
|
696
|
+
slow_ids=slow_ids,
|
|
695
697
|
)
|
|
696
698
|
return by_id[chosen_id].entry.id, by_id[chosen_id].variant.quant
|
|
697
699
|
|