@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 0.1.0-dev.37
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 +119 -98
- package/kit.py +1 -0
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +9 -3
- package/modules/localmodels/bifrost_config.py +188 -0
- package/modules/localmodels/budget.py +13 -2
- package/modules/localmodels/catalog.py +51 -320
- package/modules/localmodels/catalog_add.py +2 -8
- package/modules/localmodels/catalog_recipes.py +321 -0
- package/modules/localmodels/cli_parser.py +4 -1
- package/modules/localmodels/console.py +5 -4
- package/modules/localmodels/contracts.py +13 -3
- package/modules/localmodels/debug_cli.py +158 -0
- package/modules/localmodels/debug_mode.py +727 -0
- package/modules/localmodels/debug_stub_server.py +192 -0
- package/modules/localmodels/decode_calibration.json +1 -1
- package/modules/localmodels/decode_calibration.py +34 -17
- package/modules/localmodels/gateway.py +21 -155
- package/modules/localmodels/gateway_accept.py +201 -0
- package/modules/localmodels/gateway_bifrost.py +19 -184
- package/modules/localmodels/gateway_cli.py +11 -4
- package/modules/localmodels/gateway_foundations.py +2 -4
- package/modules/localmodels/gateway_probe.py +0 -1
- package/modules/localmodels/gateway_server.py +2 -3
- package/modules/localmodels/gpu_specs.py +12 -0
- package/modules/localmodels/guard.py +2 -7
- package/modules/localmodels/harness.py +16 -129
- package/modules/localmodels/harness_cleanup.py +135 -0
- package/modules/localmodels/harness_gateway.py +16 -14
- package/modules/localmodels/harness_probe.py +12 -4
- package/modules/localmodels/hosts.py +25 -2
- package/modules/localmodels/http_local.py +59 -0
- package/modules/localmodels/install.py +23 -8
- package/modules/localmodels/library_gateway.py +9 -9
- package/modules/localmodels/library_jobs.py +76 -27
- package/modules/localmodels/library_serve.py +12 -1
- package/modules/localmodels/library_state.py +6 -1
- package/modules/localmodels/llm_rank.py +102 -9
- package/modules/localmodels/probe.py +108 -174
- package/modules/localmodels/process_identity.py +109 -154
- package/modules/localmodels/process_windows.py +86 -0
- package/modules/localmodels/recommend.py +1 -1
- package/modules/localmodels/recommend_cli.py +14 -6
- package/modules/localmodels/remote_ops.py +65 -0
- package/modules/localmodels/remote_ops_service.py +14 -2
- package/modules/localmodels/runtime_args.py +10 -3
- package/modules/localmodels/runtime_auth.py +5 -9
- package/modules/localmodels/runtime_cli.py +128 -129
- package/modules/localmodels/runtime_discovery.py +84 -0
- package/modules/localmodels/runtime_install.py +101 -0
- package/modules/localmodels/runtime_releases.py +302 -0
- package/modules/localmodels/service_stop.py +8 -108
- package/modules/localmodels/service_upgrade.py +394 -63
- package/modules/localmodels/services_cli.py +24 -14
- package/modules/localmodels/setup_inspection.py +97 -9
- package/modules/localmodels/setup_text.py +7 -0
- package/modules/localmodels/sizecalc.py +0 -1
- package/modules/localmodels/stack.py +14 -221
- package/modules/localmodels/stack_arena.py +732 -0
- package/modules/localmodels/stack_args.py +15 -9
- package/modules/localmodels/stack_auto.py +384 -3
- package/modules/localmodels/stack_aux_gpu.py +4 -3
- package/modules/localmodels/stack_capacity.py +138 -0
- package/modules/localmodels/stack_cleanup.py +9 -4
- package/modules/localmodels/stack_cli.py +286 -0
- package/modules/localmodels/stack_compose.py +58 -25
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +92 -263
- package/modules/localmodels/stack_hardware_text.py +263 -0
- package/modules/localmodels/stack_journal.py +3 -9
- package/modules/localmodels/stack_ledger.py +48 -18
- package/modules/localmodels/stack_lifecycle.py +33 -312
- package/modules/localmodels/stack_mcp.py +729 -0
- package/modules/localmodels/stack_memory.py +0 -2
- package/modules/localmodels/stack_picks.py +59 -12
- package/modules/localmodels/stack_plan.py +19 -1
- package/modules/localmodels/stack_preflight.py +11 -19
- package/modules/localmodels/stack_remove.py +373 -0
- package/modules/localmodels/stack_route.py +101 -17
- package/modules/localmodels/stack_suite.py +11 -7
- package/modules/localmodels/stack_summary.py +14 -0
- package/modules/localmodels/stack_try.py +238 -24
- package/modules/localmodels/stack_try_client.py +53 -15
- package/modules/localmodels/stack_try_docs.py +2 -2
- package/modules/localmodels/stack_view.py +24 -171
- package/modules/localmodels/stack_view_access.py +114 -1
- package/modules/localmodels/stack_view_agent.py +3 -13
- package/modules/localmodels/stack_view_hub.py +9 -10
- package/modules/localmodels/stack_view_llm.py +1 -1
- package/modules/localmodels/stack_view_sandbox.py +2 -2
- package/modules/localmodels/stack_view_schema.py +183 -0
- package/modules/localmodels/stack_view_serve.py +7 -1
- package/modules/localmodels/stack_view_service.py +1 -2
- package/modules/localmodels/stack_view_text.py +13 -9
- package/modules/localmodels/stack_warm.py +3 -0
- package/modules/localmodels/stack_warm_store.py +517 -0
- package/modules/localmodels/tui.py +28 -4
- package/modules/localmodels/tui_dialogs.py +136 -0
- package/modules/localmodels/tui_modals.py +279 -0
- package/modules/localmodels/tui_screen.py +113 -154
- package/modules/localmodels/tui_views.py +134 -203
- package/modules/localmodels/web/index.html +510 -101
- package/modules/localmodels/web/sizecalc/app.js +363 -10
- package/modules/localmodels/web/sizecalc/page.html +27 -3
- package/modules/localmodels/web/view/fleet.html +11 -2
- package/modules/localmodels/web/view/fleet.js +191 -17
- package/modules/localmodels/web/view/i18n.js +3 -2
- package/modules/localmodels/web/view/index.html +1 -1
- package/modules/localmodels/web/view/nav.js +22 -3
- package/modules/localmodels/web/view/view.css +63 -18
- package/modules/localmodels/web/view/view.js +169 -32
- package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +115 -94
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""Read-only host facts, stdlib-only on the target host (Python 3.8+).
|
|
3
|
-
Delivered as ``ssh HOST python3 - < probe.py``; budgets and policy belong to the controller.
|
|
4
|
-
Bounded nvidia-smi, engine --version/--help and loopback /props or /models; no service changes.
|
|
2
|
+
"""Read-only host facts, stdlib-only on the target host (Python 3.8+); budgets live on controller.
|
|
5
3
|
Ported from hermes_cli/local_runtime/hardware.py (MIT, Copyright (c) 2025 Nous Research).
|
|
6
|
-
service_probe.py adds holders; bandwidth_probe.py measures memory bandwidth only on request.
|
|
7
4
|
"""
|
|
8
5
|
|
|
9
6
|
from __future__ import annotations
|
|
@@ -48,15 +45,12 @@ class GPUBase(TypedDict):
|
|
|
48
45
|
|
|
49
46
|
|
|
50
47
|
class GPU(GPUBase, total=False):
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
|
|
54
|
-
pcie_width: int
|
|
55
|
-
mig_mode: str # enabled | disabled; absent where the card or driver has no MIG
|
|
56
|
-
# Since 2026-10-28, each absent where the driver does not report it (_mark_details).
|
|
48
|
+
pcie_gen: int # max shared by card and slot
|
|
49
|
+
pcie_width: int # negotiated link width
|
|
50
|
+
mig_mode: str # enabled | disabled
|
|
57
51
|
compute_capability: str # e.g. "8.9"
|
|
58
|
-
reserved_bytes: int # held by
|
|
59
|
-
display_active: bool # a display
|
|
52
|
+
reserved_bytes: int # held by driver/firmware outside used and free
|
|
53
|
+
display_active: bool # driving a display, so free memory can shift
|
|
60
54
|
|
|
61
55
|
|
|
62
56
|
class CudaPool(TypedDict):
|
|
@@ -148,9 +142,7 @@ class Services(TypedDict):
|
|
|
148
142
|
|
|
149
143
|
|
|
150
144
|
class MemoryBandwidth(TypedDict):
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
measured_gbps: float # bytes / seconds / 1e9
|
|
145
|
+
measured_gbps: float # bytes / seconds / 1e9; copy speed from bandwidth_probe.py
|
|
154
146
|
method: str
|
|
155
147
|
bytes: int # read + write traffic over the timed copies
|
|
156
148
|
seconds: float
|
|
@@ -180,7 +172,6 @@ class RequiredHostFacts(TypedDict):
|
|
|
180
172
|
|
|
181
173
|
|
|
182
174
|
class HostFacts(RequiredHostFacts, total=False):
|
|
183
|
-
# Added 2026-10-23 under the same schema id: facts cached before then still decode.
|
|
184
175
|
environment: str # bare | container | wsl | unknown
|
|
185
176
|
cgroup_memory: CgroupMemory | None
|
|
186
177
|
services: Services
|
|
@@ -203,17 +194,10 @@ _ENGINE_GLOBS = (
|
|
|
203
194
|
"/usr/local/bin/llama-server",
|
|
204
195
|
"/opt/homebrew/bin/llama-server",
|
|
205
196
|
)
|
|
206
|
-
# Older builds print "version: 11370 (bed0a856)"; the 0.5 line prints
|
|
207
|
-
# "version: 0.5.0-dev (build 11370, commit bed0a8566)", where a source build without git history
|
|
208
|
-
# reports build 1 and has no comparable release number.
|
|
209
197
|
_VERSION_RE = re.compile(r"version:\s*(\d+)\s*\(([0-9a-f]+)\)")
|
|
210
198
|
_SEMVER_RE = re.compile(r"version:\s*([\w.\-]+)\s*\(build\s*(\d+),\s*commit\s*([0-9a-f]+)\)")
|
|
211
|
-
# Ports the plans and the 24GB+64GB baseline use, plus llama-server's default (8080 up to b11549,
|
|
212
|
-
# 9931 from b11550, ggml-org/llama.cpp#30159); the controller adds every catalog port.
|
|
213
199
|
SERVICE_PORTS = (8080, 9931, 18100, 18321, 18331, 18351, 18352, 18370)
|
|
214
200
|
_CONTAINER_CGROUP_RE = re.compile(r"docker|kubepods|containerd|libpod|lxc|crio")
|
|
215
|
-
# System libraries a pinned engine build may need that minimal images lack (engine locks name
|
|
216
|
-
# them in host_libraries); upstream llama.cpp and whisper.cpp Linux builds link GCC's OpenMP.
|
|
217
201
|
HOST_LIBRARIES = ("libgomp.so.1",)
|
|
218
202
|
DETAIL_FIELDS = ("compute_cap", "memory.reserved", "display_active") # nvidia-smi names
|
|
219
203
|
_UNLIMITED = 1 << 60 # cgroup v1 reports "no limit" as a page-aligned LONG_MAX
|
|
@@ -240,16 +224,15 @@ def _run(
|
|
|
240
224
|
|
|
241
225
|
|
|
242
226
|
def _arch() -> str:
|
|
243
|
-
|
|
244
|
-
return {"x86_64": "x64", "amd64": "x64", "aarch64": "arm64"}.get(
|
|
227
|
+
m = platform.machine().lower()
|
|
228
|
+
return {"x86_64": "x64", "amd64": "x64", "aarch64": "arm64"}.get(m, m)
|
|
245
229
|
|
|
246
230
|
|
|
247
231
|
def _distro() -> str:
|
|
248
232
|
if sys.platform == "darwin":
|
|
249
233
|
return f"macOS {platform.mac_ver()[0]}".strip()
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
return fields.get("PRETTY_NAME", "").strip('"')
|
|
234
|
+
kv = dict(s.split("=", 1) for s in (_text("/etc/os-release") or "").splitlines() if "=" in s)
|
|
235
|
+
return kv.get("PRETTY_NAME", "").strip('"')
|
|
253
236
|
|
|
254
237
|
|
|
255
238
|
def _cpu_model() -> str:
|
|
@@ -265,66 +248,57 @@ def _cpu_model() -> str:
|
|
|
265
248
|
|
|
266
249
|
with winreg.OpenKey(
|
|
267
250
|
winreg.HKEY_LOCAL_MACHINE, r"HARDWARE\DESCRIPTION\System\CentralProcessor\0"
|
|
268
|
-
) as
|
|
269
|
-
|
|
270
|
-
return str(value).strip()
|
|
251
|
+
) as k:
|
|
252
|
+
return str(winreg.QueryValueEx(k, "ProcessorNameString")[0]).strip()
|
|
271
253
|
except (ImportError, OSError):
|
|
272
254
|
pass
|
|
273
255
|
return platform.processor()
|
|
274
256
|
|
|
275
257
|
|
|
276
258
|
def ram_from_meminfo(text: str) -> tuple[int, int] | None:
|
|
277
|
-
"""(total, available) from /proc/meminfo text, or None
|
|
278
|
-
page cache; kernels without it fall back to MemFree. Zero is a real value."""
|
|
259
|
+
"""(total, available) from /proc/meminfo text, or None (falls back to MemFree)."""
|
|
279
260
|
fields = {}
|
|
280
261
|
for line in text.splitlines():
|
|
281
262
|
name, sep, value = line.partition(":")
|
|
282
|
-
if
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
fields[name] = int(parts[0]) * 1024
|
|
289
|
-
except ValueError:
|
|
290
|
-
return None
|
|
263
|
+
parts = value.split() if sep and name in ("MemTotal", "MemAvailable", "MemFree") else []
|
|
264
|
+
if len(parts) == 2 and parts[1] == "kB":
|
|
265
|
+
try:
|
|
266
|
+
fields[name] = int(parts[0]) * 1024
|
|
267
|
+
except ValueError:
|
|
268
|
+
return None
|
|
291
269
|
total = fields.get("MemTotal")
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return None
|
|
295
|
-
return total, available
|
|
270
|
+
avail = fields["MemAvailable"] if "MemAvailable" in fields else fields.get("MemFree")
|
|
271
|
+
return (total, avail) if total and avail is not None and 0 <= avail <= total else None
|
|
296
272
|
|
|
297
273
|
|
|
298
274
|
def ram() -> tuple[int, int]:
|
|
299
275
|
if sys.platform == "win32":
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if not kernel.GlobalMemoryStatusEx(ctypes.byref(memory)):
|
|
276
|
+
mem = (ctypes.c_uint64 * 8)(64) # MEMORYSTATUSEX: 64B header + 7 DWORDLONGs
|
|
277
|
+
k32 = ctypes.WinDLL("kernel32", use_last_error=True) # type: ignore[attr-defined]
|
|
278
|
+
if not k32.GlobalMemoryStatusEx(ctypes.byref(mem)):
|
|
304
279
|
raise OSError("GlobalMemoryStatusEx failed")
|
|
305
|
-
return int(
|
|
280
|
+
return int(mem[1]), int(mem[2]) # ullTotalPhys, ullAvailPhys
|
|
306
281
|
if sys.platform.startswith("linux"):
|
|
307
282
|
parsed = ram_from_meminfo(_text("/proc/meminfo") or "")
|
|
308
283
|
if parsed:
|
|
309
284
|
return parsed
|
|
310
285
|
if sys.platform == "darwin":
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if
|
|
286
|
+
rc1, total_out, _ = _run(["/usr/sbin/sysctl", "-n", "hw.memsize"])
|
|
287
|
+
rc2, out, _ = _run(["/usr/bin/vm_stat"])
|
|
288
|
+
if rc1 or rc2:
|
|
314
289
|
raise OSError("RAM measurement unavailable")
|
|
315
290
|
return metal_probe.available_memory(total_out, out)
|
|
316
291
|
try:
|
|
317
|
-
|
|
318
|
-
return os.sysconf("SC_PHYS_PAGES") *
|
|
292
|
+
pg = os.sysconf("SC_PAGE_SIZE")
|
|
293
|
+
return os.sysconf("SC_PHYS_PAGES") * pg, os.sysconf("SC_AVPHYS_PAGES") * pg
|
|
319
294
|
except (ValueError, OSError, AttributeError):
|
|
320
295
|
return 0, 0
|
|
321
296
|
|
|
322
297
|
|
|
323
298
|
def _nvidia_smi() -> str | None:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return found
|
|
299
|
+
return shutil.which("nvidia-smi") or (
|
|
300
|
+
"/usr/lib/wsl/lib/nvidia-smi" if os.path.exists("/usr/lib/wsl/lib/nvidia-smi") else None
|
|
301
|
+
)
|
|
328
302
|
|
|
329
303
|
|
|
330
304
|
def parse_gpu_csv(text: str) -> list[GPU]:
|
|
@@ -349,8 +323,8 @@ def parse_gpu_csv(text: str) -> list[GPU]:
|
|
|
349
323
|
"total_bytes": int(total) << 20,
|
|
350
324
|
"free_bytes": int(free) << 20,
|
|
351
325
|
"used_bytes": int(used) << 20,
|
|
352
|
-
"util_percent": int(util) if util.isdigit() else None,
|
|
353
326
|
"driver_version": driver,
|
|
327
|
+
"util_percent": int(util) if util.isdigit() else None,
|
|
354
328
|
}
|
|
355
329
|
except ValueError:
|
|
356
330
|
continue
|
|
@@ -364,31 +338,22 @@ def _nvidia(errors: list[dict[str, str]]) -> tuple[dict[str, str] | None, list[G
|
|
|
364
338
|
exe = _nvidia_smi()
|
|
365
339
|
if exe is None:
|
|
366
340
|
return None, []
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
"--query-gpu=index,uuid,name,pci.bus_id,pci.device_id,memory.total,"
|
|
371
|
-
"memory.free,memory.used,utilization.gpu,driver_version,"
|
|
372
|
-
"pcie.link.gen.max,pcie.link.width.current",
|
|
373
|
-
"--format=csv,noheader,nounits",
|
|
374
|
-
]
|
|
341
|
+
fields = (
|
|
342
|
+
"index,uuid,name,pci.bus_id,pci.device_id,memory.total,memory.free,"
|
|
343
|
+
"memory.used,utilization.gpu,driver_version,pcie.link.gen.max,pcie.link.width.current"
|
|
375
344
|
)
|
|
345
|
+
rc, out, err = _run([exe, f"--query-gpu={fields}", "--format=csv,noheader,nounits"])
|
|
376
346
|
if rc != 0:
|
|
377
347
|
errors.append({"source": "nvidia-smi", "error": (err or out).strip()[:300]})
|
|
378
348
|
return None, []
|
|
379
349
|
gpus = parse_gpu_csv(out)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
"driver_version": gpus[0]["driver_version"] if gpus else "",
|
|
384
|
-
"cuda_version": m.group(1) if m else "",
|
|
385
|
-
}
|
|
386
|
-
return info, gpus
|
|
350
|
+
m = re.search(r"CUDA Version:\s*([\d.]+)", _run([exe])[1])
|
|
351
|
+
drv = gpus[0]["driver_version"] if gpus else ""
|
|
352
|
+
return {"driver_version": drv, "cuda_version": m.group(1) if m else ""}, gpus
|
|
387
353
|
|
|
388
354
|
|
|
389
355
|
def _cuda_pool() -> CudaPool | None:
|
|
390
|
-
"""Allocator pool and INTEGRATED attribute of CUDA device 0 via
|
|
391
|
-
Ported from Hermes: this is how unified-memory NVIDIA parts are told apart from discrete."""
|
|
356
|
+
"""Allocator pool and INTEGRATED attribute of CUDA device 0 via driver library, or None."""
|
|
392
357
|
for name in ("libcuda.so.1", "libcuda.so", "nvcuda.dll"):
|
|
393
358
|
try:
|
|
394
359
|
cuda = ctypes.CDLL(name)
|
|
@@ -398,27 +363,23 @@ def _cuda_pool() -> CudaPool | None:
|
|
|
398
363
|
else:
|
|
399
364
|
return None
|
|
400
365
|
try:
|
|
401
|
-
|
|
402
|
-
return None
|
|
403
|
-
dev = ctypes.c_int()
|
|
404
|
-
if cuda.cuDeviceGet(ctypes.byref(dev), 0) != 0:
|
|
405
|
-
return None
|
|
406
|
-
total = ctypes.c_size_t()
|
|
366
|
+
dev, total, attr, byref = ctypes.c_int(), ctypes.c_size_t(), ctypes.c_int(), ctypes.byref
|
|
407
367
|
getter = getattr(cuda, "cuDeviceTotalMem_v2", None) or cuda.cuDeviceTotalMem
|
|
408
|
-
if
|
|
368
|
+
if (
|
|
369
|
+
cuda.cuInit(0)
|
|
370
|
+
or cuda.cuDeviceGet(byref(dev), 0)
|
|
371
|
+
or getter(byref(total), dev)
|
|
372
|
+
or total.value <= 0
|
|
373
|
+
):
|
|
409
374
|
return None
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if cuda.cuDeviceGetAttribute(ctypes.byref(attr), _CU_DEVICE_ATTRIBUTE_INTEGRATED, dev) == 0:
|
|
413
|
-
integrated = bool(attr.value)
|
|
414
|
-
return {"total_bytes": total.value, "integrated": integrated}
|
|
375
|
+
ok_attr = cuda.cuDeviceGetAttribute(byref(attr), _CU_DEVICE_ATTRIBUTE_INTEGRATED, dev) == 0
|
|
376
|
+
return {"total_bytes": total.value, "integrated": bool(attr.value) if ok_attr else None}
|
|
415
377
|
except (OSError, AttributeError):
|
|
416
378
|
return None
|
|
417
379
|
|
|
418
380
|
|
|
419
381
|
def shared_libraries(names: Sequence[str] = HOST_LIBRARIES) -> dict[str, bool]:
|
|
420
|
-
"""Whether the dynamic loader finds each library on its default search path
|
|
421
|
-
an engine without its own copy has."""
|
|
382
|
+
"""Whether the dynamic loader finds each library on its default search path."""
|
|
422
383
|
found = {}
|
|
423
384
|
for name in names:
|
|
424
385
|
try:
|
|
@@ -461,37 +422,26 @@ def _get_json(url: str, timeout: float = 3) -> tuple[int, object]:
|
|
|
461
422
|
|
|
462
423
|
|
|
463
424
|
def probe_llama_server(port: int) -> Server | None:
|
|
464
|
-
"""Fingerprint
|
|
465
|
-
not /props). Ported from Hermes detect.py."""
|
|
425
|
+
"""Fingerprint llama-server via /props (Ollama and LM Studio answer /v1/models only)."""
|
|
466
426
|
root = f"http://127.0.0.1:{port}"
|
|
467
427
|
status, props = _get_json(root + "/props")
|
|
468
|
-
if
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return {
|
|
472
|
-
"port": port,
|
|
473
|
-
"base_url": root + "/v1",
|
|
474
|
-
"build_info": "",
|
|
475
|
-
"model_path": "",
|
|
476
|
-
"n_ctx": None,
|
|
477
|
-
"router_mode": False,
|
|
478
|
-
"auth_required": True,
|
|
479
|
-
"verified": False,
|
|
480
|
-
}
|
|
481
|
-
if status != 200 or not isinstance(props, dict) or not props.get("build_info"):
|
|
428
|
+
pdict = props if isinstance(props, dict) else {}
|
|
429
|
+
ok = status == 200 and bool(pdict)
|
|
430
|
+
if status != 401 and (not ok or not pdict.get("build_info")):
|
|
482
431
|
return None
|
|
483
|
-
dgs =
|
|
484
|
-
|
|
432
|
+
dgs = pdict.get("default_generation_settings")
|
|
433
|
+
m_st, models = _get_json(root + "/models") if ok else (0, None)
|
|
485
434
|
n_ctx = dgs.get("n_ctx") if isinstance(dgs, dict) else None
|
|
435
|
+
router = ok and m_st == 200 and isinstance(models, dict) and "data" in models
|
|
486
436
|
return {
|
|
487
437
|
"port": port,
|
|
488
438
|
"base_url": root + "/v1",
|
|
489
|
-
"build_info": str(
|
|
490
|
-
"model_path": str(
|
|
439
|
+
"build_info": str(pdict.get("build_info", "")) if ok else "",
|
|
440
|
+
"model_path": str(pdict.get("model_path", "")) if ok else "",
|
|
491
441
|
"n_ctx": n_ctx if type(n_ctx) is int else None,
|
|
492
|
-
"router_mode":
|
|
493
|
-
"auth_required":
|
|
494
|
-
"verified":
|
|
442
|
+
"router_mode": router,
|
|
443
|
+
"auth_required": status == 401,
|
|
444
|
+
"verified": ok,
|
|
495
445
|
}
|
|
496
446
|
|
|
497
447
|
|
|
@@ -504,30 +454,23 @@ def _flags(path: str, env: dict[str, str]) -> list[str]:
|
|
|
504
454
|
|
|
505
455
|
|
|
506
456
|
def _engines(extra_paths: Sequence[str]) -> list[OptionalEngine]:
|
|
507
|
-
|
|
508
|
-
which = shutil.which("llama-server")
|
|
509
|
-
if which:
|
|
510
|
-
candidates.append(which)
|
|
457
|
+
paths = [p for p in [shutil.which("llama-server")] if p]
|
|
511
458
|
for pattern in _ENGINE_GLOBS:
|
|
512
|
-
|
|
513
|
-
candidates.extend(extra_paths)
|
|
459
|
+
paths.extend(sorted(glob.glob(os.path.expanduser(pattern))))
|
|
514
460
|
engines: list[OptionalEngine] = []
|
|
515
|
-
for path in dict.fromkeys(os.path.realpath(p) for p in
|
|
461
|
+
for path in dict.fromkeys(os.path.realpath(p) for p in (*paths, *extra_paths)):
|
|
516
462
|
if not os.access(path, os.X_OK):
|
|
517
463
|
continue
|
|
518
|
-
env = dict(os.environ, CUDA_VISIBLE_DEVICES="") # version only; do not wake
|
|
519
|
-
|
|
520
|
-
env["LD_LIBRARY_PATH"] = directory + os.pathsep + env.get("LD_LIBRARY_PATH", "")
|
|
464
|
+
env = dict(os.environ, CUDA_VISIBLE_DEVICES="") # version only; do not wake GPUs
|
|
465
|
+
env["LD_LIBRARY_PATH"] = os.path.dirname(path) + os.pathsep + env.get("LD_LIBRARY_PATH", "")
|
|
521
466
|
rc, out, err = _run([path, "--version"], timeout=20, env=env)
|
|
522
467
|
text = out + err
|
|
523
468
|
build = version = commit = None
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
build = "b" +
|
|
529
|
-
elif legacy:
|
|
530
|
-
build, commit = "b" + legacy.group(1), legacy.group(2)
|
|
469
|
+
if sv := _SEMVER_RE.search(text):
|
|
470
|
+
version, commit = sv.group(1), sv.group(3)
|
|
471
|
+
build = "b" + sv.group(2) if int(sv.group(2)) > 1 else None
|
|
472
|
+
elif lg := _VERSION_RE.search(text):
|
|
473
|
+
build, commit = "b" + lg.group(1), lg.group(2)
|
|
531
474
|
engines.append(
|
|
532
475
|
{
|
|
533
476
|
"path": path,
|
|
@@ -558,8 +501,7 @@ def _at(root: str, path: str) -> str:
|
|
|
558
501
|
|
|
559
502
|
|
|
560
503
|
def environment(root: str = "/") -> str:
|
|
561
|
-
"""bare, container
|
|
562
|
-
a cgroup-v2 container with a private namespace looks like a bare host from there."""
|
|
504
|
+
"""bare, container, wsl or unknown (cgroup-v2 private namespace looks bare)."""
|
|
563
505
|
if any(os.path.exists(_at(root, p)) for p in ("/.dockerenv", "/run/.containerenv")):
|
|
564
506
|
return "container"
|
|
565
507
|
init = _text(_at(root, "/proc/1/cgroup"))
|
|
@@ -571,58 +513,49 @@ def environment(root: str = "/") -> str:
|
|
|
571
513
|
|
|
572
514
|
|
|
573
515
|
def cgroup_memory(root: str = "/") -> CgroupMemory | None:
|
|
574
|
-
"""
|
|
575
|
-
least headroom (limit minus usage). None where there is no cgroup (macOS)."""
|
|
516
|
+
"""Memory ceiling of this process's cgroup (tightest limit-usage headroom across ancestors)."""
|
|
576
517
|
rows = [r.split(":", 2) for r in (_text(_at(root, "/proc/self/cgroup")) or "").splitlines()]
|
|
577
|
-
for
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
def _tightest(mount: str, path: str, files: tuple[str, str], version: int) -> CgroupMemory:
|
|
518
|
+
v1 = next((r[2] for r in rows if len(r) == 3 and "memory" in r[1].split(",")), None)
|
|
519
|
+
if v1 is not None:
|
|
520
|
+
spec = ("/sys/fs/cgroup/memory", v1, ("memory.limit_in_bytes", "memory.usage_in_bytes"), 1)
|
|
521
|
+
elif (v2 := next((r[2] for r in rows if len(r) == 3 and r[:2] == ["0", ""]), None)) is not None:
|
|
522
|
+
spec = ("/sys/fs/cgroup", v2, ("memory.max", "memory.current"), 2)
|
|
523
|
+
else:
|
|
524
|
+
return None
|
|
525
|
+
return _tightest(_at(root, spec[0]), spec[1], spec[2], spec[3])
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _tightest(mount: str, path: str, files: tuple[str, str], v: int) -> CgroupMemory:
|
|
590
529
|
# Without a cgroup namespace the path is the host's, mounted as a container's root: walk up.
|
|
591
530
|
parts = [p for p in path.strip().split("/") if p]
|
|
592
|
-
levels = [
|
|
593
|
-
|
|
531
|
+
levels = [
|
|
532
|
+
d for n in range(len(parts), -1, -1) if os.path.isdir(d := os.path.join(mount, *parts[:n]))
|
|
533
|
+
]
|
|
594
534
|
readable = bool(levels)
|
|
595
|
-
|
|
535
|
+
best: tuple[int | None, int | None, int | None] = (None, None, None)
|
|
596
536
|
for level in levels:
|
|
597
537
|
try:
|
|
598
538
|
limit = int(_read(os.path.join(level, files[0])).strip())
|
|
599
539
|
except (FileNotFoundError, ValueError):
|
|
600
|
-
continue #
|
|
540
|
+
continue # root cgroup omits limit; v2 uses "max"
|
|
601
541
|
except OSError:
|
|
602
542
|
readable = False
|
|
603
543
|
continue
|
|
604
544
|
usage = _text(os.path.join(level, files[1])) or ""
|
|
605
545
|
used = int(usage) if usage.strip().isdigit() else None
|
|
606
|
-
if limit < _UNLIMITED and (
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
return {
|
|
610
|
-
"version": version,
|
|
611
|
-
"limit_bytes": limit_bytes,
|
|
612
|
-
"usage_bytes": usage_bytes,
|
|
613
|
-
"readable": readable,
|
|
614
|
-
}
|
|
546
|
+
if limit < _UNLIMITED and (best[0] is None or limit - (used or 0) < best[0]):
|
|
547
|
+
best = (limit - (used or 0), limit, used)
|
|
548
|
+
return {"version": v, "limit_bytes": best[1], "usage_bytes": best[2], "readable": readable}
|
|
615
549
|
|
|
616
550
|
|
|
617
551
|
def parse_field_csv(text: str) -> dict[int, str]:
|
|
618
|
-
"""{index: value} of an ``index,FIELD`` query; [N/A] and [Not Supported] cells
|
|
552
|
+
"""{index: value} of an ``index,FIELD`` query; [N/A] and [Not Supported] cells left out."""
|
|
619
553
|
rows = csv.reader(text.strip().splitlines(), skipinitialspace=True)
|
|
620
554
|
cells = {int(r[0]): r[1].strip() for r in rows if len(r) == 2 and r[0].strip().isdigit()}
|
|
621
555
|
return {i: v for i, v in cells.items() if v and not v.startswith("[")}
|
|
622
556
|
|
|
623
557
|
|
|
624
558
|
def _field(exe: str, name: str) -> dict[int, str]:
|
|
625
|
-
# Its own query: a driver that does not know the field fails it without losing the cards.
|
|
626
559
|
rc, out, _ = _run([exe, f"--query-gpu=index,{name}", "--format=csv,noheader,nounits"])
|
|
627
560
|
return parse_field_csv(out) if rc == 0 else {}
|
|
628
561
|
|
|
@@ -635,7 +568,6 @@ def _mark_mig(exe: str, gpus: list[GPU]) -> None:
|
|
|
635
568
|
|
|
636
569
|
|
|
637
570
|
def _mark_details(exe: str, gpus: list[GPU]) -> None:
|
|
638
|
-
"""Compute capability, reserved MiB and display state where the driver reports them."""
|
|
639
571
|
cap, reserved, display = (_field(exe, f) for f in DETAIL_FIELDS)
|
|
640
572
|
for gpu in gpus:
|
|
641
573
|
i = gpu["index"]
|
|
@@ -691,11 +623,14 @@ def collect(
|
|
|
691
623
|
errors.append({"source": "memory-probe", "error": "RAM measurement unavailable"})
|
|
692
624
|
nvidia, gpus = _nvidia(errors)
|
|
693
625
|
if gpus:
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
626
|
+
smi = _nvidia_smi() or "nvidia-smi"
|
|
627
|
+
_mark_mig(smi, gpus)
|
|
628
|
+
_mark_details(smi, gpus)
|
|
697
629
|
with ThreadPoolExecutor(max_workers=16) as pool: # Windows refuses a closed port after ~2 s
|
|
698
|
-
servers = [
|
|
630
|
+
servers = [
|
|
631
|
+
s for s in pool.map(probe_llama_server, dict.fromkeys([*ports, *SERVICE_PORTS])) if s
|
|
632
|
+
]
|
|
633
|
+
is_linux = sys.platform.startswith("linux")
|
|
699
634
|
facts: HostFacts = {
|
|
700
635
|
"schema": SCHEMA,
|
|
701
636
|
"collected_at": dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds"),
|
|
@@ -719,15 +654,15 @@ def collect(
|
|
|
719
654
|
"gpu_vendor_class": _gpu_vendor_class(),
|
|
720
655
|
"nvidia": nvidia,
|
|
721
656
|
"gpus": gpus,
|
|
722
|
-
"cuda_pool": _cuda_pool() if gpus or
|
|
657
|
+
"cuda_pool": _cuda_pool() if gpus or is_linux else None,
|
|
723
658
|
"llama_servers": servers,
|
|
724
659
|
"engines": _engines(engine_paths),
|
|
725
660
|
"disk": _disk(models_dir),
|
|
726
661
|
"service_manager": _service_manager(),
|
|
727
662
|
"errors": errors,
|
|
728
|
-
"environment": environment() if
|
|
663
|
+
"environment": environment() if is_linux else "bare",
|
|
729
664
|
"cgroup_memory": cgroup_memory(),
|
|
730
|
-
"shared_libraries": shared_libraries() if
|
|
665
|
+
"shared_libraries": shared_libraries() if is_linux else {},
|
|
731
666
|
}
|
|
732
667
|
if facts["platform"] == "darwin" and facts["arch"] == "arm64":
|
|
733
668
|
facts["metal"] = metal_probe.metal_device()
|
|
@@ -736,8 +671,7 @@ def collect(
|
|
|
736
671
|
|
|
737
672
|
def main(argv: list[str] | None = None) -> None:
|
|
738
673
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
739
|
-
|
|
740
|
-
parser.add_argument("--ports", default=listed, help="comma-separated loopback ports to read")
|
|
674
|
+
parser.add_argument("--ports", default=",".join(map(str, SERVICE_PORTS)), help="ports to read")
|
|
741
675
|
parser.add_argument("--models-dir", default="~/.local/share/localmodels/models")
|
|
742
676
|
parser.add_argument("--engine", action="append", default=[], help="extra llama-server path")
|
|
743
677
|
args = parser.parse_args(argv)
|