@simplexai/localmodels-darwin-arm64 0.1.0-dev.48 → 0.1.0-dev.49
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 +54 -50
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/budget.py +40 -14
- package/modules/localmodels/catalog.json +57 -34
- package/modules/localmodels/debug_mode.py +25 -0
- package/modules/localmodels/deploy.py +3 -0
- package/modules/localmodels/engines-b12588-mix-c0c3de8.json +13 -1
- package/modules/localmodels/engines.py +31 -6
- package/modules/localmodels/library_jobs.py +22 -1
- package/modules/localmodels/library_model.py +38 -2
- package/modules/localmodels/library_pricing.py +261 -78
- package/modules/localmodels/library_serve.py +20 -4
- package/modules/localmodels/library_status.py +19 -11
- package/modules/localmodels/library_vram.py +123 -0
- package/modules/localmodels/llm_rank.py +28 -1
- 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_service.py +15 -46
- package/modules/localmodels/service_probe.py +1 -1
- package/modules/localmodels/setup_inspection.py +14 -1
- package/modules/localmodels/setup_text.py +12 -0
- package/modules/localmodels/setup_upgrade.py +145 -0
- package/modules/localmodels/stack_compose.py +5 -1
- package/modules/localmodels/stack_hardware.py +5 -2
- package/modules/localmodels/stack_route.py +5 -1
- package/modules/localmodels/stack_suite.py +1 -1
- 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/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/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 +187 -0
- package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/RECORD +51 -47
- 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.dev49.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev48.dist-info → simplex_localmodels-0.1.0.dev49.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -12,10 +12,12 @@ from typing import cast
|
|
|
12
12
|
|
|
13
13
|
from localmodels import (
|
|
14
14
|
__version__,
|
|
15
|
+
debug_mode,
|
|
15
16
|
hosts,
|
|
16
17
|
library_gateway,
|
|
17
18
|
library_pricing,
|
|
18
19
|
library_state,
|
|
20
|
+
library_vram,
|
|
19
21
|
metal,
|
|
20
22
|
plan_envelope,
|
|
21
23
|
suite,
|
|
@@ -27,6 +29,7 @@ from localmodels.library_model import (
|
|
|
27
29
|
LOAD_STEPS_PUBLIC,
|
|
28
30
|
STATUS_SCHEMA,
|
|
29
31
|
Availability,
|
|
32
|
+
DebugInfo,
|
|
30
33
|
Download,
|
|
31
34
|
DownloadSource,
|
|
32
35
|
Holder,
|
|
@@ -401,20 +404,22 @@ def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
|
401
404
|
}
|
|
402
405
|
)
|
|
403
406
|
now = library_pricing.live(lib.facts, lib.reserved())
|
|
407
|
+
gpu_pool_count = sum(1 for p in holders if p.startswith("gpu:"))
|
|
404
408
|
found: list[Pool] = []
|
|
405
409
|
for pool, held in holders.items():
|
|
406
410
|
total = library_pricing.pool_total(lib.facts, pool)
|
|
407
411
|
free = library_pricing.pool_free(now, pool)
|
|
408
412
|
used = min(total, max(0, total - free))
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
413
|
+
entry: Pool = {
|
|
414
|
+
"id": pool,
|
|
415
|
+
"total_bytes": total,
|
|
416
|
+
"used_bytes": used,
|
|
417
|
+
"holders": held,
|
|
418
|
+
"reserve_bytes": library_pricing.pool_reserve(now, pool),
|
|
419
|
+
}
|
|
420
|
+
if ext := library_vram.pool_external_holders(lib.facts, pool, gpu_pool_count):
|
|
421
|
+
entry["external_holders"] = ext
|
|
422
|
+
found.append(entry)
|
|
418
423
|
return found
|
|
419
424
|
|
|
420
425
|
|
|
@@ -481,10 +486,10 @@ def build(lib: Library) -> Status:
|
|
|
481
486
|
and r["availability"]["downloadable"]
|
|
482
487
|
and r.get("fits_now") is True
|
|
483
488
|
]
|
|
484
|
-
chosen = library_pricing.recommend(now, candidates)
|
|
489
|
+
chosen = library_pricing.recommend(now, candidates, lib.base_dir)
|
|
485
490
|
for r in rows:
|
|
486
491
|
r["recommended"] = r["id"] == chosen
|
|
487
|
-
|
|
492
|
+
status_doc: Status = {
|
|
488
493
|
"schema": STATUS_SCHEMA,
|
|
489
494
|
"tool_version": __version__,
|
|
490
495
|
"observed_at": dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds"),
|
|
@@ -492,6 +497,9 @@ def build(lib: Library) -> Status:
|
|
|
492
497
|
"pools": pools(lib, rows),
|
|
493
498
|
"models": rows,
|
|
494
499
|
}
|
|
500
|
+
if (debug_info := debug_mode.status_info()) is not None:
|
|
501
|
+
status_doc["debug"] = cast(DebugInfo, debug_info)
|
|
502
|
+
return status_doc
|
|
495
503
|
|
|
496
504
|
|
|
497
505
|
def model_row(lib: Library, model_id: str) -> Row:
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Desktop/WDDM GPU VRAM guidance shared by model library status and Quick Install."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import copy
|
|
6
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
7
|
+
|
|
8
|
+
from localmodels import budget, plan_envelope, win_probe
|
|
9
|
+
from localmodels.library_model import ExternalHolder
|
|
10
|
+
from localmodels.probe import GPU, HostFacts
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _owned_gpu_bytes(facts: HostFacts, gpu: GPU, reclaimable: Mapping[str, int] | None) -> int:
|
|
14
|
+
pool = f"gpu:{gpu['index']}"
|
|
15
|
+
from_records = max(0, int((reclaimable or {}).get(pool, 0)))
|
|
16
|
+
services = facts.get("services")
|
|
17
|
+
procs = (services.get("compute_processes") if services else None) or []
|
|
18
|
+
from_procs = sum(
|
|
19
|
+
int(p.get("used_bytes") or 0)
|
|
20
|
+
for p in procs
|
|
21
|
+
if p["gpu_uuid"] == gpu["uuid"] and p.get("owned") is True
|
|
22
|
+
)
|
|
23
|
+
return max(from_records, from_procs)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _foreign_gpu_bytes(facts: HostFacts, gpu: GPU) -> int:
|
|
27
|
+
services = facts.get("services")
|
|
28
|
+
procs = (services.get("compute_processes") if services else None) or []
|
|
29
|
+
return sum(
|
|
30
|
+
int(p.get("used_bytes") or 0)
|
|
31
|
+
for p in procs
|
|
32
|
+
if p["gpu_uuid"] == gpu["uuid"] and budget.foreign_work(p, facts)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def gpu_capacity_free(
|
|
37
|
+
facts: HostFacts,
|
|
38
|
+
gpu: GPU,
|
|
39
|
+
reclaimable: Mapping[str, int] | None,
|
|
40
|
+
desktop_cap: int = budget.DESKTOP_VRAM_BASELINE_CAP_BYTES,
|
|
41
|
+
) -> int:
|
|
42
|
+
"""Loadable VRAM on ``gpu`` once owned models and transient foreign work clear, keeping
|
|
43
|
+
observed desktop/WDDM baseline occupancy on Windows and display-active GPUs."""
|
|
44
|
+
total = gpu["total_bytes"]
|
|
45
|
+
if facts.get("platform") != "win32" and not gpu.get("display_active"):
|
|
46
|
+
return total
|
|
47
|
+
taken = max(gpu["used_bytes"], max(0, total - gpu["free_bytes"]))
|
|
48
|
+
desktop_used = max(
|
|
49
|
+
0, taken - _owned_gpu_bytes(facts, gpu, reclaimable) - _foreign_gpu_bytes(facts, gpu)
|
|
50
|
+
)
|
|
51
|
+
baseline = min(desktop_used, desktop_cap)
|
|
52
|
+
return min(total, max(gpu["free_bytes"], total - baseline))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def closeable_gpu_apps(facts: HostFacts) -> list[win_probe.GpuAppMemory]:
|
|
56
|
+
"""Closeable desktop GPU apps from Windows CIM, excluding owned localmodels PIDs."""
|
|
57
|
+
raw_procs = facts.get("gpu_processes") or []
|
|
58
|
+
if not raw_procs:
|
|
59
|
+
return []
|
|
60
|
+
services = facts.get("services")
|
|
61
|
+
owned_pids = {
|
|
62
|
+
int(p["pid"])
|
|
63
|
+
for p in ((services.get("compute_processes") if services else None) or [])
|
|
64
|
+
if p.get("owned") is True
|
|
65
|
+
}
|
|
66
|
+
found: list[win_probe.GpuAppMemory] = []
|
|
67
|
+
for proc in raw_procs:
|
|
68
|
+
pids = [int(pid) for pid in proc["pids"] if int(pid) not in owned_pids]
|
|
69
|
+
if pids and proc["bytes"] > 0:
|
|
70
|
+
found.append({"name": proc["name"], "pids": pids, "bytes": int(proc["bytes"])})
|
|
71
|
+
return found
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def pool_external_holders(facts: HostFacts, pool: str, gpu_pool_count: int) -> list[ExternalHolder]:
|
|
75
|
+
"""External closeable desktop GPU apps attributable to ``pool`` (single GPU or display GPU)."""
|
|
76
|
+
if not pool.startswith("gpu:"):
|
|
77
|
+
return []
|
|
78
|
+
index = int(pool.split(":", 1)[1])
|
|
79
|
+
gpu = next((g for g in facts.get("gpus") or [] if g["index"] == index), None)
|
|
80
|
+
if gpu is None or (gpu_pool_count > 1 and not gpu.get("display_active")):
|
|
81
|
+
return []
|
|
82
|
+
return [
|
|
83
|
+
{"name": app["name"], "bytes": app["bytes"], "pids": app["pids"]}
|
|
84
|
+
for app in closeable_gpu_apps(facts)
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def idle_desktop_capacity(facts: HostFacts, cap: HostFacts) -> HostFacts | None:
|
|
89
|
+
"""``cap`` with desktop/WDDM discrete GPUs raised to the 1 GiB idle floor, or None when no
|
|
90
|
+
card gains headroom over ``cap``."""
|
|
91
|
+
if facts.get("platform") != "win32" and not any(
|
|
92
|
+
g.get("display_active") for g in facts.get("gpus") or []
|
|
93
|
+
):
|
|
94
|
+
return None
|
|
95
|
+
roomy = copy.deepcopy(cap)
|
|
96
|
+
gained = False
|
|
97
|
+
for gpu in roomy.get("gpus") or []:
|
|
98
|
+
idle = max(0, gpu["total_bytes"] - budget.IDLE_USED_BYTES)
|
|
99
|
+
if gpu["free_bytes"] < idle:
|
|
100
|
+
gpu["free_bytes"], gpu["used_bytes"] = idle, gpu["total_bytes"] - idle
|
|
101
|
+
gained = True
|
|
102
|
+
return roomy if gained else None
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def fits_idle_desktop(
|
|
106
|
+
facts: HostFacts,
|
|
107
|
+
cap: HostFacts,
|
|
108
|
+
pools: Sequence[str],
|
|
109
|
+
try_price: Callable[[HostFacts, str], object],
|
|
110
|
+
) -> bool:
|
|
111
|
+
"""True when ``try_price`` succeeds on any discrete GPU once desktop VRAM nears 1 GiB idle."""
|
|
112
|
+
roomy = idle_desktop_capacity(facts, cap)
|
|
113
|
+
if roomy is None:
|
|
114
|
+
return False
|
|
115
|
+
for pool in pools:
|
|
116
|
+
if not pool.startswith("gpu:"):
|
|
117
|
+
continue
|
|
118
|
+
try:
|
|
119
|
+
try_price(roomy, pool)
|
|
120
|
+
return True
|
|
121
|
+
except plan_envelope.PlanError:
|
|
122
|
+
continue
|
|
123
|
+
return False
|
|
@@ -13,7 +13,7 @@ from __future__ import annotations
|
|
|
13
13
|
from collections.abc import Iterable, Mapping
|
|
14
14
|
from dataclasses import dataclass
|
|
15
15
|
|
|
16
|
-
from localmodels import metal, vision
|
|
16
|
+
from localmodels import engines, metal, vision
|
|
17
17
|
from localmodels.budget import HARNESS_RAM, RAM_FLOOR, host_ram
|
|
18
18
|
from localmodels.catalog import (
|
|
19
19
|
CatalogEntry,
|
|
@@ -27,6 +27,7 @@ from localmodels.catalog import (
|
|
|
27
27
|
)
|
|
28
28
|
from localmodels.context_policy import AGENT, AgentPosture
|
|
29
29
|
from localmodels.estimator import HardwareBudget, PhysicsRefusal, llama_host_bytes
|
|
30
|
+
from localmodels.plan_envelope import PlanError
|
|
30
31
|
from localmodels.probe import HostFacts
|
|
31
32
|
|
|
32
33
|
# Installed SimplexAI scores closer than this are a tie (model-scoring.md; AIHOT: 3 points or more
|
|
@@ -133,10 +134,36 @@ def listed_default(facts: HostFacts, fits: list[tuple[str, int]]) -> str | None:
|
|
|
133
134
|
return rungs[0] if rungs and keeps_default(others) else None
|
|
134
135
|
|
|
135
136
|
|
|
137
|
+
def _engine_supported(entry: CatalogEntry, facts: HostFacts) -> bool:
|
|
138
|
+
"""When an entry pins a non-default engine lock, skip it in auto selection if this host
|
|
139
|
+
cannot run that lock while the default lock does run here (e.g. Linux arm64 CUDA, minimal
|
|
140
|
+
containers without libgomp1, or Windows drivers on CUDA 12.4-12.7)."""
|
|
141
|
+
if not entry.engine:
|
|
142
|
+
return True
|
|
143
|
+
backend = (
|
|
144
|
+
"metal"
|
|
145
|
+
if metal.supported(facts)
|
|
146
|
+
else "cuda"
|
|
147
|
+
if any(g["vendor"] == "nvidia" for g in facts.get("gpus") or [])
|
|
148
|
+
else "cpu"
|
|
149
|
+
)
|
|
150
|
+
try:
|
|
151
|
+
engines.select_engine_build(facts, backend, engines.engine_lock_path(entry.engine))
|
|
152
|
+
except PlanError:
|
|
153
|
+
try:
|
|
154
|
+
engines.select_engine_build(facts, backend)
|
|
155
|
+
except PlanError:
|
|
156
|
+
return True
|
|
157
|
+
return False
|
|
158
|
+
return True
|
|
159
|
+
|
|
160
|
+
|
|
136
161
|
def automatic_here(entry: CatalogEntry, facts: HostFacts) -> bool:
|
|
137
162
|
"""Validated entries and the scoped Mac ladder / Windows fallback candidates."""
|
|
138
163
|
if entry.id in MAC_LADDER_REPLACES and mac_ladder(facts) is not None:
|
|
139
164
|
return False
|
|
165
|
+
if not _engine_supported(entry, facts):
|
|
166
|
+
return False
|
|
140
167
|
return (
|
|
141
168
|
mac_rung(entry, facts)
|
|
142
169
|
or windows_fallback(entry, facts)
|
|
@@ -26,9 +26,10 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
26
26
|
from typing import TypedDict
|
|
27
27
|
|
|
28
28
|
try:
|
|
29
|
-
from localmodels import metal_probe
|
|
29
|
+
from localmodels import metal_probe, win_probe
|
|
30
30
|
except ImportError:
|
|
31
31
|
import metal_probe # type: ignore[import-not-found,no-redef]
|
|
32
|
+
import win_probe # type: ignore[import-not-found,no-redef]
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
class GPUBase(TypedDict):
|
|
@@ -102,10 +103,7 @@ class CgroupMemory(TypedDict):
|
|
|
102
103
|
|
|
103
104
|
class _ComputeSince20261024(TypedDict, total=False):
|
|
104
105
|
in_suite: bool # verified current-user deployment in the suite; never just a cgroup label
|
|
105
|
-
#
|
|
106
|
-
# (mapped GGUF weights that are not wired). The RAM available already counts these pages
|
|
107
|
-
# (metal_probe.available_memory), so a stop gives back only the rest. Absent: unknown.
|
|
108
|
-
cached_bytes: int
|
|
106
|
+
cached_bytes: int # Mac process resident file cache (already counted as available RAM)
|
|
109
107
|
|
|
110
108
|
|
|
111
109
|
class ComputeProcess(_ComputeSince20261024):
|
|
@@ -183,6 +181,7 @@ class HostFacts(RequiredHostFacts, total=False):
|
|
|
183
181
|
memory_bandwidth: MemoryBandwidth # only after probe --measure-bandwidth
|
|
184
182
|
shared_libraries: dict[str, bool] # HOST_LIBRARIES: can the loader find each one
|
|
185
183
|
metal: dict[str, object] | None # metal_probe.py on Apple Silicon (2026-10-29; metal.Metal)
|
|
184
|
+
gpu_processes: list[win_probe.GpuAppMemory] # Windows WDDM per-app dedicated VRAM (CIM)
|
|
186
185
|
|
|
187
186
|
|
|
188
187
|
SCHEMA = "localmodels.host-facts/v1"
|
|
@@ -250,15 +249,8 @@ def _cpu_model() -> str:
|
|
|
250
249
|
if sys.platform == "darwin":
|
|
251
250
|
return _run(["/usr/sbin/sysctl", "-n", "machdep.cpu.brand_string"])[1].strip()
|
|
252
251
|
if sys.platform == "win32":
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
with winreg.OpenKey(
|
|
257
|
-
winreg.HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\CentralProcessor\0"
|
|
258
|
-
) as k:
|
|
259
|
-
return str(winreg.QueryValueEx(k, "ProcessorNameString")[0]).strip()
|
|
260
|
-
except (ImportError, OSError):
|
|
261
|
-
pass
|
|
252
|
+
if model := win_probe.cpu_model():
|
|
253
|
+
return model
|
|
262
254
|
return platform.processor()
|
|
263
255
|
|
|
264
256
|
|
|
@@ -280,11 +272,7 @@ def ram_from_meminfo(text: str) -> tuple[int, int] | None:
|
|
|
280
272
|
|
|
281
273
|
def ram() -> tuple[int, int]:
|
|
282
274
|
if sys.platform == "win32":
|
|
283
|
-
|
|
284
|
-
k32 = ctypes.WinDLL("kernel32", use_last_error=True) # type: ignore[attr-defined]
|
|
285
|
-
if not k32.GlobalMemoryStatusEx(ctypes.byref(mem)):
|
|
286
|
-
raise OSError("GlobalMemoryStatusEx failed")
|
|
287
|
-
return int(mem[1]), int(mem[2]) # ullTotalPhys, ullAvailPhys
|
|
275
|
+
return win_probe.ram()
|
|
288
276
|
if sys.platform.startswith("linux"):
|
|
289
277
|
parsed = ram_from_meminfo(_text("/proc/meminfo") or "")
|
|
290
278
|
if parsed:
|
|
@@ -403,17 +391,24 @@ def _nvidia(errors: list[dict[str, str]]) -> tuple[dict[str, str] | None, list[G
|
|
|
403
391
|
if rc != 0:
|
|
404
392
|
errors.append({"source": "nvidia-smi", "error": (err or out).strip()[:300]})
|
|
405
393
|
return None, []
|
|
406
|
-
gpus = parse_gpu_csv(out)
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
394
|
+
gpus, text = parse_gpu_csv(out), out.strip()
|
|
395
|
+
if not gpus and text:
|
|
396
|
+
no_dev = "no devices were found" in text.lower()
|
|
397
|
+
msg = text[:300] if no_dev else "nvidia-smi reported unmeasured GPU memory"
|
|
398
|
+
errors.append({"source": "nvidia-smi", "error": msg})
|
|
399
|
+
if no_dev:
|
|
400
|
+
return None, []
|
|
401
|
+
raw_drv = gpus[0]["driver_version"] if gpus else ""
|
|
402
|
+
drv, cuda_version = "" if raw_drv.startswith("[") else raw_drv, _cuda_driver_version()
|
|
403
|
+
if not (cuda_version and drv):
|
|
410
404
|
banner = _run([exe])[1]
|
|
411
405
|
cuda_version = cuda_version or parse_cuda_version(banner)
|
|
412
406
|
drv = drv or parse_driver_version(banner)
|
|
413
407
|
for gpu in gpus:
|
|
414
408
|
if not gpu["driver_version"] or gpu["driver_version"].startswith("["):
|
|
415
409
|
gpu["driver_version"] = drv
|
|
416
|
-
|
|
410
|
+
meta = {"driver_version": drv, "cuda_version": cuda_version}
|
|
411
|
+
return (meta, gpus) if (gpus or drv or cuda_version) else (None, [])
|
|
417
412
|
|
|
418
413
|
|
|
419
414
|
def _cuda_pool() -> CudaPool | None:
|
|
@@ -449,15 +444,22 @@ def shared_libraries(names: Sequence[str] = HOST_LIBRARIES) -> dict[str, bool]:
|
|
|
449
444
|
return found
|
|
450
445
|
|
|
451
446
|
|
|
447
|
+
def _windows_gpu_vendor_class() -> str:
|
|
448
|
+
"""Inspect Windows display adapter PCI vendor IDs via stdlib winreg."""
|
|
449
|
+
return win_probe.gpu_vendor_class(_GPU_PCI_VENDORS, _GPU_PRIORITY)
|
|
450
|
+
|
|
451
|
+
|
|
452
452
|
def _gpu_vendor_class() -> str:
|
|
453
453
|
exists = os.path.exists
|
|
454
454
|
if sys.platform == "darwin":
|
|
455
455
|
return "apple_silicon" if _arch() == "arm64" else "unknown"
|
|
456
456
|
if sys.platform == "win32":
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return
|
|
460
|
-
if exists("/
|
|
457
|
+
if _nvidia_smi() or exists(_win_system32("nvcuda.dll")):
|
|
458
|
+
return "nvidia"
|
|
459
|
+
return _windows_gpu_vendor_class()
|
|
460
|
+
if exists("/proc/driver/nvidia/version") or any(
|
|
461
|
+
exists("/usr/lib/wsl/lib/" + f) for f in ("nvidia-smi", "libcuda.so.1")
|
|
462
|
+
):
|
|
461
463
|
return "nvidia"
|
|
462
464
|
root = "/sys/class/drm"
|
|
463
465
|
try:
|
|
@@ -466,9 +468,8 @@ def _gpu_vendor_class() -> str:
|
|
|
466
468
|
return "unknown"
|
|
467
469
|
found = set()
|
|
468
470
|
for card in cards:
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
found.add(_GPU_PCI_VENDORS.get(vendor))
|
|
471
|
+
v = (_text(os.path.join(root, card, "device", "vendor")) or "")[:16].strip().lower()
|
|
472
|
+
found.add(_GPU_PCI_VENDORS.get(v[2:] if v.startswith("0x") else v))
|
|
472
473
|
return next((name for name in _GPU_PRIORITY if name in found), "none")
|
|
473
474
|
|
|
474
475
|
|
|
@@ -644,8 +645,7 @@ def _mark_details(exe: str, gpus: list[GPU]) -> None:
|
|
|
644
645
|
|
|
645
646
|
|
|
646
647
|
def _disk(path: str) -> Disk:
|
|
647
|
-
path = os.path.expanduser(path)
|
|
648
|
-
probe = path
|
|
648
|
+
path = probe = os.path.expanduser(path)
|
|
649
649
|
while probe and not os.path.exists(probe):
|
|
650
650
|
probe = os.path.dirname(probe)
|
|
651
651
|
try:
|
|
@@ -695,6 +695,7 @@ def collect(
|
|
|
695
695
|
s for s in pool.map(probe_llama_server, dict.fromkeys([*ports, *SERVICE_PORTS])) if s
|
|
696
696
|
]
|
|
697
697
|
is_linux = sys.platform.startswith("linux")
|
|
698
|
+
vendor = _gpu_vendor_class()
|
|
698
699
|
facts: HostFacts = {
|
|
699
700
|
"schema": SCHEMA,
|
|
700
701
|
"collected_at": dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds"),
|
|
@@ -715,10 +716,10 @@ def collect(
|
|
|
715
716
|
"available_bytes": ram_avail,
|
|
716
717
|
**(metal_probe.memory_status() if sys.platform == "darwin" else {}),
|
|
717
718
|
},
|
|
718
|
-
"gpu_vendor_class":
|
|
719
|
+
"gpu_vendor_class": vendor,
|
|
719
720
|
"nvidia": nvidia,
|
|
720
721
|
"gpus": gpus,
|
|
721
|
-
"cuda_pool": _cuda_pool() if gpus or is_linux else None,
|
|
722
|
+
"cuda_pool": _cuda_pool() if gpus or is_linux or vendor == "nvidia" else None,
|
|
722
723
|
"llama_servers": servers,
|
|
723
724
|
"engines": _engines(engine_paths),
|
|
724
725
|
"disk": _disk(models_dir),
|
|
@@ -730,6 +731,8 @@ def collect(
|
|
|
730
731
|
}
|
|
731
732
|
if facts["platform"] == "darwin" and facts["arch"] == "arm64":
|
|
732
733
|
facts["metal"] = metal_probe.metal_device()
|
|
734
|
+
if facts["platform"] == "win32" and gpus and (gpu_procs := win_probe.gpu_process_memory()):
|
|
735
|
+
facts["gpu_processes"] = gpu_procs
|
|
733
736
|
return facts
|
|
734
737
|
|
|
735
738
|
|
|
@@ -740,8 +743,7 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
740
743
|
parser.add_argument("--engine", action="append", default=[], help="extra llama-server path")
|
|
741
744
|
args = parser.parse_args(argv)
|
|
742
745
|
ports = tuple(int(p) for p in args.ports.split(",") if p.strip())
|
|
743
|
-
json.
|
|
744
|
-
sys.stdout.write("\n")
|
|
746
|
+
print(json.dumps(collect(ports, args.models_dir, args.engine), indent=1, sort_keys=True))
|
|
745
747
|
|
|
746
748
|
|
|
747
749
|
if __name__ == "__main__":
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
"""Owned process identity receipts and
|
|
1
|
+
"""Owned process identity receipts and command proof; stdlib-only, Python 3.8+.
|
|
2
2
|
|
|
3
3
|
Receipts bind PID, UID, PGID and start time against PID reuse without storing secrets. On
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
Linux, receipts use ``/proc/<pid>/stat`` boot ticks; on macOS, ``libSystem`` ``sysctl``
|
|
5
|
+
microsecond start times; on Windows, kernel32/advapi32 creation times and SID tokens (uid 0
|
|
6
|
+
for this user, -1 otherwise; pgid=pid), and stopping kills the tree via ``taskkill``.
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
from __future__ import annotations
|
|
@@ -18,8 +19,9 @@ from pathlib import Path
|
|
|
18
19
|
from typing import Any, TypedDict
|
|
19
20
|
|
|
20
21
|
try:
|
|
21
|
-
from localmodels import process_identity_linux
|
|
22
|
+
from localmodels import process_identity_darwin, process_identity_linux
|
|
22
23
|
except ImportError: # run as a bare file from this directory
|
|
24
|
+
import process_identity_darwin # type: ignore[import-not-found,no-redef]
|
|
23
25
|
import process_identity_linux # type: ignore[import-not-found,no-redef]
|
|
24
26
|
|
|
25
27
|
|
|
@@ -490,9 +492,15 @@ _IDENTITY_FIELDS = {"pid": int, "uid": int, "pgid": int, "started": str}
|
|
|
490
492
|
|
|
491
493
|
|
|
492
494
|
def _same_start(current: str, saved: str) -> bool:
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
)
|
|
495
|
+
if current == saved:
|
|
496
|
+
return True
|
|
497
|
+
if sys.platform.startswith("linux"):
|
|
498
|
+
epoch = process_identity_linux.started_epoch(current)
|
|
499
|
+
elif sys.platform == "darwin":
|
|
500
|
+
epoch = process_identity_darwin.started_epoch(current)
|
|
501
|
+
else:
|
|
502
|
+
return False
|
|
503
|
+
return process_identity_linux.matches_legacy_lstart(epoch, saved)
|
|
496
504
|
|
|
497
505
|
|
|
498
506
|
def _valid_identity(saved: dict[str, Any]) -> bool:
|
|
@@ -520,31 +528,13 @@ def inspect(pid: int) -> Identity | None:
|
|
|
520
528
|
return _windows_inspect(pid)
|
|
521
529
|
if sys.platform.startswith("linux"):
|
|
522
530
|
found = process_identity_linux.inspect(pid)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
["/bin/ps", "-p", str(pid), "-o", "uid=,pgid=,lstart=,stat="],
|
|
529
|
-
capture_output=True,
|
|
530
|
-
text=True,
|
|
531
|
-
timeout=5,
|
|
532
|
-
check=False,
|
|
533
|
-
env={**os.environ, "LC_ALL": "C"},
|
|
534
|
-
)
|
|
535
|
-
fields = result.stdout.split()
|
|
536
|
-
if result.returncode == 1 and not fields and not result.stderr.strip():
|
|
537
|
-
return None
|
|
538
|
-
if result.returncode or len(fields) != 8:
|
|
539
|
-
raise OSError("process identity unavailable")
|
|
540
|
-
if fields[-1].startswith("Z"):
|
|
531
|
+
elif sys.platform == "darwin":
|
|
532
|
+
found = process_identity_darwin.inspect(pid)
|
|
533
|
+
else:
|
|
534
|
+
found = process_identity_linux.posix_ps_inspect(pid)
|
|
535
|
+
if found is None:
|
|
541
536
|
return None
|
|
542
|
-
return {
|
|
543
|
-
"pid": pid,
|
|
544
|
-
"uid": int(fields[0]),
|
|
545
|
-
"pgid": int(fields[1]),
|
|
546
|
-
"started": " ".join(fields[2:7]),
|
|
547
|
-
}
|
|
537
|
+
return {"pid": pid, "uid": found[0], "pgid": found[1], "started": found[2]}
|
|
548
538
|
|
|
549
539
|
|
|
550
540
|
def _private(path: Path) -> str:
|
|
@@ -706,9 +696,12 @@ def listener_owned(port: int, pid: int | None) -> bool:
|
|
|
706
696
|
|
|
707
697
|
|
|
708
698
|
def command_matches(pid: int, expected: list[str], root: str = "/") -> bool:
|
|
709
|
-
"""Read-only
|
|
710
|
-
if _windows():
|
|
699
|
+
"""Read-only argv proof (plus shebang); on Windows checks owned executable image path."""
|
|
700
|
+
if root == "/" and _windows():
|
|
711
701
|
return _windows_command_matches(pid, expected)
|
|
702
|
+
if root == "/" and sys.platform == "darwin":
|
|
703
|
+
info = process_identity_darwin.command_info(pid)
|
|
704
|
+
return info is not None and process_identity_linux.argv_matches(info[0], info[1], expected)
|
|
712
705
|
return process_identity_linux.command_matches(pid, expected, root)
|
|
713
706
|
|
|
714
707
|
|