@simplexai/localmodels-win32-x64 0.1.0-dev.58 → 0.1.0-dev.60
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 -98
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +104 -43
- package/modules/localmodels/app.py +1 -1
- package/modules/localmodels/apple_sensors.py +431 -0
- package/modules/localmodels/bifrost_admin.py +83 -8
- package/modules/localmodels/bifrost_checks.py +2 -2
- package/modules/localmodels/bifrost_config.py +235 -13
- package/modules/localmodels/bifrost_log.py +166 -0
- package/modules/localmodels/bifrost_models.py +1 -1
- package/modules/localmodels/budget.py +1 -1
- package/modules/localmodels/catalog.json +192 -77
- package/modules/localmodels/catalog.py +20 -3
- package/modules/localmodels/catalog_add.py +42 -11
- package/modules/localmodels/custom_hub.py +983 -0
- package/modules/localmodels/custom_hub_http.py +579 -0
- package/modules/localmodels/custom_probe.py +451 -0
- package/modules/localmodels/deploy.py +27 -5
- package/modules/localmodels/deploy_steps.py +5 -0
- package/modules/localmodels/download-mirrors.json +8 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +131 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.6.json +94 -0
- package/modules/localmodels/engines.py +38 -8
- package/modules/localmodels/estimator.py +60 -7
- package/modules/localmodels/frontend.py +26 -21
- package/modules/localmodels/gateway.py +48 -3
- package/modules/localmodels/gateway_app_bifrost.py +4 -4
- package/modules/localmodels/gateway_bifrost.py +128 -21
- package/modules/localmodels/gguf.py +6 -0
- package/modules/localmodels/host_sensors.py +704 -0
- package/modules/localmodels/hosts.py +99 -12
- package/modules/localmodels/library_cli.py +181 -3
- package/modules/localmodels/library_convert.py +34 -0
- package/modules/localmodels/library_custom.py +831 -0
- package/modules/localmodels/library_elastic.py +182 -127
- package/modules/localmodels/library_gateway.py +193 -40
- package/modules/localmodels/library_jobs.py +92 -18
- package/modules/localmodels/library_kept.py +50 -6
- package/modules/localmodels/library_model.py +254 -2
- package/modules/localmodels/library_pricing.py +97 -8
- package/modules/localmodels/library_serve.py +196 -66
- package/modules/localmodels/library_smoke.py +315 -0
- package/modules/localmodels/library_state.py +81 -2
- package/modules/localmodels/library_status.py +144 -8
- package/modules/localmodels/metal.py +1 -1
- package/modules/localmodels/metal_probe.py +4 -4
- package/modules/localmodels/nvml_ctypes.py +431 -0
- package/modules/localmodels/plan_envelope.py +18 -7
- package/modules/localmodels/process_identity_linux.py +39 -0
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +57 -8
- package/modules/localmodels/remote_ops_download.py +205 -53
- package/modules/localmodels/remote_ops_mirrors.py +43 -2
- package/modules/localmodels/remote_ops_ranges.py +2 -5
- package/modules/localmodels/remote_ops_service.py +95 -37
- package/modules/localmodels/remote_ops_verify.py +22 -5
- package/modules/localmodels/runtime-lock.json +19 -19
- package/modules/localmodels/runtime_auth.py +4 -1
- package/modules/localmodels/service_control.py +32 -1
- package/modules/localmodels/service_wiring.py +237 -12
- package/modules/localmodels/service_worker.py +6 -2
- package/modules/localmodels/services_cli.py +35 -27
- 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 +9 -7
- 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 +18 -2
- package/modules/localmodels/stack_lifecycle.py +26 -3
- package/modules/localmodels/stack_memory.py +1 -0
- 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/stack_view.py +77 -53
- package/modules/localmodels/stack_view_demo.py +36 -5
- package/modules/localmodels/stack_view_events.py +147 -12
- package/modules/localmodels/stack_view_gpu.py +97 -17
- package/modules/localmodels/stack_view_llm.py +15 -0
- package/modules/localmodels/stack_view_measure.py +4 -1
- package/modules/localmodels/stack_view_schema.py +54 -8
- package/modules/localmodels/stack_view_serve.py +40 -3
- package/modules/localmodels/stack_view_slots.py +89 -10
- package/modules/localmodels/stack_view_telemetry.py +163 -0
- package/modules/localmodels/stack_view_text.py +5 -2
- package/modules/localmodels/stack_view_tick.py +658 -0
- package/modules/localmodels/stack_view_words.py +4 -0
- package/modules/localmodels/{strata-poly-serve-0.2.19-poly.1.txt → strata-poly-serve-0.2.20-poly.6.txt} +1 -1
- package/modules/localmodels/suite.py +45 -27
- package/modules/localmodels/telemetry_math.py +538 -0
- package/modules/localmodels/transport.py +13 -2
- package/modules/localmodels/web/view/view.js +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/RECORD +102 -95
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/bifrost_datasheet.py +0 -53
- package/modules/localmodels/bifrost_provider.py +0 -88
- package/modules/localmodels/bifrost_unit.py +0 -99
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +0 -79
- package/modules/localmodels/gateway_switch.py +0 -51
- package/modules/localmodels/library_floor.py +0 -78
- package/modules/localmodels/service_stop.py +0 -52
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev58.dist-info → simplex_localmodels-0.1.0.dev60.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -11,6 +11,7 @@ non-critical VM pressure, admission succeeds at the floor posture with a pressur
|
|
|
11
11
|
from __future__ import annotations
|
|
12
12
|
|
|
13
13
|
import copy
|
|
14
|
+
import math
|
|
14
15
|
from dataclasses import dataclass, replace
|
|
15
16
|
from typing import cast
|
|
16
17
|
|
|
@@ -181,6 +182,32 @@ def elastic_posture_ladder(
|
|
|
181
182
|
return tuple(rungs)
|
|
182
183
|
|
|
183
184
|
|
|
185
|
+
def _project_cuda_uma(
|
|
186
|
+
facts: HostFacts, unified: int, target: int, *, bypass_working_set: bool
|
|
187
|
+
) -> HostFacts:
|
|
188
|
+
seen = copy.deepcopy(facts)
|
|
189
|
+
need = target + AGENT_VRAM_RESERVE_BYTES
|
|
190
|
+
raw = int(math.ceil(need / (1 - budget._UMA_HEADROOM_FRACTION)))
|
|
191
|
+
while int(raw * (1 - budget._UMA_HEADROOM_FRACTION)) < need:
|
|
192
|
+
raw += 1
|
|
193
|
+
raw = raw if bypass_working_set else min(unified, raw)
|
|
194
|
+
if bypass_working_set and isinstance(cuda_pool := seen.get("cuda_pool"), dict):
|
|
195
|
+
cuda_pool["total_bytes"], cuda_pool["integrated"] = max(unified, raw), True
|
|
196
|
+
for gpu in seen.get("gpus") or []:
|
|
197
|
+
if gpu.get("vendor") == "nvidia" and gpu.get("mig_mode") != "enabled":
|
|
198
|
+
gpu["free_bytes"], gpu["used_bytes"] = 0, gpu["total_bytes"]
|
|
199
|
+
break
|
|
200
|
+
ram = seen["ram"]
|
|
201
|
+
if bypass_working_set:
|
|
202
|
+
ram["total_bytes"] = max(int(ram["total_bytes"]), raw)
|
|
203
|
+
if (cgroup := seen.get("cgroup_memory")) is not None:
|
|
204
|
+
if (limit := cgroup.get("limit_bytes")) is not None and limit < raw:
|
|
205
|
+
cgroup["limit_bytes"] = raw
|
|
206
|
+
cgroup["usage_bytes"] = 0
|
|
207
|
+
ram["available_bytes"] = min(int(ram["total_bytes"]), raw)
|
|
208
|
+
return seen
|
|
209
|
+
|
|
210
|
+
|
|
184
211
|
def facts_for_budget(
|
|
185
212
|
facts: HostFacts,
|
|
186
213
|
pool: str,
|
|
@@ -201,16 +228,18 @@ def facts_for_budget(
|
|
|
201
228
|
)
|
|
202
229
|
ram["pressure_level"] = metal.PRESSURE_NORMAL
|
|
203
230
|
ram.pop("pressure_kept_bytes", None)
|
|
204
|
-
metal_doc
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
231
|
+
if isinstance(metal_doc := seen.get("metal"), dict):
|
|
232
|
+
ceiling = (
|
|
233
|
+
max(0, wired_cap_bytes) + METAL_VRAM_RESERVE_BYTES
|
|
234
|
+
if wired_cap_bytes is not None
|
|
235
|
+
else max(metal.wired_ceiling_bytes(facts), target + METAL_VRAM_RESERVE_BYTES)
|
|
236
|
+
if bypass_working_set
|
|
237
|
+
else metal.wired_ceiling_bytes(facts)
|
|
238
|
+
)
|
|
212
239
|
metal_doc["recommended_max_working_set_bytes"] = ceiling
|
|
213
240
|
return seen
|
|
241
|
+
if pool == "unified" and (unified := budget.unified_pool_bytes(facts)) is not None:
|
|
242
|
+
return _project_cuda_uma(facts, unified, target, bypass_working_set=bypass_working_set)
|
|
214
243
|
if (idx := library_pricing.gpu_index(pool)) is not None:
|
|
215
244
|
seen = copy.deepcopy(facts)
|
|
216
245
|
for gpu in seen.get("gpus") or []:
|
|
@@ -349,14 +378,20 @@ def validate_plan_bounds(
|
|
|
349
378
|
raise deploy.AgentMemoryError(refused.message, refused, "system memory")
|
|
350
379
|
|
|
351
380
|
|
|
381
|
+
@dataclass(frozen=True)
|
|
382
|
+
class _PriceCtx:
|
|
383
|
+
facts: HostFacts
|
|
384
|
+
model: Model
|
|
385
|
+
pool: str
|
|
386
|
+
placement: str
|
|
387
|
+
base_dir: str
|
|
388
|
+
catalog: tuple[cat.CatalogEntry, ...]
|
|
389
|
+
port: int
|
|
390
|
+
use_jinja: bool = True
|
|
391
|
+
|
|
392
|
+
|
|
352
393
|
def _price_rung(
|
|
353
|
-
|
|
354
|
-
model: Model,
|
|
355
|
-
pool: str,
|
|
356
|
-
placement: str,
|
|
357
|
-
base_dir: str,
|
|
358
|
-
catalog: tuple[cat.CatalogEntry, ...],
|
|
359
|
-
port: int,
|
|
394
|
+
ctx: _PriceCtx,
|
|
360
395
|
rung_posture: AgentPosture,
|
|
361
396
|
*,
|
|
362
397
|
budget_bytes: int,
|
|
@@ -366,8 +401,8 @@ def _price_rung(
|
|
|
366
401
|
bypass_working_set: bool = False,
|
|
367
402
|
) -> Plan:
|
|
368
403
|
priced_facts = facts_for_budget(
|
|
369
|
-
facts,
|
|
370
|
-
pool,
|
|
404
|
+
ctx.facts,
|
|
405
|
+
ctx.pool,
|
|
371
406
|
budget_bytes,
|
|
372
407
|
wired_cap_bytes=wired_cap_bytes,
|
|
373
408
|
bypass_working_set=bypass_working_set,
|
|
@@ -376,24 +411,25 @@ def _price_rung(
|
|
|
376
411
|
hosts.LOCAL_ID,
|
|
377
412
|
priced_facts,
|
|
378
413
|
deploy.PlanOptions(
|
|
379
|
-
model_id=model.entry.id,
|
|
380
|
-
placement_id=placement,
|
|
381
|
-
port=port,
|
|
382
|
-
base_dir=base_dir,
|
|
414
|
+
model_id=ctx.model.entry.id,
|
|
415
|
+
placement_id=ctx.placement,
|
|
416
|
+
port=ctx.port,
|
|
417
|
+
base_dir=ctx.base_dir,
|
|
383
418
|
hf_download_endpoint=deploy.hf_endpoint(),
|
|
384
419
|
hf_api_endpoint=deploy.hf_endpoint(),
|
|
385
420
|
agent=rung_posture,
|
|
386
|
-
quant=model.variant.quant,
|
|
421
|
+
quant=ctx.model.variant.quant,
|
|
422
|
+
use_jinja=ctx.use_jinja,
|
|
387
423
|
),
|
|
388
|
-
entries=catalog,
|
|
424
|
+
entries=ctx.catalog,
|
|
389
425
|
resolver=deploy.catalog_pins,
|
|
390
426
|
)
|
|
391
427
|
validate_plan_bounds(
|
|
392
|
-
facts,
|
|
393
|
-
model,
|
|
394
|
-
pool,
|
|
428
|
+
ctx.facts,
|
|
429
|
+
ctx.model,
|
|
430
|
+
ctx.pool,
|
|
395
431
|
plan,
|
|
396
|
-
catalog,
|
|
432
|
+
ctx.catalog,
|
|
397
433
|
check_pool_total=check_pool_total,
|
|
398
434
|
check_host_ram=check_host_ram,
|
|
399
435
|
)
|
|
@@ -409,13 +445,7 @@ def _fits_hard_ceiling(plan: Plan, adm: budget.AdmissionBudget) -> bool:
|
|
|
409
445
|
|
|
410
446
|
|
|
411
447
|
def _try_tier1_ladder(
|
|
412
|
-
|
|
413
|
-
model: Model,
|
|
414
|
-
pool: str,
|
|
415
|
-
placement: str,
|
|
416
|
-
base_dir: str,
|
|
417
|
-
catalog: tuple[cat.CatalogEntry, ...],
|
|
418
|
-
port: int,
|
|
448
|
+
ctx: _PriceCtx,
|
|
419
449
|
ladder: tuple[PostureRung, ...],
|
|
420
450
|
requested_spec: PostureSpec,
|
|
421
451
|
adm: budget.AdmissionBudget,
|
|
@@ -428,21 +458,11 @@ def _try_tier1_ladder(
|
|
|
428
458
|
else min(adm.soft_budget_bytes, adm.hard_ceiling_bytes)
|
|
429
459
|
)
|
|
430
460
|
ram_shortfall: deploy.AgentMemoryError | None = None
|
|
431
|
-
|
|
432
|
-
for idx in range(start_idx, len(ladder)):
|
|
461
|
+
for idx in range(max(0, min(min_rung_index, len(ladder))), len(ladder)):
|
|
433
462
|
rung = ladder[idx]
|
|
434
463
|
try:
|
|
435
464
|
plan = _price_rung(
|
|
436
|
-
|
|
437
|
-
model,
|
|
438
|
-
pool,
|
|
439
|
-
placement,
|
|
440
|
-
base_dir,
|
|
441
|
-
catalog,
|
|
442
|
-
port,
|
|
443
|
-
rung.posture,
|
|
444
|
-
budget_bytes=tier1_budget,
|
|
445
|
-
wired_cap_bytes=wired_cap,
|
|
465
|
+
ctx, rung.posture, budget_bytes=tier1_budget, wired_cap_bytes=wired_cap
|
|
446
466
|
)
|
|
447
467
|
except deploy.AgentMemoryError as exc:
|
|
448
468
|
if exc.memory == "system memory":
|
|
@@ -468,14 +488,65 @@ def _try_tier1_ladder(
|
|
|
468
488
|
return None, ram_shortfall
|
|
469
489
|
|
|
470
490
|
|
|
491
|
+
def _force_within_hard_limits(
|
|
492
|
+
adm: budget.AdmissionBudget, min_need: int, min_wired_need: int
|
|
493
|
+
) -> bool:
|
|
494
|
+
"""Whether ``--force`` stays within non-overridable hardware ceilings (non-critical pressure,
|
|
495
|
+
physical memory limit, and on Apple Silicon the kernel/Metal wired ceiling)."""
|
|
496
|
+
if adm.critical_pressure or min_need > adm.physical_limit_bytes:
|
|
497
|
+
return False
|
|
498
|
+
return not (
|
|
499
|
+
adm.backend == "metal"
|
|
500
|
+
and adm.wired_ceiling_bytes is not None
|
|
501
|
+
and min_wired_need > adm.wired_ceiling_bytes
|
|
502
|
+
)
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def _price_forced_floor(
|
|
506
|
+
ctx: _PriceCtx,
|
|
507
|
+
compact_floor: AgentPosture,
|
|
508
|
+
adm: budget.AdmissionBudget,
|
|
509
|
+
min_need: int,
|
|
510
|
+
min_wired_need: int,
|
|
511
|
+
*,
|
|
512
|
+
raise_system_ram: bool = False,
|
|
513
|
+
) -> Plan | None:
|
|
514
|
+
"""Price the compact floor under ``--force`` while enforcing hard physical ceilings."""
|
|
515
|
+
if not _force_within_hard_limits(adm, min_need, min_wired_need):
|
|
516
|
+
return None
|
|
517
|
+
wired_cap = adm.wired_ceiling_bytes if adm.backend == "metal" else None
|
|
518
|
+
try:
|
|
519
|
+
plan = _price_rung(
|
|
520
|
+
ctx,
|
|
521
|
+
compact_floor,
|
|
522
|
+
budget_bytes=adm.physical_limit_bytes,
|
|
523
|
+
wired_cap_bytes=wired_cap,
|
|
524
|
+
check_pool_total=False,
|
|
525
|
+
check_host_ram=True,
|
|
526
|
+
bypass_working_set=True,
|
|
527
|
+
)
|
|
528
|
+
except deploy.AgentMemoryError as exc:
|
|
529
|
+
if raise_system_ram and exc.memory == "system memory":
|
|
530
|
+
raise ElasticRoomError(
|
|
531
|
+
str(exc),
|
|
532
|
+
pool="system",
|
|
533
|
+
need_bytes=exc.needed_bytes,
|
|
534
|
+
free_bytes=exc.available_bytes,
|
|
535
|
+
memory="system memory",
|
|
536
|
+
soft_available_bytes=exc.available_bytes,
|
|
537
|
+
can_force=False,
|
|
538
|
+
) from None
|
|
539
|
+
return None
|
|
540
|
+
wired_ok = (
|
|
541
|
+
adm.backend != "metal"
|
|
542
|
+
or adm.wired_ceiling_bytes is None
|
|
543
|
+
or _vram_bytes(plan) <= adm.wired_ceiling_bytes
|
|
544
|
+
)
|
|
545
|
+
return plan if wired_ok and memory_bytes(plan) <= adm.physical_limit_bytes else None
|
|
546
|
+
|
|
547
|
+
|
|
471
548
|
def _try_floor_admission(
|
|
472
|
-
|
|
473
|
-
model: Model,
|
|
474
|
-
pool: str,
|
|
475
|
-
placement: str,
|
|
476
|
-
base_dir: str,
|
|
477
|
-
catalog: tuple[cat.CatalogEntry, ...],
|
|
478
|
-
port: int,
|
|
549
|
+
ctx: _PriceCtx,
|
|
479
550
|
ladder: tuple[PostureRung, ...],
|
|
480
551
|
compact_floor: AgentPosture,
|
|
481
552
|
requested_spec: PostureSpec,
|
|
@@ -492,19 +563,14 @@ def _try_floor_admission(
|
|
|
492
563
|
allow_overcommit
|
|
493
564
|
and adm.allows_soft_overcommit
|
|
494
565
|
and not adm.critical_pressure
|
|
566
|
+
and adm.pressure_level != metal.PRESSURE_WARN
|
|
495
567
|
and min_rung_index <= floor_idx
|
|
496
568
|
and min_wired_need <= adm.hard_ceiling_bytes
|
|
497
569
|
and min_need <= adm.physical_limit_bytes
|
|
498
570
|
):
|
|
499
571
|
try:
|
|
500
572
|
plan = _price_rung(
|
|
501
|
-
|
|
502
|
-
model,
|
|
503
|
-
pool,
|
|
504
|
-
placement,
|
|
505
|
-
base_dir,
|
|
506
|
-
catalog,
|
|
507
|
-
port,
|
|
573
|
+
ctx,
|
|
508
574
|
compact_floor,
|
|
509
575
|
budget_bytes=adm.physical_limit_bytes,
|
|
510
576
|
wired_cap_bytes=adm.hard_ceiling_bytes,
|
|
@@ -512,12 +578,10 @@ def _try_floor_admission(
|
|
|
512
578
|
except deploy.AgentMemoryError:
|
|
513
579
|
plan = None
|
|
514
580
|
if plan is not None and _fits_hard_ceiling(plan, adm):
|
|
515
|
-
level: MemoryPressureWarningLevel =
|
|
516
|
-
"high" if adm.pressure_level == metal.PRESSURE_WARN else "soft"
|
|
517
|
-
)
|
|
581
|
+
level: MemoryPressureWarningLevel = "soft"
|
|
518
582
|
warning: MemoryPressureWarning = {
|
|
519
583
|
"level": level,
|
|
520
|
-
"pool": pool,
|
|
584
|
+
"pool": ctx.pool,
|
|
521
585
|
"free_bytes": adm.soft_budget_bytes,
|
|
522
586
|
"budget_bytes": adm.hard_ceiling_bytes,
|
|
523
587
|
}
|
|
@@ -533,28 +597,14 @@ def _try_floor_admission(
|
|
|
533
597
|
forced=False,
|
|
534
598
|
admission=adm,
|
|
535
599
|
)
|
|
536
|
-
if force
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
pool,
|
|
542
|
-
placement,
|
|
543
|
-
base_dir,
|
|
544
|
-
catalog,
|
|
545
|
-
port,
|
|
546
|
-
compact_floor,
|
|
547
|
-
budget_bytes=adm.physical_limit_bytes,
|
|
548
|
-
check_pool_total=False,
|
|
549
|
-
check_host_ram=False,
|
|
550
|
-
bypass_working_set=True,
|
|
551
|
-
)
|
|
552
|
-
except deploy.AgentMemoryError:
|
|
553
|
-
plan = None
|
|
554
|
-
if plan is not None and memory_bytes(plan) <= adm.physical_limit_bytes:
|
|
600
|
+
if force:
|
|
601
|
+
plan = _price_forced_floor(
|
|
602
|
+
ctx, compact_floor, adm, min_need, min_wired_need, raise_system_ram=True
|
|
603
|
+
)
|
|
604
|
+
if plan is not None:
|
|
555
605
|
forced_warning: MemoryPressureWarning = {
|
|
556
606
|
"level": "high",
|
|
557
|
-
"pool": pool,
|
|
607
|
+
"pool": ctx.pool,
|
|
558
608
|
"free_bytes": min(adm.soft_budget_bytes, adm.hard_ceiling_bytes),
|
|
559
609
|
"budget_bytes": adm.physical_limit_bytes,
|
|
560
610
|
}
|
|
@@ -573,6 +623,22 @@ def _try_floor_admission(
|
|
|
573
623
|
return None
|
|
574
624
|
|
|
575
625
|
|
|
626
|
+
def _custom_ctx_ladder(
|
|
627
|
+
base: AgentPosture, backend: str, ctx_tokens: int
|
|
628
|
+
) -> tuple[PostureRung, ...]:
|
|
629
|
+
requested = context_policy.posture_for(base, backend)
|
|
630
|
+
pinned = replace(
|
|
631
|
+
requested,
|
|
632
|
+
slots=1,
|
|
633
|
+
floor=ctx_tokens,
|
|
634
|
+
preferred=ctx_tokens,
|
|
635
|
+
target=ctx_tokens,
|
|
636
|
+
prompt_cache_mib=min(requested.prompt_cache_mib, 512),
|
|
637
|
+
prompt_cache_min_mib=min(requested.prompt_cache_min_mib, 512),
|
|
638
|
+
)
|
|
639
|
+
return (PostureRung(pinned, degraded=False, reason=None),)
|
|
640
|
+
|
|
641
|
+
|
|
576
642
|
def price_elastic(
|
|
577
643
|
facts: HostFacts,
|
|
578
644
|
model: Model,
|
|
@@ -584,8 +650,13 @@ def price_elastic(
|
|
|
584
650
|
allow_overcommit: bool = True,
|
|
585
651
|
force: bool = False,
|
|
586
652
|
min_rung_index: int = 0,
|
|
653
|
+
ctx_override: int | None = None,
|
|
654
|
+
use_jinja: bool = True,
|
|
587
655
|
) -> ElasticPlan:
|
|
588
656
|
"""Dual-tier memory admission + elastic posture ladder for loading ``model`` on ``pool``."""
|
|
657
|
+
effective_catalog = (
|
|
658
|
+
catalog if any(e.id == model.entry.id for e in catalog) else (*catalog, model.entry)
|
|
659
|
+
)
|
|
589
660
|
placement = library_pricing.pools(facts).get(pool)
|
|
590
661
|
if placement is None:
|
|
591
662
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -605,24 +676,16 @@ def price_elastic(
|
|
|
605
676
|
require_live=True,
|
|
606
677
|
)
|
|
607
678
|
eff = _plan_posture(poly_plan)
|
|
608
|
-
return ElasticPlan(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
forced=False,
|
|
618
|
-
admission=adm,
|
|
679
|
+
return ElasticPlan(poly_plan, 0, (), eff, eff, False, None, None, False, adm)
|
|
680
|
+
if ctx_override is not None and ctx_override > 0:
|
|
681
|
+
ladder = _custom_ctx_ladder(library_pricing.posture(), adm.backend, ctx_override)
|
|
682
|
+
else:
|
|
683
|
+
ladder = elastic_posture_ladder(
|
|
684
|
+
library_pricing.posture(),
|
|
685
|
+
backend=adm.backend,
|
|
686
|
+
native_ctx=model.entry.n_ctx_train,
|
|
687
|
+
max_agent_window=model.entry.max_agent_window,
|
|
619
688
|
)
|
|
620
|
-
ladder = elastic_posture_ladder(
|
|
621
|
-
library_pricing.posture(),
|
|
622
|
-
backend=adm.backend,
|
|
623
|
-
native_ctx=model.entry.n_ctx_train,
|
|
624
|
-
max_agent_window=model.entry.max_agent_window,
|
|
625
|
-
)
|
|
626
689
|
floor_rung = ladder[-1]
|
|
627
690
|
compact_floor = replace(
|
|
628
691
|
floor_rung.posture, kv_types=(floor_rung.posture.kv_types[-1],), kv_pinned=True
|
|
@@ -651,19 +714,10 @@ def price_elastic(
|
|
|
651
714
|
context_tokens=req_window, slots=req_p.slots, kv_types=req_p.kv_types[0]
|
|
652
715
|
)
|
|
653
716
|
|
|
654
|
-
|
|
655
|
-
facts,
|
|
656
|
-
model,
|
|
657
|
-
pool,
|
|
658
|
-
placement,
|
|
659
|
-
base_dir,
|
|
660
|
-
catalog,
|
|
661
|
-
port,
|
|
662
|
-
ladder,
|
|
663
|
-
requested_spec,
|
|
664
|
-
adm,
|
|
665
|
-
min_rung_index,
|
|
717
|
+
ctx = _PriceCtx(
|
|
718
|
+
facts, model, pool, placement, base_dir, effective_catalog, port, use_jinja=use_jinja
|
|
666
719
|
)
|
|
720
|
+
admitted, ram_shortfall = _try_tier1_ladder(ctx, ladder, requested_spec, adm, min_rung_index)
|
|
667
721
|
if admitted is not None:
|
|
668
722
|
return admitted
|
|
669
723
|
if ram_shortfall is not None:
|
|
@@ -677,13 +731,7 @@ def price_elastic(
|
|
|
677
731
|
can_force=False,
|
|
678
732
|
)
|
|
679
733
|
floor_admitted = _try_floor_admission(
|
|
680
|
-
|
|
681
|
-
model,
|
|
682
|
-
pool,
|
|
683
|
-
placement,
|
|
684
|
-
base_dir,
|
|
685
|
-
catalog,
|
|
686
|
-
port,
|
|
734
|
+
ctx,
|
|
687
735
|
ladder,
|
|
688
736
|
compact_floor,
|
|
689
737
|
requested_spec,
|
|
@@ -698,16 +746,23 @@ def price_elastic(
|
|
|
698
746
|
return floor_admitted
|
|
699
747
|
|
|
700
748
|
memory_label = "unified memory" if pool == "unified" else "GPU memory"
|
|
701
|
-
can_force = (
|
|
749
|
+
can_force = (
|
|
750
|
+
not force
|
|
751
|
+
and _price_forced_floor(ctx, compact_floor, adm, min_need, min_wired_need) is not None
|
|
752
|
+
)
|
|
702
753
|
wired_blocked = adm.backend == "metal" and min_wired_need > adm.hard_ceiling_bytes
|
|
754
|
+
phys_blocked = min_need > adm.physical_limit_bytes
|
|
755
|
+
soft_blocked = adm.backend == "metal" and not wired_blocked and not phys_blocked
|
|
703
756
|
report_need = min_wired_need if wired_blocked else min_need
|
|
704
|
-
|
|
705
|
-
adm.hard_ceiling_bytes
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
757
|
+
if wired_blocked or adm.backend != "metal":
|
|
758
|
+
report_free = adm.hard_ceiling_bytes
|
|
759
|
+
elif phys_blocked:
|
|
760
|
+
report_free = adm.physical_limit_bytes
|
|
761
|
+
else:
|
|
762
|
+
report_free = adm.soft_budget_bytes
|
|
763
|
+
ceiling_label = "soft budget" if soft_blocked else "hard ceiling"
|
|
709
764
|
raise ElasticRoomError(
|
|
710
|
-
f"{model.id} does not fit {pool} now (floor needs {report_need} bytes,
|
|
765
|
+
f"{model.id} does not fit {pool} now (floor needs {report_need} bytes, {ceiling_label} "
|
|
711
766
|
f"{report_free} bytes)",
|
|
712
767
|
pool=pool,
|
|
713
768
|
need_bytes=report_need,
|