@simplexai/localmodels-linux-arm64 0.1.0-dev.62 → 0.1.0-dev.64
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 +112 -103
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/app.py +15 -2
- package/modules/localmodels/bifrost_checks.py +19 -13
- package/modules/localmodels/bifrost_clients.py +38 -36
- package/modules/localmodels/bifrost_config.py +19 -6
- package/modules/localmodels/bifrost_log.py +3 -3
- package/modules/localmodels/bifrost_models.py +9 -8
- package/modules/localmodels/bifrost_pi.py +27 -72
- package/modules/localmodels/catalog.json +85 -58
- package/modules/localmodels/catalog.py +26 -4
- package/modules/localmodels/catalog_recipes.py +37 -1
- package/modules/localmodels/context_policy.py +6 -1
- package/modules/localmodels/custom_hub.py +10 -1
- package/modules/localmodels/custom_hub_http.py +14 -3
- package/modules/localmodels/debug_mode.py +85 -103
- package/modules/localmodels/deploy.py +41 -6
- package/modules/localmodels/download-mirrors.json +126 -6
- package/modules/localmodels/draft_spec.py +122 -0
- package/modules/localmodels/engine_adapters/__init__.py +4 -0
- package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
- package/modules/localmodels/engine_adapters/base.py +40 -0
- package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
- package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
- package/modules/localmodels/gateway.py +56 -55
- package/modules/localmodels/gateway_bifrost.py +70 -83
- package/modules/localmodels/gateway_clients.py +33 -116
- package/modules/localmodels/gateway_home.py +5 -5
- package/modules/localmodels/gateway_keys.py +8 -6
- package/modules/localmodels/gateway_probe.py +4 -4
- package/modules/localmodels/gateway_server.py +4 -4
- package/modules/localmodels/gateway_speed.py +2 -2
- package/modules/localmodels/harness.py +185 -401
- package/modules/localmodels/harness_core.py +409 -0
- package/modules/localmodels/harness_gateway.py +75 -73
- package/modules/localmodels/harness_probe.py +19 -216
- package/modules/localmodels/install.py +15 -0
- package/modules/localmodels/library_convert.py +2 -8
- package/modules/localmodels/library_custom.py +51 -16
- package/modules/localmodels/library_elastic.py +3 -119
- package/modules/localmodels/library_gateway.py +59 -176
- package/modules/localmodels/library_jobs.py +1 -2
- package/modules/localmodels/library_model.py +23 -0
- package/modules/localmodels/library_poly.py +3 -2
- package/modules/localmodels/library_pricing.py +124 -15
- package/modules/localmodels/library_serve.py +9 -9
- package/modules/localmodels/library_smoke.py +33 -21
- package/modules/localmodels/library_status.py +330 -2
- package/modules/localmodels/llm_rank.py +14 -5
- package/modules/localmodels/magpie_setup.py +5 -4
- package/modules/localmodels/magpie_windows.py +1 -1
- package/modules/localmodels/memcalc_cli.py +2 -2
- package/modules/localmodels/pi_profile.py +384 -0
- package/modules/localmodels/planning/__init__.py +3 -0
- package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
- package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
- package/modules/localmodels/process_identity.py +3 -3
- package/modules/localmodels/runtime_cli.py +32 -46
- package/modules/localmodels/runtime_pi.py +1 -1
- package/modules/localmodels/service_deployment.py +2 -1
- package/modules/localmodels/sizecalc_cli.py +10 -2
- package/modules/localmodels/source_byok.py +9 -16
- package/modules/localmodels/speech_worker_sensevoice.py +30 -0
- package/modules/localmodels/stack.py +2 -4
- package/modules/localmodels/stack_arena.py +2 -2
- package/modules/localmodels/stack_auto.py +1 -1
- package/modules/localmodels/stack_aux_gpu.py +4 -2
- package/modules/localmodels/stack_binding.py +9 -7
- package/modules/localmodels/stack_card.py +2 -2
- package/modules/localmodels/stack_cleanup.py +3 -2
- package/modules/localmodels/stack_clients.py +137 -21
- package/modules/localmodels/stack_compose.py +9 -1
- package/modules/localmodels/stack_doctor.py +6 -3
- package/modules/localmodels/stack_hardware.py +18 -0
- package/modules/localmodels/stack_ledger.py +2 -1
- package/modules/localmodels/stack_lifecycle.py +3 -2
- package/modules/localmodels/stack_mcp.py +1 -1
- package/modules/localmodels/stack_memory.py +3 -3
- package/modules/localmodels/stack_remove.py +2 -1
- package/modules/localmodels/stack_run.py +16 -0
- package/modules/localmodels/stack_suite.py +4 -3
- package/modules/localmodels/stack_try.py +2 -1
- package/modules/localmodels/stack_up.py +15 -30
- package/modules/localmodels/stack_verify.py +2 -2
- package/modules/localmodels/stack_view_events.py +2 -2
- package/modules/localmodels/stack_view_llm.py +12 -7
- package/modules/localmodels/stack_warm.py +6 -3
- package/modules/localmodels/stack_whatif.py +1 -1
- package/modules/localmodels/suite.py +6 -334
- package/modules/localmodels/tui_views.py +17 -2
- package/modules/localmodels/web/index.html +595 -226
- package/modules/localmodels/web/sizecalc/app.js +34 -40
- package/modules/localmodels/web/sizecalc/calc.js +3 -3
- package/modules/localmodels/web/sizecalc/page.html +4 -3
- package/modules/localmodels/web/view/fleet.html +18 -3
- package/modules/localmodels/web/view/fleet.js +135 -14
- package/modules/localmodels/web/view/i18n.js +4 -0
- package/modules/localmodels/web/view/index.html +16 -0
- package/modules/localmodels/web/view/nav.js +49 -0
- package/modules/localmodels/web/view/theme.js +1 -1
- package/modules/localmodels/web/view/view.css +51 -15
- package/modules/localmodels/web/view/view.js +22 -4
- package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/RECORD +109 -100
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev62.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Validated ``strata-poly`` chat recipes that declare model-card metadata (``display_name``,
|
|
4
4
|
``description``, ``family``, ``publisher``, ``parameters``) join ``localmodels library`` on
|
|
5
5
|
supported NVIDIA Linux and Windows hosts alongside ``llama.cpp`` models. Pricing runs
|
|
6
|
-
``
|
|
6
|
+
``suite_plan.build_plan`` so CUDA 13 driver checks, glibc checks, vision reader placement and host
|
|
7
7
|
RAM ceilings stay identical to ``stack plan``.
|
|
8
8
|
"""
|
|
9
9
|
|
|
@@ -22,6 +22,7 @@ from localmodels import (
|
|
|
22
22
|
)
|
|
23
23
|
from localmodels import catalog as cat
|
|
24
24
|
from localmodels.context_policy import AgentPosture
|
|
25
|
+
from localmodels.engine_adapters import suite_plan
|
|
25
26
|
from localmodels.estimator import PhysicsRefusal
|
|
26
27
|
from localmodels.library_model import Reason, split_id
|
|
27
28
|
from localmodels.probe import GPU, HostFacts
|
|
@@ -297,7 +298,7 @@ def price(
|
|
|
297
298
|
vram_reserve_mib=reserve,
|
|
298
299
|
vision_reader=reader,
|
|
299
300
|
)
|
|
300
|
-
plan =
|
|
301
|
+
plan = suite_plan.build_plan(hosts.LOCAL_ID, facts, recipe, opts)
|
|
301
302
|
if facts["platform"] == "win32":
|
|
302
303
|
plan = suite.unbounded(plan)
|
|
303
304
|
_calibrate_host_ram(plan, recipe, gpu)
|
|
@@ -14,6 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import copy
|
|
16
16
|
import functools
|
|
17
|
+
import math
|
|
17
18
|
import os
|
|
18
19
|
import shutil
|
|
19
20
|
from collections.abc import Iterable, Mapping
|
|
@@ -24,6 +25,7 @@ from typing import Any, Literal
|
|
|
24
25
|
from localmodels import (
|
|
25
26
|
budget,
|
|
26
27
|
context_policy,
|
|
28
|
+
debug_mode,
|
|
27
29
|
deploy,
|
|
28
30
|
engines,
|
|
29
31
|
hosts,
|
|
@@ -33,6 +35,8 @@ from localmodels import (
|
|
|
33
35
|
llm_rank,
|
|
34
36
|
metal,
|
|
35
37
|
plan_envelope,
|
|
38
|
+
remote_ops_download,
|
|
39
|
+
stack_compose,
|
|
36
40
|
stack_hardware,
|
|
37
41
|
stack_llm_ram,
|
|
38
42
|
suite,
|
|
@@ -43,13 +47,14 @@ from localmodels.context_policy import AgentPosture
|
|
|
43
47
|
from localmodels.estimator import (
|
|
44
48
|
AGENT_VRAM_RESERVE_BYTES,
|
|
45
49
|
METAL_VRAM_RESERVE_BYTES,
|
|
50
|
+
PhysicsRefusal,
|
|
46
51
|
agent_footprint_bytes,
|
|
47
52
|
eager,
|
|
48
53
|
)
|
|
49
54
|
from localmodels.library_model import LibraryError, Reason, display_name, split_id
|
|
50
55
|
from localmodels.probe import HostFacts
|
|
51
56
|
from localmodels.records import Plan
|
|
52
|
-
from localmodels.stack_plan import platform_error
|
|
57
|
+
from localmodels.stack_plan import default_options, platform_error
|
|
53
58
|
|
|
54
59
|
POOL_RAM_FRACTION = 0.8 # a "system" pool's budget: RAM x 0.8 (contract v2)
|
|
55
60
|
UNIFIED_RESERVE_BYTES = metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
|
|
@@ -59,9 +64,7 @@ DESKTOP_VRAM_BASELINE_CAP_BYTES = budget.DESKTOP_VRAM_BASELINE_CAP_BYTES
|
|
|
59
64
|
@functools.cache
|
|
60
65
|
def posture() -> AgentPosture:
|
|
61
66
|
"""The default stack plan's agent posture: its slots, image input and thinking cap."""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return stack_compose.agent_posture(stack.default_options())
|
|
67
|
+
return stack_compose.agent_posture(default_options())
|
|
65
68
|
|
|
66
69
|
|
|
67
70
|
@dataclass(frozen=True)
|
|
@@ -363,6 +366,116 @@ def _required_host_ram(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int
|
|
|
363
366
|
return host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
|
|
364
367
|
|
|
365
368
|
|
|
369
|
+
def _project_cuda_uma(
|
|
370
|
+
facts: HostFacts, unified: int, target: int, *, bypass_working_set: bool
|
|
371
|
+
) -> HostFacts:
|
|
372
|
+
seen = copy.deepcopy(facts)
|
|
373
|
+
need = target + AGENT_VRAM_RESERVE_BYTES
|
|
374
|
+
raw = int(math.ceil(need / (1 - budget._UMA_HEADROOM_FRACTION)))
|
|
375
|
+
while int(raw * (1 - budget._UMA_HEADROOM_FRACTION)) < need:
|
|
376
|
+
raw += 1
|
|
377
|
+
raw = raw if bypass_working_set else min(unified, raw)
|
|
378
|
+
if bypass_working_set and isinstance(cuda_pool := seen.get("cuda_pool"), dict):
|
|
379
|
+
cuda_pool["total_bytes"], cuda_pool["integrated"] = max(unified, raw), True
|
|
380
|
+
for gpu in seen.get("gpus") or []:
|
|
381
|
+
if gpu.get("vendor") == "nvidia" and gpu.get("mig_mode") != "enabled":
|
|
382
|
+
gpu["free_bytes"], gpu["used_bytes"] = 0, gpu["total_bytes"]
|
|
383
|
+
break
|
|
384
|
+
ram = seen["ram"]
|
|
385
|
+
if bypass_working_set:
|
|
386
|
+
ram["total_bytes"] = max(int(ram["total_bytes"]), raw)
|
|
387
|
+
if (cgroup := seen.get("cgroup_memory")) is not None:
|
|
388
|
+
if (limit := cgroup.get("limit_bytes")) is not None and limit < raw:
|
|
389
|
+
cgroup["limit_bytes"] = raw
|
|
390
|
+
cgroup["usage_bytes"] = 0
|
|
391
|
+
ram["available_bytes"] = min(int(ram["total_bytes"]), raw)
|
|
392
|
+
return seen
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def facts_for_budget(
|
|
396
|
+
facts: HostFacts,
|
|
397
|
+
pool: str,
|
|
398
|
+
target_bytes: int,
|
|
399
|
+
*,
|
|
400
|
+
wired_cap_bytes: int | None = None,
|
|
401
|
+
bypass_working_set: bool = False,
|
|
402
|
+
) -> HostFacts:
|
|
403
|
+
"""Project ``facts`` so ``deploy.build_plan`` prices ``pool`` against ``target_bytes``
|
|
404
|
+
(unified/total) and optional ``wired_cap_bytes`` (Metal GPU wired headroom)."""
|
|
405
|
+
target = max(0, target_bytes)
|
|
406
|
+
if pool == "unified" and metal.supported(facts):
|
|
407
|
+
seen = copy.deepcopy(facts)
|
|
408
|
+
ram = seen["ram"]
|
|
409
|
+
needed_avail = target + metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
|
|
410
|
+
ram["available_bytes"] = (
|
|
411
|
+
needed_avail if bypass_working_set else min(int(ram["total_bytes"]), needed_avail)
|
|
412
|
+
)
|
|
413
|
+
ram["pressure_level"] = metal.PRESSURE_NORMAL
|
|
414
|
+
ram.pop("pressure_kept_bytes", None)
|
|
415
|
+
if isinstance(metal_doc := seen.get("metal"), dict):
|
|
416
|
+
ceiling = (
|
|
417
|
+
max(0, wired_cap_bytes) + METAL_VRAM_RESERVE_BYTES
|
|
418
|
+
if wired_cap_bytes is not None
|
|
419
|
+
else max(metal.wired_ceiling_bytes(facts), target + METAL_VRAM_RESERVE_BYTES)
|
|
420
|
+
if bypass_working_set
|
|
421
|
+
else metal.wired_ceiling_bytes(facts)
|
|
422
|
+
)
|
|
423
|
+
metal_doc["recommended_max_working_set_bytes"] = ceiling
|
|
424
|
+
return seen
|
|
425
|
+
if pool == "unified" and (unified := budget.unified_pool_bytes(facts)) is not None:
|
|
426
|
+
return _project_cuda_uma(facts, unified, target, bypass_working_set=bypass_working_set)
|
|
427
|
+
if (idx := gpu_index(pool)) is not None:
|
|
428
|
+
seen = copy.deepcopy(facts)
|
|
429
|
+
for gpu in seen.get("gpus") or []:
|
|
430
|
+
if gpu["index"] == idx:
|
|
431
|
+
free = target + AGENT_VRAM_RESERVE_BYTES
|
|
432
|
+
gpu["free_bytes"] = free if bypass_working_set else min(gpu["total_bytes"], free)
|
|
433
|
+
gpu["used_bytes"] = max(0, gpu["total_bytes"] - gpu["free_bytes"])
|
|
434
|
+
break
|
|
435
|
+
return seen
|
|
436
|
+
return facts
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def validate_plan_bounds(
|
|
440
|
+
facts: HostFacts,
|
|
441
|
+
model: Model,
|
|
442
|
+
pool: str,
|
|
443
|
+
plan: Plan,
|
|
444
|
+
catalog: tuple[cat.CatalogEntry, ...],
|
|
445
|
+
*,
|
|
446
|
+
check_pool_total: bool = True,
|
|
447
|
+
check_host_ram: bool = True,
|
|
448
|
+
) -> None:
|
|
449
|
+
"""Reject a plan exceeding ``pool``'s total capacity or host RAM on a discrete GPU."""
|
|
450
|
+
if check_pool_total:
|
|
451
|
+
total = pool_total(facts, pool)
|
|
452
|
+
used = memory_bytes(plan)
|
|
453
|
+
if used > total:
|
|
454
|
+
refused = PhysicsRefusal(
|
|
455
|
+
needed_bytes=used,
|
|
456
|
+
available_bytes=total,
|
|
457
|
+
message=f"{model.id} needs {used} bytes, exceeding pool {pool} total {total} bytes",
|
|
458
|
+
)
|
|
459
|
+
raise deploy.AgentMemoryError(
|
|
460
|
+
refused.message,
|
|
461
|
+
refused,
|
|
462
|
+
"unified memory" if pool == "unified" else "GPU memory",
|
|
463
|
+
)
|
|
464
|
+
if check_host_ram and gpu_index(pool) is not None:
|
|
465
|
+
needed_ram = host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
|
|
466
|
+
_, avail_ram = budget.host_ram(facts)
|
|
467
|
+
if needed_ram > avail_ram:
|
|
468
|
+
refused = PhysicsRefusal(
|
|
469
|
+
needed_bytes=needed_ram,
|
|
470
|
+
available_bytes=avail_ram,
|
|
471
|
+
message=(
|
|
472
|
+
f"{model.id} needs {needed_ram} bytes of system memory, "
|
|
473
|
+
f"exceeding {avail_ram} bytes available"
|
|
474
|
+
),
|
|
475
|
+
)
|
|
476
|
+
raise deploy.AgentMemoryError(refused.message, refused, "system memory")
|
|
477
|
+
|
|
478
|
+
|
|
366
479
|
def price(
|
|
367
480
|
facts: HostFacts,
|
|
368
481
|
model: Model,
|
|
@@ -374,8 +487,6 @@ def price(
|
|
|
374
487
|
require_live: bool = False,
|
|
375
488
|
) -> Plan:
|
|
376
489
|
"""The deployment plan on ``pool``; AgentMemoryError when it does not fit there."""
|
|
377
|
-
from localmodels import library_elastic
|
|
378
|
-
|
|
379
490
|
placement = pools(facts).get(pool)
|
|
380
491
|
if placement is None:
|
|
381
492
|
raise plan_envelope.PlanError(f"this computer has no pool {pool}")
|
|
@@ -390,7 +501,7 @@ def price(
|
|
|
390
501
|
raise LiveMemoryUnavailable(problem)
|
|
391
502
|
adm = budget.admission_budget(facts, "unified")
|
|
392
503
|
if adm is not None:
|
|
393
|
-
facts =
|
|
504
|
+
facts = facts_for_budget(
|
|
394
505
|
facts, "unified", adm.soft_budget_bytes, wired_cap_bytes=adm.wired_headroom_bytes
|
|
395
506
|
)
|
|
396
507
|
else:
|
|
@@ -414,7 +525,7 @@ def price(
|
|
|
414
525
|
entries=effective_catalog,
|
|
415
526
|
resolver=deploy.catalog_pins,
|
|
416
527
|
)
|
|
417
|
-
|
|
528
|
+
validate_plan_bounds(facts, model, pool, plan, effective_catalog)
|
|
418
529
|
return plan
|
|
419
530
|
|
|
420
531
|
|
|
@@ -586,8 +697,10 @@ def judge(
|
|
|
586
697
|
|
|
587
698
|
|
|
588
699
|
def base_free(base_dir: str) -> int:
|
|
589
|
-
"""Free bytes on the filesystem that will hold
|
|
590
|
-
|
|
700
|
+
"""Free bytes on the filesystem that will hold ``<base_dir>/models``."""
|
|
701
|
+
if (simulated := debug_mode.simulating()) is not None:
|
|
702
|
+
return debug_mode.simulated_disk_free(simulated)
|
|
703
|
+
path = Path(base_dir).expanduser() / "models"
|
|
591
704
|
while not path.exists() and path != path.parent:
|
|
592
705
|
path = path.parent
|
|
593
706
|
try:
|
|
@@ -598,8 +711,6 @@ def base_free(base_dir: str) -> int:
|
|
|
598
711
|
|
|
599
712
|
def missing_bytes(plan: Plan) -> int:
|
|
600
713
|
"""Bytes a download still has to fetch: files neither verified in place nor partly kept."""
|
|
601
|
-
from localmodels import remote_ops_download
|
|
602
|
-
|
|
603
714
|
left = 0
|
|
604
715
|
for f in plan["files"]:
|
|
605
716
|
if plan_envelope.verified_in_place(f):
|
|
@@ -711,13 +822,11 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
|
|
|
711
822
|
def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple[str, str] | None:
|
|
712
823
|
"""(catalog id, quant) of the smartest live library pick; falls back to library models when
|
|
713
824
|
``stack`` selects Strata/PolyStrata or on CUDA unified-memory hosts."""
|
|
714
|
-
from localmodels import stack
|
|
715
|
-
|
|
716
825
|
seen = copy.deepcopy(facts)
|
|
717
826
|
if (shown_cards := visible(facts)) is not None:
|
|
718
827
|
seen["gpus"] = [g for g in seen.get("gpus") or [] if g["index"] in shown_cards]
|
|
719
828
|
try:
|
|
720
|
-
view = stack_hardware.view(seen,
|
|
829
|
+
view = stack_hardware.view(seen, default_options(), posture())
|
|
721
830
|
except (KeyError, ValueError, TypeError, OSError):
|
|
722
831
|
return None
|
|
723
832
|
pick = next(
|
|
@@ -21,11 +21,13 @@ from typing import cast
|
|
|
21
21
|
|
|
22
22
|
from localmodels import (
|
|
23
23
|
app,
|
|
24
|
+
debug_mode,
|
|
24
25
|
deploy,
|
|
25
26
|
engines,
|
|
26
27
|
frontend,
|
|
27
28
|
harness,
|
|
28
29
|
hosts,
|
|
30
|
+
library_convert,
|
|
29
31
|
library_elastic,
|
|
30
32
|
library_gateway,
|
|
31
33
|
library_jobs,
|
|
@@ -281,6 +283,8 @@ def _room(
|
|
|
281
283
|
def _port(facts: HostFacts) -> int:
|
|
282
284
|
"""Under ``locked()``: a free port that no recorded server and no live load holds; the
|
|
283
285
|
caller reserves it in its load job before releasing the lock."""
|
|
286
|
+
if debug_mode.simulating() is not None:
|
|
287
|
+
return debug_mode.simulated_port()
|
|
284
288
|
taken = [r["plan"]["service"]["port"] for r in library_state.records() if r["state"] != "idle"]
|
|
285
289
|
taken += [
|
|
286
290
|
job.get("port", 0)
|
|
@@ -295,11 +299,13 @@ def _port(facts: HostFacts) -> int:
|
|
|
295
299
|
raise LibraryError("ENGINE_START_FAILED", str(exc)) from None
|
|
296
300
|
|
|
297
301
|
|
|
298
|
-
def _start_code(finished: FinishedRecord) -> str:
|
|
302
|
+
def _start_code(finished: FinishedRecord, *, custom: bool = False) -> str:
|
|
299
303
|
failed = next((s for s in finished["steps"] if not s["ok"]), None)
|
|
300
304
|
text = " ".join(str(x) for x in (finished.get("error"), failed and failed.get("stderr")) if x)
|
|
301
305
|
kind, code = classify_failure_text(text)
|
|
302
|
-
if kind
|
|
306
|
+
if kind == "oom":
|
|
307
|
+
return code
|
|
308
|
+
if custom and kind != "unknown":
|
|
303
309
|
return code
|
|
304
310
|
if failed is not None and failed["step"] == "verify":
|
|
305
311
|
return "HEALTH_CHECK_FAILED"
|
|
@@ -579,7 +585,7 @@ def _start(
|
|
|
579
585
|
finished = app.run_deploy(hosts.LOCAL_ID, plan, on_event=seen)
|
|
580
586
|
if finished["ok"]:
|
|
581
587
|
break
|
|
582
|
-
code = _start_code(finished)
|
|
588
|
+
code = _start_code(finished, custom=record.get("custom") is not None)
|
|
583
589
|
error = LibraryError(code, str(finished.get("error") or "start failed"))
|
|
584
590
|
try:
|
|
585
591
|
_remove_service(plan, run)
|
|
@@ -703,8 +709,6 @@ def load(
|
|
|
703
709
|
force: bool = False,
|
|
704
710
|
ctx: int | None = None,
|
|
705
711
|
) -> Row:
|
|
706
|
-
from localmodels import library_convert
|
|
707
|
-
|
|
708
712
|
if ctx is not None and (isinstance(ctx, bool) or ctx <= 0):
|
|
709
713
|
raise LibraryError("INVALID_STATE", "--ctx must be a positive integer")
|
|
710
714
|
library_convert.convert_once()
|
|
@@ -778,8 +782,6 @@ def _claim(model: Model, kind: str) -> tuple[Record, Job]:
|
|
|
778
782
|
|
|
779
783
|
|
|
780
784
|
def unload(model_id: str, base_dir: str) -> Row:
|
|
781
|
-
from localmodels import library_convert
|
|
782
|
-
|
|
783
785
|
library_convert.convert_once()
|
|
784
786
|
model = library_pricing.find(model_id, library_pricing.entries())
|
|
785
787
|
record, job = _claim(model, "unload")
|
|
@@ -800,8 +802,6 @@ def _clear_removed_source(pi_model: str | None) -> None:
|
|
|
800
802
|
|
|
801
803
|
|
|
802
804
|
def remove(model_id: str, base_dir: str) -> Row:
|
|
803
|
-
from localmodels import library_convert
|
|
804
|
-
|
|
805
805
|
library_convert.convert_once()
|
|
806
806
|
model = library_pricing.find(model_id, library_pricing.entries())
|
|
807
807
|
record, job = _claim(model, "remove")
|
|
@@ -208,6 +208,14 @@ def _run_attempt(
|
|
|
208
208
|
_cleanup_smoke_plan(smoke_plan)
|
|
209
209
|
|
|
210
210
|
|
|
211
|
+
def _restore_verification(model_id: str, prior: VerificationRecord | None) -> None:
|
|
212
|
+
with library_state.locked():
|
|
213
|
+
current = library_state.load(model_id)
|
|
214
|
+
if current is not None:
|
|
215
|
+
current["verification"] = prior if prior is not None else {"status": "untested"}
|
|
216
|
+
library_state.save(current)
|
|
217
|
+
|
|
218
|
+
|
|
211
219
|
def smoke_test(model_id: str, base_dir: str, *, ctx: int = 4096) -> Row:
|
|
212
220
|
"""Run an isolated ephemeral smoke-test at ``ctx`` tokens and persist ``verification``."""
|
|
213
221
|
if isinstance(ctx, bool) or ctx <= 0:
|
|
@@ -235,6 +243,7 @@ def smoke_test(model_id: str, base_dir: str, *, ctx: int = 4096) -> Row:
|
|
|
235
243
|
library_state.save(record)
|
|
236
244
|
job = library_state.acquire("smoke_test", model.id, record["pool"], 0, [], port=port)
|
|
237
245
|
|
|
246
|
+
library_jobs.cancel_on_sigterm()
|
|
238
247
|
record_base = record.get("base_dir") or base_dir
|
|
239
248
|
custom_meta = record.get("custom")
|
|
240
249
|
use_jinja = (
|
|
@@ -243,30 +252,33 @@ def smoke_test(model_id: str, base_dir: str, *, ctx: int = 4096) -> Row:
|
|
|
243
252
|
progress(model.id, "smoke_test", 0, 3)
|
|
244
253
|
with library_state.held([job]):
|
|
245
254
|
try:
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
255
|
+
with library_jobs.watch_cancel(job):
|
|
256
|
+
smoke_plan = _build_smoke_plan(
|
|
257
|
+
record, facts, record_base, port, ctx, use_jinja=use_jinja
|
|
258
|
+
)
|
|
259
|
+
finished, server_log = _run_attempt(model.id, smoke_plan)
|
|
260
|
+
jinja_fallback = False
|
|
261
|
+
if not finished["ok"] and use_jinja and not library_state.cancelled(job):
|
|
262
|
+
diag = _diagnostic_text(finished, server_log)
|
|
263
|
+
if _is_template_error(diag):
|
|
264
|
+
jinja_fallback = True
|
|
265
|
+
retry_plan = _build_smoke_plan(
|
|
266
|
+
record, facts, record_base, port, ctx, use_jinja=False
|
|
267
|
+
)
|
|
268
|
+
finished, server_log = _run_attempt(model.id, retry_plan)
|
|
269
|
+
except KeyboardInterrupt:
|
|
270
|
+
_restore_verification(model.id, prior_verification)
|
|
271
|
+
raise LibraryError("CANCELLED", "the smoke test was cancelled") from None
|
|
259
272
|
except BaseException:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if prior_verification is not None:
|
|
264
|
-
current["verification"] = prior_verification
|
|
265
|
-
else:
|
|
266
|
-
current["verification"] = {"status": "untested"}
|
|
267
|
-
library_state.save(current)
|
|
273
|
+
_restore_verification(model.id, prior_verification)
|
|
274
|
+
if library_state.cancelled(job):
|
|
275
|
+
raise LibraryError("CANCELLED", "the smoke test was cancelled") from None
|
|
268
276
|
raise
|
|
269
277
|
|
|
278
|
+
if library_state.cancelled(job):
|
|
279
|
+
_restore_verification(model.id, prior_verification)
|
|
280
|
+
raise LibraryError("CANCELLED", "the smoke test was cancelled")
|
|
281
|
+
|
|
270
282
|
now_iso = plan_envelope.utc_now()
|
|
271
283
|
if finished["ok"]:
|
|
272
284
|
progress(model.id, "smoke_test", 3, 3)
|