@simplexai/localmodels-linux-arm64 0.1.0-dev.110 → 0.1.0-dev.112
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/README.md +1 -1
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +52 -52
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +482 -103
- package/modules/localmodels/catalog_recipes.py +10 -1
- package/modules/localmodels/custom_hub.py +66 -2
- package/modules/localmodels/custom_hub_http.py +18 -0
- package/modules/localmodels/deploy.py +70 -5
- package/modules/localmodels/download-mirrors.json +70 -0
- package/modules/localmodels/engine_adapters/strata_poly.py +20 -4
- package/modules/localmodels/engine_adapters/suite_plan.py +7 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.10.json +132 -0
- package/modules/localmodels/engines.json +96 -91
- package/modules/localmodels/engines.py +9 -2
- package/modules/localmodels/http_local.py +46 -0
- package/modules/localmodels/library_cli.py +2 -1
- package/modules/localmodels/library_custom.py +73 -0
- package/modules/localmodels/library_jobs.py +47 -23
- package/modules/localmodels/library_model.py +3 -1
- package/modules/localmodels/library_poly.py +78 -33
- package/modules/localmodels/library_presentation.py +28 -0
- package/modules/localmodels/library_pricing.py +125 -20
- package/modules/localmodels/library_serve.py +90 -27
- package/modules/localmodels/library_smoke.py +1 -1
- package/modules/localmodels/library_state.py +23 -1
- package/modules/localmodels/library_status.py +57 -56
- package/modules/localmodels/mirrors.py +217 -21
- package/modules/localmodels/npm_transport.py +46 -35
- package/modules/localmodels/plan_envelope.py +8 -1
- package/modules/localmodels/region.py +90 -23
- package/modules/localmodels/remote_ops_common.py +1 -0
- package/modules/localmodels/remote_ops_download.py +583 -126
- package/modules/localmodels/remote_ops_prepare.py +8 -2
- package/modules/localmodels/remote_ops_ranges.py +80 -44
- package/modules/localmodels/remote_ops_redirect.py +3 -1
- package/modules/localmodels/remote_ops_remove.py +4 -2
- package/modules/localmodels/runtime_index.py +3 -1
- package/modules/localmodels/stack.py +1 -6
- package/modules/localmodels/stack_suite.py +15 -2
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.9.txt → strata-poly-serve-0.2.20-poly.10.txt} +1 -1
- package/modules/localmodels/suite.py +110 -8
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/view.js +11 -3
- package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/RECORD +48 -48
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +0 -132
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/LICENSE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -22,7 +22,6 @@ from localmodels import (
|
|
|
22
22
|
app,
|
|
23
23
|
deploy_steps,
|
|
24
24
|
deployment_lifecycle,
|
|
25
|
-
draft_spec,
|
|
26
25
|
frontend,
|
|
27
26
|
hosts,
|
|
28
27
|
library_direct,
|
|
@@ -563,6 +562,7 @@ def _shared(model: str, plan: Plan, handle: JobHandle, run: Executor, waiting: l
|
|
|
563
562
|
|
|
564
563
|
|
|
565
564
|
def _refuse_download(lib: library_status.Library, model: Model) -> library_pricing.Priced:
|
|
565
|
+
"""Reject a download only for a hard blocker; a memory shortfall still downloads."""
|
|
566
566
|
if (problem := library_pricing.platform_problem(lib.facts)) is not None:
|
|
567
567
|
raise LibraryError("PLATFORM_UNSUPPORTED", problem)
|
|
568
568
|
job, alive = lib.jobs.get(model.id, (None, False))
|
|
@@ -571,8 +571,13 @@ def _refuse_download(lib: library_status.Library, model: Model) -> library_prici
|
|
|
571
571
|
if model.id in lib.records:
|
|
572
572
|
raise LibraryError("INVALID_STATE", f"{model.id} is already downloaded")
|
|
573
573
|
priced = lib.judge(model)
|
|
574
|
+
download_bytes = (
|
|
575
|
+
sum(f["size_bytes"] for f in priced.plan["files"])
|
|
576
|
+
if priced.plan is not None
|
|
577
|
+
else library_pricing.floor_metadata(lib.facts, model)[3]
|
|
578
|
+
)
|
|
574
579
|
reason = library_pricing.download_reason(
|
|
575
|
-
lib.facts, priced, library_pricing.base_free(lib.base_dir)
|
|
580
|
+
lib.facts, priced, library_pricing.base_free(lib.base_dir), download_bytes
|
|
576
581
|
)
|
|
577
582
|
if reason is not None:
|
|
578
583
|
code = reason["code"]
|
|
@@ -594,6 +599,8 @@ def _refuse_download(lib: library_status.Library, model: Model) -> library_prici
|
|
|
594
599
|
elif code == "GPU_UNSUPPORTED":
|
|
595
600
|
vendor = reason.get("gpu_vendor") or "unknown"
|
|
596
601
|
detail = f"{model.id} requires an NVIDIA or Apple Silicon GPU (detected: {vendor})"
|
|
602
|
+
elif code == "DISK_INSUFFICIENT":
|
|
603
|
+
detail = f"{model.id} needs more free disk space than this computer has"
|
|
597
604
|
else:
|
|
598
605
|
detail = f"{model.id} cannot be downloaded here"
|
|
599
606
|
error = LibraryError(code, detail)
|
|
@@ -659,6 +666,21 @@ def _fetch_and_commit(
|
|
|
659
666
|
runtime_index.refresh()
|
|
660
667
|
|
|
661
668
|
|
|
669
|
+
def _plan_to_download(
|
|
670
|
+
lib: library_status.Library, model: Model, priced: library_pricing.Priced, base_dir: str
|
|
671
|
+
) -> tuple[Plan, str]:
|
|
672
|
+
"""The plan and pool a download writes: the priced one, else a download-only plan (fit none)."""
|
|
673
|
+
if priced.plan is not None:
|
|
674
|
+
return priced.plan, priced.pool
|
|
675
|
+
pool = priced.pool or priced.download_pool
|
|
676
|
+
return (
|
|
677
|
+
library_pricing.download_plan(
|
|
678
|
+
lib.facts, model, pool, base_dir, lib.catalog, priced.need_bytes
|
|
679
|
+
),
|
|
680
|
+
pool,
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
|
|
662
684
|
def download(
|
|
663
685
|
model_id: str,
|
|
664
686
|
base_dir: str,
|
|
@@ -666,12 +688,17 @@ def download(
|
|
|
666
688
|
autoload: bool,
|
|
667
689
|
load: Callable[[str, str, list[str]], Row],
|
|
668
690
|
) -> Row:
|
|
669
|
-
"""Fetch the model into ``base_dir``, record it, then load it when its pool has room.
|
|
691
|
+
"""Fetch the model into ``base_dir``, record it, then load it when its pool has room.
|
|
692
|
+
|
|
693
|
+
A model this computer cannot load now (memory or VRAM short) still downloads: the entry is
|
|
694
|
+
recorded ``idle`` with the standby note ``NO_ROOM_TO_LOAD`` and no load attempt, and
|
|
695
|
+
``library load`` prices live memory again when the user asks for it.
|
|
696
|
+
"""
|
|
670
697
|
lib = library_status.Library.read(probe(), base_dir)
|
|
671
698
|
model = library_pricing.find(model_id, lib.catalog)
|
|
672
699
|
priced = _refuse_download(lib, model)
|
|
673
|
-
|
|
674
|
-
|
|
700
|
+
plan, pool = _plan_to_download(lib, model, priced, base_dir)
|
|
701
|
+
files = dests(plan)
|
|
675
702
|
memory = memory_pools.memory_bytes(plan)
|
|
676
703
|
cancel_on_sigterm()
|
|
677
704
|
with library_state.locked(): # validated again with the claim, as one step
|
|
@@ -680,12 +707,12 @@ def download(
|
|
|
680
707
|
raise LibraryError("INVALID_STATE", f"{model.id} is already downloaded")
|
|
681
708
|
others = claimed_elsewhere(model.id)
|
|
682
709
|
mine = [f for f in files if os.path.realpath(f) not in others]
|
|
683
|
-
job = library_state.acquire("download", model.id,
|
|
710
|
+
job = library_state.acquire("download", model.id, pool, memory, mine, files)
|
|
684
711
|
claims = [job]
|
|
685
712
|
with library_state.held(claims):
|
|
686
713
|
handle = library_state.JobHandle(job)
|
|
687
714
|
try:
|
|
688
|
-
_fetch_and_commit(model, plan, handle,
|
|
715
|
+
_fetch_and_commit(model, plan, handle, pool, memory, base_dir, mine, files)
|
|
689
716
|
except KeyboardInterrupt: # anywhere before the commit (a cancel's SIGTERM may land
|
|
690
717
|
# after the transfer, while waiting to commit): what it claimed, unless the record
|
|
691
718
|
# took the files or something else needs them now
|
|
@@ -715,25 +742,33 @@ def download(
|
|
|
715
742
|
if library_state.load(model.id) is None and library_state.current(job):
|
|
716
743
|
_give_up(model.id, job, handle)
|
|
717
744
|
raise
|
|
718
|
-
if not autoload:
|
|
745
|
+
if not autoload or priced.fit == "none":
|
|
746
|
+
if priced.fit == "none":
|
|
747
|
+
_note_no_room(model.id)
|
|
748
|
+
runtime_index.refresh()
|
|
719
749
|
return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
|
|
720
750
|
try:
|
|
721
751
|
return load(model.id, base_dir, [])
|
|
722
752
|
except LibraryError as exc:
|
|
723
753
|
if exc.code != "LOAD_NO_ROOM":
|
|
724
754
|
raise
|
|
755
|
+
_note_no_room(model.id)
|
|
756
|
+
runtime_index.refresh()
|
|
757
|
+
return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
def _note_no_room(model_id: str) -> None:
|
|
761
|
+
"""Mark a downloaded entry that cannot load now with the standby note."""
|
|
725
762
|
with library_state.locked(): # a load or remove admitted since then owns the record now:
|
|
726
763
|
# this note must never put a record it changed back (loaded to idle, removed to present)
|
|
727
|
-
record_ = library_state.load(
|
|
764
|
+
record_ = library_state.load(model_id)
|
|
728
765
|
if (
|
|
729
766
|
record_ is not None
|
|
730
767
|
and record_["state"] == "idle"
|
|
731
|
-
and library_state.read_job(
|
|
768
|
+
and library_state.read_job(model_id) is None
|
|
732
769
|
):
|
|
733
770
|
record_["note"] = {"code": NO_ROOM_TO_LOAD}
|
|
734
771
|
library_state.save(record_)
|
|
735
|
-
runtime_index.refresh()
|
|
736
|
-
return library_status.model_row(library_status.Library.read(probe(), base_dir), model.id)
|
|
737
772
|
|
|
738
773
|
|
|
739
774
|
def cancel(model_id: str, base_dir: str) -> Row:
|
|
@@ -764,14 +799,3 @@ def cancel(model_id: str, base_dir: str) -> Row:
|
|
|
764
799
|
prune_empty_custom_dirs(gone, job.get("base_dir") or base_dir)
|
|
765
800
|
library_state.clear_job(model.id)
|
|
766
801
|
return library_status.row(library_status.Library.read(probe(), base_dir), model)
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
def files_missing(plan: Plan) -> list[str]:
|
|
770
|
-
"""The files ``plan`` cannot start without that are not verified in place. Its optional
|
|
771
|
-
drafter is never one: a load plans without it (``library_elastic.load_posture``)."""
|
|
772
|
-
optional = draft_spec.drafter_dest(plan)
|
|
773
|
-
return [
|
|
774
|
-
Path(f["dest"]).name
|
|
775
|
-
for f in plan["files"]
|
|
776
|
-
if f["dest"] != optional and not plan_envelope.verified_in_place(f)
|
|
777
|
-
]
|
|
@@ -291,7 +291,9 @@ class _Availability(TypedDict):
|
|
|
291
291
|
|
|
292
292
|
|
|
293
293
|
class Availability(_Availability, total=False):
|
|
294
|
-
|
|
294
|
+
# Why the model cannot be downloaded, or, on a downloadable row whose fit is "none", why it
|
|
295
|
+
# cannot load now (MEMORY_INSUFFICIENT with the VRAM/RAM shortfall).
|
|
296
|
+
reason: Reason
|
|
295
297
|
|
|
296
298
|
|
|
297
299
|
class _Download(TypedDict):
|
|
@@ -87,14 +87,25 @@ def _validated_for(recipe: suite.SuiteRecipe, platform: str) -> bool:
|
|
|
87
87
|
return key in scope or (key == "win32" and "linux" in scope)
|
|
88
88
|
|
|
89
89
|
|
|
90
|
+
def _metal_priced(recipe: suite.SuiteRecipe) -> bool:
|
|
91
|
+
"""Whether the catalog prices this recipe for Apple Silicon Metal.
|
|
92
|
+
|
|
93
|
+
A recipe declares a ``darwin`` ``card_args`` tier when it was planned and measured on Metal:
|
|
94
|
+
that tier sets the unified-memory window (and the profile's parallel/batching where it
|
|
95
|
+
differs from the CUDA one), so a Metal plan and its unified footprint are the ones the
|
|
96
|
+
catalog documents. Recipes without one only carry CUDA geometry.
|
|
97
|
+
"""
|
|
98
|
+
return any("darwin" in group.get("platforms", ()) for group in recipe.get("card_args") or ())
|
|
99
|
+
|
|
100
|
+
|
|
90
101
|
def _candidate_for(recipe: suite.SuiteRecipe, platform: str) -> bool:
|
|
91
|
-
# A candidate has no validated_on scope (
|
|
92
|
-
#
|
|
93
|
-
#
|
|
102
|
+
# A candidate has no validated_on scope (that needs status validated); it is listed on the
|
|
103
|
+
# CUDA platforms, and on Apple Silicon only when the catalog prices it for Metal
|
|
104
|
+
# (``_metal_priced``), so no Mac is offered a plan priced from CUDA-only geometry.
|
|
94
105
|
return (
|
|
95
106
|
bool(recipe.get("library"))
|
|
96
107
|
and recipe.get("status") == "candidate"
|
|
97
|
-
and platform != "darwin"
|
|
108
|
+
and (platform != "darwin" or _metal_priced(recipe))
|
|
98
109
|
and stack_suite.built_for(recipe, platform)
|
|
99
110
|
)
|
|
100
111
|
|
|
@@ -261,37 +272,62 @@ def _ram_experts_bytes(recipe: suite.SuiteRecipe) -> int:
|
|
|
261
272
|
|
|
262
273
|
|
|
263
274
|
def _calibrate_host_ram(plan: Plan, recipe: suite.SuiteRecipe, gpu: GPU) -> None:
|
|
264
|
-
"""
|
|
275
|
+
"""Price the experts the card keeps out of VRAM against host RAM.
|
|
265
276
|
|
|
266
277
|
Recipes targeting 8-16 GB cards (such as ``inkling-2-mini-q3-poly``) size
|
|
267
|
-
``memory_estimate_bytes`` for heavy 8 GB RAM expert offloading
|
|
268
|
-
|
|
269
|
-
|
|
278
|
+
``memory_estimate_bytes`` for heavy 8 GB RAM expert offloading, either through an explicit
|
|
279
|
+
``--ram-experts-mib`` pool or through the ``host_ram_spill_bytes`` their 8 GB plan spills.
|
|
280
|
+
A bigger card discounts the pool it does not need: on a 16 GB card where nearly all experts
|
|
281
|
+
stay in VRAM (~1.52 GiB host RAM actual), charging the full 8 GB spill blocks ``library
|
|
282
|
+
load`` at ~16.89 GB free RAM. Qwen4's ``--basinkv`` profiles never pass ``--ram-experts-mib``
|
|
283
|
+
(it evicts the 11.52 GB PLE shard from page cache) but still spill their 14 GiB of 8 GB-tier
|
|
284
|
+
experts.
|
|
285
|
+
|
|
286
|
+
The same physics runs the other way on a card below the recipe's full-cache tier: every
|
|
287
|
+
expert the expert cache cannot hold lives in host RAM, so the plan is charged the cold
|
|
288
|
+
experts its declared spill does not already cover. That is what makes an 8 GB card report a
|
|
289
|
+
host-RAM shortfall for ``qwen4-35b-a3b-q4-poly`` (33.75 GiB of weights + PLE cannot fit in
|
|
290
|
+
32 GB) instead of a bogus VRAM one, and what lets ``inkling-2-mini-q4-poly`` run at 64K on
|
|
291
|
+
the same host.
|
|
292
|
+
|
|
293
|
+
The PLE shard is never discounted: it stays in host RAM on every card, and BasinKV's pinned
|
|
294
|
+
host KV (726 MiB at 128K, ~1.45 GiB at 256K measured on an 8 GB budget) already rides inside
|
|
295
|
+
the recipe's estimate, so the discount only gives back the expert pool.
|
|
270
296
|
"""
|
|
271
|
-
ram_experts = _ram_experts_bytes(recipe)
|
|
297
|
+
ram_experts = _ram_experts_bytes(recipe) or max(0, int(recipe.get("host_ram_spill_bytes") or 0))
|
|
272
298
|
recipe_base = int(recipe.get("memory_estimate_bytes") or 0)
|
|
273
|
-
if ram_experts <= 0 or recipe_base <=
|
|
299
|
+
if ram_experts <= 0 or recipe_base <= 0:
|
|
274
300
|
return
|
|
275
301
|
weight_bytes = suite.poly_weight_bytes(recipe)
|
|
276
302
|
if weight_bytes <= 0:
|
|
277
303
|
return
|
|
278
304
|
gpu_weights = max(0, weight_bytes - int(recipe.get("embd_table_bytes") or 0))
|
|
279
305
|
vram_for_weights = max(0, gpu["free_bytes"] - suite.VRAM_NON_EXPERT_BYTES)
|
|
280
|
-
|
|
281
|
-
saved = ram_experts - spilled
|
|
282
|
-
if saved <= 0:
|
|
283
|
-
return
|
|
306
|
+
cold = max(0, gpu_weights - vram_for_weights)
|
|
284
307
|
plan_mem = int(str(plan["launch"]["memory_estimate_bytes"]))
|
|
285
|
-
|
|
286
|
-
|
|
308
|
+
if cold <= ram_experts and recipe_base <= ram_experts:
|
|
309
|
+
return # the estimate does not cover its own declared pool: nothing to give back
|
|
310
|
+
if cold <= ram_experts:
|
|
311
|
+
# The estimate already holds the declared pool: give back the part the card does not use.
|
|
312
|
+
delta = cold - ram_experts
|
|
313
|
+
elif recipe_base > ram_experts:
|
|
314
|
+
# The estimate holds the declared pool, so charge only the experts beyond it.
|
|
315
|
+
delta = cold - ram_experts
|
|
316
|
+
else:
|
|
317
|
+
# The estimate never held the pool (the smallest tier's experts are page cache), so every
|
|
318
|
+
# cold expert is extra host RAM.
|
|
319
|
+
delta = cold
|
|
320
|
+
if delta == 0:
|
|
321
|
+
return
|
|
322
|
+
plan["launch"]["memory_estimate_bytes"] = max(0, plan_mem + delta)
|
|
287
323
|
limits = plan["service"].get("limits")
|
|
288
324
|
if isinstance(limits, dict) and "MemoryHigh" in limits:
|
|
289
325
|
old_high = suite.size_bytes(limits["MemoryHigh"])
|
|
290
|
-
new_high = max(
|
|
326
|
+
new_high = max(0, old_high + delta)
|
|
291
327
|
limits["MemoryHigh"] = f"{(new_high + (1 << 20) - 1) >> 20}M"
|
|
292
328
|
if "MemoryMax" in limits:
|
|
293
329
|
old_max = suite.size_bytes(limits["MemoryMax"])
|
|
294
|
-
new_max = max(
|
|
330
|
+
new_max = max(0, old_max + delta)
|
|
295
331
|
limits["MemoryMax"] = f"{(new_max + (1 << 20) - 1) >> 20}M"
|
|
296
332
|
|
|
297
333
|
|
|
@@ -386,10 +422,22 @@ def price(
|
|
|
386
422
|
posture: AgentPosture,
|
|
387
423
|
*,
|
|
388
424
|
require_live: bool = False,
|
|
425
|
+
allow_shortfall: bool = False,
|
|
389
426
|
) -> Plan:
|
|
390
|
-
"""Price one ``strata-poly`` library model on discrete NVIDIA or Apple Silicon unified pool.
|
|
427
|
+
"""Price one ``strata-poly`` library model on discrete NVIDIA or Apple Silicon unified pool.
|
|
428
|
+
|
|
429
|
+
``allow_shortfall`` builds the plan a download needs on a computer whose memory or VRAM is
|
|
430
|
+
too small to load it now (``library download`` for a model the user will load after freeing
|
|
431
|
+
memory): platform, engine and geometry are still checked, capacity is not."""
|
|
391
432
|
if pool == "unified" and metal.supported(facts):
|
|
392
|
-
return _price_unified(
|
|
433
|
+
return _price_unified(
|
|
434
|
+
facts,
|
|
435
|
+
recipe_id,
|
|
436
|
+
base_dir,
|
|
437
|
+
port,
|
|
438
|
+
posture,
|
|
439
|
+
require_live=require_live and not allow_shortfall,
|
|
440
|
+
)
|
|
393
441
|
if facts["platform"] not in ("linux", "win32"):
|
|
394
442
|
raise plan_envelope.PlanError(
|
|
395
443
|
"PolyStrata recipes run on Apple Silicon Metal and Linux/Windows NVIDIA GPUs only"
|
|
@@ -399,16 +447,18 @@ def price(
|
|
|
399
447
|
if not stack_suite.built_for(recipe, facts["platform"]):
|
|
400
448
|
raise plan_envelope.PlanError(f"{recipe_id} has no engine build for {facts['platform']}")
|
|
401
449
|
# Reject immutable hardware capacity shortfalls before checking the CUDA driver so an
|
|
402
|
-
# outdated driver never promises that a 24 GB recipe will unlock on an 8 GB card.
|
|
403
|
-
|
|
404
|
-
|
|
450
|
+
# outdated driver never promises that a 24 GB recipe will unlock on an 8 GB card. The floor
|
|
451
|
+
# is the hybrid-offload one when the recipe declares it: its full expert cache (vram_bytes)
|
|
452
|
+
# is the high-speed tier, not the least it starts in.
|
|
453
|
+
need_vram = suite.poly_min_vram_bytes(recipe)
|
|
454
|
+
if not allow_shortfall and need_vram > gpu["total_bytes"]:
|
|
405
455
|
msg = f"{recipe_id} needs {need_vram} bytes of VRAM, exceeding {gpu['total_bytes']} bytes"
|
|
406
456
|
raise deploy.AgentMemoryError(
|
|
407
457
|
msg, PhysicsRefusal(need_vram, gpu["total_bytes"], msg), "GPU memory"
|
|
408
458
|
)
|
|
409
459
|
min_total_ram = int(recipe.get("min_ram_total_bytes") or 0)
|
|
410
460
|
total_ram = facts["ram"]["total_bytes"]
|
|
411
|
-
if min_total_ram > total_ram:
|
|
461
|
+
if not allow_shortfall and min_total_ram > total_ram:
|
|
412
462
|
msg = (
|
|
413
463
|
f"{recipe_id} recommends at least {min_total_ram} bytes of system memory, "
|
|
414
464
|
f"this host has {total_ram} bytes"
|
|
@@ -432,17 +482,12 @@ def price(
|
|
|
432
482
|
plan = suite.unbounded(plan)
|
|
433
483
|
_calibrate_host_ram(plan, recipe, gpu)
|
|
434
484
|
min_free = int(recipe.get("min_vram_free_bytes") or need_vram)
|
|
435
|
-
if
|
|
485
|
+
if not allow_shortfall and min_free > gpu["free_bytes"]:
|
|
436
486
|
msg = (
|
|
437
487
|
f"{recipe_id} needs at least {min_free} bytes of free VRAM now, "
|
|
438
488
|
f"only {gpu['free_bytes']} bytes free"
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
msg, PhysicsRefusal(min_free, gpu["free_bytes"], msg), "GPU memory"
|
|
442
|
-
)
|
|
443
|
-
if not require_live and min_free > gpu["free_bytes"]:
|
|
444
|
-
msg = (
|
|
445
|
-
f"{recipe_id} needs at least {min_free} bytes of loadable VRAM, "
|
|
489
|
+
if require_live
|
|
490
|
+
else f"{recipe_id} needs at least {min_free} bytes of loadable VRAM, "
|
|
446
491
|
f"only {gpu['free_bytes']} bytes available"
|
|
447
492
|
)
|
|
448
493
|
raise deploy.AgentMemoryError(
|
|
@@ -450,7 +495,7 @@ def price(
|
|
|
450
495
|
)
|
|
451
496
|
needed_ram = suite.bounded_ram(plan) + budget.HARNESS_RAM + budget.RAM_FLOOR
|
|
452
497
|
_, avail_ram = budget.host_ram(facts)
|
|
453
|
-
if needed_ram > avail_ram:
|
|
498
|
+
if not allow_shortfall and needed_ram > avail_ram:
|
|
454
499
|
msg = (
|
|
455
500
|
f"{recipe_id} needs {needed_ram} bytes of system memory, "
|
|
456
501
|
f"exceeding {avail_ram} bytes available"
|
|
@@ -55,6 +55,34 @@ _Q4_REFERENCE_PRIORITY: tuple[str, ...] = (
|
|
|
55
55
|
)
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
HUB_REPO = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def card(model: Model, vision_on: bool) -> Row:
|
|
62
|
+
"""The model card fields of a row, each only when the catalog states it: family,
|
|
63
|
+
publisher and parameter scales as written there, the architecture from its MoE flag, its
|
|
64
|
+
license, the Hugging Face page of the repository the weights come from, and vision when
|
|
65
|
+
this deployment reads images (its projector is pinned and priced). Nothing is guessed from
|
|
66
|
+
a name; Linger rejects a whole status document over one value outside its sets."""
|
|
67
|
+
entry = model.entry
|
|
68
|
+
found: dict[str, object] = {
|
|
69
|
+
"family": entry.family,
|
|
70
|
+
"publisher": entry.publisher.strip()[:120],
|
|
71
|
+
"architecture": "moe" if entry.moe else "dense",
|
|
72
|
+
"parameters": entry.parameters,
|
|
73
|
+
"active_parameters": entry.active_parameters if entry.moe else "",
|
|
74
|
+
"license": entry.license.strip()[:120],
|
|
75
|
+
}
|
|
76
|
+
if HUB_REPO.fullmatch(entry.repo):
|
|
77
|
+
found["source_url"] = f"https://huggingface.co/{entry.repo}"
|
|
78
|
+
caps = [c for c in entry.capabilities if c != "vision" or vision_on]
|
|
79
|
+
if vision_on and "vision" not in caps:
|
|
80
|
+
caps = ["vision", *caps]
|
|
81
|
+
if caps:
|
|
82
|
+
found["capabilities"] = caps
|
|
83
|
+
return cast(Row, {k: v for k, v in found.items() if v})
|
|
84
|
+
|
|
85
|
+
|
|
58
86
|
def _slug(text: str) -> str:
|
|
59
87
|
cleaned = _SLUG_BAD_RE.sub("-", text.strip().lower()).strip("-._")
|
|
60
88
|
return cleaned or "model"
|
|
@@ -199,8 +199,13 @@ def price(
|
|
|
199
199
|
port: int = deploy.DEFAULT_PORT,
|
|
200
200
|
*,
|
|
201
201
|
require_live: bool = False,
|
|
202
|
+
allow_shortfall: bool = False,
|
|
202
203
|
) -> Plan:
|
|
203
|
-
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there.
|
|
204
|
+
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there.
|
|
205
|
+
|
|
206
|
+
``allow_shortfall`` builds the plan a download needs when this computer cannot load the
|
|
207
|
+
model now (see ``download_plan``): platform and engine checks stay, capacity is not priced.
|
|
208
|
+
"""
|
|
204
209
|
placement = memory_pools.pools(facts).get(pool)
|
|
205
210
|
if placement is None:
|
|
206
211
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -208,7 +213,14 @@ def price(
|
|
|
208
213
|
raise plan_envelope.PlanError(f"this version no longer ships {model.id}")
|
|
209
214
|
if model.entry.runtime == "strata-poly":
|
|
210
215
|
return library_poly.price(
|
|
211
|
-
facts,
|
|
216
|
+
facts,
|
|
217
|
+
model.entry.id,
|
|
218
|
+
pool,
|
|
219
|
+
base_dir,
|
|
220
|
+
port,
|
|
221
|
+
posture(),
|
|
222
|
+
require_live=require_live,
|
|
223
|
+
allow_shortfall=allow_shortfall,
|
|
212
224
|
)
|
|
213
225
|
if require_live and pool == "unified" and metal.supported(facts):
|
|
214
226
|
if problem := metal.problem(facts):
|
|
@@ -239,7 +251,8 @@ def price(
|
|
|
239
251
|
entries=effective_catalog,
|
|
240
252
|
resolver=deploy.catalog_pins,
|
|
241
253
|
)
|
|
242
|
-
|
|
254
|
+
if not allow_shortfall:
|
|
255
|
+
validate_plan_bounds(facts, model, pool, plan, effective_catalog)
|
|
243
256
|
return plan
|
|
244
257
|
|
|
245
258
|
|
|
@@ -259,6 +272,29 @@ class Priced:
|
|
|
259
272
|
blocker: Reason | None = None # driver/runtime incompatibility when no pool priced
|
|
260
273
|
reclaimable_desktop_vram: bool = False # fits discrete GPU once desktop apps near 1 GiB idle
|
|
261
274
|
reclaim_bytes: int = 0 # approximate VRAM to free when reclaimable_desktop_vram is True
|
|
275
|
+
download_pool: str = "" # fit "none": the pool a later load would run in
|
|
276
|
+
|
|
277
|
+
@property
|
|
278
|
+
def memory_shortfall(self) -> Reason | None:
|
|
279
|
+
"""The structured capacity shortfall, when only memory stands between here and a load.
|
|
280
|
+
|
|
281
|
+
``library status`` publishes it as ``availability.reason`` on a downloadable row whose
|
|
282
|
+
``fit`` is ``none``, so a client offers a download now and names the exact VRAM/RAM gap.
|
|
283
|
+
"""
|
|
284
|
+
if self.fit != "none" or self.plan is not None:
|
|
285
|
+
return None
|
|
286
|
+
reason: Reason = {
|
|
287
|
+
"code": "MEMORY_INSUFFICIENT",
|
|
288
|
+
"need_bytes": self.need_bytes,
|
|
289
|
+
"have_bytes": self.have_bytes,
|
|
290
|
+
}
|
|
291
|
+
if self.memory_kind in ("vram", "ram", "unified"):
|
|
292
|
+
reason["memory_kind"] = self.memory_kind # type: ignore[typeddict-item]
|
|
293
|
+
if self.reclaimable_desktop_vram:
|
|
294
|
+
reason["reclaimable_desktop_vram"] = True
|
|
295
|
+
if self.reclaim_bytes > 0:
|
|
296
|
+
reason["reclaim_bytes"] = self.reclaim_bytes
|
|
297
|
+
return reason
|
|
262
298
|
|
|
263
299
|
|
|
264
300
|
def _min_pool_need(model: Model, pool: str, exc: deploy.AgentMemoryError, facts: HostFacts) -> int:
|
|
@@ -350,7 +386,7 @@ def judge(
|
|
|
350
386
|
)
|
|
351
387
|
order = sorted(memory_pools.pools(facts), key=lambda p: -memory_pools.pool_free(now, p))
|
|
352
388
|
fallback: Priced | None = None
|
|
353
|
-
shortfall: tuple[int, int, str] | None = None
|
|
389
|
+
shortfall: tuple[int, int, str, str] | None = None
|
|
354
390
|
blocker: Reason | None = None
|
|
355
391
|
for pool in order:
|
|
356
392
|
if pool == "system":
|
|
@@ -363,7 +399,7 @@ def judge(
|
|
|
363
399
|
if exc.memory == "system memory"
|
|
364
400
|
else ("unified" if pool == "unified" else "vram")
|
|
365
401
|
)
|
|
366
|
-
gap = (exc.needed_bytes, exc.available_bytes, kind)
|
|
402
|
+
gap = (exc.needed_bytes, exc.available_bytes, kind, pool)
|
|
367
403
|
if shortfall is None or gap[0] - gap[1] < shortfall[0] - shortfall[1]:
|
|
368
404
|
shortfall = gap
|
|
369
405
|
continue
|
|
@@ -390,7 +426,7 @@ def judge(
|
|
|
390
426
|
)
|
|
391
427
|
if fallback is not None:
|
|
392
428
|
return fallback
|
|
393
|
-
need, have, memory_kind = shortfall or (0, 0, "")
|
|
429
|
+
need, have, memory_kind, pool = shortfall or (0, 0, "", "")
|
|
394
430
|
reclaim = (
|
|
395
431
|
blocker is None
|
|
396
432
|
and memory_kind == "vram"
|
|
@@ -410,6 +446,7 @@ def judge(
|
|
|
410
446
|
blocker=blocker,
|
|
411
447
|
reclaimable_desktop_vram=reclaim,
|
|
412
448
|
reclaim_bytes=max(1, need - have) if reclaim else 0,
|
|
449
|
+
download_pool=pool,
|
|
413
450
|
)
|
|
414
451
|
|
|
415
452
|
|
|
@@ -461,7 +498,16 @@ def _gpu_unsupported_reason(facts: HostFacts) -> Reason | None:
|
|
|
461
498
|
return {"code": "GPU_UNSUPPORTED", "gpu_vendor": vendor}
|
|
462
499
|
|
|
463
500
|
|
|
464
|
-
def download_reason(
|
|
501
|
+
def download_reason(
|
|
502
|
+
facts: HostFacts, priced: Priced, disk_free: int, download_bytes: int = 0
|
|
503
|
+
) -> Reason | None:
|
|
504
|
+
"""Why this computer cannot fetch ``model`` at all; None when it can.
|
|
505
|
+
|
|
506
|
+
Only hard blockers refuse a download: platform, GPU vendor, engine/driver or runtime
|
|
507
|
+
incompatibility, and disk space. Memory and VRAM capacity is not one of them: the weights
|
|
508
|
+
can be fetched now and loaded after the user frees memory, so those rows stay downloadable
|
|
509
|
+
and report the shortfall as ``availability.reason`` instead.
|
|
510
|
+
"""
|
|
465
511
|
if platform_problem(facts):
|
|
466
512
|
return {"code": "PLATFORM_UNSUPPORTED"}
|
|
467
513
|
if priced.plan is None:
|
|
@@ -469,23 +515,79 @@ def download_reason(facts: HostFacts, priced: Priced, disk_free: int) -> Reason
|
|
|
469
515
|
return priced.blocker
|
|
470
516
|
if gpu_reason := _gpu_unsupported_reason(facts):
|
|
471
517
|
return gpu_reason
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if priced.reclaimable_desktop_vram:
|
|
480
|
-
reason["reclaimable_desktop_vram"] = True
|
|
481
|
-
if priced.reclaim_bytes > 0:
|
|
482
|
-
reason["reclaim_bytes"] = priced.reclaim_bytes
|
|
483
|
-
return reason
|
|
518
|
+
if download_bytes > disk_free:
|
|
519
|
+
return {
|
|
520
|
+
"code": "DISK_INSUFFICIENT",
|
|
521
|
+
"need_bytes": download_bytes,
|
|
522
|
+
"have_bytes": disk_free,
|
|
523
|
+
}
|
|
524
|
+
return None
|
|
484
525
|
if (need := missing_bytes(priced.plan)) > disk_free:
|
|
485
526
|
return {"code": "DISK_INSUFFICIENT", "need_bytes": need, "have_bytes": disk_free}
|
|
486
527
|
return None
|
|
487
528
|
|
|
488
529
|
|
|
530
|
+
def download_plan(
|
|
531
|
+
facts: HostFacts,
|
|
532
|
+
model: Model,
|
|
533
|
+
pool: str,
|
|
534
|
+
base_dir: str,
|
|
535
|
+
catalog: tuple[cat.CatalogEntry, ...],
|
|
536
|
+
need_bytes: int = 0,
|
|
537
|
+
) -> Plan:
|
|
538
|
+
"""The plan ``library download`` fetches for a model that cannot load here now.
|
|
539
|
+
|
|
540
|
+
Files, engine pin and endpoint are the real ones; only capacity admission is skipped, so a
|
|
541
|
+
user can fetch the weights today and ``library load`` prices live memory again later. A
|
|
542
|
+
``pool`` that cannot be named at all still raises ``PlanError``.
|
|
543
|
+
"""
|
|
544
|
+
if not pool:
|
|
545
|
+
raise plan_envelope.PlanError(f"{model.id} has no pool to run in on this computer")
|
|
546
|
+
if model.entry.runtime == "strata-poly":
|
|
547
|
+
return library_poly.price(
|
|
548
|
+
facts,
|
|
549
|
+
model.entry.id,
|
|
550
|
+
pool,
|
|
551
|
+
base_dir,
|
|
552
|
+
deploy.DEFAULT_PORT,
|
|
553
|
+
posture(),
|
|
554
|
+
allow_shortfall=True,
|
|
555
|
+
)
|
|
556
|
+
try:
|
|
557
|
+
return price(facts, model, pool, base_dir, catalog, allow_shortfall=True)
|
|
558
|
+
except deploy.AgentMemoryError:
|
|
559
|
+
# The planner refuses to build a deployment it cannot fit; the inflation only buys the
|
|
560
|
+
# same files and engine pin, and the record is re-priced when the model is loaded.
|
|
561
|
+
# The agent budget is free memory less the safety reserve; grow the card past both so
|
|
562
|
+
# the same files and engine pin can be planned.
|
|
563
|
+
room = max(need_bytes, memory_pools.pool_total(facts, pool))
|
|
564
|
+
return price(
|
|
565
|
+
_spacious(facts, pool, room + AGENT_VRAM_RESERVE_BYTES + (1 << 30)),
|
|
566
|
+
model,
|
|
567
|
+
pool,
|
|
568
|
+
base_dir,
|
|
569
|
+
catalog,
|
|
570
|
+
allow_shortfall=True,
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def _spacious(facts: HostFacts, pool: str, need: int) -> HostFacts:
|
|
575
|
+
"""``facts`` with ``pool`` grown to ``need`` bytes, so a download plan can be built."""
|
|
576
|
+
seen = copy.deepcopy(facts)
|
|
577
|
+
index = memory_pools.gpu_index(pool)
|
|
578
|
+
if index is not None:
|
|
579
|
+
for gpu in seen.get("gpus") or []:
|
|
580
|
+
if gpu["index"] == index:
|
|
581
|
+
gpu["total_bytes"] = max(gpu["total_bytes"], need)
|
|
582
|
+
gpu["free_bytes"] = max(gpu["free_bytes"], need)
|
|
583
|
+
gpu["used_bytes"] = max(0, gpu["total_bytes"] - gpu["free_bytes"])
|
|
584
|
+
return seen
|
|
585
|
+
ram = seen["ram"]
|
|
586
|
+
ram["total_bytes"] = max(ram["total_bytes"], need)
|
|
587
|
+
ram["available_bytes"] = max(ram["available_bytes"], need)
|
|
588
|
+
return seen
|
|
589
|
+
|
|
590
|
+
|
|
489
591
|
def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, str] | None:
|
|
490
592
|
"""Best live-fitting llama.cpp library model ranked by ``llm_rank.choose()``."""
|
|
491
593
|
catalog = entries()
|
|
@@ -591,7 +693,10 @@ def floor_metadata(
|
|
|
591
693
|
return shortfall_bytes, 0, False, sum(f.size_bytes for f in model.variant.files)
|
|
592
694
|
if model.entry.runtime == "strata-poly":
|
|
593
695
|
recipe = suite.recipe(model.entry.id)
|
|
594
|
-
window
|
|
696
|
+
# Apple Silicon prices its own window: a recipe whose CUDA tier starts at a short
|
|
697
|
+
# offload window declares the Metal one separately (``metal_context``).
|
|
698
|
+
metal_window = recipe.get("metal_context") if metal.supported(facts) else None
|
|
699
|
+
window = int(metal_window or recipe.get("context") or model.entry.n_ctx_train)
|
|
595
700
|
metal_unified = metal.supported(facts)
|
|
596
701
|
active = model.entry.agent_posture(
|
|
597
702
|
context_policy.posture_for(posture(), "metal" if metal_unified else "cuda")
|