@simplexai/localmodels-linux-x64 0.1.0-dev.48 → 0.1.0-dev.50
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 +82 -72
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/budget.py +40 -14
- package/modules/localmodels/catalog.json +473 -36
- package/modules/localmodels/debug_mode.py +25 -0
- package/modules/localmodels/deploy.py +3 -0
- package/modules/localmodels/download-mirrors.json +47 -0
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +13 -1
- package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +79 -0
- package/modules/localmodels/engines.py +31 -6
- package/modules/localmodels/gateway.py +23 -6
- package/modules/localmodels/gateway_bifrost.py +6 -2
- package/modules/localmodels/harness.py +8 -2
- package/modules/localmodels/harness_gateway.py +78 -17
- package/modules/localmodels/harness_probe.py +5 -1
- package/modules/localmodels/hosts.py +52 -5
- package/modules/localmodels/library_floor.py +76 -0
- package/modules/localmodels/library_jobs.py +60 -7
- package/modules/localmodels/library_model.py +38 -2
- package/modules/localmodels/library_poly.py +272 -0
- package/modules/localmodels/library_pricing.py +251 -79
- package/modules/localmodels/library_serve.py +27 -4
- package/modules/localmodels/library_state.py +16 -0
- package/modules/localmodels/library_status.py +46 -18
- package/modules/localmodels/library_vram.py +123 -0
- package/modules/localmodels/llm_rank.py +42 -1
- package/modules/localmodels/magpie_windows.py +312 -0
- package/modules/localmodels/probe.py +39 -37
- package/modules/localmodels/process_identity.py +26 -33
- package/modules/localmodels/process_identity_darwin.py +189 -0
- package/modules/localmodels/process_identity_linux.py +62 -30
- package/modules/localmodels/recommend.py +3 -1
- package/modules/localmodels/remote_ops.py +11 -0
- package/modules/localmodels/remote_ops_download.py +30 -5
- package/modules/localmodels/remote_ops_service.py +15 -46
- package/modules/localmodels/reuse.py +13 -6
- package/modules/localmodels/runtime_io.py +32 -18
- package/modules/localmodels/service_probe.py +1 -1
- package/modules/localmodels/setup_inspection.py +97 -80
- package/modules/localmodels/setup_inspection_harness.py +147 -0
- package/modules/localmodels/setup_text.py +24 -0
- package/modules/localmodels/setup_upgrade.py +155 -0
- package/modules/localmodels/stack.py +3 -1
- package/modules/localmodels/stack_auto.py +6 -2
- package/modules/localmodels/stack_clients.py +1 -1
- package/modules/localmodels/stack_compose.py +5 -1
- package/modules/localmodels/stack_down.py +25 -16
- package/modules/localmodels/stack_hardware.py +17 -3
- package/modules/localmodels/stack_picks.py +28 -13
- package/modules/localmodels/stack_remove.py +3 -1
- package/modules/localmodels/stack_route.py +5 -1
- package/modules/localmodels/stack_suite.py +29 -8
- package/modules/localmodels/stack_view_access.py +238 -58
- package/modules/localmodels/stack_view_hub.py +12 -7
- package/modules/localmodels/stack_view_serve.py +13 -6
- package/modules/localmodels/strata-poly-serve-0.2.19-poly.1.txt +428 -0
- package/modules/localmodels/strata_poly_server.py +14 -2
- package/modules/localmodels/suite.py +19 -3
- package/modules/localmodels/tool_archive.py +4 -0
- package/modules/localmodels/transport.py +3 -1
- package/modules/localmodels/tui.py +4 -1
- package/modules/localmodels/tui_dialogs.py +42 -9
- package/modules/localmodels/tui_modals.py +63 -16
- package/modules/localmodels/tui_screen.py +80 -53
- package/modules/localmodels/tui_views.py +36 -6
- package/modules/localmodels/vision.py +4 -2
- package/modules/localmodels/web/index.html +996 -300
- package/modules/localmodels/web/sizecalc/app.js +616 -88
- package/modules/localmodels/web/sizecalc/page.html +239 -106
- package/modules/localmodels/web/view/fleet.js +25 -2
- package/modules/localmodels/web/view/nav.js +19 -3
- package/modules/localmodels/web/view/view.css +110 -22
- package/modules/localmodels/web/view/view.js +40 -22
- package/modules/localmodels/win_probe.py +204 -0
- package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/RECORD +79 -69
- package/package.json +1 -1
- package/tool.json +1 -1
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev50.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -454,13 +454,30 @@ def _resume_ranges(part: str, size: int) -> list[list[int]]:
|
|
|
454
454
|
return segments
|
|
455
455
|
|
|
456
456
|
|
|
457
|
+
def _retryable(exc: BaseException) -> bool:
|
|
458
|
+
"""Permanent HTTP responses (unfollowed redirects such as 308, client errors other than
|
|
459
|
+
408/429) will not turn into the pinned file on retry; move on to the next source at once."""
|
|
460
|
+
if isinstance(exc, urllib.error.HTTPError):
|
|
461
|
+
return exc.code in (408, 429) or exc.code >= 500
|
|
462
|
+
return True
|
|
463
|
+
|
|
464
|
+
|
|
457
465
|
class _Transfer:
|
|
458
466
|
"""Parallel ranged download of one file: each segment resumes from its own ``done`` offset
|
|
459
467
|
with retries; ``done`` advances only after the bytes are written, so the saved record never
|
|
460
468
|
claims bytes the file lacks."""
|
|
461
469
|
|
|
462
|
-
def __init__(
|
|
470
|
+
def __init__(
|
|
471
|
+
self,
|
|
472
|
+
url: str,
|
|
473
|
+
part: str,
|
|
474
|
+
size: int,
|
|
475
|
+
segments: list[list[int]],
|
|
476
|
+
*,
|
|
477
|
+
attempts: int | None = None,
|
|
478
|
+
) -> None:
|
|
463
479
|
self.url, self.part, self.size, self.segments = url, part, size, segments
|
|
480
|
+
self.attempts = ATTEMPTS if attempts is None else max(1, attempts)
|
|
464
481
|
self.lock, self.stop = threading.Lock(), threading.Event()
|
|
465
482
|
self.errors: list[BaseException] = []
|
|
466
483
|
|
|
@@ -503,7 +520,7 @@ class _Transfer:
|
|
|
503
520
|
self.fail(exc)
|
|
504
521
|
except (urllib.error.URLError, OSError, http.client.HTTPException) as exc:
|
|
505
522
|
attempt += 1
|
|
506
|
-
if attempt >=
|
|
523
|
+
if not _retryable(exc) or attempt >= self.attempts:
|
|
507
524
|
self.fail(exc)
|
|
508
525
|
return
|
|
509
526
|
self.stop.wait(min(30, 2**attempt))
|
|
@@ -516,19 +533,27 @@ class _Transfer:
|
|
|
516
533
|
self.stop.set()
|
|
517
534
|
|
|
518
535
|
|
|
519
|
-
def transfer(
|
|
536
|
+
def transfer(
|
|
537
|
+
source: remote_ops.Source,
|
|
538
|
+
part: str,
|
|
539
|
+
size: int,
|
|
540
|
+
label: str,
|
|
541
|
+
ranged: bool,
|
|
542
|
+
*,
|
|
543
|
+
attempts: int | None = None,
|
|
544
|
+
) -> None:
|
|
520
545
|
"""Fill ``part`` with all ``size`` bytes from ``source``, reporting progress events; raises
|
|
521
546
|
on failure with the kept ranges saved so the next call (or source) resumes them. A source
|
|
522
547
|
that turns out not to serve ranges is read once as one plain stream from the start."""
|
|
523
548
|
if ranged:
|
|
524
|
-
job = _Transfer(source["url"], part, size, _resume_ranges(part, size))
|
|
549
|
+
job = _Transfer(source["url"], part, size, _resume_ranges(part, size), attempts=attempts)
|
|
525
550
|
_run(job, source, label, ranged=True)
|
|
526
551
|
if not (job.errors and isinstance(job.errors[0], _NoRangeError)):
|
|
527
552
|
_finish(job, label)
|
|
528
553
|
return
|
|
529
554
|
discard(part)
|
|
530
555
|
open(part, "wb").close()
|
|
531
|
-
job = _Transfer(source["url"], part, size, [[0, size, 0]])
|
|
556
|
+
job = _Transfer(source["url"], part, size, [[0, size, 0]], attempts=attempts)
|
|
532
557
|
_run(job, source, label, ranged=False)
|
|
533
558
|
_finish(job, label)
|
|
534
559
|
|
|
@@ -23,9 +23,15 @@ from pathlib import Path
|
|
|
23
23
|
from typing import cast
|
|
24
24
|
|
|
25
25
|
try:
|
|
26
|
-
from localmodels import
|
|
26
|
+
from localmodels import (
|
|
27
|
+
process_identity,
|
|
28
|
+
process_identity_darwin,
|
|
29
|
+
remote_ops,
|
|
30
|
+
remote_ops_launchd,
|
|
31
|
+
)
|
|
27
32
|
except ImportError: # run as a bare file from this directory
|
|
28
33
|
import process_identity # type: ignore[import-not-found,no-redef]
|
|
34
|
+
import process_identity_darwin # type: ignore[import-not-found,no-redef]
|
|
29
35
|
import remote_ops # type: ignore[import-not-found,no-redef]
|
|
30
36
|
import remote_ops_launchd # type: ignore[import-not-found,no-redef]
|
|
31
37
|
|
|
@@ -133,21 +139,6 @@ def _previous_install(
|
|
|
133
139
|
return {**p, "argv": cast("list[str]", argv), "env": cast("dict[str, str]", env), "port": port}
|
|
134
140
|
|
|
135
141
|
|
|
136
|
-
def _ps(columns: str, pid: int | None = None) -> list[list[str]] | None:
|
|
137
|
-
"""macOS process rows from /bin/ps (no /proc there); None when ps cannot answer."""
|
|
138
|
-
argv = ["/bin/ps", "-ww", "-o", columns] + (["-p", str(pid)] if pid else ["-A"])
|
|
139
|
-
c_locale = {**os.environ, "LC_ALL": "C"} # lstart reads the same as a receipt's, whatever LANG
|
|
140
|
-
try:
|
|
141
|
-
done = subprocess.run(
|
|
142
|
-
argv, capture_output=True, text=True, timeout=10, check=False, env=c_locale
|
|
143
|
-
)
|
|
144
|
-
except (OSError, subprocess.SubprocessError):
|
|
145
|
-
return None
|
|
146
|
-
if done.returncode not in (0, 1): # 1: no such process
|
|
147
|
-
return None
|
|
148
|
-
return [line.split(None, 4) for line in done.stdout.splitlines() if line.strip()]
|
|
149
|
-
|
|
150
|
-
|
|
151
142
|
def _darwin_listener_pids(port: int) -> set[int] | None:
|
|
152
143
|
"""Processes listening on TCP ``port`` (lsof; its warnings about unrelated mounts aside)."""
|
|
153
144
|
argv = ["/usr/sbin/lsof", "-wnP", f"-iTCP:{port}", "-sTCP:LISTEN", "-Fp"]
|
|
@@ -166,8 +157,10 @@ def _process_state(pid: int) -> str | None:
|
|
|
166
157
|
if sys.platform == "win32":
|
|
167
158
|
return "S" if process_identity.inspect(pid) is not None else None
|
|
168
159
|
if sys.platform == "darwin":
|
|
169
|
-
|
|
170
|
-
|
|
160
|
+
try:
|
|
161
|
+
return process_identity_darwin.process_state(pid)
|
|
162
|
+
except OSError:
|
|
163
|
+
return None
|
|
171
164
|
try:
|
|
172
165
|
return Path("/proc", str(pid), "stat").read_text().rsplit(")", 1)[1].split()[0]
|
|
173
166
|
except (FileNotFoundError, ProcessLookupError):
|
|
@@ -177,22 +170,6 @@ def _process_state(pid: int) -> str | None:
|
|
|
177
170
|
def command_matches(pid: int, argv: list[str]) -> bool:
|
|
178
171
|
"""Prove the expected executable and arguments without retaining the process command."""
|
|
179
172
|
expected = [remote_ops._home(arg) for arg in argv]
|
|
180
|
-
if sys.platform == "win32":
|
|
181
|
-
return process_identity.command_matches(pid, expected)
|
|
182
|
-
if sys.platform == "darwin": # ps joins argv with spaces; the script execs the server
|
|
183
|
-
rows = _ps("uid=,args=", pid)
|
|
184
|
-
if not rows or len(rows[0]) < 2 or rows[0][0] != str(os.getuid()):
|
|
185
|
-
return False
|
|
186
|
-
actual = " ".join(rows[0][1:])
|
|
187
|
-
if actual == " ".join(expected):
|
|
188
|
-
return True
|
|
189
|
-
try:
|
|
190
|
-
with open(expected[0], "rb") as executable:
|
|
191
|
-
header = executable.readline(512).decode()
|
|
192
|
-
interpreter = shlex.split(header[2:].strip()) if header.startswith("#!") else []
|
|
193
|
-
return len(interpreter) == 1 and actual == " ".join([interpreter[0], *expected])
|
|
194
|
-
except (OSError, UnicodeError, ValueError, IndexError):
|
|
195
|
-
return False
|
|
196
173
|
return process_identity.command_matches(pid, expected)
|
|
197
174
|
|
|
198
175
|
|
|
@@ -206,18 +183,10 @@ def _group_members(pid: int) -> dict[int, str]:
|
|
|
206
183
|
raise RuntimeError("the service process has another owner; config left unchanged")
|
|
207
184
|
return {pid: found["started"]}
|
|
208
185
|
if sys.platform == "darwin":
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if len(row) < 5 or row[1] != str(pid) or row[3].startswith("Z"):
|
|
214
|
-
continue
|
|
215
|
-
if row[2] != str(os.getuid()):
|
|
216
|
-
raise RuntimeError(
|
|
217
|
-
"the service process group has another owner; config left unchanged"
|
|
218
|
-
)
|
|
219
|
-
members[int(row[0])] = row[4].strip() # the start time, as /proc's starttime on Linux
|
|
220
|
-
return members
|
|
186
|
+
try:
|
|
187
|
+
return process_identity_darwin.group_members(pid)
|
|
188
|
+
except OSError:
|
|
189
|
+
raise RuntimeError("cannot list processes; config left unchanged") from None
|
|
221
190
|
for entry in Path("/proc").glob("[0-9]*"):
|
|
222
191
|
try:
|
|
223
192
|
fields = entry.joinpath("stat").read_text().rsplit(")", 1)[1].split()
|
|
@@ -194,7 +194,11 @@ def _walk(root: Path, depth: int = 0) -> Iterator[Path]:
|
|
|
194
194
|
except OSError:
|
|
195
195
|
return
|
|
196
196
|
for entry in entries:
|
|
197
|
-
|
|
197
|
+
try:
|
|
198
|
+
is_dir = entry.is_dir(follow_symlinks=False)
|
|
199
|
+
except OSError:
|
|
200
|
+
continue
|
|
201
|
+
if is_dir:
|
|
198
202
|
if depth < MAX_DEPTH and entry.name not in SKIP_DIRS:
|
|
199
203
|
yield from _walk(Path(entry.path), depth + 1)
|
|
200
204
|
elif entry.name.endswith(".gguf"):
|
|
@@ -204,8 +208,11 @@ def _walk(root: Path, depth: int = 0) -> Iterator[Path]:
|
|
|
204
208
|
def device(path: str) -> int | None:
|
|
205
209
|
"""The filesystem a path is or would be on: that of its nearest existing ancestor."""
|
|
206
210
|
for candidate in (Path(path), *Path(path).parents):
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
try:
|
|
212
|
+
if candidate.exists():
|
|
213
|
+
return candidate.stat().st_dev
|
|
214
|
+
except OSError:
|
|
215
|
+
continue
|
|
209
216
|
return None
|
|
210
217
|
|
|
211
218
|
|
|
@@ -230,18 +237,18 @@ def find_copies(
|
|
|
230
237
|
spec = wanted.get(path.name)
|
|
231
238
|
if spec is None or path.name in found:
|
|
232
239
|
continue
|
|
233
|
-
real = os.path.realpath(path)
|
|
234
240
|
dest = os.path.expanduser(spec[1])
|
|
235
241
|
try:
|
|
242
|
+
real = os.path.realpath(path)
|
|
236
243
|
same = (
|
|
237
244
|
os.path.isfile(real)
|
|
238
245
|
and os.path.getsize(real) == spec[0]
|
|
239
246
|
and (allow_cross_device or os.stat(real).st_dev == device(dest))
|
|
240
247
|
)
|
|
248
|
+
if same and real != os.path.realpath(dest):
|
|
249
|
+
found[path.name] = real
|
|
241
250
|
except OSError:
|
|
242
251
|
continue
|
|
243
|
-
if same and real != os.path.realpath(dest):
|
|
244
|
-
found[path.name] = real
|
|
245
252
|
return found
|
|
246
253
|
|
|
247
254
|
|
|
@@ -13,6 +13,7 @@ import socket
|
|
|
13
13
|
import ssl
|
|
14
14
|
import stat
|
|
15
15
|
import subprocess
|
|
16
|
+
import sys
|
|
16
17
|
import tarfile
|
|
17
18
|
import time
|
|
18
19
|
import urllib.error
|
|
@@ -30,7 +31,25 @@ from localmodels import npm_transport, region, remote_ops, remote_ops_download,
|
|
|
30
31
|
Event = Callable[[dict[str, Any]], None]
|
|
31
32
|
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
_MACOS_SYSTEM_LINKS = {Path(p): Path("/private" + p) for p in ("/tmp", "/var", "/etc")}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _macos_system_link(parent: Path, info: os.stat_result) -> bool:
|
|
38
|
+
target = _MACOS_SYSTEM_LINKS.get(parent) if sys.platform == "darwin" else None
|
|
39
|
+
if target is None:
|
|
40
|
+
return False
|
|
41
|
+
try:
|
|
42
|
+
if parent.resolve(strict=True) != target:
|
|
43
|
+
return False
|
|
44
|
+
stats = [p.lstat() for p in (*reversed(target.parents), target)]
|
|
45
|
+
except OSError:
|
|
46
|
+
return False
|
|
47
|
+
return all(not stat.S_ISLNK(s.st_mode) and stat.S_ISDIR(s.st_mode) for s in stats) and all(
|
|
48
|
+
s.st_uid == 0 for s in (info, *stats)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def regular_directories(path: Path, *, allow_terminal_system_link: bool = False) -> None:
|
|
34
53
|
"""Validate existing directory components without creating or repairing them."""
|
|
35
54
|
for parent in [*reversed(path.parents), path]:
|
|
36
55
|
try:
|
|
@@ -38,6 +57,8 @@ def regular_directories(path: Path) -> None:
|
|
|
38
57
|
except FileNotFoundError:
|
|
39
58
|
continue
|
|
40
59
|
if stat.S_ISLNK(info.st_mode) or getattr(info, "st_file_attributes", 0) & 0x400:
|
|
60
|
+
if (allow_terminal_system_link or parent != path) and _macos_system_link(parent, info):
|
|
61
|
+
continue
|
|
41
62
|
raise ValueError("Unsafe runtime root")
|
|
42
63
|
if not stat.S_ISDIR(info.st_mode):
|
|
43
64
|
raise ValueError("Runtime parent must be a directory")
|
|
@@ -87,7 +108,7 @@ def private_directory(path: Path) -> None:
|
|
|
87
108
|
|
|
88
109
|
def private_permissions(path: Path, *, created: bool = False) -> None:
|
|
89
110
|
"""Repair only new owned state. Existing broad or foreign permissions fail closed."""
|
|
90
|
-
regular_directories(path.parent)
|
|
111
|
+
regular_directories(path.parent, allow_terminal_system_link=True)
|
|
91
112
|
info = path.lstat()
|
|
92
113
|
if (
|
|
93
114
|
stat.S_ISLNK(info.st_mode)
|
|
@@ -427,17 +448,8 @@ def download(
|
|
|
427
448
|
retry_missing: bool = False,
|
|
428
449
|
clock: Callable[[], float] = time.monotonic,
|
|
429
450
|
) -> None:
|
|
430
|
-
"""Fetch a pinned artifact into ``destination
|
|
431
|
-
|
|
432
|
-
call is resumed too, also from another host, since the bytes are pinned by digest. Only
|
|
433
|
-
content matching the pinned digest is published.
|
|
434
|
-
|
|
435
|
-
The hosts serving the same file (``download_urls``) are tried in turn. A host that fails
|
|
436
|
-
every retry is dropped. A host slower than SLOW_BYTES_PER_S is left once for the next host
|
|
437
|
-
and queued again last, never to be left for slowness again; only a host followed by one not
|
|
438
|
-
yet left for slowness may be left, so a uniformly slow network switches once and the last
|
|
439
|
-
host always finishes. A success on the other region's side after a failure on the preferred
|
|
440
|
-
side switches the region."""
|
|
451
|
+
"""Fetch a pinned artifact into ``destination`` (must not exist), resuming ``.part`` across
|
|
452
|
+
retries and alternate hosts, leaving slow hosts once, and switching region on host failure."""
|
|
441
453
|
urls = deque(download_urls(artifact["url"]))
|
|
442
454
|
preferred = remote_ops_download.side(urls[0])
|
|
443
455
|
failed_preferred = False
|
|
@@ -504,10 +516,12 @@ def _download_from(
|
|
|
504
516
|
if part.stat().st_size > artifact["maxBytes"]:
|
|
505
517
|
part.write_bytes(b"")
|
|
506
518
|
else:
|
|
507
|
-
|
|
508
|
-
|
|
519
|
+
os.close(
|
|
520
|
+
os.open(
|
|
521
|
+
part, os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_NOFOLLOW", 0), 0o600
|
|
522
|
+
)
|
|
523
|
+
)
|
|
509
524
|
private_permissions(part, created=True)
|
|
510
|
-
# Bytes kept by an earlier call: they may be another version's when the pin changed.
|
|
511
525
|
resumed = part.stat().st_size > 0
|
|
512
526
|
if resumed and _matches(part, artifact):
|
|
513
527
|
_publish(part, destination)
|
|
@@ -539,7 +553,7 @@ def _download_from(
|
|
|
539
553
|
break
|
|
540
554
|
except _TransferError as exc:
|
|
541
555
|
kept = part.stat().st_size
|
|
542
|
-
if exc.slow:
|
|
556
|
+
if exc.slow:
|
|
543
557
|
raise RuntimeDownloadError(
|
|
544
558
|
url, exc.reason, kept, retryable=True, slow=True
|
|
545
559
|
) from None
|
|
@@ -563,7 +577,7 @@ def _download_from(
|
|
|
563
577
|
pause(wait)
|
|
564
578
|
if _matches(part, artifact):
|
|
565
579
|
break
|
|
566
|
-
if resumed:
|
|
580
|
+
if resumed:
|
|
567
581
|
part.write_bytes(b"")
|
|
568
582
|
resumed = False
|
|
569
583
|
continue
|
|
@@ -509,7 +509,7 @@ def windows_graphics_pids(table: str) -> set[int]:
|
|
|
509
509
|
"""PIDs the plain ``nvidia-smi`` process table marks G or C+G. Under WDDM every desktop
|
|
510
510
|
program (dwm, explorer, browsers) is a C+G client of the card and nvidia-smi lists it beside
|
|
511
511
|
the compute processes without its memory; a model server is type C."""
|
|
512
|
-
rows = re.findall(r"^\|\s+\d
|
|
512
|
+
rows = re.findall(r"^\|\s+\d+(?:\s+\S+\s+\S+)?\s+(\d+)\s+(C\+G|G)\s", table, re.M)
|
|
513
513
|
return {int(pid) for pid, _ in rows}
|
|
514
514
|
|
|
515
515
|
|
|
@@ -18,7 +18,9 @@ from localmodels import (
|
|
|
18
18
|
metal,
|
|
19
19
|
probe,
|
|
20
20
|
service_probe,
|
|
21
|
+
setup_inspection_harness,
|
|
21
22
|
setup_text,
|
|
23
|
+
setup_upgrade,
|
|
22
24
|
stack,
|
|
23
25
|
stack_binding,
|
|
24
26
|
stack_hardware,
|
|
@@ -32,7 +34,6 @@ from localmodels.probe import HostFacts, Services
|
|
|
32
34
|
from localmodels.runtime_cli import inspect_runtimes
|
|
33
35
|
from localmodels.setup_text import Lang, text
|
|
34
36
|
from localmodels.stack_plan import (
|
|
35
|
-
RAM_FLOOR,
|
|
36
37
|
StackError,
|
|
37
38
|
StackOptions,
|
|
38
39
|
StackPlan,
|
|
@@ -84,6 +85,7 @@ class _Basis(TypedDict, total=False):
|
|
|
84
85
|
# With a plan (since 2026-11-13): the model, every GPU it uses and what it needs, with a
|
|
85
86
|
# sentence in --lang, so an installer shows the recommendation without composing its own.
|
|
86
87
|
summary: stack_review.PlanSummary
|
|
88
|
+
upgrade: setup_upgrade.StackUpgrade # when freeing desktop memory unlocks a stronger LLM
|
|
87
89
|
|
|
88
90
|
|
|
89
91
|
class StackAvailability(_Basis):
|
|
@@ -102,9 +104,10 @@ class SetupReport(TypedDict):
|
|
|
102
104
|
|
|
103
105
|
_DRIVER_REASON_CODES = frozenset({"cuda-driver-update-required", "cuda-driver-version-unknown"})
|
|
104
106
|
_VERSION_RE = re.compile(r"^\d+(?:\.\d+){0,2}$")
|
|
107
|
+
_capacity_facts = setup_inspection_harness.capacity_facts
|
|
105
108
|
|
|
106
109
|
|
|
107
|
-
def _plan_reason(error: PlanError | StackError
|
|
110
|
+
def _plan_reason(error: PlanError | StackError) -> Reason:
|
|
108
111
|
return {"code": "plan-unavailable", "message": str(error)}
|
|
109
112
|
|
|
110
113
|
|
|
@@ -139,19 +142,29 @@ def _cuda_driver_reason(error: CudaDriverError, lang: Lang) -> Reason:
|
|
|
139
142
|
return reason
|
|
140
143
|
|
|
141
144
|
|
|
145
|
+
def _plans_hardware(options: StackOptions, facts: HostFacts) -> bool:
|
|
146
|
+
try:
|
|
147
|
+
stack.build(options, facts=facts)
|
|
148
|
+
except (PlanError, stack.StackError):
|
|
149
|
+
return False
|
|
150
|
+
except harness.HarnessError:
|
|
151
|
+
return True
|
|
152
|
+
return True
|
|
153
|
+
|
|
154
|
+
|
|
142
155
|
def _fits_with_required_cuda(options: StackOptions, facts: HostFacts, required_cuda: str) -> bool:
|
|
143
156
|
"""Whether this computer's hardware fits a local stack once the NVIDIA driver supports
|
|
144
157
|
``required_cuda`` (live or once other programs free memory)."""
|
|
145
158
|
upgraded = copy.deepcopy(facts)
|
|
146
159
|
upgraded["nvidia"] = {**(upgraded.get("nvidia") or {}), "cuda_version": required_cuda}
|
|
147
|
-
if
|
|
160
|
+
if _plans_hardware(options, upgraded):
|
|
148
161
|
return True
|
|
149
162
|
roomy = _capacity_facts(upgraded)
|
|
150
|
-
return roomy is not None and
|
|
163
|
+
return roomy is not None and _plans_hardware(options, roomy)
|
|
151
164
|
|
|
152
165
|
|
|
153
166
|
def _driver_block(
|
|
154
|
-
error: PlanError | StackError |
|
|
167
|
+
error: PlanError | StackError | None,
|
|
155
168
|
options: StackOptions,
|
|
156
169
|
facts: HostFacts,
|
|
157
170
|
lang: Lang,
|
|
@@ -175,7 +188,7 @@ def _capacity_availability(
|
|
|
175
188
|
return None
|
|
176
189
|
try:
|
|
177
190
|
plan = stack.build(options, facts=roomy)
|
|
178
|
-
except (PlanError, stack.StackError
|
|
191
|
+
except (PlanError, stack.StackError) as roomy_exc:
|
|
179
192
|
if blocked := _driver_block(roomy_exc, options, roomy, lang):
|
|
180
193
|
return blocked
|
|
181
194
|
# The hardware itself is too small and the live refusal stands, unless only another
|
|
@@ -207,41 +220,29 @@ def _capacity_availability(
|
|
|
207
220
|
}
|
|
208
221
|
|
|
209
222
|
|
|
210
|
-
def
|
|
211
|
-
|
|
212
|
-
facts: HostFacts,
|
|
213
|
-
offline: bool,
|
|
214
|
-
defer_services: bool = False,
|
|
215
|
-
share_gpu: bool = False,
|
|
216
|
-
decision: Literal["auto", "none"] = "none",
|
|
217
|
-
unified_memory: str | None = None,
|
|
218
|
-
lang: Lang = "zh",
|
|
223
|
+
def _harness_availability(
|
|
224
|
+
options: StackOptions, facts: HostFacts, exc: harness.HarnessError, lang: Lang
|
|
219
225
|
) -> StackAvailability:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
options["decision"] = decision
|
|
237
|
-
if defer_services:
|
|
238
|
-
options["defer_services"] = True
|
|
239
|
-
if unified_memory:
|
|
240
|
-
options["unified_memory"] = unified_memory
|
|
226
|
+
"""Classify a gateway/tool HarnessError separately from hardware incapability."""
|
|
227
|
+
code, capable, message = setup_inspection_harness.classify_harness_error(
|
|
228
|
+
options, facts, exc, lang
|
|
229
|
+
)
|
|
230
|
+
return {
|
|
231
|
+
"available": False,
|
|
232
|
+
"reasons": [{"code": code, "message": message}],
|
|
233
|
+
"plan": None,
|
|
234
|
+
"hardwareCapable": capable,
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _plan_stack(
|
|
239
|
+
options: StackOptions, facts: HostFacts, share_gpu: bool, lang: Lang
|
|
240
|
+
) -> StackAvailability:
|
|
241
|
+
try:
|
|
241
242
|
try:
|
|
242
243
|
plan = stack.build(options, facts=facts)
|
|
243
|
-
except (PlanError, stack.StackError
|
|
244
|
-
last_error: PlanError | StackError |
|
|
244
|
+
except (PlanError, stack.StackError) as exc:
|
|
245
|
+
last_error: PlanError | StackError | None = exc
|
|
245
246
|
last_options = options
|
|
246
247
|
reason = _plan_reason(exc)
|
|
247
248
|
# Consent decides by free VRAM whoever else uses a card (roadmap decision 60), so
|
|
@@ -254,7 +255,7 @@ def _stack(
|
|
|
254
255
|
shared_options: StackOptions = {**options, "share_gpu": True}
|
|
255
256
|
try:
|
|
256
257
|
stack.build(shared_options, facts=facts)
|
|
257
|
-
except (PlanError, stack.StackError
|
|
258
|
+
except (PlanError, stack.StackError) as shared_exc:
|
|
258
259
|
last_error, last_options = shared_exc, shared_options
|
|
259
260
|
reason = _plan_reason(shared_exc)
|
|
260
261
|
else:
|
|
@@ -268,61 +269,62 @@ def _stack(
|
|
|
268
269
|
if reason["code"] == "plan-unavailable":
|
|
269
270
|
if capacity := _capacity_availability(options, facts, lang):
|
|
270
271
|
return capacity
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
return {"available": False, "reasons": [reason], "plan": None}
|
|
273
|
+
else:
|
|
274
|
+
availability: StackAvailability = {"available": True, "reasons": [], "plan": plan}
|
|
275
|
+
if upgrade := setup_upgrade.upgrade_hint(options, facts, plan, lang, _capacity_facts):
|
|
276
|
+
availability["upgrade"] = upgrade
|
|
277
|
+
return availability
|
|
278
|
+
except harness.HarnessError as exc:
|
|
279
|
+
return _harness_availability(options, facts, exc, lang)
|
|
273
280
|
|
|
274
281
|
|
|
275
|
-
def
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
282
|
+
def _stack(
|
|
283
|
+
root: Path,
|
|
284
|
+
facts: HostFacts,
|
|
285
|
+
offline: bool,
|
|
286
|
+
defer_services: bool = False,
|
|
287
|
+
share_gpu: bool = False,
|
|
288
|
+
decision: Literal["auto", "none"] = "none",
|
|
289
|
+
unified_memory: str | None = None,
|
|
290
|
+
lang: Lang = "zh",
|
|
291
|
+
) -> StackAvailability:
|
|
292
|
+
if error := platform_error(facts["platform"], arch=facts.get("arch")):
|
|
293
|
+
reason: Reason = {"code": "unsupported-platform", "message": error}
|
|
294
|
+
elif facts["ram"]["total_bytes"] <= 0 or facts["disk"]["free_bytes"] is None:
|
|
295
|
+
reason = {"code": "facts-unavailable", "message": text("facts-unavailable", lang)}
|
|
296
|
+
elif _nvidia_cards_unmeasured(facts):
|
|
297
|
+
reason = {"code": "facts-unavailable", "message": text("nvidia-unmeasured", lang)}
|
|
290
298
|
else:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
options = stack.default_options()
|
|
300
|
+
options["base_dir"] = str(root)
|
|
301
|
+
options["offline"] = offline
|
|
302
|
+
options["share_gpu"] = share_gpu
|
|
303
|
+
options["decision"] = decision
|
|
304
|
+
if defer_services:
|
|
305
|
+
options["defer_services"] = True
|
|
306
|
+
if unified_memory:
|
|
307
|
+
options["unified_memory"] = unified_memory
|
|
308
|
+
return _plan_stack(options, facts, share_gpu, lang)
|
|
309
|
+
return {"available": False, "reasons": [reason], "plan": None}
|
|
301
310
|
|
|
302
311
|
|
|
303
312
|
def _fits_without_other_inference(options: StackOptions, roomy: HostFacts) -> StackPlan | None:
|
|
304
313
|
"""A Mac's capacity plan once the inference apps this tool does not own on its GPU
|
|
305
314
|
(``metal.conflicts``) are quit as well, or None when it still does not fit."""
|
|
306
|
-
|
|
315
|
+
alone = setup_inspection_harness.without_other_inference(roomy)
|
|
316
|
+
if alone is None:
|
|
307
317
|
return None
|
|
308
|
-
alone = copy.deepcopy(roomy)
|
|
309
|
-
services = alone["services"]
|
|
310
|
-
assert services is not None # conflicts come from service discovery
|
|
311
|
-
services["compute_processes"] = [
|
|
312
|
-
p
|
|
313
|
-
for p in services.get("compute_processes") or []
|
|
314
|
-
if p["gpu_uuid"] != metal.METAL_UUID or p["owned"] is True
|
|
315
|
-
]
|
|
316
318
|
try:
|
|
317
319
|
return stack.build(options, facts=alone)
|
|
318
|
-
except (PlanError, stack.StackError
|
|
320
|
+
except (PlanError, stack.StackError):
|
|
319
321
|
return None
|
|
320
322
|
|
|
321
323
|
|
|
322
324
|
def _plans(options: StackOptions, facts: HostFacts) -> bool:
|
|
323
325
|
try:
|
|
324
326
|
stack.build(options, facts=facts)
|
|
325
|
-
except (PlanError, stack.StackError
|
|
327
|
+
except (PlanError, stack.StackError):
|
|
326
328
|
return False
|
|
327
329
|
return True
|
|
328
330
|
|
|
@@ -411,11 +413,16 @@ def _classify(availability: StackAvailability, facts: HostFacts) -> None:
|
|
|
411
413
|
availability.get("basis") == "capacity"
|
|
412
414
|
or "gpu-sharing-required" in codes
|
|
413
415
|
or bool(codes & _DRIVER_REASON_CODES)
|
|
416
|
+
or (
|
|
417
|
+
bool(codes & setup_inspection_harness.HARNESS_CODES)
|
|
418
|
+
and availability.get("hardwareCapable") is True
|
|
419
|
+
)
|
|
414
420
|
):
|
|
415
421
|
availability["state"], availability["hardwareCapable"] = "blocked-now", True
|
|
416
422
|
else:
|
|
417
423
|
availability["state"] = "unavailable"
|
|
418
|
-
|
|
424
|
+
if "hardwareCapable" not in availability:
|
|
425
|
+
availability["hardwareCapable"] = None if "facts-unavailable" in codes else False
|
|
419
426
|
plan, summary = availability["plan"], availability.get("summary")
|
|
420
427
|
if availability.get("basis") != "capacity" or plan is None or summary is None:
|
|
421
428
|
return
|
|
@@ -435,11 +442,17 @@ def _classify(availability: StackAvailability, facts: HostFacts) -> None:
|
|
|
435
442
|
def _nvidia_cards_unmeasured(facts: HostFacts) -> bool:
|
|
436
443
|
"""An NVIDIA driver is loaded but nvidia-smi listed no card: the cards are unknown, not absent,
|
|
437
444
|
and planning would fall back to CPU and RAM. A unified-memory part has no nvidia-smi memory
|
|
438
|
-
and is planned from its CUDA pool instead.
|
|
445
|
+
and is planned from its CUDA pool instead. An explicit 'No devices were found' from nvidia-smi
|
|
446
|
+
(e.g. a hybrid laptop in iGPU-only mode with leftover driver files) confirms no active card."""
|
|
447
|
+
no_devices = any(
|
|
448
|
+
e.get("source") == "nvidia-smi" and "no devices were found" in e.get("error", "").lower()
|
|
449
|
+
for e in facts.get("errors") or []
|
|
450
|
+
)
|
|
439
451
|
return (
|
|
440
452
|
facts.get("gpu_vendor_class") == "nvidia"
|
|
441
453
|
and not facts.get("gpus")
|
|
442
454
|
and budget.unified_pool_bytes(facts) is None
|
|
455
|
+
and not no_devices
|
|
443
456
|
)
|
|
444
457
|
|
|
445
458
|
|
|
@@ -524,13 +537,17 @@ INSPECT = (
|
|
|
524
537
|
)
|
|
525
538
|
INSPECT_REASONS = (
|
|
526
539
|
"unsupported-platform · facts-unavailable · plan-unavailable · gpu-sharing-required\n"
|
|
527
|
-
"cuda-driver-update-required · cuda-driver-version-unknown
|
|
540
|
+
"cuda-driver-update-required · cuda-driver-version-unknown · gateway-port-in-use · "
|
|
541
|
+
"harness-unavailable\n"
|
|
528
542
|
"(gpu-sharing-required: a plan fits only beside other GPU work, its owner known or not; ask, "
|
|
529
543
|
"then rerun with --share-gpu, which plans by the free VRAM)\n"
|
|
530
544
|
"cuda-driver-update-required / cuda-driver-version-unknown (stack.state is blocked-now, "
|
|
531
545
|
"hardwareCapable is true: the GPU can run local models, but the NVIDIA driver's CUDA version "
|
|
532
546
|
"is older than requiredCudaVersion or could not be read; detectedCudaVersion, "
|
|
533
547
|
"requiredCudaVersion and driverVersion carry the versions)\n"
|
|
548
|
+
"gateway-port-in-use / harness-unavailable (stack.state is blocked-now with "
|
|
549
|
+
"hardwareCapable true when the hardware fits, but the gateway port is held or tool checks "
|
|
550
|
+
"failed; free the port or fix the tool issue and check again)\n"
|
|
534
551
|
"gpu-memory-required (stack.state is blocked-now, stack.basis is capacity: other programs "
|
|
535
552
|
"use the GPU memory the plan needs; close them and check again; gpuIndex, freeBytes and "
|
|
536
553
|
"requiredBytes give the card and its free and needed VRAM)\n"
|