@simplexai/localmodels-linux-arm64 0.1.0-dev.57 → 0.1.0-dev.58
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 +28 -27
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/budget.py +161 -1
- package/modules/localmodels/catalog.py +5 -2
- package/modules/localmodels/gpu_specs.py +38 -13
- package/modules/localmodels/library_cli.py +8 -1
- package/modules/localmodels/library_elastic.py +720 -0
- package/modules/localmodels/library_model.py +101 -4
- package/modules/localmodels/library_pricing.py +31 -39
- package/modules/localmodels/library_serve.py +238 -42
- package/modules/localmodels/library_state.py +31 -0
- package/modules/localmodels/library_status.py +95 -2
- 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/probe.py +2 -2
- package/modules/localmodels/recommend.py +6 -1
- package/modules/localmodels/stack_compose.py +6 -1
- package/modules/localmodels/stack_hardware.py +3 -1
- package/modules/localmodels/stack_picks.py +16 -2
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/RECORD +25 -24
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev57.dist-info → simplex_localmodels-0.1.0.dev58.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -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,10 @@ 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
|
+
metal_doc = seen.get("metal")
|
|
320
|
+
if metal.supported(seen) and unified_delta and isinstance(metal_doc, dict):
|
|
321
|
+
cur_in_use = metal.gpu_in_use_bytes(seen)
|
|
322
|
+
metal_doc["gpu_in_use_bytes"] = max(0, cur_in_use + unified_delta)
|
|
321
323
|
seen["llama_servers"] = []
|
|
322
324
|
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
323
325
|
return seen
|
|
@@ -355,6 +357,8 @@ def price(
|
|
|
355
357
|
require_live: bool = False,
|
|
356
358
|
) -> Plan:
|
|
357
359
|
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there."""
|
|
360
|
+
from localmodels import library_elastic
|
|
361
|
+
|
|
358
362
|
placement = pools(facts).get(pool)
|
|
359
363
|
if placement is None:
|
|
360
364
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -367,7 +371,13 @@ def price(
|
|
|
367
371
|
if require_live and pool == "unified" and metal.supported(facts):
|
|
368
372
|
if problem := metal.problem(facts):
|
|
369
373
|
raise LiveMemoryUnavailable(problem)
|
|
370
|
-
|
|
374
|
+
adm = budget.admission_budget(facts, "unified")
|
|
375
|
+
if adm is not None:
|
|
376
|
+
facts = library_elastic.facts_for_budget(
|
|
377
|
+
facts, "unified", adm.soft_budget_bytes, wired_cap_bytes=adm.wired_headroom_bytes
|
|
378
|
+
)
|
|
379
|
+
else:
|
|
380
|
+
facts, _ = metal.pressured(facts)
|
|
371
381
|
plan = deploy.build_plan(
|
|
372
382
|
hosts.LOCAL_ID,
|
|
373
383
|
facts,
|
|
@@ -384,32 +394,7 @@ def price(
|
|
|
384
394
|
entries=catalog,
|
|
385
395
|
resolver=deploy.catalog_pins,
|
|
386
396
|
)
|
|
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")
|
|
397
|
+
library_elastic.validate_plan_bounds(facts, model, pool, plan, catalog)
|
|
413
398
|
return plan
|
|
414
399
|
|
|
415
400
|
|
|
@@ -690,8 +675,15 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
|
|
|
690
675
|
break
|
|
691
676
|
if not ranked:
|
|
692
677
|
return None
|
|
678
|
+
slow_ids = {
|
|
679
|
+
entry_id for (_, tok_s), entry_id, _ in ranked if 0 < tok_s < cat.USABLE_FLOOR_TOK_S
|
|
680
|
+
}
|
|
693
681
|
chosen_id, _ = llm_rank.choose(
|
|
694
|
-
ranked,
|
|
682
|
+
ranked,
|
|
683
|
+
"smartest",
|
|
684
|
+
llm_rank.mac_ladder(facts),
|
|
685
|
+
fallback_ids=fallback_ids,
|
|
686
|
+
slow_ids=slow_ids,
|
|
695
687
|
)
|
|
696
688
|
return by_id[chosen_id].entry.id, by_id[chosen_id].variant.quant
|
|
697
689
|
|