@simplexai/localmodels-linux-x64 0.1.0-dev.35 → 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 +124 -102
- 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 +15 -2
- package/modules/localmodels/catalog.json +235 -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/engines-strata-0.1.59.1.json +31 -0
- 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 +155 -7
- package/modules/localmodels/metal_probe.py +11 -7
- 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 +32 -3
- package/modules/localmodels/recommend_cli.py +14 -6
- package/modules/localmodels/remote_ops.py +65 -0
- package/modules/localmodels/remote_ops_download.py +2 -2
- package/modules/localmodels/remote_ops_prepare.py +19 -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 +76 -32
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +96 -270
- 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 +73 -18
- package/modules/localmodels/stack_plan.py +23 -5
- 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 +16 -10
- 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.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +120 -98
- 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.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
"""Private per-device decode measurements persisted from ``stack warm``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import datetime as dt
|
|
6
|
+
import json
|
|
7
|
+
import math
|
|
8
|
+
import os
|
|
9
|
+
import threading
|
|
10
|
+
from collections.abc import Mapping, Sequence
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Literal, TypedDict, TypeGuard
|
|
13
|
+
|
|
14
|
+
from localmodels import gpu_specs, hosts, metal, probe
|
|
15
|
+
from localmodels.probe import GPU, HostFacts
|
|
16
|
+
from localmodels.records import Plan
|
|
17
|
+
|
|
18
|
+
SCHEMA: Literal["localmodels.warm-speeds/v1"] = "localmodels.warm-speeds/v1"
|
|
19
|
+
_LOCK = threading.Lock()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WarmSpeedEntry(TypedDict):
|
|
23
|
+
hostname: str
|
|
24
|
+
platform: str
|
|
25
|
+
ram_total_bytes: int
|
|
26
|
+
gpu_name: str
|
|
27
|
+
model_id: str
|
|
28
|
+
quant: str
|
|
29
|
+
decode_tok_s: float
|
|
30
|
+
measured_at: str
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class WarmSpeedStore(TypedDict):
|
|
34
|
+
schema: Literal["localmodels.warm-speeds/v1"]
|
|
35
|
+
entries: dict[str, WarmSpeedEntry]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
KeyTuple = tuple[str, str, int, str, str, str]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def store_path() -> Path:
|
|
42
|
+
"""Private store of measured decode speeds under the controller state directory."""
|
|
43
|
+
return hosts.state_dir() / "warm_speeds.json"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _is_positive_int(value: object) -> TypeGuard[int]:
|
|
47
|
+
return isinstance(value, int) and not isinstance(value, bool) and value > 0
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _is_positive_speed(value: object) -> TypeGuard[int | float]:
|
|
51
|
+
if not isinstance(value, int | float) or isinstance(value, bool):
|
|
52
|
+
return False
|
|
53
|
+
try:
|
|
54
|
+
as_float = float(value)
|
|
55
|
+
except OverflowError:
|
|
56
|
+
return False
|
|
57
|
+
return math.isfinite(as_float) and as_float > 0
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _total_ram_bytes(facts: HostFacts) -> int | None:
|
|
61
|
+
ram = facts.get("ram")
|
|
62
|
+
total = ram.get("total_bytes") if isinstance(ram, Mapping) else None
|
|
63
|
+
if not _is_positive_int(total):
|
|
64
|
+
return None
|
|
65
|
+
cgroup = facts.get("cgroup_memory")
|
|
66
|
+
if facts.get("environment") == "container" and isinstance(cgroup, Mapping):
|
|
67
|
+
limit = cgroup.get("limit_bytes")
|
|
68
|
+
if _is_positive_int(limit):
|
|
69
|
+
total = min(total, limit)
|
|
70
|
+
return total
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _gpu_name(facts: HostFacts, gpu_index: int | None) -> str | None:
|
|
74
|
+
if gpu_index is None:
|
|
75
|
+
return ""
|
|
76
|
+
if not isinstance(gpu_index, int) or isinstance(gpu_index, bool):
|
|
77
|
+
return None
|
|
78
|
+
mac = metal.device(facts) if gpu_index == 0 else None
|
|
79
|
+
if mac is not None:
|
|
80
|
+
raw_gpu = str(mac.get("name") or "")
|
|
81
|
+
else:
|
|
82
|
+
card = next(
|
|
83
|
+
(
|
|
84
|
+
g
|
|
85
|
+
for g in (facts.get("gpus") or [])
|
|
86
|
+
if isinstance(g, Mapping) and g.get("index") == gpu_index
|
|
87
|
+
),
|
|
88
|
+
None,
|
|
89
|
+
)
|
|
90
|
+
if card is None:
|
|
91
|
+
return None
|
|
92
|
+
raw_gpu = str(card.get("name") or "")
|
|
93
|
+
normalized = gpu_specs.normalized(raw_gpu)
|
|
94
|
+
return normalized or None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _key_tuple(
|
|
98
|
+
facts: HostFacts, gpu_index: int | None, model_id: str, quant: str
|
|
99
|
+
) -> KeyTuple | None:
|
|
100
|
+
hostname = str(facts.get("hostname") or "").strip()
|
|
101
|
+
if not hostname or hostname == "simulated":
|
|
102
|
+
return None
|
|
103
|
+
platform = str(facts.get("platform") or "").strip()
|
|
104
|
+
if not platform:
|
|
105
|
+
return None
|
|
106
|
+
ram_total = _total_ram_bytes(facts)
|
|
107
|
+
if ram_total is None:
|
|
108
|
+
return None
|
|
109
|
+
gpu_name = _gpu_name(facts, gpu_index)
|
|
110
|
+
if gpu_name is None:
|
|
111
|
+
return None
|
|
112
|
+
mid = model_id.strip()
|
|
113
|
+
q = quant.strip()
|
|
114
|
+
if not mid or not q:
|
|
115
|
+
return None
|
|
116
|
+
return (hostname, platform, ram_total, gpu_name, mid, q)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _encode_key(key: KeyTuple) -> str:
|
|
120
|
+
return json.dumps(list(key), ensure_ascii=False, separators=(",", ":"))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _valid_entry(key: object, raw: object) -> WarmSpeedEntry | None:
|
|
124
|
+
if not isinstance(key, str) or not isinstance(raw, Mapping):
|
|
125
|
+
return None
|
|
126
|
+
hostname = raw.get("hostname")
|
|
127
|
+
platform = raw.get("platform")
|
|
128
|
+
ram_total = raw.get("ram_total_bytes")
|
|
129
|
+
gpu_name = raw.get("gpu_name")
|
|
130
|
+
model_id = raw.get("model_id")
|
|
131
|
+
quant = raw.get("quant")
|
|
132
|
+
decode_tok_s = raw.get("decode_tok_s")
|
|
133
|
+
measured_at = raw.get("measured_at")
|
|
134
|
+
if not (
|
|
135
|
+
isinstance(hostname, str)
|
|
136
|
+
and hostname
|
|
137
|
+
and hostname != "simulated"
|
|
138
|
+
and isinstance(platform, str)
|
|
139
|
+
and platform
|
|
140
|
+
and _is_positive_int(ram_total)
|
|
141
|
+
and isinstance(gpu_name, str)
|
|
142
|
+
and isinstance(model_id, str)
|
|
143
|
+
and model_id
|
|
144
|
+
and isinstance(quant, str)
|
|
145
|
+
and quant
|
|
146
|
+
and _is_positive_speed(decode_tok_s)
|
|
147
|
+
and isinstance(measured_at, str)
|
|
148
|
+
):
|
|
149
|
+
return None
|
|
150
|
+
expected = _encode_key((hostname, platform, ram_total, gpu_name, model_id, quant))
|
|
151
|
+
if key != expected:
|
|
152
|
+
return None
|
|
153
|
+
return {
|
|
154
|
+
"hostname": hostname,
|
|
155
|
+
"platform": platform,
|
|
156
|
+
"ram_total_bytes": ram_total,
|
|
157
|
+
"gpu_name": gpu_name,
|
|
158
|
+
"model_id": model_id,
|
|
159
|
+
"quant": quant,
|
|
160
|
+
"decode_tok_s": float(decode_tok_s),
|
|
161
|
+
"measured_at": measured_at,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _load_entries() -> dict[str, WarmSpeedEntry]:
|
|
166
|
+
try:
|
|
167
|
+
raw = json.loads(store_path().read_text(encoding="utf-8"))
|
|
168
|
+
except (OSError, UnicodeError, ValueError):
|
|
169
|
+
return {}
|
|
170
|
+
if not isinstance(raw, dict) or raw.get("schema") != SCHEMA:
|
|
171
|
+
return {}
|
|
172
|
+
entries = raw.get("entries")
|
|
173
|
+
if not isinstance(entries, dict):
|
|
174
|
+
return {}
|
|
175
|
+
loaded: dict[str, WarmSpeedEntry] = {}
|
|
176
|
+
for key, value in entries.items():
|
|
177
|
+
valid = _valid_entry(key, value)
|
|
178
|
+
if valid is not None:
|
|
179
|
+
loaded[key] = valid
|
|
180
|
+
return loaded
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def record(
|
|
184
|
+
facts: HostFacts,
|
|
185
|
+
gpu_index: int | None,
|
|
186
|
+
model_id: str,
|
|
187
|
+
quant: str,
|
|
188
|
+
decode_tok_s: float,
|
|
189
|
+
) -> bool:
|
|
190
|
+
"""Persist a positive same-device decode measurement atomically as 0600 JSON."""
|
|
191
|
+
if not _is_positive_speed(decode_tok_s):
|
|
192
|
+
return False
|
|
193
|
+
key = _key_tuple(facts, gpu_index, model_id, quant)
|
|
194
|
+
if key is None:
|
|
195
|
+
return False
|
|
196
|
+
encoded = _encode_key(key)
|
|
197
|
+
entry: WarmSpeedEntry = {
|
|
198
|
+
"hostname": key[0],
|
|
199
|
+
"platform": key[1],
|
|
200
|
+
"ram_total_bytes": key[2],
|
|
201
|
+
"gpu_name": key[3],
|
|
202
|
+
"model_id": key[4],
|
|
203
|
+
"quant": key[5],
|
|
204
|
+
"decode_tok_s": float(decode_tok_s),
|
|
205
|
+
"measured_at": dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds"),
|
|
206
|
+
}
|
|
207
|
+
with _LOCK:
|
|
208
|
+
entries = _load_entries()
|
|
209
|
+
entries[encoded] = entry
|
|
210
|
+
doc: WarmSpeedStore = {"schema": SCHEMA, "entries": entries}
|
|
211
|
+
hosts.save_private(store_path(), doc)
|
|
212
|
+
return True
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def lookup(facts: HostFacts, gpu_index: int, model_id: str, quant: str) -> float | None:
|
|
216
|
+
"""Return a positive measured decode speed matching this device and model, else None."""
|
|
217
|
+
key = _key_tuple(facts, gpu_index, model_id, quant)
|
|
218
|
+
if key is None:
|
|
219
|
+
return None
|
|
220
|
+
entry = _load_entries().get(_encode_key(key))
|
|
221
|
+
return float(entry["decode_tok_s"]) if entry is not None else None
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def apply_fit_measurement(facts: HostFacts, gpu_index: int, fit: Any) -> None:
|
|
225
|
+
"""Overlay a same-device warm measurement onto a ``stack_hardware.llm_fits`` entry."""
|
|
226
|
+
model_id = fit.get("id")
|
|
227
|
+
quant = fit.get("quant")
|
|
228
|
+
if not isinstance(model_id, str) or not isinstance(quant, str):
|
|
229
|
+
return
|
|
230
|
+
measured = lookup(facts, gpu_index, model_id, quant)
|
|
231
|
+
if measured is not None:
|
|
232
|
+
fit["decode_tok_s"] = round(measured, 1)
|
|
233
|
+
fit["decode_basis"] = "measured-decode"
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _resolve_legacy_gpu(
|
|
237
|
+
card_spec: Mapping[str, Any], host_gpus: Sequence[Mapping[str, Any]]
|
|
238
|
+
) -> tuple[bool, int | None]:
|
|
239
|
+
idx = card_spec.get("index")
|
|
240
|
+
spec_name = gpu_specs.normalized(str(card_spec.get("name") or ""))
|
|
241
|
+
if not isinstance(idx, int) or isinstance(idx, bool) or not spec_name:
|
|
242
|
+
return False, None
|
|
243
|
+
matched = next((g for g in host_gpus if g.get("index") == idx), None)
|
|
244
|
+
if matched is None or str(matched.get("uuid") or "").strip():
|
|
245
|
+
return False, None
|
|
246
|
+
if gpu_specs.normalized(str(matched.get("name") or "")) != spec_name:
|
|
247
|
+
return False, None
|
|
248
|
+
return True, idx
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _cuda_env(part: Plan) -> str:
|
|
252
|
+
env = part.get("service", {}).get("env")
|
|
253
|
+
raw_cuda = env.get("CUDA_VISIBLE_DEVICES") if isinstance(env, Mapping) else None
|
|
254
|
+
return raw_cuda.strip() if isinstance(raw_cuda, str) else ""
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _resolve_part_gpu(part: Plan, facts: HostFacts) -> tuple[bool, int | None]:
|
|
258
|
+
placement = part["placement"]
|
|
259
|
+
if placement.get("pooled"):
|
|
260
|
+
return False, None
|
|
261
|
+
raw_gpus = placement.get("gpus")
|
|
262
|
+
if isinstance(raw_gpus, list) and len(raw_gpus) > 1:
|
|
263
|
+
return False, None
|
|
264
|
+
cuda_dev = _cuda_env(part)
|
|
265
|
+
if "," in cuda_dev:
|
|
266
|
+
return False, None
|
|
267
|
+
if metal.on_device(placement):
|
|
268
|
+
return (True, 0) if metal.device(facts) is not None else (False, None)
|
|
269
|
+
if raw_gpus in (None, []) and not cuda_dev:
|
|
270
|
+
return True, None
|
|
271
|
+
if not (isinstance(raw_gpus, list) and len(raw_gpus) == 1 and isinstance(raw_gpus[0], Mapping)):
|
|
272
|
+
if raw_gpus not in (None, []):
|
|
273
|
+
return False, None
|
|
274
|
+
card_spec: Mapping[str, Any] = {}
|
|
275
|
+
else:
|
|
276
|
+
card_spec = raw_gpus[0]
|
|
277
|
+
place_uuid = str(card_spec.get("uuid") or "").strip()
|
|
278
|
+
if cuda_dev and place_uuid and cuda_dev != place_uuid:
|
|
279
|
+
return False, None
|
|
280
|
+
target_uuid = cuda_dev or place_uuid
|
|
281
|
+
host_gpus = [g for g in (facts.get("gpus") or []) if isinstance(g, Mapping)]
|
|
282
|
+
if not target_uuid:
|
|
283
|
+
return _resolve_legacy_gpu(card_spec, host_gpus)
|
|
284
|
+
matched = next(
|
|
285
|
+
(g for g in host_gpus if str(g.get("uuid") or "").strip() == target_uuid),
|
|
286
|
+
None,
|
|
287
|
+
)
|
|
288
|
+
if matched is None:
|
|
289
|
+
return False, None
|
|
290
|
+
idx = matched.get("index")
|
|
291
|
+
if not isinstance(idx, int) or isinstance(idx, bool):
|
|
292
|
+
return False, None
|
|
293
|
+
return True, idx
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _gpu_card(
|
|
297
|
+
index: int, uuid: str, name: str, total: int = 0, free: int = 0, used: int = 0
|
|
298
|
+
) -> GPU:
|
|
299
|
+
return {
|
|
300
|
+
"index": index,
|
|
301
|
+
"uuid": uuid,
|
|
302
|
+
"name": name,
|
|
303
|
+
"vendor": "nvidia",
|
|
304
|
+
"pci_bus_id": "",
|
|
305
|
+
"pci_device_id": None,
|
|
306
|
+
"total_bytes": total,
|
|
307
|
+
"free_bytes": free,
|
|
308
|
+
"used_bytes": used,
|
|
309
|
+
"util_percent": None,
|
|
310
|
+
"driver_version": "",
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _single_placed_card(part: Plan) -> tuple[int, str, str] | None:
|
|
315
|
+
raw_gpus = part["placement"].get("gpus")
|
|
316
|
+
if not (isinstance(raw_gpus, list) and len(raw_gpus) == 1 and isinstance(raw_gpus[0], Mapping)):
|
|
317
|
+
return None
|
|
318
|
+
card = raw_gpus[0]
|
|
319
|
+
idx = card.get("index")
|
|
320
|
+
if not isinstance(idx, int) or isinstance(idx, bool):
|
|
321
|
+
return None
|
|
322
|
+
name = str(card.get("name") or "")
|
|
323
|
+
cuda_dev = _cuda_env(part)
|
|
324
|
+
uuid = str(card.get("uuid") or "").strip() or ("" if "," in cuda_dev else cuda_dev)
|
|
325
|
+
return idx, name, uuid
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def _part_uuid_by_card(parts: Sequence[tuple[str, Plan]]) -> dict[tuple[int, str], str]:
|
|
329
|
+
found: dict[tuple[int, str], str] = {}
|
|
330
|
+
for _, part in parts:
|
|
331
|
+
placed = _single_placed_card(part)
|
|
332
|
+
if placed is None:
|
|
333
|
+
continue
|
|
334
|
+
idx, name, uuid = placed
|
|
335
|
+
norm = gpu_specs.normalized(name)
|
|
336
|
+
if norm and uuid:
|
|
337
|
+
found.setdefault((idx, norm), uuid)
|
|
338
|
+
return found
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _cards_from_parts(
|
|
342
|
+
parts: Sequence[tuple[str, Plan]],
|
|
343
|
+
) -> tuple[list[GPU], dict[str, object] | None]:
|
|
344
|
+
gpus: list[GPU] = []
|
|
345
|
+
metal_doc: dict[str, object] | None = None
|
|
346
|
+
for _, part in parts:
|
|
347
|
+
placed = _single_placed_card(part)
|
|
348
|
+
if placed is None:
|
|
349
|
+
continue
|
|
350
|
+
idx, name, uuid = placed
|
|
351
|
+
if uuid == metal.METAL_UUID and metal_doc is None:
|
|
352
|
+
metal_doc = {"name": name, "unified_memory": True}
|
|
353
|
+
elif name and not any(g["index"] == idx for g in gpus):
|
|
354
|
+
gpus.append(_gpu_card(idx, uuid, name))
|
|
355
|
+
return gpus, metal_doc
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _cards_from_hardware(
|
|
359
|
+
hardware: Mapping[str, Any],
|
|
360
|
+
parts: Sequence[tuple[str, Plan]],
|
|
361
|
+
) -> tuple[list[GPU], dict[str, object] | None, str]:
|
|
362
|
+
cards = hardware.get("cards") or []
|
|
363
|
+
part_uuids = _part_uuid_by_card(parts)
|
|
364
|
+
metal_card = next(
|
|
365
|
+
(c for c in cards if isinstance(c, Mapping) and c.get("uuid") == metal.METAL_UUID), None
|
|
366
|
+
)
|
|
367
|
+
gpus: list[GPU] = []
|
|
368
|
+
for c in cards:
|
|
369
|
+
if not isinstance(c, Mapping) or c.get("uuid") == metal.METAL_UUID:
|
|
370
|
+
continue
|
|
371
|
+
idx = int(c["index"])
|
|
372
|
+
name = str(c["name"])
|
|
373
|
+
uuid = str(c.get("uuid") or "") or part_uuids.get((idx, gpu_specs.normalized(name)), "")
|
|
374
|
+
gpus.append(
|
|
375
|
+
_gpu_card(
|
|
376
|
+
idx,
|
|
377
|
+
uuid,
|
|
378
|
+
name,
|
|
379
|
+
int(c["total_bytes"]),
|
|
380
|
+
int(c["free_bytes"]),
|
|
381
|
+
int(c["used_bytes"]),
|
|
382
|
+
)
|
|
383
|
+
)
|
|
384
|
+
metal_doc: dict[str, object] | None = (
|
|
385
|
+
{
|
|
386
|
+
"name": str(metal_card["name"]),
|
|
387
|
+
"unified_memory": True,
|
|
388
|
+
"recommended_max_working_set_bytes": int(metal_card["total_bytes"]),
|
|
389
|
+
}
|
|
390
|
+
if metal_card is not None
|
|
391
|
+
else None
|
|
392
|
+
)
|
|
393
|
+
arch = str(hardware.get("arch") or "") or ("arm64" if metal_doc is not None else "")
|
|
394
|
+
return gpus, metal_doc, arch
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _live_ram_basis(
|
|
398
|
+
platform: str, raw_total_ram: int
|
|
399
|
+
) -> tuple[int, str, probe.CgroupMemory | None]:
|
|
400
|
+
if platform.startswith("linux"):
|
|
401
|
+
env_kind = probe.environment()
|
|
402
|
+
if env_kind == "container":
|
|
403
|
+
live_cg = probe.cgroup_memory()
|
|
404
|
+
limit = live_cg.get("limit_bytes") if live_cg is not None else None
|
|
405
|
+
effective = min(raw_total_ram, limit) if _is_positive_int(limit) else raw_total_ram
|
|
406
|
+
return effective, "container", live_cg
|
|
407
|
+
return raw_total_ram, env_kind, None
|
|
408
|
+
return raw_total_ram, "bare", None
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _warm_facts(
|
|
412
|
+
plan: Mapping[str, Any],
|
|
413
|
+
report: Mapping[str, Any],
|
|
414
|
+
parts: Sequence[tuple[str, Plan]],
|
|
415
|
+
) -> HostFacts | None:
|
|
416
|
+
hostname = str(report.get("hostname") or "")
|
|
417
|
+
platform = str(report.get("platform") or "")
|
|
418
|
+
if not hostname or hostname == "simulated" or plan.get("hostname") != hostname:
|
|
419
|
+
return None
|
|
420
|
+
mem_before, mem_after = report["memory_before"], report["memory_after"]
|
|
421
|
+
raw_total_ram = mem_before.get("total_bytes")
|
|
422
|
+
if not _is_positive_int(raw_total_ram):
|
|
423
|
+
return None
|
|
424
|
+
hardware = plan.get("hardware")
|
|
425
|
+
hw_ram: int | None = None
|
|
426
|
+
if isinstance(hardware, Mapping):
|
|
427
|
+
if hardware.get("platform") and hardware["platform"] != platform:
|
|
428
|
+
return None
|
|
429
|
+
if hardware.get("assumed_unified_bytes") is None:
|
|
430
|
+
cand = hardware.get("ram_total_bytes")
|
|
431
|
+
if not _is_positive_int(cand):
|
|
432
|
+
return None
|
|
433
|
+
hw_ram = cand
|
|
434
|
+
live_effective_ram, env_kind, cgroup_doc = _live_ram_basis(platform, raw_total_ram)
|
|
435
|
+
if hw_ram is not None and hw_ram != live_effective_ram:
|
|
436
|
+
return None
|
|
437
|
+
cached = hosts.load_facts(hosts.LOCAL_ID)
|
|
438
|
+
if (
|
|
439
|
+
cached is not None
|
|
440
|
+
and cached.get("hostname") == hostname
|
|
441
|
+
and cached.get("platform") == platform
|
|
442
|
+
and cached.get("ram", {}).get("total_bytes") == raw_total_ram
|
|
443
|
+
and _total_ram_bytes(cached) == live_effective_ram
|
|
444
|
+
):
|
|
445
|
+
return cached
|
|
446
|
+
if isinstance(hardware, Mapping):
|
|
447
|
+
gpus, metal_doc, arch = _cards_from_hardware(hardware, parts)
|
|
448
|
+
else:
|
|
449
|
+
gpus, metal_doc = _cards_from_parts(parts)
|
|
450
|
+
arch = "arm64" if metal_doc is not None else ""
|
|
451
|
+
return {
|
|
452
|
+
"schema": probe.SCHEMA,
|
|
453
|
+
"collected_at": "",
|
|
454
|
+
"hostname": hostname,
|
|
455
|
+
"user": "",
|
|
456
|
+
"platform": platform,
|
|
457
|
+
"arch": arch,
|
|
458
|
+
"os": {},
|
|
459
|
+
"python": "",
|
|
460
|
+
"cpu": {},
|
|
461
|
+
"ram": {
|
|
462
|
+
"total_bytes": raw_total_ram,
|
|
463
|
+
"available_bytes": int(mem_after["available_bytes"]),
|
|
464
|
+
},
|
|
465
|
+
"gpu_vendor_class": "apple_silicon" if metal_doc is not None else "nvidia",
|
|
466
|
+
"nvidia": None,
|
|
467
|
+
"gpus": gpus,
|
|
468
|
+
"cuda_pool": None,
|
|
469
|
+
"llama_servers": [],
|
|
470
|
+
"engines": [],
|
|
471
|
+
"disk": {"path": "", "free_bytes": None, "total_bytes": None},
|
|
472
|
+
"service_manager": {"kind": "nohup", "linger": False},
|
|
473
|
+
"errors": [],
|
|
474
|
+
"environment": env_kind,
|
|
475
|
+
"cgroup_memory": cgroup_doc,
|
|
476
|
+
"metal": metal_doc,
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def persist_warm(
|
|
481
|
+
plan: Mapping[str, Any],
|
|
482
|
+
report: Mapping[str, Any],
|
|
483
|
+
parts: Sequence[tuple[str, Plan]],
|
|
484
|
+
warmed: Mapping[str, Mapping[str, Any]],
|
|
485
|
+
) -> None:
|
|
486
|
+
"""Persist ``warm.json`` in the LLM deployment directory and update ``warm_speeds.json``."""
|
|
487
|
+
llm_report = report.get("llm")
|
|
488
|
+
if isinstance(llm_report, Mapping) and llm_report.get("ok") is True:
|
|
489
|
+
deploy_dir = Path(os.path.expanduser(str(plan["llm"]["service"]["deploy_dir"])))
|
|
490
|
+
if deploy_dir.is_dir():
|
|
491
|
+
try:
|
|
492
|
+
hosts.save_private(deploy_dir / "warm.json", report)
|
|
493
|
+
except OSError:
|
|
494
|
+
pass
|
|
495
|
+
facts = _warm_facts(plan, report, parts)
|
|
496
|
+
if facts is None:
|
|
497
|
+
return
|
|
498
|
+
for role, part in parts:
|
|
499
|
+
item = warmed.get(role)
|
|
500
|
+
if item is None or item.get("ok") is not True:
|
|
501
|
+
continue
|
|
502
|
+
speed = item.get("decode_tok_s")
|
|
503
|
+
if not _is_positive_speed(speed):
|
|
504
|
+
continue
|
|
505
|
+
ok_gpu, gpu_index = _resolve_part_gpu(part, facts)
|
|
506
|
+
if not ok_gpu:
|
|
507
|
+
continue
|
|
508
|
+
try:
|
|
509
|
+
record(
|
|
510
|
+
facts,
|
|
511
|
+
gpu_index,
|
|
512
|
+
str(part["model"]["id"]),
|
|
513
|
+
str(part["model"]["quant"]),
|
|
514
|
+
float(speed),
|
|
515
|
+
)
|
|
516
|
+
except OSError:
|
|
517
|
+
pass
|
|
@@ -14,7 +14,7 @@ import os
|
|
|
14
14
|
import sys
|
|
15
15
|
|
|
16
16
|
from localmodels.tui_screen import Tui
|
|
17
|
-
from localmodels.tui_views import Style, pad
|
|
17
|
+
from localmodels.tui_views import Style, pad, width
|
|
18
18
|
|
|
19
19
|
_SPECIAL = {
|
|
20
20
|
curses.KEY_UP: "up",
|
|
@@ -29,6 +29,7 @@ _SPECIAL = {
|
|
|
29
29
|
curses.KEY_BACKSPACE: "backspace",
|
|
30
30
|
curses.KEY_DC: "backspace",
|
|
31
31
|
curses.KEY_BTAB: "btab",
|
|
32
|
+
curses.KEY_RESIZE: "resize",
|
|
32
33
|
}
|
|
33
34
|
_CONTROL = {
|
|
34
35
|
"\n": "enter",
|
|
@@ -56,6 +57,7 @@ def _attributes() -> dict[Style, int]:
|
|
|
56
57
|
"warn": curses.A_BOLD,
|
|
57
58
|
"error": curses.A_BOLD,
|
|
58
59
|
"select": curses.A_REVERSE,
|
|
60
|
+
"tabs": curses.A_BOLD | curses.A_REVERSE,
|
|
59
61
|
}
|
|
60
62
|
if curses.has_colors():
|
|
61
63
|
curses.start_color()
|
|
@@ -73,9 +75,28 @@ def _attributes() -> dict[Style, int]:
|
|
|
73
75
|
for pair, (style, color) in enumerate(colors, start=1):
|
|
74
76
|
curses.init_pair(pair, color, background)
|
|
75
77
|
attrs[style] |= curses.color_pair(pair)
|
|
78
|
+
attrs["tabs"] |= attrs["title"] & curses.A_COLOR
|
|
76
79
|
return attrs
|
|
77
80
|
|
|
78
81
|
|
|
82
|
+
def _draw_line(
|
|
83
|
+
screen: curses.window, y: int, cols: int, text: str, style: Style, attrs: dict[Style, int]
|
|
84
|
+
) -> None:
|
|
85
|
+
if style == "tabs" and "[" in text and "]" in text:
|
|
86
|
+
before, _, rest = text.partition("[")
|
|
87
|
+
active, _, after = rest.partition("]")
|
|
88
|
+
segments = [(before, attrs["dim"]), (f"[{active}]", attrs["tabs"]), (after, attrs["dim"])]
|
|
89
|
+
x = 0
|
|
90
|
+
for part, attr in segments:
|
|
91
|
+
if not part or x >= cols - 1:
|
|
92
|
+
continue
|
|
93
|
+
screen.addstr(y, x, part, attr)
|
|
94
|
+
x += width(part)
|
|
95
|
+
return
|
|
96
|
+
line = pad(text, cols - 1) if style == "select" else text
|
|
97
|
+
screen.addstr(y, 0, line, attrs[style])
|
|
98
|
+
|
|
99
|
+
|
|
79
100
|
def _loop(screen: curses.window) -> None:
|
|
80
101
|
try:
|
|
81
102
|
curses.curs_set(0)
|
|
@@ -91,14 +112,17 @@ def _loop(screen: curses.window) -> None:
|
|
|
91
112
|
rows, cols = screen.getmaxyx()
|
|
92
113
|
screen.erase()
|
|
93
114
|
for y, (text, style) in enumerate(tui.render(cols - 1, rows)):
|
|
94
|
-
line = pad(text, cols - 1) if style == "select" else text
|
|
95
115
|
try:
|
|
96
|
-
screen
|
|
116
|
+
_draw_line(screen, y, cols, text, style, attrs)
|
|
97
117
|
except curses.error: # the last cell of the screen, or a terminal resized mid-draw
|
|
98
118
|
pass
|
|
99
119
|
screen.refresh()
|
|
100
120
|
try:
|
|
101
|
-
|
|
121
|
+
key = key_name(screen.get_wch())
|
|
122
|
+
if key == "resize":
|
|
123
|
+
curses.update_lines_cols()
|
|
124
|
+
screen.clear()
|
|
125
|
+
tui.handle(key)
|
|
102
126
|
except curses.error: # timeout: no key
|
|
103
127
|
continue
|
|
104
128
|
except KeyboardInterrupt:
|