@simplexai/localmodels-linux-x64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.35
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 +138 -97
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +4 -0
- package/modules/localmodels/app.py +7 -2
- package/modules/localmodels/approval.py +4 -4
- package/modules/localmodels/bifrost_checks.py +121 -3
- package/modules/localmodels/bifrost_provider.py +53 -0
- package/modules/localmodels/bifrost_unit.py +32 -1
- package/modules/localmodels/budget.py +5 -1
- package/modules/localmodels/catalog.json +51 -10
- package/modules/localmodels/catalog.py +30 -29
- package/modules/localmodels/catalog_add.py +1 -0
- package/modules/localmodels/cli_parser.py +10 -2
- package/modules/localmodels/component.py +7 -1
- package/modules/localmodels/decode_calibration.json +6 -0
- package/modules/localmodels/decode_calibration.py +104 -0
- package/modules/localmodels/deploy.py +44 -7
- package/modules/localmodels/deploy_steps.py +10 -1
- package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
- package/modules/localmodels/engines.json +57 -1
- package/modules/localmodels/engines.py +6 -2
- package/modules/localmodels/estimator.py +21 -7
- package/modules/localmodels/frontend.py +4 -4
- package/modules/localmodels/gateway.py +14 -4
- package/modules/localmodels/gateway_app_bifrost.py +4 -3
- package/modules/localmodels/gateway_bifrost.py +70 -57
- package/modules/localmodels/gateway_probe.py +3 -4
- package/modules/localmodels/gguf.py +7 -0
- package/modules/localmodels/harness.py +24 -25
- package/modules/localmodels/harness_gateway.py +19 -10
- package/modules/localmodels/harness_probe.py +33 -6
- package/modules/localmodels/hosts.py +73 -9
- package/modules/localmodels/install.py +36 -6
- package/modules/localmodels/library_cli.py +179 -0
- package/modules/localmodels/library_convert.py +132 -0
- package/modules/localmodels/library_gateway.py +471 -0
- package/modules/localmodels/library_jobs.py +314 -0
- package/modules/localmodels/library_model.py +246 -0
- package/modules/localmodels/library_pricing.py +347 -0
- package/modules/localmodels/library_serve.py +348 -0
- package/modules/localmodels/library_state.py +373 -0
- package/modules/localmodels/library_status.py +349 -0
- package/modules/localmodels/llm_rank.py +16 -2
- package/modules/localmodels/memcalc.py +7 -30
- package/modules/localmodels/metal.py +26 -0
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/preparation.py +49 -0
- package/modules/localmodels/probe.py +8 -8
- package/modules/localmodels/process_identity.py +536 -9
- package/modules/localmodels/quant_formats.py +123 -0
- package/modules/localmodels/recommend_cli.py +8 -4
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +104 -6
- package/modules/localmodels/remote_ops_download.py +17 -2
- package/modules/localmodels/remote_ops_prepare.py +406 -0
- package/modules/localmodels/remote_ops_remove.py +40 -7
- package/modules/localmodels/remote_ops_service.py +110 -8
- package/modules/localmodels/remote_ops_verify.py +15 -2
- package/modules/localmodels/runtime_auth.py +31 -1
- package/modules/localmodels/runtime_cli.py +3 -4
- package/modules/localmodels/runtime_io.py +50 -6
- package/modules/localmodels/service_autostart.py +45 -1
- package/modules/localmodels/service_control.py +13 -0
- package/modules/localmodels/service_deployment.py +12 -3
- package/modules/localmodels/service_jobs.py +33 -4
- package/modules/localmodels/service_probe.py +67 -13
- package/modules/localmodels/service_stop.py +152 -0
- package/modules/localmodels/service_worker.py +9 -1
- package/modules/localmodels/services_cli.py +50 -6
- package/modules/localmodels/setup_inspection.py +34 -25
- package/modules/localmodels/setup_text.py +118 -0
- package/modules/localmodels/sizecalc.py +625 -0
- package/modules/localmodels/sizecalc_cli.py +249 -0
- package/modules/localmodels/stack.py +69 -17
- package/modules/localmodels/stack_args.py +91 -19
- package/modules/localmodels/stack_auto.py +78 -0
- package/modules/localmodels/stack_binding.py +23 -35
- package/modules/localmodels/stack_card.py +195 -0
- package/modules/localmodels/stack_cleanup.py +379 -0
- package/modules/localmodels/stack_clients.py +4 -1
- package/modules/localmodels/stack_compose.py +150 -194
- package/modules/localmodels/stack_console.py +2 -0
- package/modules/localmodels/stack_decision.py +3 -2
- package/modules/localmodels/stack_down.py +189 -0
- package/modules/localmodels/stack_events.py +54 -0
- package/modules/localmodels/stack_hardware.py +22 -23
- package/modules/localmodels/stack_journal.py +29 -8
- package/modules/localmodels/stack_ledger.py +411 -0
- package/modules/localmodels/stack_lifecycle.py +162 -167
- package/modules/localmodels/stack_llm_ram.py +57 -5
- package/modules/localmodels/stack_memory.py +721 -0
- package/modules/localmodels/stack_picks.py +139 -0
- package/modules/localmodels/stack_plan.py +140 -22
- package/modules/localmodels/stack_ports.py +22 -0
- package/modules/localmodels/stack_preflight.py +699 -0
- package/modules/localmodels/stack_review.py +123 -5
- package/modules/localmodels/stack_rollback.py +2 -0
- package/modules/localmodels/stack_route.py +256 -0
- package/modules/localmodels/stack_run.py +11 -0
- package/modules/localmodels/stack_suite.py +102 -17
- package/modules/localmodels/stack_summary.py +65 -4
- package/modules/localmodels/stack_try.py +354 -0
- package/modules/localmodels/stack_try_client.py +194 -0
- package/modules/localmodels/stack_try_docs.py +139 -0
- package/modules/localmodels/stack_up.py +8 -1
- package/modules/localmodels/stack_update.py +29 -4
- package/modules/localmodels/stack_verify.py +3 -1
- package/modules/localmodels/stack_view.py +10 -11
- package/modules/localmodels/stack_view_apply.py +4 -2
- package/modules/localmodels/stack_view_events.py +2 -1
- package/modules/localmodels/stack_view_serve.py +3 -0
- package/modules/localmodels/stack_view_text.py +1 -1
- package/modules/localmodels/stack_view_words.py +4 -1
- package/modules/localmodels/stack_warm.py +574 -0
- package/modules/localmodels/stack_whatif.py +558 -0
- package/modules/localmodels/suite.py +48 -39
- package/modules/localmodels/tool_archive.py +40 -0
- package/modules/localmodels/tools.json +8 -0
- package/modules/localmodels/transport.py +1 -0
- package/modules/localmodels/vision.py +8 -1
- package/modules/localmodels/web/sizecalc/app.js +431 -0
- package/modules/localmodels/web/sizecalc/calc.js +269 -0
- package/modules/localmodels/web/sizecalc/page.html +362 -0
- package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/logo-claude.svg +3 -0
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/localmodels/web/view/logo-pi.svg +6 -0
- package/modules/localmodels/web/view/view.css +4 -0
- package/modules/localmodels/web/view/view.js +15 -6
- package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/METADATA +1 -1
- package/modules/simplex_localmodels-0.1.0.dev35.dist-info/RECORD +241 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -30,6 +30,7 @@ import sys
|
|
|
30
30
|
import urllib.error
|
|
31
31
|
import urllib.request
|
|
32
32
|
from collections.abc import Callable, Sequence
|
|
33
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
33
34
|
from pathlib import Path
|
|
34
35
|
|
|
35
36
|
try:
|
|
@@ -219,8 +220,33 @@ def _linux_deployment(pid: int, root: str, argv: list[str], cgroup: str) -> str
|
|
|
219
220
|
return None
|
|
220
221
|
|
|
221
222
|
|
|
223
|
+
WINDOWS_DEPLOYMENTS = "~/.local/share/localmodels/deployments" # deploy.DEFAULT_BASE_DIR's
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _windows_owned(pid: int, deployments: str = WINDOWS_DEPLOYMENTS) -> bool | None:
|
|
227
|
+
"""Windows: a live receipt of one of this user's nohup deployments names the process."""
|
|
228
|
+
try:
|
|
229
|
+
found = process_identity.inspect(pid)
|
|
230
|
+
except OSError:
|
|
231
|
+
return None
|
|
232
|
+
if found is None:
|
|
233
|
+
return None
|
|
234
|
+
if found["uid"] != 0:
|
|
235
|
+
return False
|
|
236
|
+
for receipt in Path(os.path.expanduser(deployments)).glob("*/server.pid"):
|
|
237
|
+
if process_identity.status(receipt) == ("active", pid):
|
|
238
|
+
return True
|
|
239
|
+
return False
|
|
240
|
+
|
|
241
|
+
|
|
222
242
|
def process_owned(pid: int, root: str = "/") -> bool | None:
|
|
223
243
|
"""Bind this user's live process to a private deployment receipt, never a slice name."""
|
|
244
|
+
if sys.platform == "win32":
|
|
245
|
+
return _windows_owned(pid)
|
|
246
|
+
return _posix_owned(pid, root)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _posix_owned(pid: int, root: str) -> bool | None:
|
|
224
250
|
if not hasattr(os, "getuid"):
|
|
225
251
|
return None
|
|
226
252
|
original = _linux_identity(pid, root)
|
|
@@ -362,7 +388,21 @@ def _compute_processes() -> tuple[list[dict[str, object]] | None, str | None]:
|
|
|
362
388
|
return None, "not-installed"
|
|
363
389
|
query = "--query-compute-apps=gpu_uuid,pid,process_name,used_memory"
|
|
364
390
|
rc, out, err = _run([exe, query, "--format=csv,noheader,nounits"])
|
|
365
|
-
|
|
391
|
+
if rc != 0:
|
|
392
|
+
return None, _reason(err or out)
|
|
393
|
+
found = parse_compute_apps(out)
|
|
394
|
+
if sys.platform == "win32":
|
|
395
|
+
desktop = windows_graphics_pids(_run([exe])[1])
|
|
396
|
+
found = [p for p in found if p["pid"] not in desktop]
|
|
397
|
+
return found, None
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def windows_graphics_pids(table: str) -> set[int]:
|
|
401
|
+
"""PIDs the plain ``nvidia-smi`` process table marks G or C+G. Under WDDM every desktop
|
|
402
|
+
program (dwm, explorer, browsers) is a C+G client of the card and nvidia-smi lists it beside
|
|
403
|
+
the compute processes without its memory; a model server is type C."""
|
|
404
|
+
rows = re.findall(r"^\|\s+\d+\s+\S+\s+\S+\s+(\d+)\s+(C\+G|G)\s", table, re.M)
|
|
405
|
+
return {int(pid) for pid, _ in rows}
|
|
366
406
|
|
|
367
407
|
|
|
368
408
|
def parse_unit_show(text: str) -> list[dict[str, object]]:
|
|
@@ -484,9 +524,20 @@ def _containers() -> tuple[list[dict[str, object]] | None, str | None]:
|
|
|
484
524
|
return [b for b in boxes if b], None
|
|
485
525
|
|
|
486
526
|
|
|
527
|
+
# Windows answers a connect to a closed loopback port only after about two seconds (it retries
|
|
528
|
+
# the SYN); a shorter wait would read every closed port as unknown.
|
|
529
|
+
_CONNECT_TIMEOUT_S = 3.0 if sys.platform == "win32" else 0.5
|
|
530
|
+
|
|
531
|
+
|
|
487
532
|
def _listening(port: int) -> bool | None:
|
|
533
|
+
if sys.platform == "win32": # a refused loopback connect retries for seconds there
|
|
534
|
+
try:
|
|
535
|
+
owners = process_identity.listener_pids(port)
|
|
536
|
+
except OSError:
|
|
537
|
+
return None
|
|
538
|
+
return None if owners is None else bool(owners)
|
|
488
539
|
try:
|
|
489
|
-
with socket.create_connection(("127.0.0.1", port), timeout=
|
|
540
|
+
with socket.create_connection(("127.0.0.1", port), timeout=_CONNECT_TIMEOUT_S):
|
|
490
541
|
return True
|
|
491
542
|
except ConnectionRefusedError:
|
|
492
543
|
return False
|
|
@@ -508,18 +559,21 @@ def fingerprint(port: int) -> str | None:
|
|
|
508
559
|
return "llama-server" if isinstance(props, dict) and props.get("build_info") else None
|
|
509
560
|
|
|
510
561
|
|
|
562
|
+
def _scan(port: int) -> dict[str, object]:
|
|
563
|
+
listening = _listening(port)
|
|
564
|
+
return {
|
|
565
|
+
"port": port,
|
|
566
|
+
"listening": listening,
|
|
567
|
+
"fingerprint": fingerprint(port) if listening else None,
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
|
|
511
571
|
def scan_ports(ports: Sequence[int]) -> list[dict[str, object]]:
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
"port": port,
|
|
518
|
-
"listening": listening,
|
|
519
|
-
"fingerprint": fingerprint(port) if listening else None,
|
|
520
|
-
}
|
|
521
|
-
)
|
|
522
|
-
return found
|
|
572
|
+
"""Every port at once, in the order given: the wait for a closed port is paid once."""
|
|
573
|
+
if not ports:
|
|
574
|
+
return []
|
|
575
|
+
with ThreadPoolExecutor(max_workers=min(16, len(ports))) as pool:
|
|
576
|
+
return list(pool.map(_scan, ports))
|
|
523
577
|
|
|
524
578
|
|
|
525
579
|
def collect(ports: Sequence[int]) -> dict[str, object]:
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""``foundations stop``: end this root's controller and its autostart, for an uninstaller.
|
|
2
|
+
|
|
3
|
+
A controller started by this release exits cleanly when asked over its loopback API. One from
|
|
4
|
+
an earlier release has no such request: it is signalled only after its lock and exact command
|
|
5
|
+
prove it is this root's controller, as ``service_upgrade`` does on Linux. Model services the
|
|
6
|
+
controller started keep running; it never owned their processes.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import errno
|
|
12
|
+
import json
|
|
13
|
+
import signal
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import time
|
|
17
|
+
import urllib.error
|
|
18
|
+
import urllib.request
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from localmodels import runtime_io, service_autostart, service_upgrade
|
|
23
|
+
|
|
24
|
+
SCHEMA = "localmodels.service-controller-stop/v1"
|
|
25
|
+
GRACE = 15.0 # an install in progress finishes its current step before the worker exits
|
|
26
|
+
KILL_AFTER = 10.0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _idle(root: Path) -> bool:
|
|
30
|
+
try:
|
|
31
|
+
with runtime_io.private_lock(root / "worker.lock", blocking=False):
|
|
32
|
+
return True
|
|
33
|
+
except OSError as error:
|
|
34
|
+
# flock answers EAGAIN (BlockingIOError); msvcrt.locking EACCES or EDEADLOCK.
|
|
35
|
+
if error.errno in (errno.EAGAIN, errno.EACCES, errno.EDEADLK):
|
|
36
|
+
return False
|
|
37
|
+
raise
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _wait(root: Path, seconds: float) -> bool:
|
|
41
|
+
deadline = time.monotonic() + seconds
|
|
42
|
+
while not _idle(root):
|
|
43
|
+
if time.monotonic() >= deadline:
|
|
44
|
+
return False
|
|
45
|
+
time.sleep(0.1)
|
|
46
|
+
return True
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _request(root: Path) -> bool:
|
|
50
|
+
"""Ask the controller to exit; False when it does not answer or predates the request."""
|
|
51
|
+
from localmodels.services_cli import read_configuration
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
config = read_configuration(root)
|
|
55
|
+
runtime_io.private_permissions(root / "control.key")
|
|
56
|
+
key = json.loads((root / "control.key").read_text())
|
|
57
|
+
request = urllib.request.Request(
|
|
58
|
+
f"http://127.0.0.1:{config['port']}/v1/controller/stop",
|
|
59
|
+
data=b"{}",
|
|
60
|
+
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"},
|
|
61
|
+
method="POST",
|
|
62
|
+
)
|
|
63
|
+
with urllib.request.build_opener(urllib.request.ProxyHandler({})).open(
|
|
64
|
+
request, timeout=2
|
|
65
|
+
) as response:
|
|
66
|
+
return bool(response.status == 202)
|
|
67
|
+
except (OSError, ValueError, KeyError, urllib.error.URLError):
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _unproven() -> ValueError:
|
|
72
|
+
return ValueError("Cannot verify the existing model controller")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _identity(root: Path) -> tuple[int, str]:
|
|
76
|
+
if sys.platform == "linux":
|
|
77
|
+
return service_upgrade.controller_identity(root)
|
|
78
|
+
# Neither a command-line match nor an open lock file proves its lock holder.
|
|
79
|
+
raise _unproven()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _send(root: Path, identity: tuple[int, str], force: bool) -> None:
|
|
83
|
+
if sys.platform != "linux":
|
|
84
|
+
raise _unproven()
|
|
85
|
+
signum = signal.SIGKILL if force else signal.SIGTERM
|
|
86
|
+
service_upgrade.signal_controller(root, identity, signum)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _signal(root: Path) -> None:
|
|
90
|
+
"""SIGTERM (the worker's clean shutdown), SIGKILL after KILL_AFTER, each re-proven."""
|
|
91
|
+
deadline = time.monotonic() + KILL_AFTER
|
|
92
|
+
sent: tuple[int, str] | None = None
|
|
93
|
+
killed = False
|
|
94
|
+
while not _idle(root):
|
|
95
|
+
try:
|
|
96
|
+
identity = _identity(root)
|
|
97
|
+
if sent is None:
|
|
98
|
+
_send(root, identity, sys.platform == "win32")
|
|
99
|
+
sent = identity
|
|
100
|
+
elif identity != sent:
|
|
101
|
+
raise ValueError("Model controller changed during stop")
|
|
102
|
+
elif time.monotonic() >= deadline:
|
|
103
|
+
if killed:
|
|
104
|
+
raise ValueError("Model controller did not stop")
|
|
105
|
+
_send(root, identity, True)
|
|
106
|
+
killed = True
|
|
107
|
+
deadline = time.monotonic() + 5
|
|
108
|
+
except (OSError, ValueError, subprocess.SubprocessError) as error:
|
|
109
|
+
# The owner may exit between the lock attempt and its proof; a free lock settles it.
|
|
110
|
+
if _idle(root):
|
|
111
|
+
return
|
|
112
|
+
raise ValueError(str(error) or "Cannot verify the existing model controller") from None
|
|
113
|
+
time.sleep(0.05)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def stop(root: Path) -> dict[str, Any]:
|
|
117
|
+
"""Idempotent: nothing under ``root``, or nothing running, is a successful stop."""
|
|
118
|
+
result: dict[str, Any] = {
|
|
119
|
+
"schema": SCHEMA,
|
|
120
|
+
"root": str(root),
|
|
121
|
+
"stopped": False,
|
|
122
|
+
"method": None,
|
|
123
|
+
"autostart": "none",
|
|
124
|
+
}
|
|
125
|
+
if not (root / "control.json").is_file():
|
|
126
|
+
return result
|
|
127
|
+
try:
|
|
128
|
+
_stop(root, result)
|
|
129
|
+
except (OSError, ValueError, subprocess.SubprocessError) as error:
|
|
130
|
+
result.update(ok=False, stopped=False, error=str(error))
|
|
131
|
+
return result
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _stop(root: Path, result: dict[str, Any]) -> None:
|
|
135
|
+
from localmodels.services_cli import read_configuration
|
|
136
|
+
|
|
137
|
+
with runtime_io.private_lock(root / "ensure.lock"):
|
|
138
|
+
config = read_configuration(root)
|
|
139
|
+
config["stopped"] = True
|
|
140
|
+
runtime_io.write_private_json(root / "control.json", config)
|
|
141
|
+
running = not _idle(root)
|
|
142
|
+
result["autostart"] = service_autostart.unregister(root)
|
|
143
|
+
if not running and _idle(root):
|
|
144
|
+
return
|
|
145
|
+
result["stopped"] = True
|
|
146
|
+
if _idle(root):
|
|
147
|
+
result["method"] = "systemd"
|
|
148
|
+
elif _request(root) and _wait(root, GRACE):
|
|
149
|
+
result["method"] = "request"
|
|
150
|
+
else:
|
|
151
|
+
result["method"] = "signal"
|
|
152
|
+
_signal(root)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import contextlib
|
|
5
6
|
import json
|
|
6
7
|
import os
|
|
7
8
|
import platform
|
|
@@ -40,7 +41,13 @@ def run(root: Path) -> int:
|
|
|
40
41
|
deadline = time.monotonic() + 10
|
|
41
42
|
while True:
|
|
42
43
|
try:
|
|
43
|
-
with
|
|
44
|
+
with contextlib.ExitStack() as locks:
|
|
45
|
+
with runtime_io.private_lock(root / "ensure.lock"):
|
|
46
|
+
if read_configuration(root).get("stopped"):
|
|
47
|
+
return 0
|
|
48
|
+
locks.enter_context(
|
|
49
|
+
runtime_io.private_lock(root / "worker.lock", blocking=False)
|
|
50
|
+
)
|
|
44
51
|
return _run(root)
|
|
45
52
|
except BlockingIOError:
|
|
46
53
|
config = read_configuration(root)
|
|
@@ -129,6 +136,7 @@ def _run(root: Path) -> int:
|
|
|
129
136
|
|
|
130
137
|
for name in (signal.SIGTERM, signal.SIGINT):
|
|
131
138
|
signal.signal(name, shutdown)
|
|
139
|
+
server.stop_requested = lambda: shutdown(signal.SIGTERM, None)
|
|
132
140
|
try:
|
|
133
141
|
server.serve_forever(poll_interval=0.25)
|
|
134
142
|
finally:
|
|
@@ -8,6 +8,7 @@ import os
|
|
|
8
8
|
import secrets
|
|
9
9
|
import socket
|
|
10
10
|
import subprocess
|
|
11
|
+
import sys
|
|
11
12
|
import urllib.error
|
|
12
13
|
import urllib.request
|
|
13
14
|
from collections.abc import Sequence
|
|
@@ -119,6 +120,8 @@ def ensure(
|
|
|
119
120
|
# Read when the worker starts; a running worker keeps its mode until restarted.
|
|
120
121
|
config["residency"] = residency
|
|
121
122
|
runtime_io.write_private_json(config_path, config)
|
|
123
|
+
config.pop("stopped", None)
|
|
124
|
+
runtime_io.write_private_json(config_path, config)
|
|
122
125
|
runtime_io.private_permissions(key_path)
|
|
123
126
|
key = json.loads(key_path.read_text())
|
|
124
127
|
if os.name != "nt":
|
|
@@ -175,7 +178,8 @@ FOUNDATIONS = (
|
|
|
175
178
|
"A background controller that installs and serves the foundation models (the GPU decision "
|
|
176
179
|
"model, embedding, reranker) apart from the chat stack, one install at a time. `ensure` "
|
|
177
180
|
"configures and starts it; `status`, `retry` and `residency` ask it over its loopback API "
|
|
178
|
-
"with the key under --root; `run` is the controller process
|
|
181
|
+
"with the key under --root; `stop` ends it for an uninstall; `run` is the controller process "
|
|
182
|
+
"itself. Every command but "
|
|
179
183
|
"`run` prints one JSON object on stdout."
|
|
180
184
|
)
|
|
181
185
|
ENSURE = (
|
|
@@ -205,8 +209,9 @@ RUN = (
|
|
|
205
209
|
STATUS = (
|
|
206
210
|
"Read-only: ask the controller under --root for each selected service's state (queued, "
|
|
207
211
|
"waiting_resources, planning, downloading, verifying, starting, ready, failed, "
|
|
208
|
-
"unsupported), attempt, completedBytes, totalBytes, reason and model
|
|
209
|
-
"
|
|
212
|
+
"unsupported), attempt, completedBytes, totalBytes, reason and model; while downloading "
|
|
213
|
+
"also bytesPerSecond and etaSeconds. The bytes count every file of the download step. "
|
|
214
|
+
"Uses the loopback port and key under --root with a 2-second timeout.\n\nPrints "
|
|
210
215
|
"localmodels.service-status/v1 {components[]}."
|
|
211
216
|
)
|
|
212
217
|
RETRY = (
|
|
@@ -220,6 +225,20 @@ RESIDENCY = (
|
|
|
220
225
|
"and whether it is starting. The controller answers only if residency was on when it "
|
|
221
226
|
"started (`ensure --residency`).\n\nPrints localmodels.residency/v1 {members[]}."
|
|
222
227
|
)
|
|
228
|
+
STOP = (
|
|
229
|
+
"Stop the controller under --root and remove its autostart, for an uninstall or before "
|
|
230
|
+
"installing another version: on Linux the user unit simplex-model-services-<hash> is "
|
|
231
|
+
"stopped, disabled and its file deleted; a running controller is asked to exit over its "
|
|
232
|
+
"loopback API. An earlier Linux controller is signalled only after its lock and exact "
|
|
233
|
+
"command prove it belongs to this root (SIGTERM, then SIGKILL after 10 seconds). Legacy "
|
|
234
|
+
"controllers without that API on macOS or Windows are left running and reported as "
|
|
235
|
+
"unverified. Idempotent: no controller config "
|
|
236
|
+
"under --root, or no controller running, is a success. Model services it started, "
|
|
237
|
+
"control.json, the key, jobs and model files stay; the next `ensure` registers and starts "
|
|
238
|
+
"it again.\n\nPrints localmodels.service-controller-stop/v1: root, stopped (a controller "
|
|
239
|
+
"was running), method (null, systemd, request or signal), autostart (removed, none or "
|
|
240
|
+
"kept: the user manager could not be reached)."
|
|
241
|
+
)
|
|
223
242
|
NO_CONTROLLER = "1 no controller config under --root, or the controller did not answer"
|
|
224
243
|
|
|
225
244
|
|
|
@@ -293,6 +312,20 @@ def _ensure_options(command: argparse.ArgumentParser) -> None:
|
|
|
293
312
|
|
|
294
313
|
|
|
295
314
|
def _document_queries(commands: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
315
|
+
cli_help.document(
|
|
316
|
+
commands.choices["stop"],
|
|
317
|
+
STOP,
|
|
318
|
+
examples=[("%(prog)s --root /srv/foundations --json", "before an uninstall")],
|
|
319
|
+
sections=[
|
|
320
|
+
(
|
|
321
|
+
"exit status",
|
|
322
|
+
"0 stopped, or nothing was running\n"
|
|
323
|
+
"1 refused, message on stderr: a process holds the controller lock but cannot\n"
|
|
324
|
+
" be proven to be this root's controller, or it did not exit after SIGKILL\n"
|
|
325
|
+
"2 bad arguments, such as a relative path",
|
|
326
|
+
)
|
|
327
|
+
],
|
|
328
|
+
)
|
|
296
329
|
run, status, retry, residency = (
|
|
297
330
|
commands.choices[name] for name in ("run", "status", "retry", "residency")
|
|
298
331
|
)
|
|
@@ -360,14 +393,17 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
360
393
|
residency = commands.add_parser(
|
|
361
394
|
"residency", help="on-demand load/unload view of owned deployments (read-only)"
|
|
362
395
|
)
|
|
363
|
-
|
|
396
|
+
stop = commands.add_parser(
|
|
397
|
+
"stop", help="stop the controller and remove its autostart (for an uninstall)"
|
|
398
|
+
)
|
|
399
|
+
for command in (ensure, run, status, retry, residency, stop):
|
|
364
400
|
command.add_argument(
|
|
365
401
|
"--root",
|
|
366
402
|
type=_absolute,
|
|
367
403
|
required=True,
|
|
368
404
|
metavar="DIR",
|
|
369
405
|
help="absolute private controller directory holding control.json and control.key; "
|
|
370
|
-
"ensure creates it, the other commands read it",
|
|
406
|
+
"ensure creates it, the other commands read it (stop accepts a missing one)",
|
|
371
407
|
)
|
|
372
408
|
command.add_argument(
|
|
373
409
|
"--json",
|
|
@@ -394,6 +430,7 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
394
430
|
),
|
|
395
431
|
("%(prog)s status --root /srv/foundations", "install progress"),
|
|
396
432
|
("%(prog)s retry --root /srv/foundations --component decision", ""),
|
|
433
|
+
("%(prog)s stop --root /srv/foundations --json", "before an uninstall"),
|
|
397
434
|
],
|
|
398
435
|
)
|
|
399
436
|
|
|
@@ -403,7 +440,11 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
403
440
|
from localmodels.service_worker import run
|
|
404
441
|
|
|
405
442
|
return run(args.root)
|
|
406
|
-
if args.services_command == "
|
|
443
|
+
if args.services_command == "stop":
|
|
444
|
+
from localmodels.service_stop import stop
|
|
445
|
+
|
|
446
|
+
value = stop(args.root)
|
|
447
|
+
elif args.services_command == "ensure":
|
|
407
448
|
value = ensure(
|
|
408
449
|
args.root,
|
|
409
450
|
args.base_dir,
|
|
@@ -434,4 +475,7 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
434
475
|
) as response:
|
|
435
476
|
value = json.load(response)
|
|
436
477
|
print(json.dumps(value, ensure_ascii=False))
|
|
478
|
+
if value.get("ok") is False:
|
|
479
|
+
print(value.get("error", "Model controller did not stop"), file=sys.stderr)
|
|
480
|
+
return 1
|
|
437
481
|
return 0
|
|
@@ -17,6 +17,7 @@ from localmodels import (
|
|
|
17
17
|
metal,
|
|
18
18
|
probe,
|
|
19
19
|
service_probe,
|
|
20
|
+
setup_text,
|
|
20
21
|
stack,
|
|
21
22
|
stack_binding,
|
|
22
23
|
stack_hardware,
|
|
@@ -26,6 +27,7 @@ from localmodels.contracts import decode
|
|
|
26
27
|
from localmodels.plan_envelope import PlanError
|
|
27
28
|
from localmodels.probe import HostFacts, Services
|
|
28
29
|
from localmodels.runtime_cli import inspect_runtimes
|
|
30
|
+
from localmodels.setup_text import Lang, text
|
|
29
31
|
from localmodels.stack_plan import RAM_FLOOR, StackError, StackPlan, platform_error
|
|
30
32
|
|
|
31
33
|
|
|
@@ -38,6 +40,9 @@ class _Basis(TypedDict, total=False):
|
|
|
38
40
|
# "capacity": the plan fits this computer's hardware once other programs release the
|
|
39
41
|
# memory they hold now; absent for a plan priced on the memory free now.
|
|
40
42
|
basis: Literal["capacity"]
|
|
43
|
+
# With a plan (since 2026-11-13): the model, every GPU it uses and what it needs, with a
|
|
44
|
+
# sentence in --lang, so an installer shows the recommendation without composing its own.
|
|
45
|
+
summary: stack_review.PlanSummary
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
class StackAvailability(_Basis):
|
|
@@ -62,6 +67,7 @@ def _stack(
|
|
|
62
67
|
share_gpu: bool = False,
|
|
63
68
|
decision: Literal["auto", "none"] = "none",
|
|
64
69
|
unified_memory: str | None = None,
|
|
70
|
+
lang: Lang = "zh",
|
|
65
71
|
) -> StackAvailability:
|
|
66
72
|
reason: Reason | None = None
|
|
67
73
|
plan: StackPlan | None = None
|
|
@@ -71,17 +77,9 @@ def _stack(
|
|
|
71
77
|
"message": error,
|
|
72
78
|
}
|
|
73
79
|
elif facts["ram"]["total_bytes"] <= 0 or facts["disk"]["free_bytes"] is None:
|
|
74
|
-
reason = {
|
|
75
|
-
"code": "facts-unavailable",
|
|
76
|
-
"message": "内存或磁盘可用容量未知,无法安全生成模型套件计划。",
|
|
77
|
-
}
|
|
80
|
+
reason = {"code": "facts-unavailable", "message": text("facts-unavailable", lang)}
|
|
78
81
|
elif _nvidia_cards_unmeasured(facts):
|
|
79
|
-
reason = {
|
|
80
|
-
"code": "facts-unavailable",
|
|
81
|
-
"message": "检测到 NVIDIA 驱动,但 nvidia-smi 未找到或运行失败,显卡与显存未知,"
|
|
82
|
-
"无法安全生成模型套件计划;请安装与驱动版本一致的 nvidia-smi"
|
|
83
|
-
"(容器内需由 NVIDIA Container Toolkit 提供)后重试。",
|
|
84
|
-
}
|
|
82
|
+
reason = {"code": "facts-unavailable", "message": text("nvidia-unmeasured", lang)}
|
|
85
83
|
else:
|
|
86
84
|
options = stack.default_options()
|
|
87
85
|
options["base_dir"] = str(root)
|
|
@@ -104,7 +102,7 @@ def _stack(
|
|
|
104
102
|
else:
|
|
105
103
|
reason = {
|
|
106
104
|
"code": "gpu-sharing-required",
|
|
107
|
-
"message": "
|
|
105
|
+
"message": text("gpu-sharing-required", lang),
|
|
108
106
|
}
|
|
109
107
|
if reason["code"] == "plan-unavailable" and (roomy := _capacity_facts(facts)):
|
|
110
108
|
try:
|
|
@@ -114,7 +112,7 @@ def _stack(
|
|
|
114
112
|
else:
|
|
115
113
|
return {
|
|
116
114
|
"available": True,
|
|
117
|
-
"reasons": [_free_memory_reason(facts, roomy)],
|
|
115
|
+
"reasons": [_free_memory_reason(facts, roomy, lang)],
|
|
118
116
|
"plan": plan,
|
|
119
117
|
"basis": "capacity",
|
|
120
118
|
}
|
|
@@ -150,21 +148,21 @@ def _capacity_facts(facts: HostFacts) -> HostFacts | None:
|
|
|
150
148
|
return None if roomy == facts else roomy
|
|
151
149
|
|
|
152
150
|
|
|
153
|
-
def _free_memory_reason(facts: HostFacts, roomy: HostFacts) -> Reason:
|
|
151
|
+
def _free_memory_reason(facts: HostFacts, roomy: HostFacts, lang: Lang = "zh") -> Reason:
|
|
154
152
|
"""Names the memory other programs hold now: each reading the capacity plan counted as freed."""
|
|
155
153
|
gib = budget.gib
|
|
156
154
|
held = [
|
|
157
|
-
|
|
155
|
+
text("free-gpu", lang, index=live["index"], free=gib(live["free_bytes"]))
|
|
158
156
|
for live, idle in zip(facts.get("gpus") or [], roomy.get("gpus") or [], strict=True)
|
|
159
157
|
if live["free_bytes"] < idle["free_bytes"]
|
|
160
158
|
]
|
|
161
159
|
if facts["ram"]["available_bytes"] < roomy["ram"]["available_bytes"]:
|
|
162
|
-
held.append(
|
|
160
|
+
held.append(text("free-ram", lang, free=gib(facts["ram"]["available_bytes"])))
|
|
163
161
|
return {
|
|
164
162
|
"code": "free-memory-required",
|
|
165
|
-
"message":
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
"message": text(
|
|
164
|
+
"free-memory-required", lang, held=("; " if lang == "en" else ",").join(held)
|
|
165
|
+
),
|
|
168
166
|
}
|
|
169
167
|
|
|
170
168
|
|
|
@@ -189,6 +187,7 @@ def inspect_setup(
|
|
|
189
187
|
defer_services: bool = False,
|
|
190
188
|
share_gpu: bool = False,
|
|
191
189
|
unified_memory: str | None = None,
|
|
190
|
+
lang: Lang = "zh",
|
|
192
191
|
) -> SetupReport:
|
|
193
192
|
"""Inspect without caching facts, saving plans, downloading models, or starting services.
|
|
194
193
|
With ``unified_memory`` the report's facts are the Mac as priced (``metal.assumed_total_bytes``
|
|
@@ -202,7 +201,11 @@ def inspect_setup(
|
|
|
202
201
|
ports = app.probe_ports()
|
|
203
202
|
facts = probe.collect(ports=ports, models_dir=str(base / "models"))
|
|
204
203
|
facts["services"] = decode(service_probe.collect(ports), Services)
|
|
205
|
-
availability = _stack(
|
|
204
|
+
availability = _stack(
|
|
205
|
+
base, facts, offline, defer_services, share_gpu, decision, unified_memory, lang
|
|
206
|
+
)
|
|
207
|
+
if availability["plan"] is not None:
|
|
208
|
+
availability["summary"] = stack_review.summarize(availability["plan"], lang)
|
|
206
209
|
if unified_memory:
|
|
207
210
|
try:
|
|
208
211
|
facts = stack_hardware.assumed(facts, unified_memory)
|
|
@@ -245,8 +248,10 @@ INSPECT = (
|
|
|
245
248
|
"stack with the existing planner, and check the native agent runtimes (codex, claude, pi) "
|
|
246
249
|
"on PATH and under --root. Read-only: nothing is installed, downloaded, started or saved; "
|
|
247
250
|
"without --offline the planner asks the model hub for file pins.\n\nPrints "
|
|
248
|
-
"localmodels.setup-report/v1: facts, stack {available, reasons, plan}, harness and "
|
|
249
|
-
"recommendation (local-models, else an installed agent runtime, else codex)."
|
|
251
|
+
"localmodels.setup-report/v1: facts, stack {available, reasons, plan, summary}, harness and "
|
|
252
|
+
"recommendation (local-models, else an installed agent runtime, else codex). "
|
|
253
|
+
"stack.summary (with a plan) names the model, the GPUs the plan uses and what it needs; "
|
|
254
|
+
"--lang en gives it and the reasons in English."
|
|
250
255
|
)
|
|
251
256
|
INSPECT_REASONS = (
|
|
252
257
|
"unsupported-platform · facts-unavailable · plan-unavailable · gpu-sharing-required\n"
|
|
@@ -261,7 +266,7 @@ BINDING = (
|
|
|
261
266
|
"gateway, Pi configuration and `pi --list-models` must match the plan now. Sends no "
|
|
262
267
|
"generation request and repairs, saves or starts nothing.\n\nPrints "
|
|
263
268
|
"localmodels.stack-binding/v1: ready, planId, reasons[{code,message}] and, when ready, "
|
|
264
|
-
"pi {executable, environment, configFingerprint}."
|
|
269
|
+
"pi {executable, environment, configFingerprint}. --lang en gives the messages in English."
|
|
265
270
|
)
|
|
266
271
|
BINDING_REASONS = (
|
|
267
272
|
"plan-invalid · acceptance-unavailable · deployment-unavailable · gateway-ownership\n"
|
|
@@ -272,7 +277,7 @@ REVIEW = (
|
|
|
272
277
|
"plan file is not changed and nothing is probed, downloaded or started.\n\nPrints "
|
|
273
278
|
"localmodels.stack-review/v1: planId, gpuIndex, gpuName, llm, contextWindow, "
|
|
274
279
|
"downloadBytes, diskBytes, memoryBytes, components and warnings (with each model's "
|
|
275
|
-
"license note)."
|
|
280
|
+
"license note), gpus (every card the plan uses, the LLM's first) and summary."
|
|
276
281
|
)
|
|
277
282
|
|
|
278
283
|
|
|
@@ -321,6 +326,7 @@ def _inspect_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]
|
|
|
321
326
|
"stopped (without it busy GPUs are avoided)",
|
|
322
327
|
)
|
|
323
328
|
stack_hardware.add_arguments(inspect)
|
|
329
|
+
setup_text.add_argument(inspect)
|
|
324
330
|
inspect.add_argument(
|
|
325
331
|
"--json", action="store_true", help="accepted for installers; the report is JSON either way"
|
|
326
332
|
)
|
|
@@ -358,6 +364,7 @@ def _plan_parsers(actions: argparse._SubParsersAction[argparse.ArgumentParser])
|
|
|
358
364
|
metavar="FILE",
|
|
359
365
|
help="absolute path of the stack plan that `stack apply` installed",
|
|
360
366
|
)
|
|
367
|
+
setup_text.add_argument(binding)
|
|
361
368
|
binding.add_argument(
|
|
362
369
|
"--json", action="store_true", help="accepted for installers; the report is JSON either way"
|
|
363
370
|
)
|
|
@@ -384,6 +391,7 @@ def _plan_parsers(actions: argparse._SubParsersAction[argparse.ArgumentParser])
|
|
|
384
391
|
metavar="FILE",
|
|
385
392
|
help="absolute path of a saved stack plan (`stack plan --out FILE` writes one)",
|
|
386
393
|
)
|
|
394
|
+
setup_text.add_argument(review)
|
|
387
395
|
review.add_argument(
|
|
388
396
|
"--json", action="store_true", help="accepted for installers; the review is JSON either way"
|
|
389
397
|
)
|
|
@@ -420,9 +428,9 @@ def add_parser(sub: argparse._SubParsersAction[argparse.ArgumentParser]) -> None
|
|
|
420
428
|
|
|
421
429
|
def cli(args: argparse.Namespace) -> int:
|
|
422
430
|
report = (
|
|
423
|
-
stack_binding.inspect_binding(args.plan)
|
|
431
|
+
stack_binding.inspect_binding(args.plan, getattr(args, "lang", "zh"))
|
|
424
432
|
if args.setup_command == "binding"
|
|
425
|
-
else stack_review.review_plan(args.plan)
|
|
433
|
+
else stack_review.review_plan(args.plan, getattr(args, "lang", "zh"))
|
|
426
434
|
if args.setup_command == "review"
|
|
427
435
|
else inspect_setup(
|
|
428
436
|
args.root,
|
|
@@ -432,6 +440,7 @@ def cli(args: argparse.Namespace) -> int:
|
|
|
432
440
|
defer_services=getattr(args, "defer_services", False),
|
|
433
441
|
share_gpu=getattr(args, "share_gpu", False),
|
|
434
442
|
unified_memory=getattr(args, "unified_memory", None),
|
|
443
|
+
lang=getattr(args, "lang", "zh"),
|
|
435
444
|
)
|
|
436
445
|
)
|
|
437
446
|
json.dump(report, sys.stdout, ensure_ascii=False, indent=1)
|