@simplexai/localmodels-win32-x64 0.1.0-dev.64 → 0.1.0-dev.65
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 +105 -102
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +2 -2
- package/modules/localmodels/approval.py +5 -3
- package/modules/localmodels/bifrost_checks.py +2 -1
- package/modules/localmodels/catalog.json +4 -2
- 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_probe.py +5 -5
- package/modules/localmodels/deploy.py +88 -12
- package/modules/localmodels/deployment_lifecycle.py +167 -0
- package/modules/localmodels/draft_spec.py +43 -1
- 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 +4 -3
- package/modules/localmodels/hosts.py +22 -34
- package/modules/localmodels/library_convert.py +3 -3
- package/modules/localmodels/library_custom.py +6 -6
- package/modules/localmodels/library_elastic.py +23 -10
- package/modules/localmodels/library_jobs.py +13 -3
- package/modules/localmodels/library_order.py +4 -3
- package/modules/localmodels/library_poly.py +2 -2
- package/modules/localmodels/library_pricing.py +34 -318
- package/modules/localmodels/library_serve.py +9 -8
- package/modules/localmodels/library_smoke.py +8 -1
- package/modules/localmodels/library_status.py +16 -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} +48 -30
- 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/residency_host.py +1 -1
- package/modules/localmodels/service_control.py +4 -4
- package/modules/localmodels/service_deployment.py +1 -1
- package/modules/localmodels/service_wiring.py +17 -19
- package/modules/localmodels/setup_inspection.py +1 -1
- package/modules/localmodels/setup_inspection_harness.py +1 -1
- package/modules/localmodels/setup_upgrade.py +3 -12
- package/modules/localmodels/speech_admission.py +1 -1
- package/modules/localmodels/speech_jobs.py +2 -1
- package/modules/localmodels/speech_model.py +2 -0
- package/modules/localmodels/speech_server.py +130 -9
- package/modules/localmodels/speech_state.py +11 -0
- package/modules/localmodels/speech_worker_sensevoice.py +21 -13
- package/modules/localmodels/speech_workers.py +5 -1
- package/modules/localmodels/stack.py +2 -5
- package/modules/localmodels/stack_auto.py +4 -4
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_binding.py +24 -143
- package/modules/localmodels/stack_capacity.py +1 -1
- package/modules/localmodels/stack_card.py +1 -1
- package/modules/localmodels/stack_cleanup.py +3 -3
- package/modules/localmodels/stack_client_settings.py +9 -2
- package/modules/localmodels/stack_compose.py +35 -6
- 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 +2 -2
- 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 +10 -3
- 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/tui_views.py +11 -5
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/RECORD +102 -99
- 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.dev65.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev65.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -14,16 +14,14 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import copy
|
|
16
16
|
import functools
|
|
17
|
-
import math
|
|
18
|
-
import os
|
|
19
17
|
import shutil
|
|
20
18
|
from collections.abc import Iterable, Mapping
|
|
21
19
|
from dataclasses import dataclass
|
|
22
20
|
from pathlib import Path
|
|
23
|
-
from typing import
|
|
21
|
+
from typing import Literal
|
|
24
22
|
|
|
23
|
+
from localmodels import catalog as cat
|
|
25
24
|
from localmodels import (
|
|
26
|
-
budget,
|
|
27
25
|
context_policy,
|
|
28
26
|
debug_mode,
|
|
29
27
|
deploy,
|
|
@@ -31,35 +29,28 @@ from localmodels import (
|
|
|
31
29
|
hosts,
|
|
32
30
|
library_kept,
|
|
33
31
|
library_poly,
|
|
34
|
-
library_vram,
|
|
35
32
|
llm_rank,
|
|
36
33
|
metal,
|
|
37
34
|
plan_envelope,
|
|
38
35
|
remote_ops_download,
|
|
39
36
|
stack_compose,
|
|
40
37
|
stack_hardware,
|
|
41
|
-
stack_llm_ram,
|
|
42
38
|
suite,
|
|
43
39
|
vision,
|
|
44
40
|
)
|
|
45
|
-
from localmodels import catalog as cat
|
|
46
41
|
from localmodels.context_policy import AgentPosture
|
|
47
42
|
from localmodels.estimator import (
|
|
48
43
|
AGENT_VRAM_RESERVE_BYTES,
|
|
49
|
-
METAL_VRAM_RESERVE_BYTES,
|
|
50
44
|
PhysicsRefusal,
|
|
51
45
|
agent_footprint_bytes,
|
|
52
46
|
eager,
|
|
53
47
|
)
|
|
54
48
|
from localmodels.library_model import LibraryError, Reason, display_name, split_id
|
|
49
|
+
from localmodels.planning import budget, llm_ram, memory_pools
|
|
55
50
|
from localmodels.probe import HostFacts
|
|
56
51
|
from localmodels.records import Plan
|
|
57
52
|
from localmodels.stack_plan import default_options, platform_error
|
|
58
53
|
|
|
59
|
-
POOL_RAM_FRACTION = 0.8 # a "system" pool's budget: RAM x 0.8 (contract v2)
|
|
60
|
-
UNIFIED_RESERVE_BYTES = metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
|
|
61
|
-
DESKTOP_VRAM_BASELINE_CAP_BYTES = budget.DESKTOP_VRAM_BASELINE_CAP_BYTES
|
|
62
|
-
|
|
63
54
|
|
|
64
55
|
@functools.cache
|
|
65
56
|
def posture() -> AgentPosture:
|
|
@@ -137,214 +128,6 @@ def platform_problem(facts: HostFacts) -> str | None:
|
|
|
137
128
|
return platform_error(facts["platform"], arch=facts.get("arch"))
|
|
138
129
|
|
|
139
130
|
|
|
140
|
-
# ---------------------------------------------------------------------------- pools
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def visible(facts: HostFacts) -> set[int] | None:
|
|
144
|
-
"""The NVIDIA cards ``CUDA_VISIBLE_DEVICES`` (indices or UUIDs) leaves to the library;
|
|
145
|
-
None when it is not set. The library never places a model on a card hidden from it."""
|
|
146
|
-
given = os.environ.get("CUDA_VISIBLE_DEVICES")
|
|
147
|
-
if given is None:
|
|
148
|
-
return None
|
|
149
|
-
names = {part.strip() for part in given.split(",") if part.strip()}
|
|
150
|
-
return {
|
|
151
|
-
g["index"]
|
|
152
|
-
for g in facts.get("gpus") or []
|
|
153
|
-
if str(g["index"]) in names or g["uuid"] in names
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
def _cuda_uma(facts: HostFacts) -> int | None:
|
|
158
|
-
"""Allocator pool bytes for an NVIDIA unified-memory device (e.g. Grace/GB10), else None."""
|
|
159
|
-
if metal.supported(facts):
|
|
160
|
-
return None
|
|
161
|
-
return budget.unified_pool_bytes(facts)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def pools(facts: HostFacts) -> dict[str, str]:
|
|
165
|
-
"""Pool id -> the planner's placement id: one per discrete NVIDIA card (``gpu:N``),
|
|
166
|
-
Apple Silicon or CUDA unified memory (``unified``), and ``system`` for host RAM."""
|
|
167
|
-
found: dict[str, str] = {}
|
|
168
|
-
shown = visible(facts)
|
|
169
|
-
for p in budget.placements(facts, planning=True):
|
|
170
|
-
if p.pooled:
|
|
171
|
-
continue
|
|
172
|
-
if p.backend == "metal":
|
|
173
|
-
found["unified"] = p.id
|
|
174
|
-
elif p.backend == "cuda" and p.budget.uma:
|
|
175
|
-
if not p.gpu_indices or shown is None or p.gpu_indices[0] in shown:
|
|
176
|
-
found["unified"] = p.id
|
|
177
|
-
elif p.backend == "cuda" and not p.budget.uma and len(p.gpu_indices) == 1:
|
|
178
|
-
if shown is None or p.gpu_indices[0] in shown:
|
|
179
|
-
found[f"gpu:{p.gpu_indices[0]}"] = p.id
|
|
180
|
-
if "unified" not in found:
|
|
181
|
-
found["system"] = "cpu"
|
|
182
|
-
return found
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def gpu_index(pool: str) -> int | None:
|
|
186
|
-
return int(pool.split(":", 1)[1]) if pool.startswith("gpu:") else None
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def _cuda_uma_budget_bytes(base: int) -> int:
|
|
190
|
-
usable = int(base * (1 - budget._UMA_HEADROOM_FRACTION))
|
|
191
|
-
return max(0, usable - AGENT_VRAM_RESERVE_BYTES)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def _cuda_uma_live(facts: HostFacts) -> tuple[int, int]:
|
|
195
|
-
"""(free_bytes, reserve_bytes) on a CUDA unified-memory pool."""
|
|
196
|
-
unified = _cuda_uma(facts) or facts["ram"]["total_bytes"]
|
|
197
|
-
nvidia = [
|
|
198
|
-
g
|
|
199
|
-
for g in facts.get("gpus") or []
|
|
200
|
-
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
201
|
-
]
|
|
202
|
-
first_free = nvidia[0]["free_bytes"] if nvidia else 0
|
|
203
|
-
_, ram_avail = budget.host_ram(facts)
|
|
204
|
-
free = _cuda_uma_budget_bytes(min(unified, first_free + ram_avail))
|
|
205
|
-
return free, max(0, unified - _cuda_uma_budget_bytes(unified))
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def pool_total(facts: HostFacts, pool: str) -> int:
|
|
209
|
-
index = gpu_index(pool)
|
|
210
|
-
if index is not None:
|
|
211
|
-
return next(g["total_bytes"] for g in facts["gpus"] if g["index"] == index)
|
|
212
|
-
if pool == "unified":
|
|
213
|
-
if (unified := _cuda_uma(facts)) is not None:
|
|
214
|
-
return _cuda_uma_budget_bytes(unified)
|
|
215
|
-
return max(
|
|
216
|
-
0,
|
|
217
|
-
facts["ram"]["total_bytes"]
|
|
218
|
-
- (metal.soft_host_keep_bytes(facts) + METAL_VRAM_RESERVE_BYTES),
|
|
219
|
-
)
|
|
220
|
-
return int(facts["ram"]["total_bytes"] * POOL_RAM_FRACTION)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def _unified_live(facts: HostFacts) -> tuple[int, int]:
|
|
224
|
-
"""(free_bytes, reserve_bytes) on a unified pool (Metal soft budget or CUDA UMA)."""
|
|
225
|
-
if _cuda_uma(facts) is not None:
|
|
226
|
-
return _cuda_uma_live(facts)
|
|
227
|
-
adm = budget.admission_budget(facts, "unified")
|
|
228
|
-
base_reserve = metal.soft_host_keep_bytes(facts) + METAL_VRAM_RESERVE_BYTES
|
|
229
|
-
return (adm.soft_budget_bytes, adm.reserve_bytes) if adm is not None else (0, base_reserve)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
def pool_free(facts: HostFacts, pool: str) -> int:
|
|
233
|
-
index = gpu_index(pool)
|
|
234
|
-
if index is not None:
|
|
235
|
-
return next(g["free_bytes"] for g in facts["gpus"] if g["index"] == index)
|
|
236
|
-
if pool == "unified":
|
|
237
|
-
return _unified_live(facts)[0]
|
|
238
|
-
used = facts["ram"]["total_bytes"] - facts["ram"]["available_bytes"]
|
|
239
|
-
return max(0, pool_total(facts, pool) - used)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def pool_reserve(facts: HostFacts, pool: str) -> int:
|
|
243
|
-
"""Memory kept back from models on ``pool`` for OS, display, or safety margins."""
|
|
244
|
-
if gpu_index(pool) is not None:
|
|
245
|
-
return AGENT_VRAM_RESERVE_BYTES
|
|
246
|
-
if pool == "unified":
|
|
247
|
-
return _unified_live(facts)[1]
|
|
248
|
-
return max(0, facts["ram"]["total_bytes"] - pool_total(facts, pool))
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
def pool_of(plan: Plan) -> str:
|
|
252
|
-
"""The pool a deployment plan runs in: its card, unified memory, else RAM."""
|
|
253
|
-
placement: dict[str, Any] = dict(plan.get("placement") or {})
|
|
254
|
-
gpus: list[dict[str, Any]] = list(placement.get("gpus") or [])
|
|
255
|
-
if placement.get("id") == "host" or (gpus and gpus[0].get("uuid") == metal.METAL_UUID):
|
|
256
|
-
return "unified"
|
|
257
|
-
if gpus:
|
|
258
|
-
return f"gpu:{gpus[0]['index']}"
|
|
259
|
-
return "system"
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def capacity(facts: HostFacts, *, reclaimable: Mapping[str, int] | None = None) -> HostFacts:
|
|
263
|
-
"""``facts`` at loadable capacity once loaded library models are unloaded: keeps macOS's
|
|
264
|
-
idle baseline (``metal.in_use``) on Apple Silicon and observed desktop/WDDM baseline VRAM
|
|
265
|
-
on Windows and display-active GPUs instead of pretending zero OS/desktop overhead."""
|
|
266
|
-
seen = copy.deepcopy(facts)
|
|
267
|
-
for gpu in seen.get("gpus") or []:
|
|
268
|
-
free = library_vram.gpu_capacity_free(
|
|
269
|
-
facts, gpu, reclaimable, DESKTOP_VRAM_BASELINE_CAP_BYTES
|
|
270
|
-
)
|
|
271
|
-
gpu["free_bytes"], gpu["used_bytes"] = free, max(0, gpu["total_bytes"] - free)
|
|
272
|
-
ram = seen["ram"]
|
|
273
|
-
if metal.supported(seen):
|
|
274
|
-
total = ram["total_bytes"]
|
|
275
|
-
idle = max(0, total - metal.in_use(total))
|
|
276
|
-
ram["available_bytes"] = min(total, max(ram["available_bytes"], idle))
|
|
277
|
-
if ram.get("pressure_level") is not None:
|
|
278
|
-
ram["pressure_level"] = 1
|
|
279
|
-
ram.pop("pressure_kept_bytes", None)
|
|
280
|
-
else:
|
|
281
|
-
ram["available_bytes"] = ram["total_bytes"]
|
|
282
|
-
if cgroup := seen.get("cgroup_memory"):
|
|
283
|
-
cgroup["usage_bytes"] = 0
|
|
284
|
-
seen["llama_servers"] = []
|
|
285
|
-
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
286
|
-
if services := seen.get("services"):
|
|
287
|
-
services["compute_processes"], services["containers"] = [], []
|
|
288
|
-
services["systemd_units"] = []
|
|
289
|
-
return seen
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
def live(
|
|
293
|
-
facts: HostFacts, reserved: dict[str, int], freed: dict[str, int] | None = None
|
|
294
|
-
) -> HostFacts:
|
|
295
|
-
"""``facts`` less what loading models reserved and plus what ``freed`` gives back, per pool;
|
|
296
|
-
ports and disk are left to the load (a download plan is not bound to them)."""
|
|
297
|
-
seen = copy.deepcopy(facts)
|
|
298
|
-
change = dict(reserved)
|
|
299
|
-
for pool, n in (freed or {}).items():
|
|
300
|
-
change[pool] = change.get(pool, 0) - n
|
|
301
|
-
for gpu in seen.get("gpus") or []:
|
|
302
|
-
delta = change.get(f"gpu:{gpu['index']}", 0)
|
|
303
|
-
gpu["free_bytes"] = max(0, min(gpu["total_bytes"], gpu["free_bytes"] - delta))
|
|
304
|
-
ram = seen["ram"]
|
|
305
|
-
unified_delta = change.get("unified", 0)
|
|
306
|
-
system_delta = change.get("system", 0)
|
|
307
|
-
if (unified := _cuda_uma(seen)) is not None and unified_delta:
|
|
308
|
-
nvidia = [
|
|
309
|
-
g
|
|
310
|
-
for g in seen.get("gpus") or []
|
|
311
|
-
if g.get("vendor") == "nvidia" and g.get("mig_mode") != "enabled"
|
|
312
|
-
]
|
|
313
|
-
first = nvidia[0] if nvidia else None
|
|
314
|
-
first_free = first["free_bytes"] if first is not None else 0
|
|
315
|
-
current_live = min(unified, first_free + ram["available_bytes"])
|
|
316
|
-
scaled = int(round(unified_delta / (1 - budget._UMA_HEADROOM_FRACTION)))
|
|
317
|
-
target = max(0, min(unified, current_live - scaled))
|
|
318
|
-
if first is not None and first_free > target:
|
|
319
|
-
first["free_bytes"], ram["available_bytes"] = target, 0
|
|
320
|
-
else:
|
|
321
|
-
ram["available_bytes"] = max(0, min(ram["total_bytes"], target - first_free))
|
|
322
|
-
if system_delta:
|
|
323
|
-
ram["available_bytes"] = max(
|
|
324
|
-
0, min(ram["total_bytes"], ram["available_bytes"] - system_delta)
|
|
325
|
-
)
|
|
326
|
-
else:
|
|
327
|
-
delta = unified_delta + system_delta
|
|
328
|
-
ram["available_bytes"] = max(0, min(ram["total_bytes"], ram["available_bytes"] - delta))
|
|
329
|
-
if metal.supported(seen) and unified_delta:
|
|
330
|
-
gpu_reading = metal.gpu_in_use_reading(seen)
|
|
331
|
-
metal_doc = seen.get("metal")
|
|
332
|
-
if isinstance(metal_doc, dict):
|
|
333
|
-
cur_in_use = metal.gpu_in_use_bytes(seen)
|
|
334
|
-
metal_doc["gpu_in_use_bytes"] = max(0, cur_in_use + unified_delta)
|
|
335
|
-
wired_ram = ram.get("wired_bytes")
|
|
336
|
-
if isinstance(wired_ram, int) and not isinstance(wired_ram, bool) and wired_ram >= 0:
|
|
337
|
-
wired_delta = (
|
|
338
|
-
max(unified_delta, -gpu_reading)
|
|
339
|
-
if unified_delta < 0 and gpu_reading is not None
|
|
340
|
-
else unified_delta
|
|
341
|
-
)
|
|
342
|
-
ram["wired_bytes"] = max(0, min(ram["total_bytes"], wired_ram + wired_delta))
|
|
343
|
-
seen["llama_servers"] = []
|
|
344
|
-
seen["disk"] = {**seen["disk"], "free_bytes": None}
|
|
345
|
-
return seen
|
|
346
|
-
|
|
347
|
-
|
|
348
131
|
# ---------------------------------------------------------------------------- pricing
|
|
349
132
|
|
|
350
133
|
|
|
@@ -359,83 +142,13 @@ def host_ram_bytes(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int:
|
|
|
359
142
|
min_cache_bytes = (
|
|
360
143
|
(posture().prompt_cache_min_mib << 20) if posture().prompt_cache_mib > 0 else 0
|
|
361
144
|
)
|
|
362
|
-
return
|
|
145
|
+
return llm_ram.own_bytes(plan, catalog, running=False, metal=False) + min_cache_bytes
|
|
363
146
|
|
|
364
147
|
|
|
365
148
|
def _required_host_ram(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int:
|
|
366
149
|
return host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
|
|
367
150
|
|
|
368
151
|
|
|
369
|
-
def _project_cuda_uma(
|
|
370
|
-
facts: HostFacts, unified: int, target: int, *, bypass_working_set: bool
|
|
371
|
-
) -> HostFacts:
|
|
372
|
-
seen = copy.deepcopy(facts)
|
|
373
|
-
need = target + AGENT_VRAM_RESERVE_BYTES
|
|
374
|
-
raw = int(math.ceil(need / (1 - budget._UMA_HEADROOM_FRACTION)))
|
|
375
|
-
while int(raw * (1 - budget._UMA_HEADROOM_FRACTION)) < need:
|
|
376
|
-
raw += 1
|
|
377
|
-
raw = raw if bypass_working_set else min(unified, raw)
|
|
378
|
-
if bypass_working_set and isinstance(cuda_pool := seen.get("cuda_pool"), dict):
|
|
379
|
-
cuda_pool["total_bytes"], cuda_pool["integrated"] = max(unified, raw), True
|
|
380
|
-
for gpu in seen.get("gpus") or []:
|
|
381
|
-
if gpu.get("vendor") == "nvidia" and gpu.get("mig_mode") != "enabled":
|
|
382
|
-
gpu["free_bytes"], gpu["used_bytes"] = 0, gpu["total_bytes"]
|
|
383
|
-
break
|
|
384
|
-
ram = seen["ram"]
|
|
385
|
-
if bypass_working_set:
|
|
386
|
-
ram["total_bytes"] = max(int(ram["total_bytes"]), raw)
|
|
387
|
-
if (cgroup := seen.get("cgroup_memory")) is not None:
|
|
388
|
-
if (limit := cgroup.get("limit_bytes")) is not None and limit < raw:
|
|
389
|
-
cgroup["limit_bytes"] = raw
|
|
390
|
-
cgroup["usage_bytes"] = 0
|
|
391
|
-
ram["available_bytes"] = min(int(ram["total_bytes"]), raw)
|
|
392
|
-
return seen
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
def facts_for_budget(
|
|
396
|
-
facts: HostFacts,
|
|
397
|
-
pool: str,
|
|
398
|
-
target_bytes: int,
|
|
399
|
-
*,
|
|
400
|
-
wired_cap_bytes: int | None = None,
|
|
401
|
-
bypass_working_set: bool = False,
|
|
402
|
-
) -> HostFacts:
|
|
403
|
-
"""Project ``facts`` so ``deploy.build_plan`` prices ``pool`` against ``target_bytes``
|
|
404
|
-
(unified/total) and optional ``wired_cap_bytes`` (Metal GPU wired headroom)."""
|
|
405
|
-
target = max(0, target_bytes)
|
|
406
|
-
if pool == "unified" and metal.supported(facts):
|
|
407
|
-
seen = copy.deepcopy(facts)
|
|
408
|
-
ram = seen["ram"]
|
|
409
|
-
needed_avail = target + metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
|
|
410
|
-
ram["available_bytes"] = (
|
|
411
|
-
needed_avail if bypass_working_set else min(int(ram["total_bytes"]), needed_avail)
|
|
412
|
-
)
|
|
413
|
-
ram["pressure_level"] = metal.PRESSURE_NORMAL
|
|
414
|
-
ram.pop("pressure_kept_bytes", None)
|
|
415
|
-
if isinstance(metal_doc := seen.get("metal"), dict):
|
|
416
|
-
ceiling = (
|
|
417
|
-
max(0, wired_cap_bytes) + METAL_VRAM_RESERVE_BYTES
|
|
418
|
-
if wired_cap_bytes is not None
|
|
419
|
-
else max(metal.wired_ceiling_bytes(facts), target + METAL_VRAM_RESERVE_BYTES)
|
|
420
|
-
if bypass_working_set
|
|
421
|
-
else metal.wired_ceiling_bytes(facts)
|
|
422
|
-
)
|
|
423
|
-
metal_doc["recommended_max_working_set_bytes"] = ceiling
|
|
424
|
-
return seen
|
|
425
|
-
if pool == "unified" and (unified := budget.unified_pool_bytes(facts)) is not None:
|
|
426
|
-
return _project_cuda_uma(facts, unified, target, bypass_working_set=bypass_working_set)
|
|
427
|
-
if (idx := gpu_index(pool)) is not None:
|
|
428
|
-
seen = copy.deepcopy(facts)
|
|
429
|
-
for gpu in seen.get("gpus") or []:
|
|
430
|
-
if gpu["index"] == idx:
|
|
431
|
-
free = target + AGENT_VRAM_RESERVE_BYTES
|
|
432
|
-
gpu["free_bytes"] = free if bypass_working_set else min(gpu["total_bytes"], free)
|
|
433
|
-
gpu["used_bytes"] = max(0, gpu["total_bytes"] - gpu["free_bytes"])
|
|
434
|
-
break
|
|
435
|
-
return seen
|
|
436
|
-
return facts
|
|
437
|
-
|
|
438
|
-
|
|
439
152
|
def validate_plan_bounds(
|
|
440
153
|
facts: HostFacts,
|
|
441
154
|
model: Model,
|
|
@@ -448,8 +161,8 @@ def validate_plan_bounds(
|
|
|
448
161
|
) -> None:
|
|
449
162
|
"""Reject a plan exceeding ``pool``'s total capacity or host RAM on a discrete GPU."""
|
|
450
163
|
if check_pool_total:
|
|
451
|
-
total = pool_total(facts, pool)
|
|
452
|
-
used = memory_bytes(plan)
|
|
164
|
+
total = memory_pools.pool_total(facts, pool)
|
|
165
|
+
used = memory_pools.memory_bytes(plan)
|
|
453
166
|
if used > total:
|
|
454
167
|
refused = PhysicsRefusal(
|
|
455
168
|
needed_bytes=used,
|
|
@@ -461,8 +174,8 @@ def validate_plan_bounds(
|
|
|
461
174
|
refused,
|
|
462
175
|
"unified memory" if pool == "unified" else "GPU memory",
|
|
463
176
|
)
|
|
464
|
-
if check_host_ram and gpu_index(pool) is not None:
|
|
465
|
-
needed_ram =
|
|
177
|
+
if check_host_ram and memory_pools.gpu_index(pool) is not None:
|
|
178
|
+
needed_ram = _required_host_ram(plan, catalog)
|
|
466
179
|
_, avail_ram = budget.host_ram(facts)
|
|
467
180
|
if needed_ram > avail_ram:
|
|
468
181
|
refused = PhysicsRefusal(
|
|
@@ -487,7 +200,7 @@ def price(
|
|
|
487
200
|
require_live: bool = False,
|
|
488
201
|
) -> Plan:
|
|
489
202
|
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there."""
|
|
490
|
-
placement = pools(facts).get(pool)
|
|
203
|
+
placement = memory_pools.pools(facts).get(pool)
|
|
491
204
|
if placement is None:
|
|
492
205
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
493
206
|
if library_kept.retired(model.entry):
|
|
@@ -501,7 +214,7 @@ def price(
|
|
|
501
214
|
raise LiveMemoryUnavailable(problem)
|
|
502
215
|
adm = budget.admission_budget(facts, "unified")
|
|
503
216
|
if adm is not None:
|
|
504
|
-
facts = facts_for_budget(
|
|
217
|
+
facts = memory_pools.facts_for_budget(
|
|
505
218
|
facts, "unified", adm.soft_budget_bytes, wired_cap_bytes=adm.wired_headroom_bytes
|
|
506
219
|
)
|
|
507
220
|
else:
|
|
@@ -529,12 +242,6 @@ def price(
|
|
|
529
242
|
return plan
|
|
530
243
|
|
|
531
244
|
|
|
532
|
-
def memory_bytes(plan: Plan) -> int:
|
|
533
|
-
launch = plan["launch"]
|
|
534
|
-
value = launch.get("unified_bytes") or launch.get("vram_bytes") or 0
|
|
535
|
-
return int(str(value))
|
|
536
|
-
|
|
537
|
-
|
|
538
245
|
@dataclass
|
|
539
246
|
class Priced:
|
|
540
247
|
"""A model against this computer: fit, the pool it would take, and its plan there."""
|
|
@@ -558,7 +265,7 @@ def _min_pool_need(model: Model, pool: str, exc: deploy.AgentMemoryError, facts:
|
|
|
558
265
|
to zero inside ``agent_budget`` or ``vision.priced``."""
|
|
559
266
|
if model.entry.runtime == "strata-poly":
|
|
560
267
|
return exc.needed_bytes
|
|
561
|
-
if gpu_index(pool) is not None:
|
|
268
|
+
if memory_pools.gpu_index(pool) is not None:
|
|
562
269
|
return exc.needed_bytes + AGENT_VRAM_RESERVE_BYTES
|
|
563
270
|
if pool == "unified" and metal.supported(facts):
|
|
564
271
|
profile = model.entry.profile(model.variant)
|
|
@@ -586,10 +293,10 @@ def _live_plan(
|
|
|
586
293
|
*,
|
|
587
294
|
fallback_need: int = 0,
|
|
588
295
|
) -> tuple[Plan | None, int, int]:
|
|
589
|
-
now = live(facts, reserved)
|
|
590
|
-
if pool not in pools(now):
|
|
296
|
+
now = memory_pools.live(facts, reserved)
|
|
297
|
+
if pool not in memory_pools.pools(now):
|
|
591
298
|
return None, max(fallback_need, 1), 0
|
|
592
|
-
free = pool_free(now, pool)
|
|
299
|
+
free = memory_pools.pool_free(now, pool)
|
|
593
300
|
try:
|
|
594
301
|
plan = price(now, model, pool, base_dir, catalog, require_live=True)
|
|
595
302
|
except deploy.AgentMemoryError as exc:
|
|
@@ -636,8 +343,11 @@ def judge(
|
|
|
636
343
|
reclaimable: Mapping[str, int] | None = None,
|
|
637
344
|
) -> Priced:
|
|
638
345
|
"""Fit on loadable capacity; pick the freest card that fits live, else capacity, else unified."""
|
|
639
|
-
cap, now =
|
|
640
|
-
|
|
346
|
+
cap, now = (
|
|
347
|
+
memory_pools.capacity(facts, reclaimable=reclaimable),
|
|
348
|
+
memory_pools.live(facts, reserved),
|
|
349
|
+
)
|
|
350
|
+
order = sorted(memory_pools.pools(facts), key=lambda p: -memory_pools.pool_free(now, p))
|
|
641
351
|
fallback: Priced | None = None
|
|
642
352
|
shortfall: tuple[int, int, str] | None = None
|
|
643
353
|
blocker: Reason | None = None
|
|
@@ -663,7 +373,13 @@ def judge(
|
|
|
663
373
|
continue
|
|
664
374
|
fit = "unified" if pool == "unified" else "gpu"
|
|
665
375
|
live_plan, load_need, load_free = _live_plan(
|
|
666
|
-
facts,
|
|
376
|
+
facts,
|
|
377
|
+
model,
|
|
378
|
+
pool,
|
|
379
|
+
base_dir,
|
|
380
|
+
catalog,
|
|
381
|
+
reserved,
|
|
382
|
+
fallback_need=memory_pools.memory_bytes(plan),
|
|
667
383
|
)
|
|
668
384
|
if live_plan is not None:
|
|
669
385
|
return Priced(fit, pool, live_plan, True, load_free_bytes=load_free)
|
|
@@ -678,7 +394,7 @@ def judge(
|
|
|
678
394
|
blocker is None
|
|
679
395
|
and memory_kind == "vram"
|
|
680
396
|
and need > have
|
|
681
|
-
and
|
|
397
|
+
and memory_pools.fits_idle_desktop(
|
|
682
398
|
facts, cap, order, lambda f, p: price(f, model, p, base_dir, catalog)
|
|
683
399
|
)
|
|
684
400
|
)
|
|
@@ -725,9 +441,9 @@ def missing_bytes(plan: Plan) -> int:
|
|
|
725
441
|
|
|
726
442
|
|
|
727
443
|
def _gpu_unsupported_reason(facts: HostFacts) -> Reason | None:
|
|
728
|
-
if any(p != "system" for p in pools(facts)):
|
|
444
|
+
if any(p != "system" for p in memory_pools.pools(facts)):
|
|
729
445
|
return None
|
|
730
|
-
if visible(facts) == set() and any(
|
|
446
|
+
if memory_pools.visible(facts) == set() and any(
|
|
731
447
|
g.get("vendor") == "nvidia" for g in facts.get("gpus") or []
|
|
732
448
|
):
|
|
733
449
|
return None
|
|
@@ -772,7 +488,7 @@ def download_reason(facts: HostFacts, priced: Priced, disk_free: int) -> Reason
|
|
|
772
488
|
def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, str] | None:
|
|
773
489
|
"""Best live-fitting llama.cpp library model ranked by ``llm_rank.choose()``."""
|
|
774
490
|
catalog = entries()
|
|
775
|
-
pool_map = pools(facts)
|
|
491
|
+
pool_map = memory_pools.pools(facts)
|
|
776
492
|
live_pools = [p for p in pool_map if p != "system"]
|
|
777
493
|
if not live_pools:
|
|
778
494
|
return None
|
|
@@ -799,7 +515,7 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
|
|
|
799
515
|
)
|
|
800
516
|
is_fb = llm_rank.windows_fallback(model.entry, facts)
|
|
801
517
|
score = 0 if (is_fb or llm_rank.mac_rung(model.entry, facts)) else model.entry.quality
|
|
802
|
-
ranked.append(((score, tok_s), model.entry.id, gpu_index(pool) or 0))
|
|
518
|
+
ranked.append(((score, tok_s), model.entry.id, memory_pools.gpu_index(pool) or 0))
|
|
803
519
|
by_id[model.entry.id] = model
|
|
804
520
|
if is_fb:
|
|
805
521
|
fallback_ids.add(model.entry.id)
|
|
@@ -823,7 +539,7 @@ def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple
|
|
|
823
539
|
"""(catalog id, quant) of the smartest live library pick; falls back to library models when
|
|
824
540
|
``stack`` selects Strata/PolyStrata or on CUDA unified-memory hosts."""
|
|
825
541
|
seen = copy.deepcopy(facts)
|
|
826
|
-
if (shown_cards := visible(facts)) is not None:
|
|
542
|
+
if (shown_cards := memory_pools.visible(facts)) is not None:
|
|
827
543
|
seen["gpus"] = [g for g in seen.get("gpus") or [] if g["index"] in shown_cards]
|
|
828
544
|
try:
|
|
829
545
|
view = stack_hardware.view(seen, default_options(), posture())
|
|
@@ -837,7 +553,7 @@ def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple
|
|
|
837
553
|
pick["id"] not in library_poly.strata_ids() or library_poly.in_library(pick["id"], seen)
|
|
838
554
|
):
|
|
839
555
|
return (pick["id"], pick["quant"])
|
|
840
|
-
if pick is not None or
|
|
556
|
+
if pick is not None or memory_pools.cuda_uma_bytes(seen) is not None:
|
|
841
557
|
return _smartest_library_fallback(seen, base_dir)
|
|
842
558
|
return None
|
|
843
559
|
|
|
@@ -882,7 +598,7 @@ def floor_metadata(
|
|
|
882
598
|
effective_shortfall = 0 if memory_kind == "ram" else shortfall_bytes
|
|
883
599
|
return max(effective_shortfall, floor_bytes), window, vision_on, download
|
|
884
600
|
metal_unified = metal.supported(facts)
|
|
885
|
-
cuda_uma =
|
|
601
|
+
cuda_uma = memory_pools.cuda_uma_bytes(facts) is not None
|
|
886
602
|
active = model.entry.agent_posture(
|
|
887
603
|
context_policy.posture_for(posture(), "metal" if metal_unified else "cuda")
|
|
888
604
|
)
|
|
@@ -48,6 +48,7 @@ from localmodels.library_elastic import ElasticPlan, ElasticRoomError
|
|
|
48
48
|
from localmodels.library_model import LibraryError, LoadStep, Row, problem_from_error, progress
|
|
49
49
|
from localmodels.library_pricing import Model
|
|
50
50
|
from localmodels.library_state import Job, JobHandle, LoadPosture, PostureSnapshot, Record
|
|
51
|
+
from localmodels.planning import memory_pools
|
|
51
52
|
from localmodels.probe import HostFacts
|
|
52
53
|
from localmodels.records import FinishedRecord, Plan
|
|
53
54
|
from localmodels.transport import Executor
|
|
@@ -253,7 +254,7 @@ def _room(
|
|
|
253
254
|
ctx: int | None = None,
|
|
254
255
|
) -> ElasticPlan:
|
|
255
256
|
"""LOAD_NO_ROOM unless the model fits its pool under dual-tier admission after ``freed``."""
|
|
256
|
-
now =
|
|
257
|
+
now = memory_pools.live(facts, _reserved(model.id), freed)
|
|
257
258
|
use_jinja, _ = _custom_flags(record)
|
|
258
259
|
try:
|
|
259
260
|
return library_elastic.price_elastic(
|
|
@@ -274,7 +275,7 @@ def _room(
|
|
|
274
275
|
except engines.EngineUnavailableError as exc:
|
|
275
276
|
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc)) from None
|
|
276
277
|
except plan_envelope.PlanError as exc: # its pool is gone, hidden, or under critical pressure
|
|
277
|
-
need = record.get("memory_bytes") or
|
|
278
|
+
need = record.get("memory_bytes") or memory_pools.memory_bytes(record["plan"])
|
|
278
279
|
raise LibraryError(
|
|
279
280
|
"LOAD_NO_ROOM", str(exc), pool=record["pool"], need_bytes=need, free_bytes=0
|
|
280
281
|
) from None
|
|
@@ -401,7 +402,7 @@ def _serve_elastic_plan(
|
|
|
401
402
|
"""Price the elastic plan for ``_serve``, demoting GPU-resident speech first when tight."""
|
|
402
403
|
|
|
403
404
|
def price(seen: HostFacts) -> ElasticPlan:
|
|
404
|
-
now =
|
|
405
|
+
now = memory_pools.live(seen, _reserved(model.id))
|
|
405
406
|
return library_elastic.price_elastic(
|
|
406
407
|
now,
|
|
407
408
|
model,
|
|
@@ -432,7 +433,7 @@ def _serve_elastic_plan(
|
|
|
432
433
|
except engines.EngineUnavailableError as exc:
|
|
433
434
|
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc), failed=True) from None
|
|
434
435
|
except library_pricing.LiveMemoryUnavailable as exc:
|
|
435
|
-
need = record.get("memory_bytes") or
|
|
436
|
+
need = record.get("memory_bytes") or memory_pools.memory_bytes(record["plan"])
|
|
436
437
|
raise _fail(
|
|
437
438
|
record,
|
|
438
439
|
LibraryError(
|
|
@@ -510,7 +511,7 @@ def _next_oom_rung(
|
|
|
510
511
|
"""Build the plan for posture rung ``next_index`` after an OOM failure on rung ``k``."""
|
|
511
512
|
if ctx.elastic is None or not ctx.elastic.ladder or next_index >= len(ctx.elastic.ladder):
|
|
512
513
|
return None
|
|
513
|
-
now =
|
|
514
|
+
now = memory_pools.live(facts, _reserved(model.id))
|
|
514
515
|
try:
|
|
515
516
|
next_elastic = library_elastic.price_elastic(
|
|
516
517
|
now,
|
|
@@ -671,8 +672,8 @@ def _admit(
|
|
|
671
672
|
if not library_status.answering(str(target["plan"]["endpoint"]["base_url"])):
|
|
672
673
|
continue
|
|
673
674
|
pool = target["pool"]
|
|
674
|
-
freed[pool] = freed.get(pool, 0) +
|
|
675
|
-
if
|
|
675
|
+
freed[pool] = freed.get(pool, 0) + memory_pools.memory_bytes(target["plan"])
|
|
676
|
+
if memory_pools.gpu_index(pool) is not None:
|
|
676
677
|
freed["system"] = freed.get("system", 0) + library_pricing.host_ram_bytes(
|
|
677
678
|
target["plan"], catalog
|
|
678
679
|
)
|
|
@@ -742,7 +743,7 @@ def load(
|
|
|
742
743
|
if other != model.id and found is not None and found["state"] != "idle":
|
|
743
744
|
targets.append(found)
|
|
744
745
|
_admit(model, record, targets, facts, load_ctx)
|
|
745
|
-
memory = record.get("memory_bytes") or
|
|
746
|
+
memory = record.get("memory_bytes") or memory_pools.memory_bytes(record["plan"])
|
|
746
747
|
port = _port(facts) # reserved with the claim: no concurrent load takes it too
|
|
747
748
|
claims = [library_state.acquire("load", model.id, record["pool"], memory, [], port=port)]
|
|
748
749
|
for target in targets:
|
|
@@ -20,6 +20,7 @@ from pathlib import Path
|
|
|
20
20
|
from localmodels import (
|
|
21
21
|
app,
|
|
22
22
|
custom_hub,
|
|
23
|
+
draft_spec,
|
|
23
24
|
hosts,
|
|
24
25
|
library_jobs,
|
|
25
26
|
library_pricing,
|
|
@@ -99,8 +100,14 @@ def _build_smoke_plan(
|
|
|
99
100
|
*,
|
|
100
101
|
use_jinja: bool,
|
|
101
102
|
) -> Plan:
|
|
102
|
-
"""Build an ephemeral loopback smoke-test plan derived from ``record['plan']
|
|
103
|
+
"""Build an ephemeral loopback smoke-test plan derived from ``record['plan']``; an optional
|
|
104
|
+
drafter not verified in place is left out, as a load leaves it out."""
|
|
103
105
|
plan = copy.deepcopy(record["plan"])
|
|
106
|
+
if not any(
|
|
107
|
+
f["dest"] == draft_spec.drafter_dest(plan) and plan_envelope.verified_in_place(f)
|
|
108
|
+
for f in plan["files"]
|
|
109
|
+
):
|
|
110
|
+
plan = draft_spec.without_drafter(plan)
|
|
104
111
|
token_id = uuid.uuid4().hex[:10]
|
|
105
112
|
smoke_name = f"smoke-{token_id}"
|
|
106
113
|
base = base_dir.rstrip("/")
|