@simplexai/localmodels-darwin-arm64 0.1.0-dev.47 → 0.1.0-dev.49
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 +55 -51
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/budget.py +40 -14
- package/modules/localmodels/catalog.json +57 -34
- package/modules/localmodels/debug_mode.py +25 -0
- package/modules/localmodels/deploy.py +3 -0
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +13 -1
- package/modules/localmodels/engines.py +31 -6
- package/modules/localmodels/library_jobs.py +22 -1
- package/modules/localmodels/library_model.py +38 -2
- package/modules/localmodels/library_pricing.py +261 -78
- package/modules/localmodels/library_serve.py +20 -4
- package/modules/localmodels/library_status.py +19 -11
- package/modules/localmodels/library_vram.py +123 -0
- package/modules/localmodels/llm_rank.py +28 -1
- package/modules/localmodels/probe.py +39 -37
- package/modules/localmodels/process_identity.py +26 -33
- package/modules/localmodels/process_identity_darwin.py +189 -0
- package/modules/localmodels/process_identity_linux.py +62 -30
- package/modules/localmodels/recommend.py +3 -1
- package/modules/localmodels/remote_ops_service.py +15 -46
- package/modules/localmodels/service_probe.py +1 -1
- package/modules/localmodels/setup_inspection.py +14 -1
- package/modules/localmodels/setup_text.py +15 -3
- package/modules/localmodels/setup_upgrade.py +145 -0
- package/modules/localmodels/stack_binding.py +59 -12
- package/modules/localmodels/stack_compose.py +5 -1
- package/modules/localmodels/stack_hardware.py +5 -2
- package/modules/localmodels/stack_route.py +5 -1
- package/modules/localmodels/stack_suite.py +1 -1
- package/modules/localmodels/stack_view_access.py +238 -58
- package/modules/localmodels/stack_view_hub.py +12 -7
- package/modules/localmodels/stack_view_serve.py +13 -6
- package/modules/localmodels/transport.py +3 -1
- package/modules/localmodels/tui.py +4 -1
- package/modules/localmodels/tui_dialogs.py +42 -9
- package/modules/localmodels/tui_modals.py +63 -16
- package/modules/localmodels/tui_screen.py +80 -53
- package/modules/localmodels/tui_views.py +36 -6
- package/modules/localmodels/web/index.html +996 -300
- package/modules/localmodels/web/sizecalc/app.js +616 -88
- package/modules/localmodels/web/sizecalc/page.html +239 -106
- package/modules/localmodels/web/view/fleet.js +25 -2
- package/modules/localmodels/web/view/nav.js +19 -3
- package/modules/localmodels/web/view/view.css +110 -22
- package/modules/localmodels/web/view/view.js +40 -22
- package/modules/localmodels/win_probe.py +187 -0
- package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/RECORD +52 -48
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev47.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -19,17 +19,21 @@ import shutil
|
|
|
19
19
|
from collections.abc import Iterable, Mapping
|
|
20
20
|
from dataclasses import dataclass
|
|
21
21
|
from pathlib import Path
|
|
22
|
-
from typing import Any
|
|
22
|
+
from typing import Any, Literal
|
|
23
23
|
|
|
24
24
|
from localmodels import (
|
|
25
25
|
budget,
|
|
26
|
+
catalog_recipes,
|
|
26
27
|
context_policy,
|
|
27
28
|
deploy,
|
|
29
|
+
engines,
|
|
28
30
|
hosts,
|
|
31
|
+
library_vram,
|
|
29
32
|
llm_rank,
|
|
30
33
|
metal,
|
|
31
34
|
plan_envelope,
|
|
32
35
|
stack_hardware,
|
|
36
|
+
stack_llm_ram,
|
|
33
37
|
vision,
|
|
34
38
|
)
|
|
35
39
|
from localmodels import catalog as cat
|
|
@@ -40,7 +44,7 @@ from localmodels.estimator import (
|
|
|
40
44
|
PhysicsRefusal,
|
|
41
45
|
)
|
|
42
46
|
from localmodels.library_model import LibraryError, Reason, display_name, split_id
|
|
43
|
-
from localmodels.probe import
|
|
47
|
+
from localmodels.probe import HostFacts
|
|
44
48
|
from localmodels.records import Plan
|
|
45
49
|
from localmodels.stack_plan import platform_error
|
|
46
50
|
|
|
@@ -82,10 +86,7 @@ def is_chat(entry: cat.CatalogEntry) -> bool:
|
|
|
82
86
|
|
|
83
87
|
|
|
84
88
|
def shown(facts: HostFacts, catalog: Iterable[cat.CatalogEntry]) -> list[Model]:
|
|
85
|
-
"""
|
|
86
|
-
``stack --llm auto`` picks here too (the Mac small-memory ladder, the Windows NVIDIA
|
|
87
|
-
fallback): one row per variant. Ling-3.0-tiny, which the ladder replaces in automatic
|
|
88
|
-
selection, stays listed."""
|
|
89
|
+
"""Validated chat models, library candidates, Mac ladder, and Windows fallback rows."""
|
|
89
90
|
return [
|
|
90
91
|
Model(e, v)
|
|
91
92
|
for e in catalog
|
|
@@ -133,9 +134,16 @@ def visible(facts: HostFacts) -> set[int] | None:
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
|
|
137
|
+
def _cuda_uma(facts: HostFacts) -> int | None:
|
|
138
|
+
"""Allocator pool bytes for an NVIDIA unified-memory device (e.g. Grace/GB10), else None."""
|
|
139
|
+
if metal.supported(facts):
|
|
140
|
+
return None
|
|
141
|
+
return budget.unified_pool_bytes(facts)
|
|
142
|
+
|
|
143
|
+
|
|
136
144
|
def pools(facts: HostFacts) -> dict[str, str]:
|
|
137
|
-
"""Pool id -> the planner's placement id: one per NVIDIA card (``gpu:N``),
|
|
138
|
-
memory (``unified``), and ``system`` for host RAM
|
|
145
|
+
"""Pool id -> the planner's placement id: one per discrete NVIDIA card (``gpu:N``),
|
|
146
|
+
Apple Silicon or CUDA unified memory (``unified``), and ``system`` for host RAM."""
|
|
139
147
|
found: dict[str, str] = {}
|
|
140
148
|
shown = visible(facts)
|
|
141
149
|
for p in budget.placements(facts, planning=True):
|
|
@@ -143,6 +151,9 @@ def pools(facts: HostFacts) -> dict[str, str]:
|
|
|
143
151
|
continue
|
|
144
152
|
if p.backend == "metal":
|
|
145
153
|
found["unified"] = p.id
|
|
154
|
+
elif p.backend == "cuda" and p.budget.uma:
|
|
155
|
+
if not p.gpu_indices or shown is None or p.gpu_indices[0] in shown:
|
|
156
|
+
found["unified"] = p.id
|
|
146
157
|
elif p.backend == "cuda" and not p.budget.uma and len(p.gpu_indices) == 1:
|
|
147
158
|
if shown is None or p.gpu_indices[0] in shown:
|
|
148
159
|
found[f"gpu:{p.gpu_indices[0]}"] = p.id
|
|
@@ -155,17 +166,40 @@ def gpu_index(pool: str) -> int | None:
|
|
|
155
166
|
return int(pool.split(":", 1)[1]) if pool.startswith("gpu:") else None
|
|
156
167
|
|
|
157
168
|
|
|
169
|
+
def _cuda_uma_budget_bytes(base: int) -> int:
|
|
170
|
+
usable = int(base * (1 - budget._UMA_HEADROOM_FRACTION))
|
|
171
|
+
return max(0, usable - AGENT_VRAM_RESERVE_BYTES)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _cuda_uma_live(facts: HostFacts) -> tuple[int, int]:
|
|
175
|
+
"""(free_bytes, reserve_bytes) on a CUDA unified-memory pool."""
|
|
176
|
+
unified = _cuda_uma(facts) or facts["ram"]["total_bytes"]
|
|
177
|
+
nvidia = [
|
|
178
|
+
g
|
|
179
|
+
for g in facts.get("gpus") or []
|
|
180
|
+
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
181
|
+
]
|
|
182
|
+
first_free = nvidia[0]["free_bytes"] if nvidia else 0
|
|
183
|
+
_, ram_avail = budget.host_ram(facts)
|
|
184
|
+
free = _cuda_uma_budget_bytes(min(unified, first_free + ram_avail))
|
|
185
|
+
return free, max(0, unified - _cuda_uma_budget_bytes(unified))
|
|
186
|
+
|
|
187
|
+
|
|
158
188
|
def pool_total(facts: HostFacts, pool: str) -> int:
|
|
159
189
|
index = gpu_index(pool)
|
|
160
190
|
if index is not None:
|
|
161
191
|
return next(g["total_bytes"] for g in facts["gpus"] if g["index"] == index)
|
|
162
192
|
if pool == "unified":
|
|
193
|
+
if (unified := _cuda_uma(facts)) is not None:
|
|
194
|
+
return _cuda_uma_budget_bytes(unified)
|
|
163
195
|
return max(0, facts["ram"]["total_bytes"] - UNIFIED_RESERVE_BYTES)
|
|
164
196
|
return int(facts["ram"]["total_bytes"] * POOL_RAM_FRACTION)
|
|
165
197
|
|
|
166
198
|
|
|
167
199
|
def _unified_live(facts: HostFacts) -> tuple[int, int]:
|
|
168
|
-
"""(free_bytes, reserve_bytes) on a
|
|
200
|
+
"""(free_bytes, reserve_bytes) on a unified pool (Metal or CUDA UMA)."""
|
|
201
|
+
if _cuda_uma(facts) is not None:
|
|
202
|
+
return _cuda_uma_live(facts)
|
|
169
203
|
level = facts["ram"].get("pressure_level")
|
|
170
204
|
pressured, _ = metal.pressured(facts)
|
|
171
205
|
kept = int(pressured["ram"].get("pressure_kept_bytes") or 0)
|
|
@@ -187,7 +221,7 @@ def pool_free(facts: HostFacts, pool: str) -> int:
|
|
|
187
221
|
|
|
188
222
|
|
|
189
223
|
def pool_reserve(facts: HostFacts, pool: str) -> int:
|
|
190
|
-
"""Memory kept back from models on ``pool`` for
|
|
224
|
+
"""Memory kept back from models on ``pool`` for OS, display, or safety margins."""
|
|
191
225
|
if gpu_index(pool) is not None:
|
|
192
226
|
return AGENT_VRAM_RESERVE_BYTES
|
|
193
227
|
if pool == "unified":
|
|
@@ -196,60 +230,25 @@ def pool_reserve(facts: HostFacts, pool: str) -> int:
|
|
|
196
230
|
|
|
197
231
|
|
|
198
232
|
def pool_of(plan: Plan) -> str:
|
|
199
|
-
"""The pool a deployment plan runs in: its card,
|
|
233
|
+
"""The pool a deployment plan runs in: its card, unified memory, else RAM."""
|
|
200
234
|
placement: dict[str, Any] = dict(plan.get("placement") or {})
|
|
201
235
|
gpus: list[dict[str, Any]] = list(placement.get("gpus") or [])
|
|
202
|
-
if gpus and gpus[0].get("uuid") == metal.METAL_UUID:
|
|
236
|
+
if placement.get("id") == "host" or (gpus and gpus[0].get("uuid") == metal.METAL_UUID):
|
|
203
237
|
return "unified"
|
|
204
238
|
if gpus:
|
|
205
239
|
return f"gpu:{gpus[0]['index']}"
|
|
206
240
|
return "system"
|
|
207
241
|
|
|
208
242
|
|
|
209
|
-
def _owned_gpu_bytes(facts: HostFacts, gpu: GPU, reclaimable: Mapping[str, int] | None) -> int:
|
|
210
|
-
pool = f"gpu:{gpu['index']}"
|
|
211
|
-
from_records = max(0, int((reclaimable or {}).get(pool, 0)))
|
|
212
|
-
services = facts.get("services")
|
|
213
|
-
procs = (services.get("compute_processes") if services else None) or []
|
|
214
|
-
from_procs = sum(
|
|
215
|
-
int(p.get("used_bytes") or 0)
|
|
216
|
-
for p in procs
|
|
217
|
-
if p["gpu_uuid"] == gpu["uuid"] and p.get("owned") is True
|
|
218
|
-
)
|
|
219
|
-
return max(from_records, from_procs)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def _foreign_gpu_bytes(facts: HostFacts, gpu: GPU) -> int:
|
|
223
|
-
services = facts.get("services")
|
|
224
|
-
procs = (services.get("compute_processes") if services else None) or []
|
|
225
|
-
return sum(
|
|
226
|
-
int(p.get("used_bytes") or 0)
|
|
227
|
-
for p in procs
|
|
228
|
-
if p["gpu_uuid"] == gpu["uuid"] and budget.foreign_work(p, facts)
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
def _gpu_capacity_free(facts: HostFacts, gpu: GPU, reclaimable: Mapping[str, int] | None) -> int:
|
|
233
|
-
"""Loadable VRAM on ``gpu`` once owned models and transient foreign work clear, keeping
|
|
234
|
-
observed desktop/WDDM baseline occupancy on Windows and display-active GPUs."""
|
|
235
|
-
total = gpu["total_bytes"]
|
|
236
|
-
if facts.get("platform") != "win32" and not gpu.get("display_active"):
|
|
237
|
-
return total
|
|
238
|
-
taken = max(gpu["used_bytes"], max(0, total - gpu["free_bytes"]))
|
|
239
|
-
desktop_used = max(
|
|
240
|
-
0, taken - _owned_gpu_bytes(facts, gpu, reclaimable) - _foreign_gpu_bytes(facts, gpu)
|
|
241
|
-
)
|
|
242
|
-
baseline = min(desktop_used, DESKTOP_VRAM_BASELINE_CAP_BYTES)
|
|
243
|
-
return min(total, max(gpu["free_bytes"], total - baseline))
|
|
244
|
-
|
|
245
|
-
|
|
246
243
|
def capacity(facts: HostFacts, *, reclaimable: Mapping[str, int] | None = None) -> HostFacts:
|
|
247
244
|
"""``facts`` at loadable capacity once loaded library models are unloaded: keeps macOS's
|
|
248
245
|
idle baseline (``metal.in_use``) on Apple Silicon and observed desktop/WDDM baseline VRAM
|
|
249
246
|
on Windows and display-active GPUs instead of pretending zero OS/desktop overhead."""
|
|
250
247
|
seen = copy.deepcopy(facts)
|
|
251
248
|
for gpu in seen.get("gpus") or []:
|
|
252
|
-
free =
|
|
249
|
+
free = library_vram.gpu_capacity_free(
|
|
250
|
+
facts, gpu, reclaimable, DESKTOP_VRAM_BASELINE_CAP_BYTES
|
|
251
|
+
)
|
|
253
252
|
gpu["free_bytes"], gpu["used_bytes"] = free, max(0, gpu["total_bytes"] - free)
|
|
254
253
|
ram = seen["ram"]
|
|
255
254
|
if metal.supported(seen):
|
|
@@ -261,6 +260,8 @@ def capacity(facts: HostFacts, *, reclaimable: Mapping[str, int] | None = None)
|
|
|
261
260
|
ram.pop("pressure_kept_bytes", None)
|
|
262
261
|
else:
|
|
263
262
|
ram["available_bytes"] = ram["total_bytes"]
|
|
263
|
+
if cgroup := seen.get("cgroup_memory"):
|
|
264
|
+
cgroup["usage_bytes"] = 0
|
|
264
265
|
seen["llama_servers"] = []
|
|
265
266
|
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
266
267
|
if services := seen.get("services"):
|
|
@@ -282,8 +283,30 @@ def live(
|
|
|
282
283
|
delta = change.get(f"gpu:{gpu['index']}", 0)
|
|
283
284
|
gpu["free_bytes"] = max(0, min(gpu["total_bytes"], gpu["free_bytes"] - delta))
|
|
284
285
|
ram = seen["ram"]
|
|
285
|
-
|
|
286
|
-
|
|
286
|
+
unified_delta = change.get("unified", 0)
|
|
287
|
+
system_delta = change.get("system", 0)
|
|
288
|
+
if (unified := _cuda_uma(seen)) is not None and unified_delta:
|
|
289
|
+
nvidia = [
|
|
290
|
+
g
|
|
291
|
+
for g in seen.get("gpus") or []
|
|
292
|
+
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
293
|
+
]
|
|
294
|
+
first = nvidia[0] if nvidia else None
|
|
295
|
+
first_free = first["free_bytes"] if first is not None else 0
|
|
296
|
+
current_live = min(unified, first_free + ram["available_bytes"])
|
|
297
|
+
scaled = int(round(unified_delta / (1 - budget._UMA_HEADROOM_FRACTION)))
|
|
298
|
+
target = max(0, min(unified, current_live - scaled))
|
|
299
|
+
if first is not None and first_free > target:
|
|
300
|
+
first["free_bytes"], ram["available_bytes"] = target, 0
|
|
301
|
+
else:
|
|
302
|
+
ram["available_bytes"] = max(0, min(ram["total_bytes"], target - first_free))
|
|
303
|
+
if system_delta:
|
|
304
|
+
ram["available_bytes"] = max(
|
|
305
|
+
0, min(ram["total_bytes"], ram["available_bytes"] - system_delta)
|
|
306
|
+
)
|
|
307
|
+
else:
|
|
308
|
+
delta = unified_delta + system_delta
|
|
309
|
+
ram["available_bytes"] = max(0, min(ram["total_bytes"], ram["available_bytes"] - delta))
|
|
287
310
|
seen["llama_servers"] = []
|
|
288
311
|
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
289
312
|
return seen
|
|
@@ -296,6 +319,18 @@ class LiveMemoryUnavailable(plan_envelope.PlanError):
|
|
|
296
319
|
"""The probe cannot establish a usable live Metal budget."""
|
|
297
320
|
|
|
298
321
|
|
|
322
|
+
def host_ram_bytes(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int:
|
|
323
|
+
"""Host RAM held by one discrete-GPU llama.cpp model plus its prompt-cache floor."""
|
|
324
|
+
min_cache_bytes = (
|
|
325
|
+
(posture().prompt_cache_min_mib << 20) if posture().prompt_cache_mib > 0 else 0
|
|
326
|
+
)
|
|
327
|
+
return stack_llm_ram.own_bytes(plan, catalog, running=False, metal=False) + min_cache_bytes
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _required_host_ram(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int:
|
|
331
|
+
return host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
|
|
332
|
+
|
|
333
|
+
|
|
299
334
|
def price(
|
|
300
335
|
facts: HostFacts,
|
|
301
336
|
model: Model,
|
|
@@ -310,7 +345,7 @@ def price(
|
|
|
310
345
|
placement = pools(facts).get(pool)
|
|
311
346
|
if placement is None:
|
|
312
347
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
313
|
-
if require_live and pool == "unified":
|
|
348
|
+
if require_live and pool == "unified" and metal.supported(facts):
|
|
314
349
|
if problem := metal.problem(facts):
|
|
315
350
|
raise LiveMemoryUnavailable(problem)
|
|
316
351
|
facts, _ = metal.pressured(facts)
|
|
@@ -343,6 +378,19 @@ def price(
|
|
|
343
378
|
refused,
|
|
344
379
|
"unified memory" if pool == "unified" else "GPU memory",
|
|
345
380
|
)
|
|
381
|
+
if gpu_index(pool) is not None:
|
|
382
|
+
needed_ram = _required_host_ram(plan, catalog)
|
|
383
|
+
_, avail_ram = budget.host_ram(facts)
|
|
384
|
+
if needed_ram > avail_ram:
|
|
385
|
+
refused = PhysicsRefusal(
|
|
386
|
+
needed_bytes=needed_ram,
|
|
387
|
+
available_bytes=avail_ram,
|
|
388
|
+
message=(
|
|
389
|
+
f"{model.id} needs {needed_ram} bytes of system memory, "
|
|
390
|
+
f"exceeding {avail_ram} bytes available"
|
|
391
|
+
),
|
|
392
|
+
)
|
|
393
|
+
raise deploy.AgentMemoryError(refused.message, refused, "system memory")
|
|
346
394
|
return plan
|
|
347
395
|
|
|
348
396
|
|
|
@@ -364,14 +412,40 @@ class Priced:
|
|
|
364
412
|
have_bytes: int = 0
|
|
365
413
|
load_need_bytes: int = 0 # pool-aligned requirement when fits_now is False
|
|
366
414
|
load_free_bytes: int = 0 # pool-aligned free memory on the planned pool
|
|
415
|
+
memory_kind: str = "" # vram | ram | unified (when fit == "none" due to memory)
|
|
416
|
+
blocker: Reason | None = None # driver/runtime incompatibility when no pool priced
|
|
417
|
+
reclaimable_desktop_vram: bool = False # fits discrete GPU once desktop apps near 1 GiB idle
|
|
418
|
+
reclaim_bytes: int = 0 # approximate VRAM to free when reclaimable_desktop_vram is True
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _engine_blocker(exc: plan_envelope.PlanError) -> Reason | None:
|
|
422
|
+
if isinstance(exc, engines.CudaDriverError):
|
|
423
|
+
reason: Reason = {"code": "DRIVER_UPDATE_REQUIRED"}
|
|
424
|
+
if exc.required_cuda:
|
|
425
|
+
reason["required_cuda"] = exc.required_cuda
|
|
426
|
+
if exc.detected_cuda:
|
|
427
|
+
reason["detected_cuda"] = exc.detected_cuda
|
|
428
|
+
if exc.driver_version:
|
|
429
|
+
reason["driver_version"] = exc.driver_version
|
|
430
|
+
return reason
|
|
431
|
+
if isinstance(exc, engines.EngineUnavailableError):
|
|
432
|
+
reason = {"code": "RUNTIME_DEPENDENCY_MISSING"}
|
|
433
|
+
if exc.missing_libraries:
|
|
434
|
+
reason["missing_libraries"] = list(exc.missing_libraries)
|
|
435
|
+
if exc.required_glibc:
|
|
436
|
+
reason["required_glibc"] = exc.required_glibc
|
|
437
|
+
if exc.detected_glibc:
|
|
438
|
+
reason["detected_glibc"] = exc.detected_glibc
|
|
439
|
+
return reason
|
|
440
|
+
return None
|
|
367
441
|
|
|
368
442
|
|
|
369
|
-
def _min_pool_need(model: Model, pool: str, exc: deploy.AgentMemoryError) -> int:
|
|
443
|
+
def _min_pool_need(model: Model, pool: str, exc: deploy.AgentMemoryError, facts: HostFacts) -> int:
|
|
370
444
|
"""Exact pool-aligned free bytes required at the agent floor when ``available_bytes`` clamped
|
|
371
445
|
to zero inside ``agent_budget`` or ``vision.priced``."""
|
|
372
446
|
if gpu_index(pool) is not None:
|
|
373
447
|
return exc.needed_bytes + AGENT_VRAM_RESERVE_BYTES
|
|
374
|
-
if pool == "unified":
|
|
448
|
+
if pool == "unified" and metal.supported(facts):
|
|
375
449
|
profile = model.entry.profile(model.variant)
|
|
376
450
|
mac_posture = model.entry.agent_posture(context_policy.posture_for(posture(), "metal"))
|
|
377
451
|
host_side = context_policy.cache_floor_bytes(
|
|
@@ -404,10 +478,12 @@ def _live_plan(
|
|
|
404
478
|
try:
|
|
405
479
|
plan = price(now, model, pool, base_dir, catalog, require_live=True)
|
|
406
480
|
except deploy.AgentMemoryError as exc:
|
|
481
|
+
if exc.memory == "system memory":
|
|
482
|
+
return None, exc.needed_bytes, exc.available_bytes
|
|
407
483
|
deficit = max(1, exc.needed_bytes - exc.available_bytes)
|
|
408
484
|
need = free + deficit
|
|
409
485
|
if exc.available_bytes == 0:
|
|
410
|
-
need = max(need, _min_pool_need(model, pool, exc))
|
|
486
|
+
need = max(need, _min_pool_need(model, pool, exc, now))
|
|
411
487
|
return None, need, free
|
|
412
488
|
except plan_envelope.PlanError:
|
|
413
489
|
return None, max(fallback_need, free + 1), free
|
|
@@ -444,24 +520,30 @@ def judge(
|
|
|
444
520
|
*,
|
|
445
521
|
reclaimable: Mapping[str, int] | None = None,
|
|
446
522
|
) -> Priced:
|
|
447
|
-
"""Fit on loadable capacity; the
|
|
448
|
-
fits now, else (nothing has room now) the freest card that fits at all, else the unified pool.
|
|
449
|
-
When the model fits live now, its live plan is returned so displayed context and memory match
|
|
450
|
-
what ``library load`` will actually allocate."""
|
|
523
|
+
"""Fit on loadable capacity; pick the freest card that fits live, else capacity, else unified."""
|
|
451
524
|
cap, now = capacity(facts, reclaimable=reclaimable), live(facts, reserved)
|
|
452
525
|
order = sorted(pools(facts), key=lambda p: -pool_free(now, p))
|
|
453
526
|
fallback: Priced | None = None
|
|
454
|
-
shortfall: tuple[int, int] | None = None
|
|
527
|
+
shortfall: tuple[int, int, str] | None = None
|
|
528
|
+
blocker: Reason | None = None
|
|
455
529
|
for pool in order:
|
|
456
530
|
if pool == "system":
|
|
457
531
|
continue # no catalog chat model runs from host RAM in the agent posture
|
|
458
532
|
try:
|
|
459
533
|
plan = price(cap, model, pool, base_dir, catalog)
|
|
460
534
|
except deploy.AgentMemoryError as exc:
|
|
461
|
-
|
|
535
|
+
kind = (
|
|
536
|
+
"ram"
|
|
537
|
+
if exc.memory == "system memory"
|
|
538
|
+
else ("unified" if pool == "unified" else "vram")
|
|
539
|
+
)
|
|
540
|
+
gap = (exc.needed_bytes, exc.available_bytes, kind)
|
|
462
541
|
if shortfall is None or gap[0] - gap[1] < shortfall[0] - shortfall[1]:
|
|
463
542
|
shortfall = gap
|
|
464
543
|
continue
|
|
544
|
+
except (engines.CudaDriverError, engines.EngineUnavailableError) as exc:
|
|
545
|
+
blocker = blocker or _engine_blocker(exc)
|
|
546
|
+
continue
|
|
465
547
|
except plan_envelope.PlanError:
|
|
466
548
|
continue
|
|
467
549
|
fit = "unified" if pool == "unified" else "gpu"
|
|
@@ -476,8 +558,27 @@ def judge(
|
|
|
476
558
|
)
|
|
477
559
|
if fallback is not None:
|
|
478
560
|
return fallback
|
|
479
|
-
need, have = shortfall or (0, 0)
|
|
480
|
-
|
|
561
|
+
need, have, memory_kind = shortfall or (0, 0, "")
|
|
562
|
+
reclaim = (
|
|
563
|
+
blocker is None
|
|
564
|
+
and memory_kind == "vram"
|
|
565
|
+
and need > have
|
|
566
|
+
and library_vram.fits_idle_desktop(
|
|
567
|
+
facts, cap, order, lambda f, p: price(f, model, p, base_dir, catalog)
|
|
568
|
+
)
|
|
569
|
+
)
|
|
570
|
+
return Priced(
|
|
571
|
+
"none",
|
|
572
|
+
"",
|
|
573
|
+
None,
|
|
574
|
+
False,
|
|
575
|
+
need,
|
|
576
|
+
have,
|
|
577
|
+
memory_kind=memory_kind,
|
|
578
|
+
blocker=blocker,
|
|
579
|
+
reclaimable_desktop_vram=reclaim,
|
|
580
|
+
reclaim_bytes=max(1, need - have) if reclaim else 0,
|
|
581
|
+
)
|
|
481
582
|
|
|
482
583
|
|
|
483
584
|
def base_free(base_dir: str) -> int:
|
|
@@ -508,26 +609,102 @@ def missing_bytes(plan: Plan) -> int:
|
|
|
508
609
|
return left
|
|
509
610
|
|
|
510
611
|
|
|
612
|
+
def _gpu_unsupported_reason(facts: HostFacts) -> Reason | None:
|
|
613
|
+
if any(p != "system" for p in pools(facts)):
|
|
614
|
+
return None
|
|
615
|
+
if visible(facts) == set() and any(
|
|
616
|
+
g.get("vendor") == "nvidia" for g in facts.get("gpus") or []
|
|
617
|
+
):
|
|
618
|
+
return None
|
|
619
|
+
raw = str(facts.get("gpu_vendor_class") or "unknown")
|
|
620
|
+
vendor: Literal["amd", "intel", "none", "unknown"] = (
|
|
621
|
+
"amd"
|
|
622
|
+
if raw == "amd"
|
|
623
|
+
else "intel"
|
|
624
|
+
if raw == "intel"
|
|
625
|
+
else "unknown"
|
|
626
|
+
if raw == "unknown"
|
|
627
|
+
else "none"
|
|
628
|
+
)
|
|
629
|
+
return {"code": "GPU_UNSUPPORTED", "gpu_vendor": vendor}
|
|
630
|
+
|
|
631
|
+
|
|
511
632
|
def download_reason(facts: HostFacts, priced: Priced, disk_free: int) -> Reason | None:
|
|
512
|
-
"""Why a download is refused now, if it is."""
|
|
513
633
|
if platform_problem(facts):
|
|
514
634
|
return {"code": "PLATFORM_UNSUPPORTED"}
|
|
515
635
|
if priced.plan is None:
|
|
516
|
-
|
|
636
|
+
if priced.blocker is not None:
|
|
637
|
+
return priced.blocker
|
|
638
|
+
if gpu_reason := _gpu_unsupported_reason(facts):
|
|
639
|
+
return gpu_reason
|
|
640
|
+
reason: Reason = {
|
|
517
641
|
"code": "MEMORY_INSUFFICIENT",
|
|
518
642
|
"need_bytes": priced.need_bytes,
|
|
519
643
|
"have_bytes": priced.have_bytes,
|
|
520
644
|
}
|
|
521
|
-
|
|
522
|
-
|
|
645
|
+
if priced.memory_kind in ("vram", "ram", "unified"):
|
|
646
|
+
reason["memory_kind"] = priced.memory_kind # type: ignore[typeddict-item]
|
|
647
|
+
if priced.reclaimable_desktop_vram:
|
|
648
|
+
reason["reclaimable_desktop_vram"] = True
|
|
649
|
+
if priced.reclaim_bytes > 0:
|
|
650
|
+
reason["reclaim_bytes"] = priced.reclaim_bytes
|
|
651
|
+
return reason
|
|
652
|
+
if (need := missing_bytes(priced.plan)) > disk_free:
|
|
523
653
|
return {"code": "DISK_INSUFFICIENT", "need_bytes": need, "have_bytes": disk_free}
|
|
524
654
|
return None
|
|
525
655
|
|
|
526
656
|
|
|
527
|
-
def
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
657
|
+
def _strata_ids() -> set[str]:
|
|
658
|
+
return {
|
|
659
|
+
c["id"] for c in catalog_recipes.components() if c["runtime"] in ("strata", "strata-poly")
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, str] | None:
|
|
664
|
+
"""Best live-fitting llama.cpp library model ranked by ``llm_rank.choose()``."""
|
|
665
|
+
catalog = entries()
|
|
666
|
+
pool_map = pools(facts)
|
|
667
|
+
live_pools = [p for p in pool_map if p != "system"]
|
|
668
|
+
if not live_pools:
|
|
669
|
+
return None
|
|
670
|
+
placements_by_id = {p.id: p for p in budget.placements(facts, planning=False)}
|
|
671
|
+
ranked: list[tuple[tuple[int, float], str, int]] = []
|
|
672
|
+
by_id: dict[str, Model] = {}
|
|
673
|
+
fallback_ids: set[str] = set()
|
|
674
|
+
for model in shown(facts, catalog):
|
|
675
|
+
if (
|
|
676
|
+
not llm_rank.automatic_here(model.entry, facts)
|
|
677
|
+
or model.variant is not model.entry.variants[-1]
|
|
678
|
+
):
|
|
679
|
+
continue
|
|
680
|
+
for pool in live_pools:
|
|
681
|
+
try:
|
|
682
|
+
price(facts, model, pool, base_dir, catalog, require_live=True)
|
|
683
|
+
except plan_envelope.PlanError:
|
|
684
|
+
continue
|
|
685
|
+
pl = placements_by_id.get(pool_map[pool])
|
|
686
|
+
hw = (budget.agent_budget(pl, facts) if pl else None) or (pl.budget if pl else None)
|
|
687
|
+
tok_s = (
|
|
688
|
+
round(cat.decode_estimate(model.entry, model.variant, hw).tok_s, 1) if hw else 0.0
|
|
689
|
+
)
|
|
690
|
+
is_fb = llm_rank.windows_fallback(model.entry, facts)
|
|
691
|
+
score = 0 if (is_fb or llm_rank.mac_rung(model.entry, facts)) else model.entry.quality
|
|
692
|
+
ranked.append(((score, tok_s), model.entry.id, gpu_index(pool) or 0))
|
|
693
|
+
by_id[model.entry.id] = model
|
|
694
|
+
if is_fb:
|
|
695
|
+
fallback_ids.add(model.entry.id)
|
|
696
|
+
break
|
|
697
|
+
if not ranked:
|
|
698
|
+
return None
|
|
699
|
+
chosen_id, _ = llm_rank.choose(
|
|
700
|
+
ranked, "smartest", llm_rank.mac_ladder(facts), fallback_ids=fallback_ids
|
|
701
|
+
)
|
|
702
|
+
return by_id[chosen_id].entry.id, by_id[chosen_id].variant.quant
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple[str, str] | None:
|
|
706
|
+
"""(catalog id, quant) of the smartest live library pick; falls back to library models when
|
|
707
|
+
``stack`` selects Strata/PolyStrata or on CUDA unified-memory hosts."""
|
|
531
708
|
from localmodels import stack
|
|
532
709
|
|
|
533
710
|
seen = copy.deepcopy(facts)
|
|
@@ -541,13 +718,19 @@ def smartest(facts: HostFacts) -> tuple[str, str] | None:
|
|
|
541
718
|
(p for p in view.get("picks") or [] if p["role"] == "smartest" and not p.get("shared")),
|
|
542
719
|
None,
|
|
543
720
|
)
|
|
544
|
-
|
|
721
|
+
if pick is not None and pick["id"] not in _strata_ids():
|
|
722
|
+
return (pick["id"], pick["quant"])
|
|
723
|
+
if pick is not None or _cuda_uma(seen) is not None:
|
|
724
|
+
return _smartest_library_fallback(seen, base_dir)
|
|
725
|
+
return None
|
|
545
726
|
|
|
546
727
|
|
|
547
|
-
def recommend(
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
728
|
+
def recommend(
|
|
729
|
+
facts: HostFacts, candidates: list[Model], base_dir: str = deploy.DEFAULT_BASE_DIR
|
|
730
|
+
) -> str | None:
|
|
731
|
+
"""The one model to suggest: the smartest live library pick, when it is among the absent,
|
|
732
|
+
downloadable ``candidates`` that fit live memory now. None when it is already on disk
|
|
733
|
+
or nothing fits now."""
|
|
734
|
+
if not candidates or (pick := smartest(facts, base_dir)) is None:
|
|
552
735
|
return None
|
|
553
736
|
return next((m.id for m in candidates if (m.entry.id, m.variant.quant) == pick), None)
|
|
@@ -20,6 +20,7 @@ from pathlib import Path
|
|
|
20
20
|
from localmodels import (
|
|
21
21
|
app,
|
|
22
22
|
deploy,
|
|
23
|
+
engines,
|
|
23
24
|
harness,
|
|
24
25
|
hosts,
|
|
25
26
|
library_gateway,
|
|
@@ -81,13 +82,18 @@ def _room(facts: HostFacts, model: Model, record: Record, freed: dict[str, int])
|
|
|
81
82
|
require_live=True,
|
|
82
83
|
)
|
|
83
84
|
except deploy.AgentMemoryError as exc:
|
|
85
|
+
refused_pool = "system" if exc.memory == "system memory" else record["pool"]
|
|
84
86
|
raise LibraryError(
|
|
85
87
|
"LOAD_NO_ROOM",
|
|
86
|
-
f"{model.id} does not fit {
|
|
87
|
-
pool=
|
|
88
|
+
f"{model.id} does not fit {refused_pool} now",
|
|
89
|
+
pool=refused_pool,
|
|
88
90
|
need_bytes=exc.needed_bytes,
|
|
89
91
|
free_bytes=exc.available_bytes,
|
|
90
92
|
) from None
|
|
93
|
+
except engines.CudaDriverError as exc:
|
|
94
|
+
raise LibraryError("DRIVER_UPDATE_REQUIRED", str(exc)) from None
|
|
95
|
+
except engines.EngineUnavailableError as exc:
|
|
96
|
+
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc)) from None
|
|
91
97
|
except plan_envelope.PlanError as exc: # its pool is gone, hidden, or under critical pressure
|
|
92
98
|
need = record.get("memory_bytes") or library_pricing.memory_bytes(record["plan"])
|
|
93
99
|
raise LibraryError(
|
|
@@ -203,14 +209,19 @@ def _serve(
|
|
|
203
209
|
require_live=True,
|
|
204
210
|
)
|
|
205
211
|
except deploy.AgentMemoryError as exc: # after --unload: no longer a refusal
|
|
212
|
+
refused_pool = "system" if exc.memory == "system memory" else record["pool"]
|
|
206
213
|
raise LibraryError(
|
|
207
214
|
"LOAD_NO_ROOM",
|
|
208
|
-
f"{model.id} does not fit {
|
|
215
|
+
f"{model.id} does not fit {refused_pool} now",
|
|
209
216
|
failed=True,
|
|
210
|
-
pool=
|
|
217
|
+
pool=refused_pool,
|
|
211
218
|
need_bytes=exc.needed_bytes,
|
|
212
219
|
free_bytes=exc.available_bytes,
|
|
213
220
|
) from None
|
|
221
|
+
except engines.CudaDriverError as exc:
|
|
222
|
+
raise LibraryError("DRIVER_UPDATE_REQUIRED", str(exc), failed=True) from None
|
|
223
|
+
except engines.EngineUnavailableError as exc:
|
|
224
|
+
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc), failed=True) from None
|
|
214
225
|
except library_pricing.LiveMemoryUnavailable as exc:
|
|
215
226
|
raise LibraryError(
|
|
216
227
|
"LOAD_NO_ROOM",
|
|
@@ -313,6 +324,7 @@ def _admit(model: Model, record: Record, targets: list[Record], facts: HostFacts
|
|
|
313
324
|
stale server of the model itself give back. The caller commits its own reservation before
|
|
314
325
|
releasing the lock, so the next claimant sees it."""
|
|
315
326
|
freed: dict[str, int] = {}
|
|
327
|
+
catalog = library_pricing.entries()
|
|
316
328
|
for target in [*targets, *([record] if record["state"] != "idle" else [])]:
|
|
317
329
|
# A server that does not answer (failed, crashed, already stopped) is not counted:
|
|
318
330
|
# ``facts`` already count a gone one's memory as free (on a Mac its weights as file
|
|
@@ -321,6 +333,10 @@ def _admit(model: Model, record: Record, targets: list[Record], facts: HostFacts
|
|
|
321
333
|
continue
|
|
322
334
|
pool = target["pool"]
|
|
323
335
|
freed[pool] = freed.get(pool, 0) + library_pricing.memory_bytes(target["plan"])
|
|
336
|
+
if library_pricing.gpu_index(pool) is not None:
|
|
337
|
+
freed["system"] = freed.get("system", 0) + library_pricing.host_ram_bytes(
|
|
338
|
+
target["plan"], catalog
|
|
339
|
+
)
|
|
324
340
|
_room(facts, model, record, freed)
|
|
325
341
|
|
|
326
342
|
|