@simplexai/localmodels-win32-x64 0.1.0-dev.64 → 0.1.0-dev.66
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 +125 -121
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +2 -2
- package/modules/localmodels/approval.py +5 -3
- package/modules/localmodels/auth_proxy.py +34 -2
- package/modules/localmodels/bifrost_checks.py +2 -1
- package/modules/localmodels/catalog.json +504 -18
- 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_hub.py +54 -6
- package/modules/localmodels/custom_probe.py +33 -5
- package/modules/localmodels/debug_stub_server.py +34 -1
- package/modules/localmodels/deploy.py +45 -285
- package/modules/localmodels/deployment_lifecycle.py +167 -0
- package/modules/localmodels/download-mirrors.json +43 -3
- package/modules/localmodels/draft_spec.py +43 -1
- package/modules/localmodels/engine_adapters/__init__.py +4 -2
- package/modules/localmodels/engine_adapters/auxiliary.py +4 -1
- package/modules/localmodels/engine_adapters/llama_cpp.py +539 -0
- package/modules/localmodels/engines-b11583.json +9 -5
- package/modules/localmodels/engines-b12757-mix-ef2df21.json +85 -1
- package/modules/localmodels/engines.json +9 -5
- 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 +18 -6
- package/modules/localmodels/harness_probe.py +64 -3
- package/modules/localmodels/hosts.py +22 -34
- package/modules/localmodels/library_convert.py +3 -3
- package/modules/localmodels/library_custom.py +15 -13
- package/modules/localmodels/library_elastic.py +27 -13
- package/modules/localmodels/library_jobs.py +151 -28
- package/modules/localmodels/library_model.py +22 -2
- package/modules/localmodels/library_order.py +5 -4
- package/modules/localmodels/library_poly.py +2 -2
- package/modules/localmodels/library_pricing.py +34 -318
- package/modules/localmodels/library_serve.py +20 -12
- package/modules/localmodels/library_smoke.py +8 -1
- package/modules/localmodels/library_state.py +12 -0
- package/modules/localmodels/library_status.py +26 -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} +56 -33
- 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/remote_ops_mirrors.py +55 -19
- package/modules/localmodels/residency_host.py +1 -1
- package/modules/localmodels/service_control.py +4 -4
- package/modules/localmodels/service_deployment.py +4 -4
- package/modules/localmodels/service_wiring.py +17 -19
- package/modules/localmodels/setup_inspection.py +29 -2
- package/modules/localmodels/setup_inspection_harness.py +5 -2
- package/modules/localmodels/setup_text.py +6 -0
- package/modules/localmodels/setup_upgrade.py +3 -12
- package/modules/localmodels/slot_cache.py +1 -3
- package/modules/localmodels/speech_admission.py +17 -5
- package/modules/localmodels/speech_catalog.py +5 -1
- package/modules/localmodels/speech_cli.py +5 -5
- package/modules/localmodels/speech_jobs.py +103 -20
- package/modules/localmodels/speech_model.py +2 -0
- package/modules/localmodels/speech_server.py +132 -9
- package/modules/localmodels/speech_state.py +11 -0
- package/modules/localmodels/speech_worker_sensevoice.py +215 -19
- package/modules/localmodels/speech_workers.py +79 -7
- package/modules/localmodels/stack.py +15 -6
- package/modules/localmodels/stack_auto.py +10 -4
- package/modules/localmodels/stack_aux_gpu.py +1 -1
- package/modules/localmodels/stack_binding.py +24 -143
- package/modules/localmodels/stack_capacity.py +4 -4
- package/modules/localmodels/stack_card.py +1 -1
- package/modules/localmodels/stack_cleanup.py +3 -3
- package/modules/localmodels/stack_cli.py +3 -0
- package/modules/localmodels/stack_client_settings.py +9 -2
- package/modules/localmodels/stack_compose.py +42 -9
- 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 +60 -29
- 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 +17 -4
- 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/suite.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.dev66.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/RECORD +122 -118
- package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/NOTICE +3 -0
- 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.dev66.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev64.dist-info → simplex_localmodels-0.1.0.dev66.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -23,7 +23,6 @@ from localmodels import (
|
|
|
23
23
|
harness,
|
|
24
24
|
hosts,
|
|
25
25
|
library_gateway,
|
|
26
|
-
library_pricing,
|
|
27
26
|
library_state,
|
|
28
27
|
library_status,
|
|
29
28
|
stack_run,
|
|
@@ -33,6 +32,7 @@ from localmodels.contracts import decode
|
|
|
33
32
|
from localmodels.library_model import library_id
|
|
34
33
|
from localmodels.library_state import Record, Registration
|
|
35
34
|
from localmodels.plan_envelope import utc_now
|
|
35
|
+
from localmodels.planning import memory_pools
|
|
36
36
|
from localmodels.records import Plan
|
|
37
37
|
from localmodels.stack_plan import StackPlan
|
|
38
38
|
|
|
@@ -304,7 +304,7 @@ def _adopt_record(model: str, provider: str, deployed: Plan, base_dir: str | Non
|
|
|
304
304
|
if library_state.job_alive(model):
|
|
305
305
|
return False
|
|
306
306
|
spec = deployed["model"]
|
|
307
|
-
pool =
|
|
307
|
+
pool = memory_pools.pool_of(deployed)
|
|
308
308
|
existing = library_state.load(model)
|
|
309
309
|
prev_deploy_dir = existing["plan"]["service"]["deploy_dir"] if existing is not None else None
|
|
310
310
|
if existing is None:
|
|
@@ -331,7 +331,7 @@ def _adopt_record(model: str, provider: str, deployed: Plan, base_dir: str | Non
|
|
|
331
331
|
record["state"] = "loaded"
|
|
332
332
|
record["converted"] = True
|
|
333
333
|
record["stack_provider"] = provider
|
|
334
|
-
record["memory_bytes"] =
|
|
334
|
+
record["memory_bytes"] = memory_pools.memory_bytes(deployed)
|
|
335
335
|
if base_dir is not None:
|
|
336
336
|
record["base_dir"] = base_dir
|
|
337
337
|
elif prev_deploy_dir != deployed["service"]["deploy_dir"]:
|
|
@@ -17,7 +17,6 @@ from pathlib import Path
|
|
|
17
17
|
from typing import Any, cast
|
|
18
18
|
|
|
19
19
|
from localmodels import (
|
|
20
|
-
budget,
|
|
21
20
|
catalog_add,
|
|
22
21
|
custom_hub,
|
|
23
22
|
custom_probe,
|
|
@@ -42,10 +41,11 @@ from localmodels.library_model import (
|
|
|
42
41
|
split_id,
|
|
43
42
|
)
|
|
44
43
|
from localmodels.library_state import CustomMeta, Job, JobHandle, Record
|
|
44
|
+
from localmodels.planning import budget, memory_pools
|
|
45
45
|
from localmodels.probe import HostFacts
|
|
46
46
|
from localmodels.records import Plan, ReusableFile
|
|
47
47
|
|
|
48
|
-
CUSTOM_ENGINE_TAG =
|
|
48
|
+
CUSTOM_ENGINE_TAG = custom_probe.CUSTOM_ENGINE_TAG
|
|
49
49
|
_SAFE_SEGMENT_RE = re.compile(r"[^a-z0-9._-]+")
|
|
50
50
|
_REV_SAFE_RE = re.compile(r"[^a-zA-Z0-9._-]+")
|
|
51
51
|
|
|
@@ -232,7 +232,7 @@ def _select_pool_and_engine(
|
|
|
232
232
|
facts: HostFacts, base_dir: str
|
|
233
233
|
) -> tuple[str, str, int, dict[str, object]]:
|
|
234
234
|
"""Return ``(pool_id, placement_id, memory_ceiling_bytes, release_engine_dict)``."""
|
|
235
|
-
pool_map =
|
|
235
|
+
pool_map = memory_pools.pools(facts)
|
|
236
236
|
preferred = [p for p in pool_map if p != "system"]
|
|
237
237
|
if not preferred:
|
|
238
238
|
vendor = str(facts.get("gpu_vendor_class") or "none")
|
|
@@ -243,25 +243,22 @@ def _select_pool_and_engine(
|
|
|
243
243
|
pool_id = max(
|
|
244
244
|
preferred,
|
|
245
245
|
key=lambda p: (
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
memory_pools.pool_free(facts, p),
|
|
247
|
+
memory_pools.pool_total(facts, p),
|
|
248
248
|
),
|
|
249
249
|
)
|
|
250
250
|
placement_id = pool_map[pool_id]
|
|
251
251
|
adm = budget.admission_budget(facts, pool_id)
|
|
252
|
-
total =
|
|
252
|
+
total = memory_pools.pool_total(facts, pool_id)
|
|
253
253
|
ceiling = adm.hard_ceiling_bytes if adm is not None and adm.hard_ceiling_bytes > 0 else total
|
|
254
|
-
backend = "metal" if pool_id == "unified" and facts.get("platform") == "darwin" else "cuda"
|
|
255
|
-
lock_path = engines.engine_lock_path(CUSTOM_ENGINE_TAG)
|
|
256
254
|
try:
|
|
257
|
-
|
|
255
|
+
engine_doc = custom_probe.custom_engine(facts, pool_id, base_dir)
|
|
258
256
|
except engines.CudaDriverError as exc:
|
|
259
257
|
raise LibraryError("DRIVER_UPDATE_REQUIRED", str(exc)) from None
|
|
260
258
|
except engines.EngineUnavailableError as exc:
|
|
261
259
|
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc)) from None
|
|
262
260
|
except plan_envelope.PlanError as exc:
|
|
263
261
|
raise LibraryError("RUNTIME_DEPENDENCY_MISSING", str(exc)) from None
|
|
264
|
-
engine_doc = cast(dict[str, object], engines.release_engine(build, base_dir))
|
|
265
262
|
return pool_id, placement_id, ceiling, engine_doc
|
|
266
263
|
|
|
267
264
|
|
|
@@ -387,7 +384,7 @@ def _build_download_plan(
|
|
|
387
384
|
hosts.deployment_dirs(hosts.LOCAL_ID),
|
|
388
385
|
)
|
|
389
386
|
gpus = {g["index"]: g for g in facts.get("gpus") or []}
|
|
390
|
-
gpu_idx =
|
|
387
|
+
gpu_idx = memory_pools.gpu_index(pool_id)
|
|
391
388
|
placement_gpus = (
|
|
392
389
|
[
|
|
393
390
|
{
|
|
@@ -738,19 +735,21 @@ def download_custom(payload: Mapping[str, object], base_dir: str) -> Row:
|
|
|
738
735
|
_cleanup_aborted(
|
|
739
736
|
custom_model_id, job, handle, base_dir, preserve_dests=old_dests
|
|
740
737
|
)
|
|
738
|
+
library_jobs.discard_engine_parts(engine_doc)
|
|
741
739
|
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
742
740
|
except LibraryError as exc:
|
|
743
741
|
safe_detail = custom_hub.redact_secrets(
|
|
744
742
|
remote_ops.redact_text(exc.detail), extra_token=resolved_token
|
|
745
743
|
)
|
|
744
|
+
was_cancelled = False
|
|
746
745
|
with library_state.locked():
|
|
747
746
|
if library_state.current(job):
|
|
748
747
|
if library_state.cancelled(job):
|
|
749
748
|
_cleanup_aborted(
|
|
750
749
|
custom_model_id, job, handle, base_dir, preserve_dests=old_dests
|
|
751
750
|
)
|
|
752
|
-
|
|
753
|
-
|
|
751
|
+
was_cancelled = True
|
|
752
|
+
elif (
|
|
754
753
|
exc.code in library_jobs.KEEP_FAILED_DOWNLOAD_CODES
|
|
755
754
|
and library_state.load(custom_model_id) is None
|
|
756
755
|
):
|
|
@@ -762,6 +761,9 @@ def download_custom(payload: Mapping[str, object], base_dir: str) -> Row:
|
|
|
762
761
|
_cleanup_aborted(
|
|
763
762
|
custom_model_id, job, handle, base_dir, preserve_dests=old_dests
|
|
764
763
|
)
|
|
764
|
+
if was_cancelled:
|
|
765
|
+
library_jobs.discard_engine_parts(engine_doc)
|
|
766
|
+
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
765
767
|
raise LibraryError(exc.code, safe_detail, failed=exc.failed, **exc.fields) from None
|
|
766
768
|
except Exception as exc:
|
|
767
769
|
with library_state.locked():
|
|
@@ -13,8 +13,8 @@ from __future__ import annotations
|
|
|
13
13
|
from dataclasses import dataclass, replace
|
|
14
14
|
from typing import cast
|
|
15
15
|
|
|
16
|
+
from localmodels import catalog as cat
|
|
16
17
|
from localmodels import (
|
|
17
|
-
budget,
|
|
18
18
|
context_policy,
|
|
19
19
|
deploy,
|
|
20
20
|
estimator,
|
|
@@ -26,8 +26,8 @@ from localmodels import (
|
|
|
26
26
|
plan_envelope,
|
|
27
27
|
vision,
|
|
28
28
|
)
|
|
29
|
-
from localmodels import catalog as cat
|
|
30
29
|
from localmodels.context_policy import AgentPosture
|
|
30
|
+
from localmodels.engine_adapters import llama_cpp
|
|
31
31
|
from localmodels.estimator import (
|
|
32
32
|
PhysicsRefusal,
|
|
33
33
|
)
|
|
@@ -38,7 +38,9 @@ from localmodels.library_model import (
|
|
|
38
38
|
MemoryPressureWarningLevel,
|
|
39
39
|
PostureSummary,
|
|
40
40
|
)
|
|
41
|
-
from localmodels.library_pricing import LiveMemoryUnavailable, Model
|
|
41
|
+
from localmodels.library_pricing import LiveMemoryUnavailable, Model
|
|
42
|
+
from localmodels.planning import budget, memory_pools
|
|
43
|
+
from localmodels.planning.memory_pools import memory_bytes
|
|
42
44
|
from localmodels.probe import HostFacts
|
|
43
45
|
from localmodels.records import Plan
|
|
44
46
|
|
|
@@ -116,7 +118,7 @@ class ElasticRoomError(deploy.AgentMemoryError):
|
|
|
116
118
|
def elastic_posture_ladder(
|
|
117
119
|
base: AgentPosture,
|
|
118
120
|
*,
|
|
119
|
-
backend:
|
|
121
|
+
backend: budget.Backend,
|
|
120
122
|
native_ctx: int = 0,
|
|
121
123
|
max_agent_window: int = 0,
|
|
122
124
|
) -> tuple[PostureRung, ...]:
|
|
@@ -228,8 +230,8 @@ def _floor_need_bytes(
|
|
|
228
230
|
else 0
|
|
229
231
|
)
|
|
230
232
|
return core + vis, core + vis
|
|
231
|
-
if
|
|
232
|
-
total =
|
|
233
|
+
if memory_pools.gpu_index(pool) is not None and model.entry.mmproj is not None:
|
|
234
|
+
total = memory_pools.pool_total(facts, pool)
|
|
233
235
|
mode = vision.reader(active.vision, total, unified=False)
|
|
234
236
|
vis = vision.llama_device_bytes(model.entry.mmproj, mode)
|
|
235
237
|
return core + vis, core + vis
|
|
@@ -245,9 +247,9 @@ def minimum_memory_bytes(facts: HostFacts, model: Model, pool: str) -> int | Non
|
|
|
245
247
|
or library_kept.retired(model.entry)
|
|
246
248
|
):
|
|
247
249
|
return None
|
|
248
|
-
if pool not in
|
|
250
|
+
if pool not in memory_pools.pools(facts):
|
|
249
251
|
return None
|
|
250
|
-
backend = "metal" if pool == "unified" and metal.supported(facts) else "cuda"
|
|
252
|
+
backend: budget.Backend = "metal" if pool == "unified" and metal.supported(facts) else "cuda"
|
|
251
253
|
ladder = elastic_posture_ladder(
|
|
252
254
|
library_pricing.posture(),
|
|
253
255
|
backend=backend,
|
|
@@ -284,7 +286,7 @@ def _price_rung(
|
|
|
284
286
|
check_host_ram: bool = True,
|
|
285
287
|
bypass_working_set: bool = False,
|
|
286
288
|
) -> Plan:
|
|
287
|
-
priced_facts =
|
|
289
|
+
priced_facts = memory_pools.facts_for_budget(
|
|
288
290
|
ctx.facts,
|
|
289
291
|
ctx.pool,
|
|
290
292
|
budget_bytes,
|
|
@@ -508,7 +510,7 @@ def _try_floor_admission(
|
|
|
508
510
|
|
|
509
511
|
|
|
510
512
|
def _custom_ctx_ladder(
|
|
511
|
-
base: AgentPosture, backend:
|
|
513
|
+
base: AgentPosture, backend: budget.Backend, ctx_tokens: int
|
|
512
514
|
) -> tuple[PostureRung, ...]:
|
|
513
515
|
requested = context_policy.posture_for(base, backend)
|
|
514
516
|
pinned = replace(
|
|
@@ -523,6 +525,17 @@ def _custom_ctx_ladder(
|
|
|
523
525
|
return (PostureRung(pinned, degraded=False, reason=None),)
|
|
524
526
|
|
|
525
527
|
|
|
528
|
+
def load_posture(model: Model, base_dir: str) -> AgentPosture:
|
|
529
|
+
"""The library's agent posture for loading ``model`` from ``base_dir``. A load never fetches
|
|
530
|
+
and never fails for an optional accelerator: without its drafter verified on disk (a model
|
|
531
|
+
downloaded before the drafter shipped), the model is planned with the drafter off, exactly
|
|
532
|
+
as when there is no headroom for it."""
|
|
533
|
+
posture = library_pricing.posture()
|
|
534
|
+
if model.entry.draft is None or llama_cpp.drafter_in_place(model.entry, base_dir):
|
|
535
|
+
return posture
|
|
536
|
+
return replace(posture, draft="off")
|
|
537
|
+
|
|
538
|
+
|
|
526
539
|
def price_elastic(
|
|
527
540
|
facts: HostFacts,
|
|
528
541
|
model: Model,
|
|
@@ -541,7 +554,7 @@ def price_elastic(
|
|
|
541
554
|
effective_catalog = (
|
|
542
555
|
catalog if any(e.id == model.entry.id for e in catalog) else (*catalog, model.entry)
|
|
543
556
|
)
|
|
544
|
-
placement =
|
|
557
|
+
placement = memory_pools.pools(facts).get(pool)
|
|
545
558
|
if placement is None:
|
|
546
559
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
547
560
|
if library_kept.retired(model.entry):
|
|
@@ -561,11 +574,12 @@ def price_elastic(
|
|
|
561
574
|
)
|
|
562
575
|
eff = _plan_posture(poly_plan)
|
|
563
576
|
return ElasticPlan(poly_plan, 0, (), eff, eff, False, None, None, False, adm)
|
|
577
|
+
posture = load_posture(model, base_dir)
|
|
564
578
|
if ctx_override is not None and ctx_override > 0:
|
|
565
|
-
ladder = _custom_ctx_ladder(
|
|
579
|
+
ladder = _custom_ctx_ladder(posture, adm.backend, ctx_override)
|
|
566
580
|
else:
|
|
567
581
|
ladder = elastic_posture_ladder(
|
|
568
|
-
|
|
582
|
+
posture,
|
|
569
583
|
backend=adm.backend,
|
|
570
584
|
native_ctx=model.entry.n_ctx_train,
|
|
571
585
|
max_agent_window=model.entry.max_agent_window,
|
|
@@ -14,13 +14,15 @@ import os
|
|
|
14
14
|
import signal
|
|
15
15
|
import threading
|
|
16
16
|
import time
|
|
17
|
-
from collections.abc import Callable, Iterator
|
|
17
|
+
from collections.abc import Callable, Iterator, Mapping
|
|
18
18
|
from contextlib import contextmanager
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
|
|
21
21
|
from localmodels import (
|
|
22
22
|
app,
|
|
23
23
|
deploy_steps,
|
|
24
|
+
deployment_lifecycle,
|
|
25
|
+
draft_spec,
|
|
24
26
|
frontend,
|
|
25
27
|
hosts,
|
|
26
28
|
library_convert,
|
|
@@ -33,6 +35,7 @@ from localmodels import (
|
|
|
33
35
|
process_identity,
|
|
34
36
|
remote_ops,
|
|
35
37
|
remote_ops_download,
|
|
38
|
+
remote_ops_mirrors,
|
|
36
39
|
reuse,
|
|
37
40
|
)
|
|
38
41
|
from localmodels.deploy_steps import Action
|
|
@@ -46,6 +49,7 @@ from localmodels.library_model import (
|
|
|
46
49
|
)
|
|
47
50
|
from localmodels.library_pricing import Model
|
|
48
51
|
from localmodels.library_state import Job, JobHandle, Record
|
|
52
|
+
from localmodels.planning import memory_pools
|
|
49
53
|
from localmodels.probe import HostFacts
|
|
50
54
|
from localmodels.records import Plan, ReusableFile
|
|
51
55
|
from localmodels.transport import Executor
|
|
@@ -131,7 +135,7 @@ def in_use(skip: str) -> set[str]:
|
|
|
131
135
|
used.update(dests(record["plan"]))
|
|
132
136
|
library_names = {r["plan"]["name"] for r in library_state.records()}
|
|
133
137
|
for name, owned in hosts.load_owned()["deployments"].items():
|
|
134
|
-
if name not in library_names and
|
|
138
|
+
if name not in library_names and deployment_lifecycle.holds_service(owned):
|
|
135
139
|
used.update(os.path.expanduser(f) for f in owned["files"])
|
|
136
140
|
return used
|
|
137
141
|
|
|
@@ -205,6 +209,91 @@ def _download_telemetry(phase: str, event: dict[str, object]) -> tuple[str | Non
|
|
|
205
209
|
return source, connections
|
|
206
210
|
|
|
207
211
|
|
|
212
|
+
def _release_engine(spec: object) -> Mapping[str, object] | None:
|
|
213
|
+
if isinstance(spec, Mapping) and spec.get("source") == "release" and spec.get("dir"):
|
|
214
|
+
return spec
|
|
215
|
+
return None
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _engine_archives(engine: Mapping[str, object]) -> list[tuple[str, int]]:
|
|
219
|
+
"""``(archive path, size)`` of each release asset in the engines root's ``.archives``."""
|
|
220
|
+
engine_dir = os.path.expanduser(str(engine["dir"]))
|
|
221
|
+
cache = os.path.join(os.path.dirname(engine_dir), ".archives")
|
|
222
|
+
assets = engine.get("assets")
|
|
223
|
+
return [
|
|
224
|
+
(os.path.join(cache, str(a["name"])), int(a["size_bytes"]))
|
|
225
|
+
for a in (assets if isinstance(assets, list) else ())
|
|
226
|
+
if isinstance(a, Mapping)
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def engine_pending(spec: object) -> bool:
|
|
231
|
+
"""Whether the plan's engine step will fetch archives: a pinned release whose directory
|
|
232
|
+
lacks the ``.complete`` marker for these assets (remote_ops_download.act_engine)."""
|
|
233
|
+
engine = _release_engine(spec)
|
|
234
|
+
if engine is None:
|
|
235
|
+
return False
|
|
236
|
+
assets = engine.get("assets")
|
|
237
|
+
expected = ",".join(
|
|
238
|
+
str(a.get("sha256") or "")
|
|
239
|
+
for a in (assets if isinstance(assets, list) else ())
|
|
240
|
+
if isinstance(a, Mapping)
|
|
241
|
+
)
|
|
242
|
+
marker = Path(os.path.expanduser(str(engine["dir"]))) / ".complete"
|
|
243
|
+
try:
|
|
244
|
+
return marker.read_text(encoding="utf-8").strip() != expected
|
|
245
|
+
except (OSError, UnicodeError):
|
|
246
|
+
return True
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _archive_done(archive: str, size: int) -> int:
|
|
250
|
+
if os.path.isfile(archive) and os.path.getsize(archive) == size:
|
|
251
|
+
return size
|
|
252
|
+
try:
|
|
253
|
+
return min(size, remote_ops_download.kept_bytes(archive + ".part", size))
|
|
254
|
+
except OSError:
|
|
255
|
+
return 0
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def engine_missing_bytes(spec: object) -> int:
|
|
259
|
+
"""Engine archive bytes a download still has to fetch (0 when the engine is installed)."""
|
|
260
|
+
engine = _release_engine(spec)
|
|
261
|
+
if engine is None or not engine_pending(engine):
|
|
262
|
+
return 0
|
|
263
|
+
return sum(size - _archive_done(path, size) for path, size in _engine_archives(engine))
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
ENGINE_LOCK_WAIT_S = 3.0 # how long a cancel waits for its own engine step to let go
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def discard_engine_parts(spec: object) -> int:
|
|
270
|
+
"""A cancelled download's partial engine archives (``.archives/*.part``): deleted unless
|
|
271
|
+
another download is fetching the engine now (it holds the engines-root lock). Returns the
|
|
272
|
+
bytes deleted."""
|
|
273
|
+
engine = _release_engine(spec)
|
|
274
|
+
if engine is None:
|
|
275
|
+
return 0
|
|
276
|
+
freed = 0
|
|
277
|
+
with remote_ops_mirrors.try_engine_lock(
|
|
278
|
+
os.path.expanduser(str(engine["dir"])), ENGINE_LOCK_WAIT_S
|
|
279
|
+
) as held:
|
|
280
|
+
if not held:
|
|
281
|
+
return 0
|
|
282
|
+
for archive, size in _engine_archives(engine):
|
|
283
|
+
part = archive + ".part"
|
|
284
|
+
if not os.path.exists(part):
|
|
285
|
+
continue
|
|
286
|
+
try:
|
|
287
|
+
freed += min(size, remote_ops_download.kept_bytes(part, size))
|
|
288
|
+
except OSError:
|
|
289
|
+
pass
|
|
290
|
+
try:
|
|
291
|
+
remote_ops_download.discard(part)
|
|
292
|
+
except OSError:
|
|
293
|
+
pass
|
|
294
|
+
return freed
|
|
295
|
+
|
|
296
|
+
|
|
208
297
|
class _Counter:
|
|
209
298
|
"""Bytes of the whole model (plus engine archives whenever the engine step downloads them):
|
|
210
299
|
the files already verified (or partially downloaded on disk) count as done; each progress
|
|
@@ -217,6 +306,7 @@ class _Counter:
|
|
|
217
306
|
handle: JobHandle,
|
|
218
307
|
*,
|
|
219
308
|
shard_count: int | None = None,
|
|
309
|
+
engine: bool = True,
|
|
220
310
|
) -> None:
|
|
221
311
|
self.model, self.handle = model, handle
|
|
222
312
|
self.shard_count = shard_count if shard_count and shard_count >= 1 else None
|
|
@@ -239,28 +329,36 @@ class _Counter:
|
|
|
239
329
|
}
|
|
240
330
|
self.engine_sizes: dict[str, int] = {}
|
|
241
331
|
self.engine_done: dict[str, int] = {}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
self.engine_sizes[name] = size
|
|
251
|
-
archive = os.path.join(archive_cache, name)
|
|
252
|
-
if os.path.isfile(archive) and os.path.getsize(archive) == size:
|
|
253
|
-
self.engine_done[name] = size
|
|
254
|
-
else:
|
|
255
|
-
self.engine_done[name] = min(
|
|
256
|
-
size, remote_ops_download.kept_bytes(archive + ".part", size)
|
|
257
|
-
)
|
|
332
|
+
# Counted from the first line when the engine step will fetch archives, so the total
|
|
333
|
+
# does not jump once its first progress event arrives.
|
|
334
|
+
self._include_engine = engine and engine_pending(plan.get("engine"))
|
|
335
|
+
release = _release_engine(plan.get("engine")) if engine else None
|
|
336
|
+
for archive, size in _engine_archives(release) if release is not None else ():
|
|
337
|
+
name = os.path.basename(archive)
|
|
338
|
+
self.engine_sizes[name] = size
|
|
339
|
+
self.engine_done[name] = _archive_done(archive, size)
|
|
258
340
|
|
|
259
341
|
@property
|
|
260
342
|
def total(self) -> int:
|
|
261
343
|
base = sum(self.sizes.values())
|
|
262
344
|
return base + sum(self.engine_sizes.values()) if self._include_engine else base
|
|
263
345
|
|
|
346
|
+
@property
|
|
347
|
+
def finished(self) -> int:
|
|
348
|
+
done = sum(min(n, self.sizes[k]) for k, n in self.done.items())
|
|
349
|
+
return done + (self.engine_finished or 0)
|
|
350
|
+
|
|
351
|
+
@property
|
|
352
|
+
def engine_finished(self) -> int | None:
|
|
353
|
+
"""Engine archive bytes done, inside ``finished``; None when no engine is fetched."""
|
|
354
|
+
if not self._include_engine:
|
|
355
|
+
return None
|
|
356
|
+
return sum(min(n, self.engine_sizes[k]) for k, n in self.engine_done.items())
|
|
357
|
+
|
|
358
|
+
@property
|
|
359
|
+
def engine_total(self) -> int | None:
|
|
360
|
+
return sum(self.engine_sizes.values()) if self._include_engine else None
|
|
361
|
+
|
|
264
362
|
def finish_engine(self) -> None:
|
|
265
363
|
"""Mark engine assets complete once the engine step succeeds, keeping progress monotonic."""
|
|
266
364
|
if not self._include_engine:
|
|
@@ -283,9 +381,7 @@ class _Counter:
|
|
|
283
381
|
done = event.get("done")
|
|
284
382
|
speed = event.get("bytes_per_s")
|
|
285
383
|
target_done[label] = min(target_sizes[label], int(done) if isinstance(done, int) else 0)
|
|
286
|
-
finished =
|
|
287
|
-
if self._include_engine:
|
|
288
|
-
finished += sum(min(n, self.engine_sizes[k]) for k, n in self.engine_done.items())
|
|
384
|
+
finished = self.finished
|
|
289
385
|
rate = int(speed) if isinstance(speed, int) and phase == "download" else 0
|
|
290
386
|
source, connections = _download_telemetry(phase, event)
|
|
291
387
|
shard_index: int | None = None
|
|
@@ -302,6 +398,8 @@ class _Counter:
|
|
|
302
398
|
connections=connections,
|
|
303
399
|
shard_index=shard_index,
|
|
304
400
|
shard_count=shard_count,
|
|
401
|
+
engine_done=self.engine_finished,
|
|
402
|
+
engine_total=self.engine_total,
|
|
305
403
|
)
|
|
306
404
|
progress(
|
|
307
405
|
self.model,
|
|
@@ -313,6 +411,8 @@ class _Counter:
|
|
|
313
411
|
connections=connections,
|
|
314
412
|
shard_index=shard_index,
|
|
315
413
|
shard_count=shard_count,
|
|
414
|
+
engine_done=self.engine_finished,
|
|
415
|
+
engine_total=self.engine_total,
|
|
316
416
|
)
|
|
317
417
|
|
|
318
418
|
|
|
@@ -353,8 +453,8 @@ def fetch(
|
|
|
353
453
|
) -> None:
|
|
354
454
|
"""The plan's engine (when it is a pinned release) and weights, as stack apply fetches them;
|
|
355
455
|
``only`` limits the weights to the files this job claims. Progress counts the whole model."""
|
|
356
|
-
counter = _Counter(model, plan, handle, shard_count=shard_count)
|
|
357
|
-
initial_done =
|
|
456
|
+
counter = _Counter(model, plan, handle, shard_count=shard_count, engine=engine)
|
|
457
|
+
initial_done = counter.finished
|
|
358
458
|
init_shard_idx = 1 if counter.shard_count is not None else None
|
|
359
459
|
handle.update(
|
|
360
460
|
"download",
|
|
@@ -362,6 +462,8 @@ def fetch(
|
|
|
362
462
|
counter.total,
|
|
363
463
|
shard_index=init_shard_idx,
|
|
364
464
|
shard_count=counter.shard_count,
|
|
465
|
+
engine_done=counter.engine_finished,
|
|
466
|
+
engine_total=counter.engine_total,
|
|
365
467
|
)
|
|
366
468
|
progress(
|
|
367
469
|
model,
|
|
@@ -370,6 +472,8 @@ def fetch(
|
|
|
370
472
|
counter.total,
|
|
371
473
|
shard_index=init_shard_idx,
|
|
372
474
|
shard_count=counter.shard_count,
|
|
475
|
+
engine_done=counter.engine_finished,
|
|
476
|
+
engine_total=counter.engine_total,
|
|
373
477
|
)
|
|
374
478
|
files = [f for f in plan["files"] if only is None or os.path.expanduser(f["dest"]) in only]
|
|
375
479
|
steps: tuple[Action, ...] = ("download",) if files else ()
|
|
@@ -393,7 +497,14 @@ def fetch(
|
|
|
393
497
|
frontend.install(str(plan["launch"]["frontend_base_dir"]), str(reqs))
|
|
394
498
|
except frontend.FrontendError as exc:
|
|
395
499
|
raise LibraryError("DOWNLOAD_FAILED", str(exc), failed=True) from None
|
|
396
|
-
progress(
|
|
500
|
+
progress(
|
|
501
|
+
model,
|
|
502
|
+
"verify",
|
|
503
|
+
counter.total,
|
|
504
|
+
counter.total,
|
|
505
|
+
engine_done=counter.engine_total,
|
|
506
|
+
engine_total=counter.engine_total,
|
|
507
|
+
)
|
|
397
508
|
|
|
398
509
|
|
|
399
510
|
WAIT_S = 2.0 # how often a download looks at a file another download is fetching
|
|
@@ -544,7 +655,7 @@ def download(
|
|
|
544
655
|
priced = _refuse_download(lib, model)
|
|
545
656
|
assert priced.plan is not None
|
|
546
657
|
plan, files = priced.plan, dests(priced.plan)
|
|
547
|
-
memory =
|
|
658
|
+
memory = memory_pools.memory_bytes(plan)
|
|
548
659
|
cancel_on_sigterm()
|
|
549
660
|
with library_state.locked(): # validated again with the claim, as one step
|
|
550
661
|
library_state.refuse_busy(model.id, "download")
|
|
@@ -564,18 +675,23 @@ def download(
|
|
|
564
675
|
with library_state.locked():
|
|
565
676
|
if library_state.load(model.id) is None:
|
|
566
677
|
_give_up(model.id, job, handle)
|
|
678
|
+
discard_engine_parts(plan.get("engine"))
|
|
567
679
|
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
568
680
|
except LibraryError as exc:
|
|
681
|
+
was_cancelled = False
|
|
569
682
|
with library_state.locked():
|
|
570
683
|
if library_state.load(model.id) is None and library_state.current(job):
|
|
571
684
|
if library_state.cancelled(job):
|
|
572
685
|
_give_up(model.id, job, handle)
|
|
573
|
-
|
|
574
|
-
|
|
686
|
+
was_cancelled = True
|
|
687
|
+
elif exc.code in KEEP_FAILED_DOWNLOAD_CODES:
|
|
575
688
|
library_state.fail_job(handle.job, {"code": exc.code, "detail": exc.detail})
|
|
576
689
|
claims.clear()
|
|
577
690
|
else:
|
|
578
691
|
_give_up(model.id, job, handle)
|
|
692
|
+
if was_cancelled:
|
|
693
|
+
discard_engine_parts(plan.get("engine"))
|
|
694
|
+
raise LibraryError("CANCELLED", "the download was cancelled") from None
|
|
579
695
|
raise
|
|
580
696
|
except Exception:
|
|
581
697
|
with library_state.locked():
|
|
@@ -633,4 +749,11 @@ def cancel(model_id: str, base_dir: str) -> Row:
|
|
|
633
749
|
|
|
634
750
|
|
|
635
751
|
def files_missing(plan: Plan) -> list[str]:
|
|
636
|
-
|
|
752
|
+
"""The files ``plan`` cannot start without that are not verified in place. Its optional
|
|
753
|
+
drafter is never one: a load plans without it (``library_elastic.load_posture``)."""
|
|
754
|
+
optional = draft_spec.drafter_dest(plan)
|
|
755
|
+
return [
|
|
756
|
+
Path(f["dest"]).name
|
|
757
|
+
for f in plan["files"]
|
|
758
|
+
if f["dest"] != optional and not plan_envelope.verified_in_place(f)
|
|
759
|
+
]
|
|
@@ -38,6 +38,9 @@ CustomRepoFormat = Literal["gguf", "mlx", "safetensors", "unknown"]
|
|
|
38
38
|
MemoryEstimateBasis = Literal["gguf_header", "rough_1.2x_plus_0.8gb"]
|
|
39
39
|
MemoryStatus = Literal["comfortable", "tight", "exceeds"]
|
|
40
40
|
CustomIncompatibleReason = Literal["raw_safetensors", "mlx_unsupported", "no_runnable_files"]
|
|
41
|
+
# Why a probe came back "gated": access really is gated, or (Hugging Face 401 on metadata) the
|
|
42
|
+
# repo is private or does not exist; the Hub answers both alike.
|
|
43
|
+
CustomGatedReason = Literal["gated", "not_found_or_private"]
|
|
41
44
|
|
|
42
45
|
# Extend only together with the contract (contracts/linger-installer/library-v2.schema.json).
|
|
43
46
|
ERROR_CODES = (
|
|
@@ -266,6 +269,8 @@ class Download(_Download, total=False):
|
|
|
266
269
|
connections: int
|
|
267
270
|
shard_index: int
|
|
268
271
|
shard_count: int
|
|
272
|
+
engine_done_bytes: int # engine archive bytes inside done_bytes (first install only)
|
|
273
|
+
engine_total_bytes: int
|
|
269
274
|
|
|
270
275
|
|
|
271
276
|
class Load(TypedDict):
|
|
@@ -485,7 +490,7 @@ class CustomGgufMeta(TypedDict):
|
|
|
485
490
|
has_chat_template: bool
|
|
486
491
|
|
|
487
492
|
|
|
488
|
-
class
|
|
493
|
+
class _CustomProbeHost(TypedDict):
|
|
489
494
|
platform: str
|
|
490
495
|
arch: str
|
|
491
496
|
supported_formats: list[str]
|
|
@@ -496,6 +501,12 @@ class CustomProbeHost(TypedDict):
|
|
|
496
501
|
pool_hard_ceiling_bytes: int
|
|
497
502
|
|
|
498
503
|
|
|
504
|
+
class CustomProbeHost(_CustomProbeHost, total=False):
|
|
505
|
+
# llama.cpp engine archive bytes the first custom download also fetches (0 once installed;
|
|
506
|
+
# absent when no engine build fits this host). Not part of any quant's size or disk check.
|
|
507
|
+
engine_download_bytes: int
|
|
508
|
+
|
|
509
|
+
|
|
499
510
|
class CustomMmprojCandidate(TypedDict):
|
|
500
511
|
path: str
|
|
501
512
|
size_bytes: int
|
|
@@ -558,6 +569,7 @@ class CustomProbeGatedDoc(TypedDict):
|
|
|
558
569
|
outcome: Literal["gated"]
|
|
559
570
|
hub_http_status: Literal[401, 403]
|
|
560
571
|
token_provided: bool
|
|
572
|
+
access_reason: CustomGatedReason
|
|
561
573
|
repo: CustomProbeGatedRepo
|
|
562
574
|
|
|
563
575
|
|
|
@@ -624,8 +636,12 @@ def progress(
|
|
|
624
636
|
load_step: str | None = None,
|
|
625
637
|
shard_index: int | None = None,
|
|
626
638
|
shard_count: int | None = None,
|
|
639
|
+
engine_done: int | None = None,
|
|
640
|
+
engine_total: int | None = None,
|
|
627
641
|
) -> None:
|
|
628
|
-
"""One JSONL progress line; counters are clamped to 0 <= done <= total.
|
|
642
|
+
"""One JSONL progress line; counters are clamped to 0 <= done <= total. ``engine_done`` /
|
|
643
|
+
``engine_total``: the engine archive bytes inside done/total, sent while a download also
|
|
644
|
+
fetches the inference engine."""
|
|
629
645
|
total = max(0, int(total))
|
|
630
646
|
doc: dict[str, object] = {
|
|
631
647
|
"schema": EVENT_SCHEMA,
|
|
@@ -646,6 +662,10 @@ def progress(
|
|
|
646
662
|
doc["shard_index"] = shard_index
|
|
647
663
|
if isinstance(shard_count, int) and not isinstance(shard_count, bool) and shard_count >= 1:
|
|
648
664
|
doc["shard_count"] = shard_count
|
|
665
|
+
if phase in ("download", "verify") and engine_total is not None and engine_total > 0:
|
|
666
|
+
engine_cap = min(int(engine_total), total)
|
|
667
|
+
doc["engine_total"] = engine_cap
|
|
668
|
+
doc["engine_done"] = min(max(0, int(engine_done or 0)), engine_cap)
|
|
649
669
|
_line(doc)
|
|
650
670
|
|
|
651
671
|
|
|
@@ -8,11 +8,12 @@ fallback below validated models whenever a validated model fits (Decision 69).
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
-
from localmodels import budget, library_pricing, llm_rank, metal
|
|
12
11
|
from localmodels import catalog as cat
|
|
12
|
+
from localmodels import llm_rank, metal
|
|
13
13
|
from localmodels.estimator import HardwareBudget
|
|
14
14
|
from localmodels.library_model import Row
|
|
15
15
|
from localmodels.library_pricing import Model
|
|
16
|
+
from localmodels.planning import budget, memory_pools
|
|
16
17
|
from localmodels.probe import HostFacts
|
|
17
18
|
|
|
18
19
|
_ACTIONABLE_UNAVAILABLE = frozenset({"DRIVER_UPDATE_REQUIRED", "RUNTIME_DEPENDENCY_MISSING"})
|
|
@@ -60,7 +61,7 @@ def _mac_suitability_key(
|
|
|
60
61
|
-row_doc["context_tokens"],
|
|
61
62
|
-variant.size_bytes,
|
|
62
63
|
)
|
|
63
|
-
elif entry.quality >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
|
|
64
|
+
elif entry.status == "validated" and entry.quality >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
|
|
64
65
|
tier = 0
|
|
65
66
|
rank_tuple = (
|
|
66
67
|
-entry.quality,
|
|
@@ -89,7 +90,7 @@ def _mac_suitability_key(
|
|
|
89
90
|
|
|
90
91
|
|
|
91
92
|
def _best_cuda_budget(facts: HostFacts) -> HardwareBudget | None:
|
|
92
|
-
shown_cards =
|
|
93
|
+
shown_cards = memory_pools.visible(facts)
|
|
93
94
|
cuda_placements = [
|
|
94
95
|
p
|
|
95
96
|
for p in budget.placements(facts, planning=True)
|
|
@@ -108,7 +109,7 @@ def _best_cuda_budget(facts: HostFacts) -> HardwareBudget | None:
|
|
|
108
109
|
|
|
109
110
|
|
|
110
111
|
def _max_visible_nvidia_bytes(facts: HostFacts) -> int:
|
|
111
|
-
shown_cards =
|
|
112
|
+
shown_cards = memory_pools.visible(facts)
|
|
112
113
|
return max(
|
|
113
114
|
(
|
|
114
115
|
g["total_bytes"]
|