@simplexai/localmodels-darwin-x64 0.1.0-dev.106 → 0.1.0-dev.108
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 +64 -61
- package/modules/localmodels/__init__.py +2 -5
- package/modules/localmodels/catalog.json +317 -111
- package/modules/localmodels/catalog.py +13 -4
- package/modules/localmodels/catalog_recipes.py +16 -1
- package/modules/localmodels/context_policy.py +3 -4
- package/modules/localmodels/engine_adapters/__init__.py +1 -2
- package/modules/localmodels/engine_adapters/llama_cpp.py +11 -5
- package/modules/localmodels/engine_adapters/strata_poly.py +1 -1
- package/modules/localmodels/engines-b11583.json +4 -4
- package/modules/localmodels/engines-b12973.json +248 -0
- package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +5 -2
- package/modules/localmodels/engines-whisper-b5454.json +5 -5
- package/modules/localmodels/engines.json +4 -4
- package/modules/localmodels/estimator.py +0 -1
- package/modules/localmodels/gguf.py +0 -1
- package/modules/localmodels/library_cli.py +68 -1
- package/modules/localmodels/library_elastic.py +1 -1
- package/modules/localmodels/library_order.py +2 -2
- package/modules/localmodels/library_poly.py +1 -1
- package/modules/localmodels/library_pricing.py +1 -2
- package/modules/localmodels/library_unload.py +274 -0
- package/modules/localmodels/llm_rank.py +5 -5
- package/modules/localmodels/metal.py +5 -5
- package/modules/localmodels/planning/__init__.py +1 -2
- package/modules/localmodels/planning/budget.py +1 -1
- package/modules/localmodels/probe.py +98 -7
- package/modules/localmodels/remote_ops_download.py +32 -7
- package/modules/localmodels/remote_ops_ranges.py +1 -1
- package/modules/localmodels/remote_ops_remove.py +1 -1
- package/modules/localmodels/remote_ops_verify.py +1 -1
- package/modules/localmodels/runtime-lock.json +1 -1
- package/modules/localmodels/service_deployment.py +1 -1
- package/modules/localmodels/service_roots.py +148 -0
- package/modules/localmodels/service_upgrade.py +46 -1
- package/modules/localmodels/services_cli.py +8 -28
- package/modules/localmodels/speech_workers.py +4 -4
- package/modules/localmodels/stack_args.py +11 -4
- package/modules/localmodels/stack_auto.py +3 -3
- package/modules/localmodels/stack_cleanup.py +3 -3
- package/modules/localmodels/stack_compose.py +6 -7
- package/modules/localmodels/stack_down.py +368 -42
- package/modules/localmodels/stack_memory.py +1 -1
- package/modules/localmodels/stack_plan.py +5 -5
- package/modules/localmodels/stack_preflight.py +2 -2
- package/modules/localmodels/stack_suite.py +2 -2
- package/modules/localmodels/stack_view_hub_cli.py +1 -1
- package/modules/localmodels/stack_view_llm.py +2 -2
- package/modules/localmodels/suite.py +1 -1
- package/modules/localmodels/tts_backend_speechcpp.py +2 -2
- package/modules/localmodels/tts_workers.py +3 -3
- package/modules/localmodels/vision.py +2 -2
- package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/RECORD +60 -57
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/LICENSE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev106.dist-info → simplex_localmodels-0.1.0.dev108.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -209,6 +209,8 @@ _DRIVER_RE = re.compile(r"\b(?:Driver|KMD)\s+Version\s*:\s*(\d+(?:\.\d+)*)", re.
|
|
|
209
209
|
HOST_LIBRARIES = ("libgomp.so.1",)
|
|
210
210
|
DETAIL_FIELDS = ("compute_cap", "memory.reserved", "display_active") # nvidia-smi names
|
|
211
211
|
_UNLIMITED = 1 << 60 # cgroup v1 reports "no limit" as a page-aligned LONG_MAX
|
|
212
|
+
_PROC_SELF_CGROUP = "/proc/self/cgroup"
|
|
213
|
+
_V1_CPU_CONTROLLERS = ("cpu", "cpu,cpuacct", "cpuacct,cpu")
|
|
212
214
|
|
|
213
215
|
|
|
214
216
|
def _run(
|
|
@@ -579,9 +581,21 @@ def environment(root: str = "/") -> str:
|
|
|
579
581
|
return "bare" if init is not None else "unknown"
|
|
580
582
|
|
|
581
583
|
|
|
584
|
+
def _cgroup_rows(root: str) -> list[list[str]]:
|
|
585
|
+
return [r.split(":", 2) for r in (_text(_at(root, _PROC_SELF_CGROUP)) or "").splitlines()]
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def _cgroup_levels(mount: str, path: str) -> list[str]:
|
|
589
|
+
# Without a cgroup namespace the path is the host's, mounted as a container's root: walk up.
|
|
590
|
+
parts = [p for p in path.strip().split("/") if p]
|
|
591
|
+
return [
|
|
592
|
+
d for n in range(len(parts), -1, -1) if os.path.isdir(d := os.path.join(mount, *parts[:n]))
|
|
593
|
+
]
|
|
594
|
+
|
|
595
|
+
|
|
582
596
|
def cgroup_memory(root: str = "/") -> CgroupMemory | None:
|
|
583
597
|
"""Memory ceiling of this process's cgroup (tightest limit-usage headroom across ancestors)."""
|
|
584
|
-
rows =
|
|
598
|
+
rows = _cgroup_rows(root)
|
|
585
599
|
v1 = next((r[2] for r in rows if len(r) == 3 and "memory" in r[1].split(",")), None)
|
|
586
600
|
if v1 is not None:
|
|
587
601
|
spec = ("/sys/fs/cgroup/memory", v1, ("memory.limit_in_bytes", "memory.usage_in_bytes"), 1)
|
|
@@ -593,11 +607,7 @@ def cgroup_memory(root: str = "/") -> CgroupMemory | None:
|
|
|
593
607
|
|
|
594
608
|
|
|
595
609
|
def _tightest(mount: str, path: str, files: tuple[str, str], v: int) -> CgroupMemory:
|
|
596
|
-
|
|
597
|
-
parts = [p for p in path.strip().split("/") if p]
|
|
598
|
-
levels = [
|
|
599
|
-
d for n in range(len(parts), -1, -1) if os.path.isdir(d := os.path.join(mount, *parts[:n]))
|
|
600
|
-
]
|
|
610
|
+
levels = _cgroup_levels(mount, path)
|
|
601
611
|
readable = bool(levels)
|
|
602
612
|
best: tuple[int | None, int | None, int | None] = (None, None, None)
|
|
603
613
|
for level in levels:
|
|
@@ -615,6 +625,87 @@ def _tightest(mount: str, path: str, files: tuple[str, str], v: int) -> CgroupMe
|
|
|
615
625
|
return {"version": v, "limit_bytes": best[1], "usage_bytes": best[2], "readable": readable}
|
|
616
626
|
|
|
617
627
|
|
|
628
|
+
def _tighter_ratio(
|
|
629
|
+
current: tuple[int, int] | None, quota: int, period: int
|
|
630
|
+
) -> tuple[int, int] | None:
|
|
631
|
+
if quota <= 0 or period <= 0:
|
|
632
|
+
return current
|
|
633
|
+
if current is None or quota * current[1] < current[0] * period:
|
|
634
|
+
return (quota, period)
|
|
635
|
+
return current
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def _cgroup_v2_cpu_ratio(root: str, path: str) -> tuple[int, int] | None:
|
|
639
|
+
best: tuple[int, int] | None = None
|
|
640
|
+
for level in _cgroup_levels(_at(root, "/sys/fs/cgroup"), path):
|
|
641
|
+
parts = (_text(os.path.join(level, "cpu.max")) or "").split()
|
|
642
|
+
if len(parts) < 2 or parts[0] == "max":
|
|
643
|
+
continue
|
|
644
|
+
try:
|
|
645
|
+
best = _tighter_ratio(best, int(parts[0]), int(parts[1]))
|
|
646
|
+
except ValueError:
|
|
647
|
+
continue
|
|
648
|
+
return best
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
def _cgroup_v1_cpu_ratio(root: str, controller: str, path: str) -> tuple[int, int] | None:
|
|
652
|
+
mounts = [
|
|
653
|
+
_at(root, f"/sys/fs/cgroup/{name}")
|
|
654
|
+
for name in dict.fromkeys((controller, *_V1_CPU_CONTROLLERS))
|
|
655
|
+
if name in _V1_CPU_CONTROLLERS
|
|
656
|
+
]
|
|
657
|
+
best: tuple[int, int] | None = None
|
|
658
|
+
for mount in mounts:
|
|
659
|
+
if not os.path.isdir(mount):
|
|
660
|
+
continue
|
|
661
|
+
for level in _cgroup_levels(mount, path):
|
|
662
|
+
raw_q = (_text(os.path.join(level, "cpu.cfs_quota_us")) or "").strip()
|
|
663
|
+
raw_p = (_text(os.path.join(level, "cpu.cfs_period_us")) or "").strip()
|
|
664
|
+
if not raw_q or not raw_p:
|
|
665
|
+
continue
|
|
666
|
+
try:
|
|
667
|
+
best = _tighter_ratio(best, int(raw_q), int(raw_p))
|
|
668
|
+
except ValueError:
|
|
669
|
+
continue
|
|
670
|
+
return best
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
def cgroup_cpu_quota(root: str = "/") -> int | None:
|
|
674
|
+
"""Effective logical CPU cap from this process's cgroup v1/v2 CPU quota, or None."""
|
|
675
|
+
rows = _cgroup_rows(root)
|
|
676
|
+
best: tuple[int, int] | None = None
|
|
677
|
+
v1 = next(((r[1], r[2]) for r in rows if len(r) == 3 and "cpu" in r[1].split(",")), None)
|
|
678
|
+
if v1 is not None and (ratio := _cgroup_v1_cpu_ratio(root, v1[0], v1[1])) is not None:
|
|
679
|
+
best = _tighter_ratio(best, ratio[0], ratio[1])
|
|
680
|
+
v2 = next((r[2] for r in rows if len(r) == 3 and r[:2] == ["0", ""]), None)
|
|
681
|
+
if v2 is not None and (ratio := _cgroup_v2_cpu_ratio(root, v2)) is not None:
|
|
682
|
+
best = _tighter_ratio(best, ratio[0], ratio[1])
|
|
683
|
+
if best is None:
|
|
684
|
+
return None
|
|
685
|
+
quota, period = best
|
|
686
|
+
return max(1, (quota + period - 1) // period)
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
def logical_cores(root: str = "/") -> int | None:
|
|
690
|
+
"""Effective logical CPUs for this process, capped by Linux affinity and cgroup quota."""
|
|
691
|
+
count = os.cpu_count()
|
|
692
|
+
if not sys.platform.startswith("linux"):
|
|
693
|
+
return count
|
|
694
|
+
caps: list[int] = [count] if isinstance(count, int) and count > 0 else []
|
|
695
|
+
getaffinity = getattr(os, "sched_getaffinity", None)
|
|
696
|
+
if callable(getaffinity):
|
|
697
|
+
try:
|
|
698
|
+
affinity = len(getaffinity(0))
|
|
699
|
+
if affinity > 0:
|
|
700
|
+
caps.append(affinity)
|
|
701
|
+
except OSError:
|
|
702
|
+
pass
|
|
703
|
+
quota = cgroup_cpu_quota(root)
|
|
704
|
+
if quota is not None and quota > 0:
|
|
705
|
+
caps.append(quota)
|
|
706
|
+
return min(caps) if caps else count
|
|
707
|
+
|
|
708
|
+
|
|
618
709
|
def parse_field_csv(text: str) -> dict[int, str]:
|
|
619
710
|
"""{index: value} of an ``index,FIELD`` query; [N/A] and [Not Supported] cells left out."""
|
|
620
711
|
rows = csv.reader(text.strip().splitlines(), skipinitialspace=True)
|
|
@@ -733,7 +824,7 @@ def collect(
|
|
|
733
824
|
"libc": " ".join(platform.libc_ver()).strip(),
|
|
734
825
|
},
|
|
735
826
|
"python": platform.python_version(),
|
|
736
|
-
"cpu": {"model": _cpu_model(), "logical_cores":
|
|
827
|
+
"cpu": {"model": _cpu_model(), "logical_cores": logical_cores()},
|
|
737
828
|
"ram": {
|
|
738
829
|
**(metal_probe.ram_status() if sys.platform == "darwin" else {}),
|
|
739
830
|
"total_bytes": ram_total,
|
|
@@ -517,20 +517,40 @@ def fetch(
|
|
|
517
517
|
raise error or RuntimeError(f"{label} has no download source")
|
|
518
518
|
|
|
519
519
|
|
|
520
|
+
def _missing_members(directory: str, assets: list[remote_ops_common.Archive]) -> set[str]:
|
|
521
|
+
"""Single files the assets' ``members`` name that are not in ``directory``. A lock may list
|
|
522
|
+
one more file of the same archive than the lock that first unpacked it did (the PolyStrata
|
|
523
|
+
0.2.20-poly.9 source archive gained ``terminal/data/expert-profile-glm.txt`` when the GLM
|
|
524
|
+
recipe moved onto it), and the ``.complete`` marker holds only the archive digests."""
|
|
525
|
+
return {
|
|
526
|
+
m
|
|
527
|
+
for a in assets
|
|
528
|
+
for m in a.get("members") or ()
|
|
529
|
+
if not m.endswith("/") and not os.path.lexists(os.path.join(directory, m))
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
|
|
520
533
|
def act_engine(p: remote_ops_common.EngineParams) -> None:
|
|
521
|
-
"""Unpack the pinned release archives into p['dir'].
|
|
534
|
+
"""Unpack the pinned release archives into p['dir']. An engine already unpacked from the same
|
|
535
|
+
archives only gets the member files it lacks, so a running engine's files are not rewritten."""
|
|
522
536
|
directory = remote_ops_common.expand(p["dir"])
|
|
523
537
|
binary = os.path.join(directory, p.get("binary") or "llama-server")
|
|
524
538
|
done_marker = os.path.join(directory, ".complete")
|
|
525
539
|
expected = ",".join(a["sha256"] for a in p["assets"])
|
|
526
|
-
|
|
540
|
+
|
|
541
|
+
def complete() -> bool:
|
|
542
|
+
return (
|
|
543
|
+
os.path.exists(done_marker)
|
|
544
|
+
and remote_ops_common.read_text(done_marker).strip() == expected
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
if complete() and not _missing_members(directory, p["assets"]):
|
|
527
548
|
remote_ops_common.emit("result", binary=binary, reused=True)
|
|
528
549
|
return
|
|
529
550
|
with remote_ops_mirrors.engine_lock(directory):
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
):
|
|
551
|
+
unpacked = complete()
|
|
552
|
+
missing = _missing_members(directory, p["assets"]) if unpacked else set()
|
|
553
|
+
if unpacked and not missing:
|
|
534
554
|
remote_ops_common.emit("result", binary=binary, reused=True)
|
|
535
555
|
return
|
|
536
556
|
os.makedirs(directory, exist_ok=True)
|
|
@@ -540,6 +560,11 @@ def act_engine(p: remote_ops_common.EngineParams) -> None:
|
|
|
540
560
|
[(os.path.join(cache, a["name"]), a["size_bytes"]) for a in p["assets"]]
|
|
541
561
|
):
|
|
542
562
|
a = p["assets"][i]
|
|
563
|
+
keep = tuple(a.get("members") or ())
|
|
564
|
+
if unpacked:
|
|
565
|
+
keep = tuple(m for m in keep if m in missing)
|
|
566
|
+
if not keep:
|
|
567
|
+
continue
|
|
543
568
|
archive = os.path.join(cache, a["name"])
|
|
544
569
|
switched = fetch(
|
|
545
570
|
a["url"],
|
|
@@ -552,7 +577,7 @@ def act_engine(p: remote_ops_common.EngineParams) -> None:
|
|
|
552
577
|
)
|
|
553
578
|
if switched in ("cn", "global"):
|
|
554
579
|
active_region = switched
|
|
555
|
-
remote_ops_common.unpack(archive, directory,
|
|
580
|
+
remote_ops_common.unpack(archive, directory, keep)
|
|
556
581
|
if not os.access(binary, os.X_OK):
|
|
557
582
|
raise RuntimeError(f"the engine has no executable {os.path.relpath(binary, directory)}")
|
|
558
583
|
remote_ops_common.write_text(done_marker, expected)
|
|
@@ -35,7 +35,7 @@ SLOW_MIN_REMAINING_S = 30.0
|
|
|
35
35
|
# finish last (work stealing), split by the two connections' rates so both end together; a
|
|
36
36
|
# stalled connection loses all of its range. A piece is stolen only when the thief would spend
|
|
37
37
|
# at least STEAL_MIN_S on it, so the extra request (TLS, a Hub redirect) is worth it. Counts come
|
|
38
|
-
# from
|
|
38
|
+
# from multi-connection download throughput benchmarks: from
|
|
39
39
|
# China the Hugging Face CDN (also behind hf-mirror) caps each connection near 0.1 MB/s, so 16
|
|
40
40
|
# connections fetch about 16 times as fast; ModelScope reaches the link's ~100 MB/s with 8.
|
|
41
41
|
CONNECTIONS = 8
|
|
@@ -57,7 +57,7 @@ def _delete(path: str, remove: Callable[[str], None] = os.remove) -> None:
|
|
|
57
57
|
"""Delete one of a stopped service's files or emptied directories. Windows refuses while
|
|
58
58
|
another process still has it open, and a server that was just ended keeps its log and its
|
|
59
59
|
working directory open until its memory is torn down: seconds for a 10 GB llama-server
|
|
60
|
-
(
|
|
60
|
+
(observed as WinError 32 on server.log right after stopping on Windows). So a refusal is
|
|
61
61
|
retried there for RELEASE_WAIT_S; elsewhere, and after that, it is raised."""
|
|
62
62
|
deadline = time.monotonic() + RELEASE_WAIT_S
|
|
63
63
|
while True:
|
|
@@ -236,7 +236,7 @@ def _solid_png(rgb: tuple[int, int, int], side: int = 224) -> bytes:
|
|
|
236
236
|
|
|
237
237
|
|
|
238
238
|
def _picture_answer(root: str, p: remote_ops_common.VerifyParams) -> str:
|
|
239
|
-
"""The model's answer, with its reasoning, about a synthetic red picture
|
|
239
|
+
"""The model's answer, with its reasoning, about a synthetic red picture."""
|
|
240
240
|
image = "data:image/png;base64," + base64.b64encode(_solid_png((220, 20, 20))).decode()
|
|
241
241
|
parts = [
|
|
242
242
|
{"type": "text", "text": PICTURE_PROMPT},
|
|
@@ -176,7 +176,7 @@
|
|
|
176
176
|
},
|
|
177
177
|
"launchers": {
|
|
178
178
|
"win32-x64": {
|
|
179
|
-
"url": "https://
|
|
179
|
+
"url": "https://releases.heylinger.com/cli/simplex-installer/localmodels-tools-20261028/5f362bed89424350/pi-win32-x64.exe",
|
|
180
180
|
"algorithm": "sha256",
|
|
181
181
|
"digest": "5f362bed894243500b603cbb4996c9e408f547dd209ce9007bad745abc0d2a34",
|
|
182
182
|
"maxBytes": 1982464,
|
|
@@ -57,7 +57,7 @@ def plan_component(
|
|
|
57
57
|
if owned := _existing_parts(role, root):
|
|
58
58
|
return owned
|
|
59
59
|
if role == "decision":
|
|
60
|
-
# With sharing consent the free VRAM decides whoever else uses a card
|
|
60
|
+
# With sharing consent the free VRAM decides whoever else uses a card.
|
|
61
61
|
if not share_gpu and budget.unknown_services(facts):
|
|
62
62
|
raise WaitingForResourcesError("gpu")
|
|
63
63
|
candidates = budget.sharing_cards(facts, 0) if share_gpu else budget.idle_cards(facts, 0)
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Discovery and private registry of optional ``foundations`` controller roots.
|
|
2
|
+
|
|
3
|
+
``foundations ensure`` records its ``--root`` under ``$LOCALMODELS_STATE/foundations/roots.json``
|
|
4
|
+
so ``stack down --all`` can cleanly stop active controllers without requiring callers to track
|
|
5
|
+
every root separately. Legacy installations that predate this registry are also discovered across
|
|
6
|
+
standard sibling/parent layouts, strictly verified against ``control.json["stateDir"]``.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import contextlib
|
|
12
|
+
import json
|
|
13
|
+
import os
|
|
14
|
+
from collections.abc import Sequence
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from localmodels import hosts, service_control, service_upgrade
|
|
18
|
+
|
|
19
|
+
ROOTS_SCHEMA = "localmodels.foundations-roots/v1"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def roots_path(state_dir: Path | None = None) -> Path:
|
|
23
|
+
base = hosts.state_dir() if state_dir is None else state_dir
|
|
24
|
+
return base / "foundations" / "roots.json"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _lock_path(state_dir: Path | None = None) -> Path:
|
|
28
|
+
base = hosts.state_dir() if state_dir is None else state_dir
|
|
29
|
+
return base / "foundations" / ".roots.lock"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _norm_key(path: str | Path) -> str:
|
|
33
|
+
return os.path.normcase(os.path.realpath(os.path.expanduser(str(path))))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _same_path(raw: object, target: Path) -> bool:
|
|
37
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
38
|
+
return False
|
|
39
|
+
return _norm_key(raw) == _norm_key(target)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def read_registered_roots(state_dir: Path | None = None) -> list[Path]:
|
|
43
|
+
"""Read controller roots previously registered under ``state_dir`` (ignores corrupt files)."""
|
|
44
|
+
path = roots_path(state_dir)
|
|
45
|
+
try:
|
|
46
|
+
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
47
|
+
except (OSError, ValueError):
|
|
48
|
+
return []
|
|
49
|
+
entries = raw.get("roots") if isinstance(raw, dict) else raw
|
|
50
|
+
if not isinstance(entries, list):
|
|
51
|
+
return []
|
|
52
|
+
found: list[Path] = []
|
|
53
|
+
seen: set[str] = set()
|
|
54
|
+
for item in entries:
|
|
55
|
+
if not isinstance(item, str) or not item.strip():
|
|
56
|
+
continue
|
|
57
|
+
candidate = Path(os.path.expanduser(item))
|
|
58
|
+
if not candidate.is_absolute():
|
|
59
|
+
continue
|
|
60
|
+
key = _norm_key(candidate)
|
|
61
|
+
if key not in seen:
|
|
62
|
+
seen.add(key)
|
|
63
|
+
found.append(candidate)
|
|
64
|
+
return found
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def register_root(state_dir: Path, root: Path) -> None:
|
|
68
|
+
"""Atomically record ``root`` under ``state_dir/foundations/roots.json`` (best-effort)."""
|
|
69
|
+
resolved_root = Path(os.path.abspath(os.path.expanduser(str(root))))
|
|
70
|
+
target_key = _norm_key(resolved_root)
|
|
71
|
+
parent = roots_path(state_dir).parent
|
|
72
|
+
with contextlib.suppress(OSError, ValueError):
|
|
73
|
+
if not parent.exists():
|
|
74
|
+
parent.mkdir(parents=True, exist_ok=True)
|
|
75
|
+
if os.name != "nt":
|
|
76
|
+
parent.chmod(0o700)
|
|
77
|
+
with hosts.file_lock(_lock_path(state_dir)):
|
|
78
|
+
existing = read_registered_roots(state_dir)
|
|
79
|
+
if any(_norm_key(entry) == target_key for entry in existing):
|
|
80
|
+
return
|
|
81
|
+
updated = [str(entry) for entry in existing] + [str(resolved_root)]
|
|
82
|
+
hosts.save_private(
|
|
83
|
+
roots_path(state_dir),
|
|
84
|
+
{"schema": ROOTS_SCHEMA, "roots": updated},
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _legacy_candidates(state_dir: Path) -> list[Path]:
|
|
89
|
+
"""Well-known controller root locations relative to ``state_dir`` for pre-registry installs."""
|
|
90
|
+
resolved = Path(os.path.abspath(os.path.expanduser(str(state_dir))))
|
|
91
|
+
candidates: list[Path] = [
|
|
92
|
+
resolved / "foundations",
|
|
93
|
+
resolved.parent,
|
|
94
|
+
resolved.parent / "model-services",
|
|
95
|
+
]
|
|
96
|
+
if resolved.parent.parent != resolved.parent:
|
|
97
|
+
candidates.append(resolved.parent.parent / "model-services")
|
|
98
|
+
return candidates
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _matches_state_dir(candidate: Path, state_dir: Path, *, registered: bool) -> bool:
|
|
102
|
+
if candidate.is_symlink():
|
|
103
|
+
return False
|
|
104
|
+
control_path = candidate / "control.json"
|
|
105
|
+
if not control_path.is_file() or control_path.is_symlink():
|
|
106
|
+
return False
|
|
107
|
+
try:
|
|
108
|
+
config = service_control.read_configuration(candidate)
|
|
109
|
+
except (OSError, ValueError):
|
|
110
|
+
if not registered:
|
|
111
|
+
return False
|
|
112
|
+
lock_path = candidate / "worker.lock"
|
|
113
|
+
if not lock_path.exists() or lock_path.is_symlink():
|
|
114
|
+
return False
|
|
115
|
+
try:
|
|
116
|
+
return not service_upgrade.idle(candidate)
|
|
117
|
+
except OSError:
|
|
118
|
+
return False
|
|
119
|
+
return _same_path(config.get("stateDir"), state_dir)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def discover_roots(
|
|
123
|
+
state_dir: Path | None = None,
|
|
124
|
+
explicit: Sequence[Path] = (),
|
|
125
|
+
) -> list[tuple[Path, bool]]:
|
|
126
|
+
"""Return deduplicated ``(root, is_explicit)`` controller roots belonging to ``state_dir``."""
|
|
127
|
+
base = hosts.state_dir() if state_dir is None else state_dir
|
|
128
|
+
found: list[tuple[Path, bool]] = []
|
|
129
|
+
seen: set[str] = set()
|
|
130
|
+
|
|
131
|
+
for raw in explicit:
|
|
132
|
+
candidate = Path(os.path.abspath(os.path.expanduser(str(raw))))
|
|
133
|
+
key = _norm_key(candidate)
|
|
134
|
+
if key not in seen:
|
|
135
|
+
seen.add(key)
|
|
136
|
+
found.append((candidate, True))
|
|
137
|
+
|
|
138
|
+
registered = read_registered_roots(base)
|
|
139
|
+
registered_keys = {_norm_key(entry) for entry in registered}
|
|
140
|
+
for candidate in [*registered, *_legacy_candidates(base)]:
|
|
141
|
+
key = _norm_key(candidate)
|
|
142
|
+
if key in seen:
|
|
143
|
+
continue
|
|
144
|
+
if _matches_state_dir(candidate, base, registered=key in registered_keys):
|
|
145
|
+
seen.add(key)
|
|
146
|
+
found.append((candidate, False))
|
|
147
|
+
|
|
148
|
+
return found
|
|
@@ -22,8 +22,17 @@ import urllib.error
|
|
|
22
22
|
import urllib.request
|
|
23
23
|
from collections.abc import Callable
|
|
24
24
|
from pathlib import Path
|
|
25
|
+
from typing import Any
|
|
25
26
|
|
|
26
|
-
from localmodels import
|
|
27
|
+
from localmodels import (
|
|
28
|
+
process_identity,
|
|
29
|
+
process_windows,
|
|
30
|
+
runtime_io,
|
|
31
|
+
service_autostart,
|
|
32
|
+
service_control,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
STOP_SCHEMA = "localmodels.service-controller-stop/v1"
|
|
27
36
|
|
|
28
37
|
GRACE = 15.0 # an install in progress finishes its current step before the worker exits
|
|
29
38
|
KILL_AFTER = 10.0 # after SIGTERM, before SIGKILL
|
|
@@ -426,3 +435,39 @@ def retire_implicit_jobs(root: Path) -> None:
|
|
|
426
435
|
CHANGED, "another model controller took the lock during the upgrade"
|
|
427
436
|
) from None
|
|
428
437
|
raise
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def stop_controller(root: Path) -> dict[str, Any]:
|
|
441
|
+
"""End this root's controller and its autostart, for an uninstaller or full shutdown.
|
|
442
|
+
|
|
443
|
+
Idempotent: nothing under ``root``, or nothing running, is a successful stop.
|
|
444
|
+
"""
|
|
445
|
+
result: dict[str, Any] = {
|
|
446
|
+
"schema": STOP_SCHEMA,
|
|
447
|
+
"root": str(root),
|
|
448
|
+
"stopped": False,
|
|
449
|
+
"method": None,
|
|
450
|
+
"autostart": "none",
|
|
451
|
+
}
|
|
452
|
+
if not (root / "control.json").is_file():
|
|
453
|
+
return result
|
|
454
|
+
try:
|
|
455
|
+
_stop_controller(root, result)
|
|
456
|
+
except (OSError, ValueError, subprocess.SubprocessError) as error:
|
|
457
|
+
result.update(ok=False, stopped=False, error=str(error))
|
|
458
|
+
if isinstance(error, ControllerError):
|
|
459
|
+
result["code"] = error.code
|
|
460
|
+
return result
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _stop_controller(root: Path, result: dict[str, Any]) -> None:
|
|
464
|
+
with runtime_io.private_lock(root / "ensure.lock"):
|
|
465
|
+
config = service_control.read_configuration(root)
|
|
466
|
+
config["stopped"] = True
|
|
467
|
+
runtime_io.write_private_json(root / "control.json", config)
|
|
468
|
+
running = not idle(root)
|
|
469
|
+
result["autostart"] = service_autostart.unregister(root)
|
|
470
|
+
if not running and idle(root):
|
|
471
|
+
return
|
|
472
|
+
result["stopped"] = True
|
|
473
|
+
result["method"] = end_controller(root) or "systemd"
|
|
@@ -19,7 +19,7 @@ from localmodels.service_control import controller_available as controller_avail
|
|
|
19
19
|
from localmodels.service_control import read_configuration as read_configuration
|
|
20
20
|
from localmodels.service_jobs import ACTIVE, ROLES, selected_roles
|
|
21
21
|
|
|
22
|
-
STOP_SCHEMA =
|
|
22
|
+
STOP_SCHEMA = service_upgrade.STOP_SCHEMA
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def stop(root: Path) -> dict[str, Any]:
|
|
@@ -27,35 +27,14 @@ def stop(root: Path) -> dict[str, Any]:
|
|
|
27
27
|
|
|
28
28
|
Idempotent: nothing under ``root``, or nothing running, is a successful stop.
|
|
29
29
|
"""
|
|
30
|
-
|
|
31
|
-
"schema": STOP_SCHEMA,
|
|
32
|
-
"root": str(root),
|
|
33
|
-
"stopped": False,
|
|
34
|
-
"method": None,
|
|
35
|
-
"autostart": "none",
|
|
36
|
-
}
|
|
37
|
-
if not (root / "control.json").is_file():
|
|
38
|
-
return result
|
|
39
|
-
try:
|
|
40
|
-
_stop(root, result)
|
|
41
|
-
except (OSError, ValueError, subprocess.SubprocessError) as error:
|
|
42
|
-
result.update(ok=False, stopped=False, error=str(error))
|
|
43
|
-
if isinstance(error, service_upgrade.ControllerError):
|
|
44
|
-
result["code"] = error.code
|
|
45
|
-
return result
|
|
30
|
+
return service_upgrade.stop_controller(root)
|
|
46
31
|
|
|
47
32
|
|
|
48
|
-
def
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
running = not service_upgrade.idle(root)
|
|
54
|
-
result["autostart"] = service_autostart.unregister(root)
|
|
55
|
-
if not running and service_upgrade.idle(root):
|
|
56
|
-
return
|
|
57
|
-
result["stopped"] = True
|
|
58
|
-
result["method"] = service_upgrade.end_controller(root) or "systemd"
|
|
33
|
+
def _register_controller_root(config: dict[str, Any], root: Path) -> None:
|
|
34
|
+
if isinstance(state_dir := config.get("stateDir"), str) and state_dir:
|
|
35
|
+
from localmodels import service_roots
|
|
36
|
+
|
|
37
|
+
service_roots.register_root(Path(state_dir), root)
|
|
59
38
|
|
|
60
39
|
|
|
61
40
|
def ensure(
|
|
@@ -132,6 +111,7 @@ def ensure(
|
|
|
132
111
|
runtime_io.write_private_json(config_path, config)
|
|
133
112
|
config.pop("stopped", None)
|
|
134
113
|
runtime_io.write_private_json(config_path, config)
|
|
114
|
+
_register_controller_root(config, root)
|
|
135
115
|
runtime_io.private_permissions(key_path)
|
|
136
116
|
key = json.loads(key_path.read_text())
|
|
137
117
|
if os.name != "nt":
|
|
@@ -35,7 +35,7 @@ from localmodels import (
|
|
|
35
35
|
speech_worker_sensevoice,
|
|
36
36
|
windows_job,
|
|
37
37
|
)
|
|
38
|
-
from localmodels.probe import HostFacts
|
|
38
|
+
from localmodels.probe import HostFacts, logical_cores
|
|
39
39
|
from localmodels.sidecar_http import (
|
|
40
40
|
GPU_OOM_SIGNATURES as GPU_OOM_SIGNATURES,
|
|
41
41
|
)
|
|
@@ -304,7 +304,7 @@ def whisper_argv(
|
|
|
304
304
|
threads: int | None = None,
|
|
305
305
|
) -> list[str]:
|
|
306
306
|
"""Build ``whisper-server`` argv (no ``--convert``, ``-mc 0``, ``-ng`` on CPU, ``-fa`` on GPU)."""
|
|
307
|
-
num_threads = threads if threads is not None else min(4, max(1,
|
|
307
|
+
num_threads = threads if threads is not None else min(4, max(1, logical_cores() or 1))
|
|
308
308
|
argv = [
|
|
309
309
|
binary,
|
|
310
310
|
"-m",
|
|
@@ -335,7 +335,7 @@ def sensevoice_argv(
|
|
|
335
335
|
threads: int | None = None,
|
|
336
336
|
) -> list[str]:
|
|
337
337
|
"""Build isolated ``speech_worker_sensevoice.py`` child worker argv."""
|
|
338
|
-
num_threads = threads if threads is not None else min(4, max(1,
|
|
338
|
+
num_threads = threads if threads is not None else min(4, max(1, logical_cores() or 1))
|
|
339
339
|
script = str(Path(speech_worker_sensevoice.__file__).resolve())
|
|
340
340
|
return [
|
|
341
341
|
python_bin,
|
|
@@ -366,7 +366,7 @@ def qwen3_asr_argv(
|
|
|
366
366
|
max_new_tokens: int = speech_worker_sensevoice.QWEN3_ASR_MAX_NEW_TOKENS,
|
|
367
367
|
) -> list[str]:
|
|
368
368
|
"""Build isolated ``speech_worker_sensevoice.py`` child worker argv for Qwen3-ASR."""
|
|
369
|
-
num_threads = threads if threads is not None else min(4, max(1,
|
|
369
|
+
num_threads = threads if threads is not None else min(4, max(1, logical_cores() or 1))
|
|
370
370
|
script = str(Path(speech_worker_sensevoice.__file__).resolve())
|
|
371
371
|
return [
|
|
372
372
|
python_bin,
|
|
@@ -648,14 +648,21 @@ def _day2(actions: Parsers, only: str | None = None) -> None:
|
|
|
648
648
|
[("%(prog)s", "the last accepted plan"), ("%(prog)s --timeout 300", "")],
|
|
649
649
|
),
|
|
650
650
|
"down": (
|
|
651
|
-
"stop the stack's services
|
|
651
|
+
"stop the stack's services (--all: also library, sidecars, foundations)",
|
|
652
652
|
"Stop every service a stack apply under this "
|
|
653
653
|
"state directory deployed, each only through its own unit or process receipt. "
|
|
654
654
|
"Units stay enabled and nothing is deleted or forgotten, so `stack up` starts the "
|
|
655
655
|
"same stack again; external services and deployments "
|
|
656
|
-
"made outside `stack` are left running
|
|
657
|
-
"
|
|
658
|
-
|
|
656
|
+
"made outside `stack` are left running unless --all is passed. With --all, also "
|
|
657
|
+
"stop foundations controllers and deployments, unload active library models and "
|
|
658
|
+
"jobs, stop voice sidecars, and refresh runtime-index.json in one call. Nothing "
|
|
659
|
+
"running is a success. Exit 0 all stopped, 1 any stop failed, 2 refused (bad flags "
|
|
660
|
+
"or another apply is running).",
|
|
661
|
+
[
|
|
662
|
+
("%(prog)s", ""),
|
|
663
|
+
("%(prog)s --json", "localmodels.stack-down/v1, for installers"),
|
|
664
|
+
("%(prog)s --all --json", "stop stack, library models, sidecars, and foundations"),
|
|
665
|
+
],
|
|
659
666
|
),
|
|
660
667
|
"remove": (
|
|
661
668
|
"uninstall the stack; only downloaded files stay (--purge: those too)",
|
|
@@ -124,9 +124,9 @@ def strata_parts(
|
|
|
124
124
|
Rebuilding an ``approved`` plan tries its Strata recipe first and keeps it while it still
|
|
125
125
|
fits this computer, whatever the ranking says now: more memory free than at plan time, or a
|
|
126
126
|
newer kit that ranks or admits recipes differently, does not replace the LLM the operator
|
|
127
|
-
approved (
|
|
128
|
-
|
|
129
|
-
changed plan."""
|
|
127
|
+
approved (e.g. if q2 was approved on 15.6 GB free and q3 later fits on 17.9 GB, resuming
|
|
128
|
+
must not refuse the approved plan). A recipe that no longer fits falls through to the ranking,
|
|
129
|
+
and apply refuses the changed plan."""
|
|
130
130
|
bar, llama_id = llama
|
|
131
131
|
prefer = str(options.get("prefer") or "smartest")
|
|
132
132
|
skipped: list[str] = []
|
|
@@ -248,9 +248,9 @@ def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
|
|
|
248
248
|
own record in this state directory: one the manifest does not list yet is added, and one
|
|
249
249
|
the manifest lists at ANOTHER directory is corrected. Deployment names repeat across
|
|
250
250
|
installations that share a tools directory (another stack, the Simplex installer's, a test
|
|
251
|
-
run), and the manifest keeps one entry per name:
|
|
252
|
-
temporary directory,
|
|
253
|
-
|
|
251
|
+
run), and the manifest keeps one entry per name: if a stale entry points to a
|
|
252
|
+
temporary directory, uninstalling it would otherwise drop the record of the live server
|
|
253
|
+
that is still running. The other directory is left alone. ``dry_run`` keeps
|
|
254
254
|
the correction in memory.
|
|
255
255
|
|
|
256
256
|
An adopted entry's phase is its record's (``deployment_lifecycle.advance``): a failed or
|
|
@@ -309,11 +309,11 @@ def _llama_quality(
|
|
|
309
309
|
|
|
310
310
|
|
|
311
311
|
def agent_posture(options: StackOptions) -> AgentPosture:
|
|
312
|
-
"""The stack's agent posture with the operator's slot count. One slot is allowed
|
|
312
|
+
"""The stack's agent posture with the operator's slot count. One slot is allowed by
|
|
313
313
|
default policy (the smartest model does not have to serve two requests at once);
|
|
314
|
-
``--prefer concurrent`` keeps
|
|
315
|
-
otherwise
|
|
316
|
-
thinking cap and ``--context``'s window ceiling come from the plan
|
|
314
|
+
``--prefer concurrent`` keeps two slots. Images are on unless the plan says
|
|
315
|
+
otherwise; a plan saved before ``--vision`` existed stays text-only. The
|
|
316
|
+
thinking cap and ``--context``'s window ceiling come from the plan."""
|
|
317
317
|
given = options.get("slots")
|
|
318
318
|
slots = AGENT.slots if given is None else int(given)
|
|
319
319
|
if slots < 1:
|
|
@@ -420,7 +420,7 @@ def _llm_warnings(
|
|
|
420
420
|
warnings.append(f"LLM: {llm_rank.WINDOWS_FALLBACK_WARNING}")
|
|
421
421
|
if llm_id in getattr(llm_rank.mac_ladder(facts), "smartest", ()) and options["llm"] == "auto":
|
|
422
422
|
warnings.append(
|
|
423
|
-
f"LLM: {llm_id} is on the
|
|
423
|
+
f"LLM: {llm_id} is on the Mac small-memory ladder;"
|
|
424
424
|
" no SimplexAI score, physical 16 GB install and full product acceptance pending"
|
|
425
425
|
)
|
|
426
426
|
if options["conversation_cache"] not in ("auto", "off"):
|
|
@@ -561,8 +561,7 @@ def _llama_parts(
|
|
|
561
561
|
f"({named}) first; the LLM, decision model and prompt cache are chosen in the rest"
|
|
562
562
|
)
|
|
563
563
|
if not running_llm and approved is None:
|
|
564
|
-
# Decision model first, then the embedding and reranker take the GPU it leaves
|
|
565
|
-
# (decision 21; 2026-10-30 order: decision index before GPU auxiliaries).
|
|
564
|
+
# Decision model first, then the embedding and reranker take the GPU it leaves.
|
|
566
565
|
opts = stack_suite.suite_options(options)
|
|
567
566
|
candidates, llm = aux_gpu.place(facts, llm, choice, candidates, opts, price_llm, warnings)
|
|
568
567
|
approved_mib = llm_ram.approved_cache_mib(approved.get("llm") if approved else None, llm)
|