@simplexai/localmodels-darwin-arm64 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
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
"""What ``stack plan`` reads about this computer before asking for approval.
|
|
2
|
+
|
|
3
|
+
Composing a plan prices it against one set of facts; this module checks the parts a budget
|
|
4
|
+
cannot: whether the machine is in a state to run the plan now (memory pressure, swap, load,
|
|
5
|
+
power, thermal throttling, sleep, disk headroom and writability, a network install directory,
|
|
6
|
+
foreign GPU processes, held ports, a running apply, systemd linger, proxy settings, a missing
|
|
7
|
+
venv module), whether another deployment of this tool keeps resources the plan does not price,
|
|
8
|
+
and whether the plan will still be the same when apply re-probes (a Mac plan that follows live
|
|
9
|
+
free memory). Everything here is read-only: nothing is installed, started, stopped or changed,
|
|
10
|
+
and a finding names only observations, never a key, a prompt, an answer, an environment value
|
|
11
|
+
or a log line.
|
|
12
|
+
|
|
13
|
+
Findings are grouped by ``check`` id and carry the same levels as ``stack doctor``: ``fail``
|
|
14
|
+
means apply would fail or the result would not run as approved, ``warn`` means it may, and
|
|
15
|
+
``pass`` records a check that found nothing. A failed check does not block approval by itself:
|
|
16
|
+
the plan is a proposal, and apply's own guards still re-probe. The summary shows every check
|
|
17
|
+
that did not pass, so the operator can fix them and plan again.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import getpass
|
|
23
|
+
import importlib.util
|
|
24
|
+
import os
|
|
25
|
+
import re
|
|
26
|
+
import shutil
|
|
27
|
+
import socket
|
|
28
|
+
import subprocess
|
|
29
|
+
import sys
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
from typing import cast
|
|
32
|
+
|
|
33
|
+
from localmodels import deploy, hosts, metal, stack_llm_ram
|
|
34
|
+
from localmodels.budget import gib
|
|
35
|
+
from localmodels.context_policy import AGENT
|
|
36
|
+
from localmodels.gateway_probe import Finding, finding
|
|
37
|
+
from localmodels.probe import HostFacts
|
|
38
|
+
from localmodels.stack_plan import Preflight, StackPlan, command, deployments, platform_error
|
|
39
|
+
|
|
40
|
+
SCHEMA = "localmodels.stack-preflight/v1"
|
|
41
|
+
LEVELS = ("pass", "warn", "fail")
|
|
42
|
+
DISK_FLOOR = 5 << 30 # keep in step with stack_doctor.DISK_FLOOR
|
|
43
|
+
SWAP_WARN_BYTES = 2 << 30
|
|
44
|
+
PROXY_VARS = ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY", "http_proxy", "https_proxy", "all_proxy")
|
|
45
|
+
NETWORK_FILESYSTEMS = (
|
|
46
|
+
"nfs",
|
|
47
|
+
"smbfs",
|
|
48
|
+
"afpfs",
|
|
49
|
+
"webdav",
|
|
50
|
+
"cifs",
|
|
51
|
+
"smb3",
|
|
52
|
+
"sshfs",
|
|
53
|
+
"davfs",
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _gib(n: int | float) -> str:
|
|
58
|
+
return gib(int(n))
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _profile(plan: StackPlan) -> str | None:
|
|
62
|
+
return plan["options"].get("profile")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _base_dir(plan: StackPlan) -> Path:
|
|
66
|
+
base = plan["options"]["base_dir"] or deploy.DEFAULT_BASE_DIR
|
|
67
|
+
return Path(os.path.expanduser(str(base)))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _existing(path: Path) -> Path:
|
|
71
|
+
"""``path`` or its nearest existing parent: where a free-space or permission check reads."""
|
|
72
|
+
while not path.exists() and path != path.parent:
|
|
73
|
+
path = path.parent
|
|
74
|
+
return path
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _run(argv: list[str]) -> str | None:
|
|
78
|
+
try:
|
|
79
|
+
done = subprocess.run(argv, capture_output=True, text=True, timeout=10, check=False)
|
|
80
|
+
except (OSError, subprocess.SubprocessError):
|
|
81
|
+
return None
|
|
82
|
+
return done.stdout if done.returncode == 0 else None
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# ---------------------------------------------------------------------------- host checks
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _platform(plan: StackPlan, facts: HostFacts) -> Finding:
|
|
89
|
+
error = platform_error(facts["platform"], _profile(plan), facts.get("arch", ""))
|
|
90
|
+
if error:
|
|
91
|
+
return finding("preflight.platform", "fail", error, "run stack plan on a supported host")
|
|
92
|
+
# ``system`` is "Darwin" on macOS; the distro field names the release ("macOS 27.2").
|
|
93
|
+
os_facts = facts.get("os") or {}
|
|
94
|
+
system = os_facts.get("distro") or os_facts.get("system") or facts["platform"]
|
|
95
|
+
return finding(
|
|
96
|
+
"preflight.platform",
|
|
97
|
+
"pass",
|
|
98
|
+
f"{facts['platform']} {facts.get('arch', '')} on {system}",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _memory(plan: StackPlan, facts: HostFacts, live: bool) -> list[Finding]:
|
|
103
|
+
budget = plan.get("budget") or {}
|
|
104
|
+
needed = int(str(budget.get("ram_needed_bytes") or 0))
|
|
105
|
+
planned = int(str(budget.get("ram_available_bytes") or 0))
|
|
106
|
+
available = planned
|
|
107
|
+
if live and metal.supported(facts):
|
|
108
|
+
# The plan reclaims this tool's own servers' memory (compose does the same); comparing
|
|
109
|
+
# with the raw reading would count them twice and refuse a plan that fits.
|
|
110
|
+
real = int(metal.reclaimed(facts)["ram"]["available_bytes"])
|
|
111
|
+
available = min(planned, real)
|
|
112
|
+
if needed > available:
|
|
113
|
+
return [
|
|
114
|
+
finding(
|
|
115
|
+
"preflight.memory",
|
|
116
|
+
"fail",
|
|
117
|
+
f"the plan needs {_gib(needed)}, but only {_gib(available)} is available now",
|
|
118
|
+
"another program took memory since planning; close it, then run stack plan again",
|
|
119
|
+
)
|
|
120
|
+
]
|
|
121
|
+
return [
|
|
122
|
+
finding(
|
|
123
|
+
"preflight.memory",
|
|
124
|
+
"pass",
|
|
125
|
+
f"needs {_gib(needed)} of {_gib(available)} available",
|
|
126
|
+
)
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _pressure(facts: HostFacts) -> list[Finding]:
|
|
131
|
+
level = (facts.get("ram") or {}).get("pressure_level")
|
|
132
|
+
if level is None:
|
|
133
|
+
return []
|
|
134
|
+
if level == 1:
|
|
135
|
+
return [finding("preflight.pressure", "pass", "macOS memory pressure is normal")]
|
|
136
|
+
if level == 2:
|
|
137
|
+
return [
|
|
138
|
+
finding(
|
|
139
|
+
"preflight.pressure",
|
|
140
|
+
"warn",
|
|
141
|
+
"macOS memory pressure is at warning level; the plan keeps 25% of the memory free "
|
|
142
|
+
"as it is, and more pressure slows loading and inference",
|
|
143
|
+
"quit applications you do not need, then run stack plan again",
|
|
144
|
+
)
|
|
145
|
+
]
|
|
146
|
+
return [
|
|
147
|
+
finding(
|
|
148
|
+
"preflight.pressure",
|
|
149
|
+
"fail",
|
|
150
|
+
"macOS memory pressure is critical",
|
|
151
|
+
"close applications or use an idle Mac, then run stack plan again; this tool does not "
|
|
152
|
+
"stop other programs",
|
|
153
|
+
)
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _swap(facts: HostFacts) -> list[Finding]:
|
|
158
|
+
used = (facts.get("ram") or {}).get("swap_used_bytes")
|
|
159
|
+
if used is None:
|
|
160
|
+
return []
|
|
161
|
+
if int(used) > SWAP_WARN_BYTES:
|
|
162
|
+
return [
|
|
163
|
+
finding(
|
|
164
|
+
"preflight.swap",
|
|
165
|
+
"warn",
|
|
166
|
+
f"swap already holds {_gib(int(used))}; macOS was short of memory and paging "
|
|
167
|
+
"makes loading and inference slower",
|
|
168
|
+
"close applications to bring swap down before applying",
|
|
169
|
+
)
|
|
170
|
+
]
|
|
171
|
+
return [finding("preflight.swap", "pass", f"swap holds {_gib(int(used))}")]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _load(facts: HostFacts, live: bool) -> list[Finding]:
|
|
175
|
+
if not live or not hasattr(os, "getloadavg"):
|
|
176
|
+
return []
|
|
177
|
+
try:
|
|
178
|
+
load = os.getloadavg()[0]
|
|
179
|
+
except OSError:
|
|
180
|
+
return []
|
|
181
|
+
cores = int((facts.get("cpu") or {}).get("logical_cores") or os.cpu_count() or 0)
|
|
182
|
+
detail = f"1-minute load average {load:.2f} on {cores or '?'} logical cores"
|
|
183
|
+
if cores and load > cores:
|
|
184
|
+
return [
|
|
185
|
+
finding(
|
|
186
|
+
"preflight.load",
|
|
187
|
+
"warn",
|
|
188
|
+
detail + "; other work is using the CPU inference will need",
|
|
189
|
+
"finish or pause that work before applying and benchmarking",
|
|
190
|
+
)
|
|
191
|
+
]
|
|
192
|
+
return [finding("preflight.load", "pass", detail)]
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _pmset(*args: str) -> str | None:
|
|
196
|
+
return _run(["/usr/bin/pmset", *args])
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _power(live: bool) -> list[Finding]:
|
|
200
|
+
"""Battery, Low Power Mode, thermal throttling and sleep, from read-only ``pmset``."""
|
|
201
|
+
if not live or sys.platform != "darwin":
|
|
202
|
+
return []
|
|
203
|
+
found: list[Finding] = []
|
|
204
|
+
battery = _pmset("-g", "batt")
|
|
205
|
+
if battery:
|
|
206
|
+
if "Battery Power" in battery:
|
|
207
|
+
found.append(
|
|
208
|
+
finding(
|
|
209
|
+
"preflight.power",
|
|
210
|
+
"warn",
|
|
211
|
+
"this Mac is drawing from battery power; Metal inference is slower and the "
|
|
212
|
+
"Mac can sleep mid-session",
|
|
213
|
+
"connect AC power for the install and for long sessions",
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
elif "AC Power" in battery:
|
|
217
|
+
found.append(finding("preflight.power", "pass", "running on AC power"))
|
|
218
|
+
settings = _pmset("-g")
|
|
219
|
+
if settings:
|
|
220
|
+
low = re.search(r"^ lowpowermode\s+(\d+)", settings, re.M)
|
|
221
|
+
if low and low.group(1) != "0":
|
|
222
|
+
found.append(
|
|
223
|
+
finding(
|
|
224
|
+
"preflight.low_power",
|
|
225
|
+
"warn",
|
|
226
|
+
"Low Power Mode is on; macOS limits CPU and GPU speed",
|
|
227
|
+
"turn Low Power Mode off while installing or using the stack",
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
elif low:
|
|
231
|
+
found.append(finding("preflight.low_power", "pass", "Low Power Mode is off"))
|
|
232
|
+
asleep = re.search(r"^ sleep\s+(\d+)", settings, re.M)
|
|
233
|
+
if asleep and int(asleep.group(1)) > 0:
|
|
234
|
+
found.append(
|
|
235
|
+
finding(
|
|
236
|
+
"preflight.sleep",
|
|
237
|
+
"warn",
|
|
238
|
+
f"this Mac sleeps after {asleep.group(1)} minutes; running services pause and "
|
|
239
|
+
"requests fail until it wakes",
|
|
240
|
+
"run caffeinate -i while installing or using the stack, or change the sleep "
|
|
241
|
+
"setting yourself if you want it always awake",
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
elif asleep:
|
|
245
|
+
found.append(finding("preflight.sleep", "pass", "sleep is off"))
|
|
246
|
+
thermal = _pmset("-g", "therm")
|
|
247
|
+
limit = re.search(r"CPU_Speed_Limit\s*=\s*(\d+)", thermal or "")
|
|
248
|
+
if limit:
|
|
249
|
+
speed = int(limit.group(1))
|
|
250
|
+
if speed < 100:
|
|
251
|
+
found.append(
|
|
252
|
+
finding(
|
|
253
|
+
"preflight.thermal",
|
|
254
|
+
"warn",
|
|
255
|
+
f"macOS throttles the CPU to {speed}% of full speed",
|
|
256
|
+
"let the Mac cool and check again; a throttled Mac is slower at load and decode",
|
|
257
|
+
)
|
|
258
|
+
)
|
|
259
|
+
else:
|
|
260
|
+
found.append(finding("preflight.thermal", "pass", "no thermal throttling reported"))
|
|
261
|
+
return found
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _linger(plan: StackPlan, facts: HostFacts, live: bool) -> list[Finding]:
|
|
265
|
+
if not live or not facts["platform"].startswith("linux"):
|
|
266
|
+
return []
|
|
267
|
+
kinds = {p["service"]["kind"] for p in deployments(plan)}
|
|
268
|
+
unit_gateway = any(
|
|
269
|
+
t["tool"] == "gateway" and t["action"] == "unit" for t in plan["harness"]["tools"]
|
|
270
|
+
)
|
|
271
|
+
if "systemd-user" not in kinds and not unit_gateway:
|
|
272
|
+
return []
|
|
273
|
+
manager = facts.get("service_manager")
|
|
274
|
+
if manager and manager.get("linger"):
|
|
275
|
+
return [finding("preflight.linger", "pass", "systemd linger is on")]
|
|
276
|
+
user = getpass.getuser()
|
|
277
|
+
if Path("/var/lib/systemd/linger", user).exists():
|
|
278
|
+
return [finding("preflight.linger", "pass", "systemd linger is on")]
|
|
279
|
+
return [
|
|
280
|
+
finding(
|
|
281
|
+
"preflight.linger",
|
|
282
|
+
"warn",
|
|
283
|
+
"systemd linger is off: the stack's user services stop when your last login ends",
|
|
284
|
+
f"loginctl enable-linger {user}",
|
|
285
|
+
)
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _proxy() -> list[Finding]:
|
|
290
|
+
names = [name for name in PROXY_VARS if os.environ.get(name)]
|
|
291
|
+
if not names:
|
|
292
|
+
return []
|
|
293
|
+
bypass = f"{os.environ.get('NO_PROXY', '')},{os.environ.get('no_proxy', '')}"
|
|
294
|
+
if "127.0.0.1" in bypass and "localhost" in bypass:
|
|
295
|
+
return [
|
|
296
|
+
finding("preflight.proxy", "pass", f"{', '.join(names)} set; NO_PROXY covers loopback")
|
|
297
|
+
]
|
|
298
|
+
return [
|
|
299
|
+
finding(
|
|
300
|
+
"preflight.proxy",
|
|
301
|
+
"warn",
|
|
302
|
+
f"{', '.join(names)} set, but NO_PROXY lacks 127.0.0.1 and localhost: clients may "
|
|
303
|
+
"send loopback requests through the proxy",
|
|
304
|
+
'export NO_PROXY="127.0.0.1,localhost${NO_PROXY:+,$NO_PROXY}" in your shell profile',
|
|
305
|
+
)
|
|
306
|
+
]
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _python_version() -> str:
|
|
310
|
+
return ".".join(str(part) for part in sys.version_info[:3])
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def _python(plan: StackPlan, live: bool) -> list[Finding]:
|
|
314
|
+
"""A venv component (the TTS front, a decision front) needs Python's venv module."""
|
|
315
|
+
needs = plan.get("decision_front") is not None or any(
|
|
316
|
+
"frontend_requirements" in p["launch"] for p in deployments(plan)
|
|
317
|
+
)
|
|
318
|
+
if not live or not needs:
|
|
319
|
+
return []
|
|
320
|
+
if importlib.util.find_spec("venv") is None:
|
|
321
|
+
version = _python_version()
|
|
322
|
+
return [
|
|
323
|
+
finding(
|
|
324
|
+
"preflight.python",
|
|
325
|
+
"warn",
|
|
326
|
+
f"this Python {version} has no venv module, but the plan builds a component in a "
|
|
327
|
+
"virtual environment",
|
|
328
|
+
"install the distribution's python3-venv package, then run stack plan again",
|
|
329
|
+
)
|
|
330
|
+
]
|
|
331
|
+
return [finding("preflight.python", "pass", f"Python {_python_version()} can build the venv")]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
# ------------------------------------------------------------------- resources and placement
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _disk(plan: StackPlan, facts: HostFacts, live: bool) -> list[Finding]:
|
|
338
|
+
budget = plan.get("budget") or {}
|
|
339
|
+
needed = int(str(budget.get("disk_needed_bytes") or 0))
|
|
340
|
+
path = _existing(_base_dir(plan))
|
|
341
|
+
try:
|
|
342
|
+
free = shutil.disk_usage(path).free if live else facts["disk"]["free_bytes"]
|
|
343
|
+
except OSError:
|
|
344
|
+
return []
|
|
345
|
+
if free is None:
|
|
346
|
+
return []
|
|
347
|
+
free = int(free)
|
|
348
|
+
if needed and free < needed:
|
|
349
|
+
return [
|
|
350
|
+
finding(
|
|
351
|
+
"preflight.disk",
|
|
352
|
+
"fail",
|
|
353
|
+
f"the stack needs {_gib(needed)} on the disk holding {path}, which has "
|
|
354
|
+
f"{_gib(free)} free",
|
|
355
|
+
f"free space, then run stack plan again; {command()} stack prune lists "
|
|
356
|
+
"engine and model directories no longer used",
|
|
357
|
+
)
|
|
358
|
+
]
|
|
359
|
+
if free - needed < DISK_FLOOR:
|
|
360
|
+
return [
|
|
361
|
+
finding(
|
|
362
|
+
"preflight.disk",
|
|
363
|
+
"warn",
|
|
364
|
+
f"only {_gib(free - needed)} would be left on the disk holding {path} after the "
|
|
365
|
+
"planned files; logs and the next update need room",
|
|
366
|
+
f"free about {_gib(DISK_FLOOR)}; {command()} stack prune lists what can go",
|
|
367
|
+
)
|
|
368
|
+
]
|
|
369
|
+
return [
|
|
370
|
+
finding(
|
|
371
|
+
"preflight.disk",
|
|
372
|
+
"pass",
|
|
373
|
+
f"{_gib(free)} free where the stack installs ({_gib(needed)} needed)",
|
|
374
|
+
)
|
|
375
|
+
]
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _filesystem(path: Path) -> str | None:
|
|
379
|
+
"""The filesystem holding ``path``, from read-only mount tables; None when unknown."""
|
|
380
|
+
real = os.path.realpath(path)
|
|
381
|
+
if sys.platform == "darwin":
|
|
382
|
+
table = _run(["mount"])
|
|
383
|
+
if table is None:
|
|
384
|
+
return None
|
|
385
|
+
best: tuple[int, str] | None = None
|
|
386
|
+
for line in table.splitlines():
|
|
387
|
+
match = re.match(r".* on (.+) \(([^)]*)\)$", line)
|
|
388
|
+
if not match:
|
|
389
|
+
continue
|
|
390
|
+
mount, options = match.group(1), match.group(2)
|
|
391
|
+
if real == mount or real.startswith(mount.rstrip("/") + "/"):
|
|
392
|
+
if best is None or len(mount) > best[0]:
|
|
393
|
+
best = (len(mount), options)
|
|
394
|
+
return best[1] if best else None
|
|
395
|
+
try:
|
|
396
|
+
table = Path("/proc/mounts").read_text(encoding="utf-8").splitlines()
|
|
397
|
+
except OSError:
|
|
398
|
+
return None
|
|
399
|
+
found: tuple[int, str] | None = None
|
|
400
|
+
for line in table:
|
|
401
|
+
fields = line.split()
|
|
402
|
+
if len(fields) < 3:
|
|
403
|
+
continue
|
|
404
|
+
mount = fields[1].replace("\\040", " ")
|
|
405
|
+
if real == mount or real.startswith(mount.rstrip("/") + "/"):
|
|
406
|
+
if found is None or len(mount) > found[0]:
|
|
407
|
+
found = (len(mount), fields[2])
|
|
408
|
+
return found[1] if found else None
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _network_filesystem(kind: str) -> bool:
|
|
412
|
+
lowered = kind.lower()
|
|
413
|
+
return any(marks in lowered for marks in NETWORK_FILESYSTEMS)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _storage(plan: StackPlan, live: bool) -> list[Finding]:
|
|
417
|
+
if not live:
|
|
418
|
+
return []
|
|
419
|
+
path = _existing(_base_dir(plan))
|
|
420
|
+
if not os.access(path, os.W_OK):
|
|
421
|
+
return [
|
|
422
|
+
finding(
|
|
423
|
+
"preflight.storage",
|
|
424
|
+
"fail",
|
|
425
|
+
f"{path} is not writable by {getpass.getuser()}",
|
|
426
|
+
"choose a writable --base-dir, or fix its permissions, then run stack plan again",
|
|
427
|
+
)
|
|
428
|
+
]
|
|
429
|
+
found = [finding("preflight.storage", "pass", f"{path} is writable")]
|
|
430
|
+
kind = _filesystem(path)
|
|
431
|
+
# macOS reports the whole mount option list. On a Mac a path under /Users matches the
|
|
432
|
+
# read-only system volume first; the Data volume is reachable through a firmlink, not a
|
|
433
|
+
# longer mount prefix. Writability is already checked above, so only name the type.
|
|
434
|
+
name = kind.split(",")[0].strip() if kind else None
|
|
435
|
+
if name and _network_filesystem(kind or ""):
|
|
436
|
+
found.append(
|
|
437
|
+
finding(
|
|
438
|
+
"preflight.filesystem",
|
|
439
|
+
"warn",
|
|
440
|
+
f"the stack installs to {path} on a network filesystem ({name}); weights are read "
|
|
441
|
+
"over the network, measured at 39-77 tok/s against 100 tok/s from local disk",
|
|
442
|
+
"put --base-dir on a local disk for speed; a network copy is for smoke tests only",
|
|
443
|
+
)
|
|
444
|
+
)
|
|
445
|
+
elif name:
|
|
446
|
+
found.append(finding("preflight.filesystem", "pass", f"{path} is on {name}"))
|
|
447
|
+
return found
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def _gpu(plan: StackPlan, facts: HostFacts) -> list[Finding]:
|
|
451
|
+
if _profile(plan) == "macos-mlx-preview":
|
|
452
|
+
return []
|
|
453
|
+
services = facts.get("services")
|
|
454
|
+
processes = services.get("compute_processes") if services else None
|
|
455
|
+
if metal.supported(facts):
|
|
456
|
+
if processes is None:
|
|
457
|
+
return []
|
|
458
|
+
conflicts = metal.conflicts(facts)
|
|
459
|
+
if conflicts:
|
|
460
|
+
listed = ", ".join(conflicts[:3])
|
|
461
|
+
return [
|
|
462
|
+
finding(
|
|
463
|
+
"preflight.gpu",
|
|
464
|
+
"warn",
|
|
465
|
+
f"another inference process holds the Metal GPU: {listed}; its memory is "
|
|
466
|
+
"already missing from the plan's available RAM",
|
|
467
|
+
"quit it before applying, or keep it and confirm sharing with --share-gpu",
|
|
468
|
+
)
|
|
469
|
+
]
|
|
470
|
+
return [finding("preflight.gpu", "pass", "no other inference process on the Metal GPU")]
|
|
471
|
+
placed = [
|
|
472
|
+
part["placement"].get("gpus")
|
|
473
|
+
for part in (plan["llm"], plan.get("llm_fast"))
|
|
474
|
+
if part is not None
|
|
475
|
+
]
|
|
476
|
+
cards = {
|
|
477
|
+
str(c.get("uuid"))
|
|
478
|
+
for group in placed
|
|
479
|
+
if isinstance(group, list)
|
|
480
|
+
for c in group
|
|
481
|
+
if isinstance(c, dict) and c.get("uuid")
|
|
482
|
+
}
|
|
483
|
+
processes = processes or []
|
|
484
|
+
others = [
|
|
485
|
+
p
|
|
486
|
+
for p in processes
|
|
487
|
+
if p.get("gpu_uuid") in cards and p.get("owned") is not True and p.get("pid") != os.getpid()
|
|
488
|
+
]
|
|
489
|
+
if others:
|
|
490
|
+
listed = ", ".join(
|
|
491
|
+
f"pid {p['pid']} {p['name']}"
|
|
492
|
+
+ (f" ({_gib(int(p['used_bytes'] or 0))})" if p.get("used_bytes") else "")
|
|
493
|
+
for p in others[:5]
|
|
494
|
+
)
|
|
495
|
+
return [
|
|
496
|
+
finding(
|
|
497
|
+
"preflight.gpu",
|
|
498
|
+
"warn",
|
|
499
|
+
f"{len(others)} compute process(es) outside the stack on its GPU: {listed}",
|
|
500
|
+
"make sure they can share the card; with too little VRAM, loading or long-context "
|
|
501
|
+
"requests fail",
|
|
502
|
+
)
|
|
503
|
+
]
|
|
504
|
+
if cards:
|
|
505
|
+
return [
|
|
506
|
+
finding(
|
|
507
|
+
"preflight.gpu",
|
|
508
|
+
"pass",
|
|
509
|
+
f"no other compute process on the stack's {len(cards)} GPU(s)",
|
|
510
|
+
)
|
|
511
|
+
]
|
|
512
|
+
return []
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def _ports(plan: StackPlan, facts: HostFacts, live: bool) -> list[Finding]:
|
|
516
|
+
if plan.get("update") and not live:
|
|
517
|
+
return [
|
|
518
|
+
finding(
|
|
519
|
+
"preflight.ports",
|
|
520
|
+
"pass",
|
|
521
|
+
"update plan: its own old deployments are stopped before the new ports start",
|
|
522
|
+
)
|
|
523
|
+
]
|
|
524
|
+
# This tool's recorded deployments on this computer: apply keeps, replaces or retires them, so
|
|
525
|
+
# their listeners are not another program's. Saved facts of another computer name another
|
|
526
|
+
# host, and its listener is then a real conflict; saved facts of this one still match records.
|
|
527
|
+
owned: set[int] = set()
|
|
528
|
+
if live or facts.get("hostname") == socket.gethostname():
|
|
529
|
+
owned = {
|
|
530
|
+
int(r["plan"]["service"]["port"]) for r in hosts.records(hosts.LOCAL_ID) if r["ok"]
|
|
531
|
+
}
|
|
532
|
+
services = facts.get("services")
|
|
533
|
+
rows = services.get("ports", []) if services else []
|
|
534
|
+
listening = {int(row["port"]) for row in rows if row.get("listening") is True}
|
|
535
|
+
servers = {int(s["port"]): s for s in facts.get("llama_servers") or []}
|
|
536
|
+
dests = {os.path.expanduser(f["dest"]) for p in deployments(plan) for f in p["files"]}
|
|
537
|
+
busy: list[tuple[str, int]] = []
|
|
538
|
+
for part in deployments(plan):
|
|
539
|
+
port = int(part["service"]["port"])
|
|
540
|
+
if port not in listening and port not in servers:
|
|
541
|
+
continue
|
|
542
|
+
server = servers.get(port)
|
|
543
|
+
if port in owned:
|
|
544
|
+
continue
|
|
545
|
+
if server and os.path.expanduser(str(server.get("model_path") or "")) in dests:
|
|
546
|
+
continue # this tool's own deployment of the same model; apply keeps or replaces it
|
|
547
|
+
busy.append((part["name"], port))
|
|
548
|
+
if busy:
|
|
549
|
+
listed = ", ".join(f"{port} ({name})" for name, port in busy)
|
|
550
|
+
return [
|
|
551
|
+
finding(
|
|
552
|
+
"preflight.ports",
|
|
553
|
+
"warn",
|
|
554
|
+
f"planned ports are held: {listed}",
|
|
555
|
+
"identify the program with lsof -nP -iTCP:<port> -sTCP:LISTEN; free it or plan "
|
|
556
|
+
"another --llm-port, then run stack plan again",
|
|
557
|
+
)
|
|
558
|
+
]
|
|
559
|
+
ports = sorted({int(p["service"]["port"]) for p in deployments(plan)})
|
|
560
|
+
return [
|
|
561
|
+
finding(
|
|
562
|
+
"preflight.ports",
|
|
563
|
+
"pass",
|
|
564
|
+
"planned ports free when probed: " + ", ".join(map(str, ports)),
|
|
565
|
+
)
|
|
566
|
+
]
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
def _reproducible(plan: StackPlan, facts: HostFacts) -> list[Finding]:
|
|
570
|
+
"""A Mac plan without a ceiling follows live memory, so apply may refuse a changed plan.
|
|
571
|
+
``facts`` is the priced document, so --unified-memory shows as an assumed total."""
|
|
572
|
+
if not metal.supported(facts) or _profile(plan) == "macos-mlx-preview":
|
|
573
|
+
return []
|
|
574
|
+
if metal.assumed_total(facts) is not None:
|
|
575
|
+
return [
|
|
576
|
+
finding(
|
|
577
|
+
"preflight.reproducible",
|
|
578
|
+
"pass",
|
|
579
|
+
f"pinned at {_gib(int(metal.assumed_total(facts) or 0))} of unified memory",
|
|
580
|
+
)
|
|
581
|
+
]
|
|
582
|
+
cache = stack_llm_ram.prompt_cache_bytes(plan["llm"])
|
|
583
|
+
if cache <= 0 or cache >= (AGENT.prompt_cache_mib << 20):
|
|
584
|
+
return []
|
|
585
|
+
ceiling = metal.stable_ceiling(facts)
|
|
586
|
+
if ceiling is None:
|
|
587
|
+
return []
|
|
588
|
+
return [
|
|
589
|
+
finding(
|
|
590
|
+
"preflight.reproducible",
|
|
591
|
+
"warn",
|
|
592
|
+
f"this plan's {_gib(cache)} prompt cache follows the free memory read now; when "
|
|
593
|
+
"another program takes RAM, apply re-plans a different cache size and refuses this "
|
|
594
|
+
"approval",
|
|
595
|
+
f"plan again with --unified-memory {ceiling >> 30}G to pin it (window, KV types and "
|
|
596
|
+
"slots stay the same)",
|
|
597
|
+
)
|
|
598
|
+
]
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
# ------------------------------------------------------------------- state on this computer
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def _running(plan: StackPlan) -> list[Finding]:
|
|
605
|
+
"""This tool's own deployments from another plan keep their memory, ports and services."""
|
|
606
|
+
from localmodels import stack_lifecycle
|
|
607
|
+
|
|
608
|
+
planned = {p["name"] for p in deployments(plan)}
|
|
609
|
+
update = plan.get("update")
|
|
610
|
+
retire = set(update.get("retire") or []) if update else set()
|
|
611
|
+
running: list[tuple[str, int]] = []
|
|
612
|
+
for record in hosts.records(hosts.LOCAL_ID):
|
|
613
|
+
part = record["plan"]
|
|
614
|
+
if not record.get("ok") or part["name"] in planned or part["name"] in retire:
|
|
615
|
+
continue
|
|
616
|
+
if stack_lifecycle.deployment_pids(part):
|
|
617
|
+
running.append((part["name"], int(part["service"]["port"])))
|
|
618
|
+
if not running:
|
|
619
|
+
return [finding("preflight.running", "pass", "no other deployment of this tool is running")]
|
|
620
|
+
listed = ", ".join(f"{name} (127.0.0.1:{port})" for name, port in running[:5])
|
|
621
|
+
return [
|
|
622
|
+
finding(
|
|
623
|
+
"preflight.running",
|
|
624
|
+
"warn",
|
|
625
|
+
f"this tool still runs {len(running)} other deployment(s): {listed}; they keep their "
|
|
626
|
+
"memory and ports and the plan does not price them",
|
|
627
|
+
"use stack plan --update to replace the running stack, or stop one with "
|
|
628
|
+
"'stack service local <name> stop'",
|
|
629
|
+
)
|
|
630
|
+
]
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
def _apply_lock() -> list[Finding]:
|
|
634
|
+
path = hosts.stacks_dir() / ".apply.lock"
|
|
635
|
+
if not path.exists():
|
|
636
|
+
return [finding("preflight.apply", "pass", "no other stack apply is running")]
|
|
637
|
+
try:
|
|
638
|
+
import fcntl
|
|
639
|
+
|
|
640
|
+
with path.open("a") as lock:
|
|
641
|
+
try:
|
|
642
|
+
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
643
|
+
except BlockingIOError:
|
|
644
|
+
return [
|
|
645
|
+
finding(
|
|
646
|
+
"preflight.apply",
|
|
647
|
+
"warn",
|
|
648
|
+
"another stack apply is running; its services and memory are changing",
|
|
649
|
+
"wait for it to finish, then run stack plan again",
|
|
650
|
+
)
|
|
651
|
+
]
|
|
652
|
+
fcntl.flock(lock, fcntl.LOCK_UN)
|
|
653
|
+
except (OSError, ImportError):
|
|
654
|
+
return []
|
|
655
|
+
return [finding("preflight.apply", "pass", "no other stack apply is running")]
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
# ---------------------------------------------------------------------------- document
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def check(
|
|
662
|
+
plan: StackPlan, facts: HostFacts, *, live: bool, priced: HostFacts | None = None
|
|
663
|
+
) -> Preflight:
|
|
664
|
+
"""Run every check against ``plan`` and ``facts``; ``live`` says the facts were probed
|
|
665
|
+
from this computer just now (False: a saved ``--facts`` document from another moment).
|
|
666
|
+
``priced`` is the document the plan was priced against when ``--unified-memory`` simulated
|
|
667
|
+
a smaller Mac: host readings still come from ``facts``, the memory ceiling from ``priced``."""
|
|
668
|
+
found: list[Finding] = [
|
|
669
|
+
_platform(plan, facts),
|
|
670
|
+
*_memory(plan, facts, live),
|
|
671
|
+
*_pressure(facts),
|
|
672
|
+
*_swap(facts),
|
|
673
|
+
*_load(facts, live),
|
|
674
|
+
*_power(live),
|
|
675
|
+
*_disk(plan, facts, live),
|
|
676
|
+
*_storage(plan, live),
|
|
677
|
+
*_gpu(plan, facts),
|
|
678
|
+
*_ports(plan, facts, live),
|
|
679
|
+
*_reproducible(plan, priced or facts),
|
|
680
|
+
]
|
|
681
|
+
if live:
|
|
682
|
+
found += [*_running(plan), *_apply_lock(), *_linger(plan, facts, live), *_proxy()]
|
|
683
|
+
found += _python(plan, live)
|
|
684
|
+
else:
|
|
685
|
+
found.append(
|
|
686
|
+
finding(
|
|
687
|
+
"preflight.saved_facts",
|
|
688
|
+
"pass",
|
|
689
|
+
"checks used saved facts; power, load, storage, linger, proxy and running "
|
|
690
|
+
"deployments were not read from this computer",
|
|
691
|
+
)
|
|
692
|
+
)
|
|
693
|
+
counts = {level: sum(f["level"] == level for f in found) for level in LEVELS}
|
|
694
|
+
# Finding.level is a Literal; PreflightFinding.level is str so the plan decoder accepts a
|
|
695
|
+
# saved plan. The dicts are otherwise identical, and list invariance hides that from mypy.
|
|
696
|
+
return cast(
|
|
697
|
+
"Preflight",
|
|
698
|
+
{"schema": SCHEMA, "live": live, "counts": counts, "findings": found},
|
|
699
|
+
)
|