@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
|
@@ -17,7 +17,7 @@ import math
|
|
|
17
17
|
import os
|
|
18
18
|
import shutil
|
|
19
19
|
import time
|
|
20
|
-
from dataclasses import dataclass
|
|
20
|
+
from dataclasses import dataclass, field, replace
|
|
21
21
|
from pathlib import Path
|
|
22
22
|
|
|
23
23
|
from localmodels import (
|
|
@@ -156,6 +156,7 @@ class LoadContext:
|
|
|
156
156
|
base: str = ""
|
|
157
157
|
pool: str = ""
|
|
158
158
|
port: int = 0
|
|
159
|
+
fallback_api_key: str | None = field(default=None, repr=False)
|
|
159
160
|
|
|
160
161
|
|
|
161
162
|
def _deploy_load_step(step: str) -> LoadStep:
|
|
@@ -166,14 +167,6 @@ def _deploy_load_step(step: str) -> LoadStep:
|
|
|
166
167
|
return "load"
|
|
167
168
|
|
|
168
169
|
|
|
169
|
-
def base_of(record: Record) -> str:
|
|
170
|
-
"""The base directory the model was downloaded into."""
|
|
171
|
-
if record.get("base_dir"):
|
|
172
|
-
return record["base_dir"]
|
|
173
|
-
deploy_dir = os.path.expanduser(record["plan"]["service"]["deploy_dir"])
|
|
174
|
-
return os.path.dirname(os.path.dirname(deploy_dir))
|
|
175
|
-
|
|
176
|
-
|
|
177
170
|
def _reserved(skip: str) -> dict[str, int]:
|
|
178
171
|
found: dict[str, int] = {}
|
|
179
172
|
for model, (job, alive) in library_state.jobs().items():
|
|
@@ -301,7 +294,7 @@ def _room(
|
|
|
301
294
|
now,
|
|
302
295
|
model,
|
|
303
296
|
record["pool"],
|
|
304
|
-
base_of(record),
|
|
297
|
+
library_state.base_of(record),
|
|
305
298
|
library_pricing.entries(),
|
|
306
299
|
allow_overcommit=True,
|
|
307
300
|
force=force,
|
|
@@ -361,8 +354,11 @@ def _start_code(finished: FinishedRecord, *, custom: bool = False) -> str:
|
|
|
361
354
|
return "ENGINE_START_FAILED"
|
|
362
355
|
|
|
363
356
|
|
|
364
|
-
def _remove_service(plan: Plan, run: Executor) -> None:
|
|
365
|
-
|
|
357
|
+
def _remove_service(plan: Plan, run: Executor, *, keep_key: bool = True) -> None:
|
|
358
|
+
params = stack_lifecycle.plan_params(plan)
|
|
359
|
+
if keep_key:
|
|
360
|
+
params["keep_key"] = True
|
|
361
|
+
outcome = run.run_action("remove", params, timeout=600)[0]
|
|
366
362
|
if outcome.get("event") != "result":
|
|
367
363
|
raise LibraryError(
|
|
368
364
|
"ENGINE_START_FAILED", f"stopping {plan['name']}: {outcome.get('message')}"
|
|
@@ -370,15 +366,51 @@ def _remove_service(plan: Plan, run: Executor) -> None:
|
|
|
370
366
|
hosts.delete_record(hosts.LOCAL_ID, plan["name"], deploy_dir=plan["service"]["deploy_dir"])
|
|
371
367
|
|
|
372
368
|
|
|
369
|
+
def _forget_deploy_dir(deploy_dir: str, name: str) -> None:
|
|
370
|
+
"""Delete one deployment directory (its log/key) and purge its manifest entry."""
|
|
371
|
+
path = Path(os.path.expanduser(deploy_dir))
|
|
372
|
+
if path.parent.name == "deployments" and path.is_dir():
|
|
373
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
374
|
+
hosts.delete_record(hosts.LOCAL_ID, name, purged=True, deploy_dir=deploy_dir)
|
|
375
|
+
|
|
376
|
+
|
|
373
377
|
def _forget_deployment(plan: Plan) -> None:
|
|
374
378
|
"""The removed server's directory (its log) and its manifest entry: nothing of the model is
|
|
375
379
|
left for a later purge to find."""
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
_forget_deploy_dir(plan["service"]["deploy_dir"], plan["name"])
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _prior_key_dirs(record: Record) -> list[Path]:
|
|
384
|
+
"""Candidate deployment directories that may hold a preserved api-key or .pinned-api-key."""
|
|
385
|
+
raw: list[str] = []
|
|
386
|
+
active_dir = record["plan"]["service"]["deploy_dir"]
|
|
387
|
+
last_dir = record.get("last_deploy_dir")
|
|
388
|
+
if record["state"] == "idle":
|
|
389
|
+
if last_dir:
|
|
390
|
+
raw.append(last_dir)
|
|
391
|
+
raw.append(active_dir)
|
|
392
|
+
else:
|
|
393
|
+
raw.append(active_dir)
|
|
394
|
+
if last_dir:
|
|
395
|
+
raw.append(last_dir)
|
|
396
|
+
if (baseline := record.get("baseline_plan")) is not None:
|
|
397
|
+
raw.append(baseline["service"]["deploy_dir"])
|
|
398
|
+
dirs: list[Path] = []
|
|
399
|
+
seen: set[Path] = set()
|
|
400
|
+
for item in raw:
|
|
401
|
+
path = Path(os.path.expanduser(item))
|
|
402
|
+
resolved = path.resolve()
|
|
403
|
+
if resolved not in seen:
|
|
404
|
+
seen.add(resolved)
|
|
405
|
+
dirs.append(path)
|
|
406
|
+
return dirs
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def _saved_prior_key(dirs: list[Path]) -> str | None:
|
|
410
|
+
for path in dirs:
|
|
411
|
+
if key := deploy.saved_api_key_in(path):
|
|
412
|
+
return key
|
|
413
|
+
return None
|
|
382
414
|
|
|
383
415
|
|
|
384
416
|
def _clear_load_timing(record: Record) -> None:
|
|
@@ -500,7 +532,7 @@ def _restore_baseline_plan(record: Record) -> None:
|
|
|
500
532
|
record["plan"] = baseline
|
|
501
533
|
|
|
502
534
|
|
|
503
|
-
def stop(record: Record, run: Executor) -> None:
|
|
535
|
+
def stop(record: Record, run: Executor, *, keep_key: bool = True) -> None:
|
|
504
536
|
"""Demote a loaded record, then stop and remove the model's server; its weights stay."""
|
|
505
537
|
had_registration = record.pop("registration", None) is not None
|
|
506
538
|
if record["state"] == "loaded":
|
|
@@ -514,8 +546,16 @@ def stop(record: Record, run: Executor) -> None:
|
|
|
514
546
|
library_state.save(record)
|
|
515
547
|
record.pop("load_posture", None)
|
|
516
548
|
_clear_load_timing(record)
|
|
549
|
+
stopped_deploy_dir = record["plan"]["service"]["deploy_dir"]
|
|
517
550
|
if record["state"] != "idle": # loaded, failed, or starting when a load was cut short
|
|
518
|
-
|
|
551
|
+
if keep_key:
|
|
552
|
+
_remove_service(record["plan"], run)
|
|
553
|
+
else:
|
|
554
|
+
_remove_service(record["plan"], run, keep_key=False)
|
|
555
|
+
if not keep_key:
|
|
556
|
+
record.pop("last_deploy_dir", None)
|
|
557
|
+
elif deploy.saved_api_key_in(stopped_deploy_dir) is not None:
|
|
558
|
+
record["last_deploy_dir"] = stopped_deploy_dir
|
|
519
559
|
record["state"] = "idle"
|
|
520
560
|
for key in ("registration", "error", "note"):
|
|
521
561
|
record.pop(key, None) # type: ignore[misc]
|
|
@@ -620,13 +660,13 @@ def _serve(
|
|
|
620
660
|
) -> Record:
|
|
621
661
|
load_started = time.monotonic()
|
|
622
662
|
first_load = not bool(record.get("ever_loaded") or record.get("tokens_per_second") is not None)
|
|
623
|
-
base = base_of(record)
|
|
663
|
+
base = library_state.base_of(record)
|
|
624
664
|
use_jinja, autostart = _custom_flags(record)
|
|
625
665
|
facts, elastic = _serve_elastic_plan(model, record, facts, base, port, ctx, use_jinja=use_jinja)
|
|
626
666
|
plan = elastic.plan
|
|
627
667
|
if not autostart:
|
|
628
668
|
plan["service"]["autostart"] = False
|
|
629
|
-
if missing :=
|
|
669
|
+
if missing := library_state.files_missing(plan):
|
|
630
670
|
raise LibraryError("MODEL_FILES_MISSING", "missing: " + ", ".join(missing), failed=True)
|
|
631
671
|
steps = [str(step) for step in LOAD_STEPS]
|
|
632
672
|
record["load_posture"] = _load_posture_record(elastic)
|
|
@@ -639,6 +679,7 @@ def _serve(
|
|
|
639
679
|
base=base,
|
|
640
680
|
pool=record["pool"],
|
|
641
681
|
port=port,
|
|
682
|
+
fallback_api_key=ctx.fallback_api_key,
|
|
642
683
|
)
|
|
643
684
|
if record.get("baseline_plan") is None:
|
|
644
685
|
record["baseline_plan"] = record["plan"]
|
|
@@ -668,6 +709,7 @@ def _serve(
|
|
|
668
709
|
raise
|
|
669
710
|
record["state"] = "loaded"
|
|
670
711
|
record["ever_loaded"] = True
|
|
712
|
+
record["last_deploy_dir"] = record["plan"]["service"]["deploy_dir"]
|
|
671
713
|
record.pop("error", None)
|
|
672
714
|
record.pop("note", None)
|
|
673
715
|
library_state.save(record)
|
|
@@ -735,7 +777,8 @@ def _start(
|
|
|
735
777
|
pre_deploy_ms = max(0, round((time.monotonic() - started_at) * 1000))
|
|
736
778
|
oom_retries = 0
|
|
737
779
|
while True:
|
|
738
|
-
|
|
780
|
+
resolved_key = deploy.resolve_api_key(plan, fallback_key=ctx.fallback_api_key)
|
|
781
|
+
finished = app.run_deploy(hosts.LOCAL_ID, plan, api_key=resolved_key, on_event=seen)
|
|
739
782
|
if finished["ok"]:
|
|
740
783
|
break
|
|
741
784
|
code = _start_code(finished, custom=record.get("custom") is not None)
|
|
@@ -893,7 +936,7 @@ def _try_claim_load_locked(
|
|
|
893
936
|
record = library_state.load(model.id)
|
|
894
937
|
if record is None:
|
|
895
938
|
raise LibraryError("INVALID_STATE", f"{model.id} is not downloaded")
|
|
896
|
-
if missing :=
|
|
939
|
+
if missing := library_state.files_missing(record["plan"]):
|
|
897
940
|
raise LibraryError("MODEL_FILES_MISSING", "missing: " + ", ".join(missing))
|
|
898
941
|
facts = library_jobs.probe()
|
|
899
942
|
url = str(record["plan"]["endpoint"]["base_url"])
|
|
@@ -1010,6 +1053,8 @@ def load(
|
|
|
1010
1053
|
with library_state.held(claims):
|
|
1011
1054
|
handle = library_state.JobHandle(claims[0])
|
|
1012
1055
|
handle.update("load", 0, len(LOAD_STEPS), load_step="prepare")
|
|
1056
|
+
prior_dirs = _prior_key_dirs(record)
|
|
1057
|
+
prior_key = _saved_prior_key(prior_dirs)
|
|
1013
1058
|
for target in targets:
|
|
1014
1059
|
stop(target, executor)
|
|
1015
1060
|
if record["state"] != "idle": # a server that stopped answering, or a failed load
|
|
@@ -1023,8 +1068,15 @@ def load(
|
|
|
1023
1068
|
executor,
|
|
1024
1069
|
port,
|
|
1025
1070
|
handle,
|
|
1026
|
-
load_ctx,
|
|
1071
|
+
replace(load_ctx, fallback_api_key=prior_key),
|
|
1027
1072
|
)
|
|
1073
|
+
active_deploy_dir = Path(
|
|
1074
|
+
os.path.expanduser(record["plan"]["service"]["deploy_dir"])
|
|
1075
|
+
).resolve()
|
|
1076
|
+
for prior_dir in prior_dirs:
|
|
1077
|
+
if prior_dir.resolve() != active_deploy_dir:
|
|
1078
|
+
with contextlib.suppress(OSError):
|
|
1079
|
+
(prior_dir / "api-key").unlink(missing_ok=True)
|
|
1028
1080
|
return _row(model, base_dir)
|
|
1029
1081
|
|
|
1030
1082
|
|
|
@@ -1054,15 +1106,26 @@ def remove(model_id: str, base_dir: str) -> Row:
|
|
|
1054
1106
|
record, job = _claim(model, "remove")
|
|
1055
1107
|
with library_state.held([job]):
|
|
1056
1108
|
active_plan = record["plan"]
|
|
1109
|
+
last_deploy_dir = record.get("last_deploy_dir")
|
|
1057
1110
|
if record["state"] != "idle":
|
|
1058
|
-
stop(record, library_jobs.executor())
|
|
1111
|
+
stop(record, library_jobs.executor(), keep_key=False)
|
|
1059
1112
|
with library_state.locked():
|
|
1060
1113
|
weight_dests = library_jobs.dests(record["plan"])
|
|
1061
1114
|
library_jobs.delete_weights(weight_dests, library_jobs.in_use(model.id))
|
|
1062
|
-
library_jobs.prune_empty_custom_dirs(weight_dests, base_of(record))
|
|
1115
|
+
library_jobs.prune_empty_custom_dirs(weight_dests, library_state.base_of(record))
|
|
1063
1116
|
_forget_deployment(record["plan"])
|
|
1117
|
+
forgotten = {
|
|
1118
|
+
Path(os.path.expanduser(record["plan"]["service"]["deploy_dir"])).resolve()
|
|
1119
|
+
}
|
|
1064
1120
|
if active_plan["name"] != record["plan"]["name"]:
|
|
1065
1121
|
_forget_deployment(active_plan)
|
|
1122
|
+
forgotten.add(
|
|
1123
|
+
Path(os.path.expanduser(active_plan["service"]["deploy_dir"])).resolve()
|
|
1124
|
+
)
|
|
1125
|
+
if last_deploy_dir:
|
|
1126
|
+
last_path = Path(os.path.expanduser(last_deploy_dir))
|
|
1127
|
+
if last_path.resolve() not in forgotten:
|
|
1128
|
+
_forget_deploy_dir(last_deploy_dir, last_path.name)
|
|
1066
1129
|
library_state.forget(model.id)
|
|
1067
1130
|
runtime_index.refresh()
|
|
1068
1131
|
return _row(model, base_dir)
|
|
@@ -291,7 +291,7 @@ def smoke_test(model_id: str, base_dir: str, *, ctx: int = 4096) -> Row:
|
|
|
291
291
|
if record is None:
|
|
292
292
|
raise LibraryError("INVALID_STATE", f"{model.id} is not downloaded")
|
|
293
293
|
_validate_smoke_record(model.id, record)
|
|
294
|
-
if missing :=
|
|
294
|
+
if missing := library_state.files_missing(record["plan"]):
|
|
295
295
|
raise LibraryError("MODEL_FILES_MISSING", "missing: " + ", ".join(missing))
|
|
296
296
|
facts = library_jobs.probe()
|
|
297
297
|
taken = {
|
|
@@ -22,7 +22,7 @@ from contextlib import contextmanager
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
from typing import Literal, TypedDict
|
|
24
24
|
|
|
25
|
-
from localmodels import hosts, process_identity
|
|
25
|
+
from localmodels import draft_spec, hosts, plan_envelope, process_identity
|
|
26
26
|
from localmodels.contracts import decode
|
|
27
27
|
from localmodels.library_model import LibraryError, LoadBreakdownMs, Note, Problem
|
|
28
28
|
from localmodels.plan_envelope import utc_now
|
|
@@ -142,6 +142,9 @@ class Record(_RecordRequired, total=False):
|
|
|
142
142
|
pi_model: str # what pi offers once it is loaded; fixed when the record is made
|
|
143
143
|
load_posture: LoadPosture # elastic posture & warning metadata recorded on load
|
|
144
144
|
baseline_plan: Plan # pristine capacity plan preserved while a degraded/active load runs
|
|
145
|
+
last_deploy_dir: (
|
|
146
|
+
str # last deployment directory whose api-key / .pinned-api-key may outlive unload
|
|
147
|
+
)
|
|
145
148
|
custom: CustomMeta # custom hub model metadata (absent for curated models)
|
|
146
149
|
verification: VerificationRecord # smoke-test verification state (custom models)
|
|
147
150
|
catalog_entry: dict[str, object] # schema-3 entry snapshot for custom models
|
|
@@ -234,6 +237,25 @@ def locked(state_dir: Path | None = None) -> Iterator[None]:
|
|
|
234
237
|
held.discard(resolved)
|
|
235
238
|
|
|
236
239
|
|
|
240
|
+
def base_of(record: Record) -> str:
|
|
241
|
+
"""The base directory the model was downloaded into."""
|
|
242
|
+
if record.get("base_dir"):
|
|
243
|
+
return record["base_dir"]
|
|
244
|
+
deploy_dir = os.path.expanduser(record["plan"]["service"]["deploy_dir"])
|
|
245
|
+
return os.path.dirname(os.path.dirname(deploy_dir))
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def files_missing(plan: Plan) -> list[str]:
|
|
249
|
+
"""The files ``plan`` cannot start without that are not verified in place. Its optional
|
|
250
|
+
drafter is never one: a load plans without it (``library_elastic.load_posture``)."""
|
|
251
|
+
optional = draft_spec.drafter_dest(plan)
|
|
252
|
+
return [
|
|
253
|
+
Path(f["dest"]).name
|
|
254
|
+
for f in plan["files"]
|
|
255
|
+
if f["dest"] != optional and not plan_envelope.verified_in_place(f)
|
|
256
|
+
]
|
|
257
|
+
|
|
258
|
+
|
|
237
259
|
def load(model: str) -> Record | None:
|
|
238
260
|
try:
|
|
239
261
|
value = json.loads(record_path(model).read_text(encoding="utf-8"))
|
|
@@ -6,8 +6,6 @@ from __future__ import annotations
|
|
|
6
6
|
|
|
7
7
|
import datetime as dt
|
|
8
8
|
import os
|
|
9
|
-
import re
|
|
10
|
-
import urllib.request
|
|
11
9
|
from collections.abc import Iterable, Mapping
|
|
12
10
|
from dataclasses import dataclass, field
|
|
13
11
|
from typing import Any, cast
|
|
@@ -17,6 +15,7 @@ from localmodels import (
|
|
|
17
15
|
debug_mode,
|
|
18
16
|
deployment_lifecycle,
|
|
19
17
|
hosts,
|
|
18
|
+
http_local,
|
|
20
19
|
library_direct,
|
|
21
20
|
library_elastic,
|
|
22
21
|
library_order,
|
|
@@ -82,7 +81,9 @@ ARCH = {
|
|
|
82
81
|
"arm64": "arm64",
|
|
83
82
|
"aarch64": "arm64",
|
|
84
83
|
}
|
|
85
|
-
HEALTH_TIMEOUT_S =
|
|
84
|
+
HEALTH_TIMEOUT_S = 3.0
|
|
85
|
+
HEALTH_RETRIES = 3
|
|
86
|
+
HEALTH_RETRY_BACKOFF_S = 0.5
|
|
86
87
|
_PATH: Any = os.path
|
|
87
88
|
_SIDECAR_SUFFIXES = (".sha256", ".part", ".part.ranges", ".tmp")
|
|
88
89
|
|
|
@@ -172,12 +173,12 @@ def platform_name(facts: HostFacts) -> str:
|
|
|
172
173
|
def answering(base_url: str) -> bool:
|
|
173
174
|
"""llama-server's ``/health`` answers 200 without a key once the model is loaded."""
|
|
174
175
|
url = base_url.removesuffix("/").removesuffix("/v1") + "/health"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
return http_local.probe_health(
|
|
177
|
+
url,
|
|
178
|
+
timeout=HEALTH_TIMEOUT_S,
|
|
179
|
+
retries=HEALTH_RETRIES,
|
|
180
|
+
backoff_s=HEALTH_RETRY_BACKOFF_S,
|
|
181
|
+
)
|
|
181
182
|
|
|
182
183
|
|
|
183
184
|
@dataclass
|
|
@@ -301,9 +302,11 @@ def _state(lib: Library, model: str, record: Record | None) -> tuple[str, Proble
|
|
|
301
302
|
return "failed", {"code": code, "detail": f"the {job['kind']} process ended early"}
|
|
302
303
|
if record is None:
|
|
303
304
|
return "absent", None
|
|
305
|
+
if record["state"] == "loaded" and lib.healthy(str(record["plan"]["endpoint"]["base_url"])):
|
|
306
|
+
return "loaded", None
|
|
307
|
+
if missing := library_state.files_missing(record["plan"]):
|
|
308
|
+
return "failed", _missing_files(missing)
|
|
304
309
|
if record["state"] == "loaded":
|
|
305
|
-
if lib.healthy(str(record["plan"]["endpoint"]["base_url"])):
|
|
306
|
-
return "loaded", None
|
|
307
310
|
return "failed", {
|
|
308
311
|
"code": "HEALTH_CHECK_FAILED",
|
|
309
312
|
"detail": "the model server does not answer; load it again",
|
|
@@ -318,25 +321,41 @@ def _state(lib: Library, model: str, record: Record | None) -> tuple[str, Proble
|
|
|
318
321
|
return "idle", None
|
|
319
322
|
|
|
320
323
|
|
|
324
|
+
def _missing_files(names: list[str]) -> Problem:
|
|
325
|
+
return {
|
|
326
|
+
"code": "MODEL_FILES_MISSING",
|
|
327
|
+
"detail": "Remove and re-download; missing: " + ", ".join(names),
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
321
331
|
def _plan_of(
|
|
322
332
|
lib: Library,
|
|
323
333
|
model: Model,
|
|
324
334
|
record: Record | None,
|
|
325
335
|
priced: Priced,
|
|
326
336
|
*,
|
|
327
|
-
state: str
|
|
337
|
+
state: str,
|
|
328
338
|
) -> Plan | None:
|
|
329
|
-
"""
|
|
330
|
-
|
|
331
|
-
the price on the pool that job recorded (status never moves a running download to another card)."""
|
|
339
|
+
"""Show a running server as started, but a standby curated model as the next load
|
|
340
|
+
would plan it. Never move an installed model to another pool or base directory."""
|
|
332
341
|
if record is not None:
|
|
333
|
-
if
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
if state == "loaded":
|
|
343
|
+
return record["plan"]
|
|
344
|
+
if state in ("idle", "failed") and "custom" not in record:
|
|
345
|
+
base = library_state.base_of(record)
|
|
346
|
+
if priced.pool == record["pool"] and base == lib.base_dir and priced.plan is not None:
|
|
347
|
+
return priced.plan
|
|
348
|
+
try:
|
|
349
|
+
return library_pricing.price(
|
|
350
|
+
memory_pools.capacity(lib.facts, reclaimable=lib.reclaimable()),
|
|
351
|
+
model,
|
|
352
|
+
record["pool"],
|
|
353
|
+
base,
|
|
354
|
+
lib.catalog,
|
|
355
|
+
)
|
|
356
|
+
except plan_envelope.PlanError:
|
|
357
|
+
pass # Unsupported hardware or retired recipe: retain the installation receipt.
|
|
358
|
+
return record.get("baseline_plan", record["plan"])
|
|
340
359
|
job, alive = lib.jobs.get(model.id, (None, False))
|
|
341
360
|
if job is not None and alive and job["pool"] != priced.pool:
|
|
342
361
|
try:
|
|
@@ -363,34 +382,6 @@ def pi_model_of(model: Model, record: Record | None) -> str | None:
|
|
|
363
382
|
return library_direct.pi_model(model.id, model.variant.model_id)
|
|
364
383
|
|
|
365
384
|
|
|
366
|
-
HUB_REPO = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]*/[A-Za-z0-9][A-Za-z0-9._-]*")
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
def card(model: Model, vision_on: bool) -> Row:
|
|
370
|
-
"""The model card fields of a row, each only when the catalog states it: family,
|
|
371
|
-
publisher and parameter scales as written there, the architecture from its MoE flag, its
|
|
372
|
-
license, the Hugging Face page of the repository the weights come from, and vision when
|
|
373
|
-
this deployment reads images (its projector is pinned and priced). Nothing is guessed from
|
|
374
|
-
a name; Linger rejects a whole status document over one value outside its sets."""
|
|
375
|
-
entry = model.entry
|
|
376
|
-
found: dict[str, object] = {
|
|
377
|
-
"family": entry.family,
|
|
378
|
-
"publisher": entry.publisher.strip()[:120],
|
|
379
|
-
"architecture": "moe" if entry.moe else "dense",
|
|
380
|
-
"parameters": entry.parameters,
|
|
381
|
-
"active_parameters": entry.active_parameters if entry.moe else "",
|
|
382
|
-
"license": entry.license.strip()[:120],
|
|
383
|
-
}
|
|
384
|
-
if HUB_REPO.fullmatch(entry.repo):
|
|
385
|
-
found["source_url"] = f"https://huggingface.co/{entry.repo}"
|
|
386
|
-
caps = [c for c in entry.capabilities if c != "vision" or vision_on]
|
|
387
|
-
if vision_on and "vision" not in caps:
|
|
388
|
-
caps = ["vision", *caps]
|
|
389
|
-
if caps:
|
|
390
|
-
found["capabilities"] = caps
|
|
391
|
-
return cast(Row, {k: v for k, v in found.items() if v})
|
|
392
|
-
|
|
393
|
-
|
|
394
385
|
def _apply_live_fit(
|
|
395
386
|
lib: Library,
|
|
396
387
|
found: Row,
|
|
@@ -410,7 +401,7 @@ def _apply_live_fit(
|
|
|
410
401
|
lib.facts,
|
|
411
402
|
model,
|
|
412
403
|
record["pool"],
|
|
413
|
-
|
|
404
|
+
library_state.base_of(record),
|
|
414
405
|
lib.catalog,
|
|
415
406
|
lib.reserved(),
|
|
416
407
|
fallback_need=memory,
|
|
@@ -494,6 +485,9 @@ def _apply_engine_meta(lib: Library, found: Row, model: Model, plan: Plan | None
|
|
|
494
485
|
elif engine == "polystrata":
|
|
495
486
|
recipe = next((r for r in suite.recipes("llm") if r["id"] == model.entry.id), None)
|
|
496
487
|
concurrency = suite.effective_parallel(recipe, ()) if recipe is not None else 1
|
|
488
|
+
if recipe is not None and lib.facts["platform"] == "darwin":
|
|
489
|
+
# Apple Silicon runs its own slot count where the CUDA tier is the offload one.
|
|
490
|
+
concurrency = int(str(recipe.get("metal_parallel") or concurrency))
|
|
497
491
|
else:
|
|
498
492
|
concurrency = 1 if engine == "strata" else library_pricing.posture().slots
|
|
499
493
|
found["concurrency"] = concurrency
|
|
@@ -610,7 +604,7 @@ def _apply_record_meta(
|
|
|
610
604
|
found["oom_retries"] = int(retries)
|
|
611
605
|
if lp.get("forced"):
|
|
612
606
|
found["forced"] = True
|
|
613
|
-
if state == "idle" and (note := record.get("note")):
|
|
607
|
+
if state == "idle" and not found["fits_now"] and (note := record.get("note")):
|
|
614
608
|
found["note"] = note
|
|
615
609
|
if state == "failed" and problem is not None:
|
|
616
610
|
found["error"] = sanitize_problem(problem)
|
|
@@ -927,6 +921,8 @@ def row(lib: Library, model: Model, *, now_utc: dt.datetime | None = None) -> Ro
|
|
|
927
921
|
priced = lib.judge(model)
|
|
928
922
|
state, problem = _state(lib, model.id, record)
|
|
929
923
|
plan = _plan_of(lib, model, record, priced, state=state)
|
|
924
|
+
if state == "idle" and plan is not None and (missing := library_state.files_missing(plan)):
|
|
925
|
+
state, problem = "failed", _missing_files(missing)
|
|
930
926
|
job, alive = lib.jobs.get(model.id, (None, False))
|
|
931
927
|
fallback_memory, fallback_window, fallback_vision, fallback_download = (
|
|
932
928
|
library_pricing.floor_metadata(
|
|
@@ -938,15 +934,20 @@ def row(lib: Library, model: Model, *, now_utc: dt.datetime | None = None) -> Ro
|
|
|
938
934
|
memory = memory_pools.memory_bytes(plan) if plan is not None else fallback_memory
|
|
939
935
|
if record is None and job is not None and alive:
|
|
940
936
|
memory = job["memory_bytes"] or memory
|
|
941
|
-
if record is not None and record["state"] != "loaded" and record.get("memory_bytes"):
|
|
942
|
-
memory = record["memory_bytes"]
|
|
943
937
|
availability: Availability = {"downloadable": True}
|
|
944
938
|
if record is None:
|
|
945
939
|
reason = library_pricing.download_reason(
|
|
946
|
-
lib.facts, priced, library_pricing.base_free(lib.base_dir)
|
|
940
|
+
lib.facts, priced, library_pricing.base_free(lib.base_dir), fallback_download
|
|
947
941
|
)
|
|
948
942
|
if reason is not None:
|
|
949
943
|
availability = {"downloadable": False, "reason": reason}
|
|
944
|
+
if availability["downloadable"]:
|
|
945
|
+
# Downloadable (or downloaded) but not loadable until memory is freed: the row keeps fit
|
|
946
|
+
# "none" and carries the structured shortfall in ``availability.reason``, where a blocked
|
|
947
|
+
# download carries its refusal, so a client offers "Download only" and shows the exact
|
|
948
|
+
# VRAM/RAM gap.
|
|
949
|
+
if (shortfall := priced.memory_shortfall) is not None:
|
|
950
|
+
availability["reason"] = shortfall
|
|
950
951
|
launch: dict[str, object] = dict(plan["launch"]) if plan is not None else {}
|
|
951
952
|
found: Row = {
|
|
952
953
|
"id": model.id,
|
|
@@ -981,7 +982,7 @@ def row(lib: Library, model: Model, *, now_utc: dt.datetime | None = None) -> Ro
|
|
|
981
982
|
found["download"] = _downloading(job)
|
|
982
983
|
elif state == "loading" and job is not None and alive:
|
|
983
984
|
found["load"] = _loading(job)
|
|
984
|
-
found.update(card(model, found["vision"]))
|
|
985
|
+
found.update(library_presentation.card(model, found["vision"]))
|
|
985
986
|
_apply_engine_meta(lib, found, model, plan)
|
|
986
987
|
library_presentation.apply_row_meta(lib.facts, found, model, plan)
|
|
987
988
|
_apply_record_meta(found, model, record, state, problem, now_utc=observed_now)
|