@simplexai/localmodels-linux-x64 0.1.0-dev.39 → 0.1.0-dev.42
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 +70 -69
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/auth_proxy.py +74 -16
- package/modules/localmodels/budget.py +27 -18
- package/modules/localmodels/catalog.json +4 -130
- package/modules/localmodels/catalog.py +10 -0
- package/modules/localmodels/chat_template.py +35 -0
- package/modules/localmodels/debug_mode.py +8 -0
- package/modules/localmodels/deploy.py +7 -1
- package/modules/localmodels/download-mirrors.json +0 -8
- package/modules/localmodels/gateway.py +2 -0
- package/modules/localmodels/gateway_bifrost.py +3 -0
- package/modules/localmodels/gateway_home.py +132 -0
- package/modules/localmodels/harness.py +48 -13
- package/modules/localmodels/harness_probe.py +5 -1
- package/modules/localmodels/library_gateway.py +13 -2
- package/modules/localmodels/library_jobs.py +63 -6
- package/modules/localmodels/library_model.py +60 -15
- package/modules/localmodels/library_pricing.py +99 -26
- package/modules/localmodels/library_serve.py +69 -14
- package/modules/localmodels/library_state.py +33 -2
- package/modules/localmodels/library_status.py +109 -13
- package/modules/localmodels/llm_rank.py +16 -27
- package/modules/localmodels/metal.py +29 -12
- package/modules/localmodels/probe.py +4 -0
- package/modules/localmodels/recommend.py +30 -13
- package/modules/localmodels/recommend_cli.py +6 -4
- package/modules/localmodels/remote_ops_download.py +75 -14
- package/modules/localmodels/remote_ops_remove.py +15 -0
- package/modules/localmodels/remote_ops_service.py +10 -0
- package/modules/localmodels/reuse.py +31 -5
- package/modules/localmodels/runtime_cli.py +61 -40
- package/modules/localmodels/runtime_discovery.py +38 -10
- package/modules/localmodels/runtime_install.py +31 -10
- package/modules/localmodels/runtime_io.py +4 -3
- package/modules/localmodels/runtime_pi.py +71 -19
- package/modules/localmodels/runtime_process.py +4 -2
- package/modules/localmodels/service_deployment.py +5 -3
- package/modules/localmodels/service_probe.py +84 -27
- package/modules/localmodels/setup_inspection.py +104 -25
- package/modules/localmodels/setup_text.py +12 -5
- package/modules/localmodels/sizecalc.py +0 -2
- package/modules/localmodels/slot_cache.py +467 -0
- package/modules/localmodels/stack_binding.py +90 -13
- package/modules/localmodels/stack_capacity.py +3 -3
- package/modules/localmodels/stack_card.py +1 -0
- package/modules/localmodels/stack_compose.py +2 -3
- package/modules/localmodels/stack_down.py +22 -7
- package/modules/localmodels/stack_events.py +59 -0
- package/modules/localmodels/stack_hardware.py +35 -29
- package/modules/localmodels/stack_hardware_text.py +40 -35
- package/modules/localmodels/stack_lifecycle.py +12 -3
- package/modules/localmodels/stack_mlx.py +4 -1
- package/modules/localmodels/stack_picks.py +6 -1
- package/modules/localmodels/stack_plan.py +1 -0
- package/modules/localmodels/stack_rollback.py +9 -4
- package/modules/localmodels/stack_summary.py +2 -0
- package/modules/localmodels/stack_up.py +27 -20
- package/modules/localmodels/stack_update.py +3 -1
- package/modules/localmodels/stack_warm.py +21 -11
- package/modules/localmodels/stack_warm_store.py +5 -16
- package/modules/localmodels/tools.json +1 -0
- package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/RECORD +67 -66
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-b12167.json +0 -26
- /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev39.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -73,6 +73,9 @@ class _JobSince20261113(TypedDict, total=False):
|
|
|
73
73
|
id: str # this operation's identity: a cancel or a release acts on this job, never another
|
|
74
74
|
needs: list[str] # every file the job relies on (writes or reuses): none is deleted under it
|
|
75
75
|
port: int # a load's port, reserved from admission until its record names it
|
|
76
|
+
source: str # download source label: huggingface | modelscope | custom | cache
|
|
77
|
+
connections: int # active parallel download connections
|
|
78
|
+
load_step: str # load sub-step: prepare | start | load | warm
|
|
76
79
|
|
|
77
80
|
|
|
78
81
|
class Job(_JobSince20261113):
|
|
@@ -237,13 +240,41 @@ class JobHandle:
|
|
|
237
240
|
self.job = job
|
|
238
241
|
self._written = 0.0
|
|
239
242
|
|
|
240
|
-
def update(
|
|
243
|
+
def update(
|
|
244
|
+
self,
|
|
245
|
+
phase: str,
|
|
246
|
+
done: int,
|
|
247
|
+
total: int,
|
|
248
|
+
bytes_per_second: int = 0,
|
|
249
|
+
*,
|
|
250
|
+
source: str | None = None,
|
|
251
|
+
connections: int | None = None,
|
|
252
|
+
load_step: str | None = None,
|
|
253
|
+
) -> None:
|
|
241
254
|
import time
|
|
242
255
|
|
|
256
|
+
prev = (self.job.get("phase"), self.job.get("load_step"), self.job.get("source"))
|
|
243
257
|
self.job["phase"], self.job["done"], self.job["total"] = phase, done, total
|
|
244
258
|
self.job["bytes_per_second"] = bytes_per_second
|
|
259
|
+
if phase == "download":
|
|
260
|
+
if source is not None:
|
|
261
|
+
self.job["source"] = source
|
|
262
|
+
else:
|
|
263
|
+
self.job.pop("source", None)
|
|
264
|
+
if connections is not None:
|
|
265
|
+
self.job["connections"] = connections
|
|
266
|
+
else:
|
|
267
|
+
self.job.pop("connections", None)
|
|
268
|
+
else:
|
|
269
|
+
self.job.pop("source", None)
|
|
270
|
+
self.job.pop("connections", None)
|
|
271
|
+
if phase in ("load", "warm") and load_step is not None:
|
|
272
|
+
self.job["load_step"] = load_step
|
|
273
|
+
else:
|
|
274
|
+
self.job.pop("load_step", None)
|
|
275
|
+
changed = (self.job.get("phase"), self.job.get("load_step"), self.job.get("source")) != prev
|
|
245
276
|
now = time.monotonic()
|
|
246
|
-
if now - self._written >= JOB_WRITE_EVERY_S or done >= total:
|
|
277
|
+
if changed or now - self._written >= JOB_WRITE_EVERY_S or done >= total:
|
|
247
278
|
self._written = now
|
|
248
279
|
self.job["updated_at"] = utc_now()
|
|
249
280
|
with contextlib.suppress(OSError):
|
|
@@ -16,16 +16,24 @@ from localmodels import (
|
|
|
16
16
|
library_gateway,
|
|
17
17
|
library_pricing,
|
|
18
18
|
library_state,
|
|
19
|
+
metal,
|
|
19
20
|
plan_envelope,
|
|
20
21
|
suite,
|
|
21
22
|
vision,
|
|
22
23
|
)
|
|
23
24
|
from localmodels import catalog as cat
|
|
24
25
|
from localmodels.library_model import (
|
|
26
|
+
DOWNLOAD_SOURCES,
|
|
27
|
+
LOAD_STEPS_PUBLIC,
|
|
25
28
|
STATUS_SCHEMA,
|
|
26
29
|
Availability,
|
|
30
|
+
Download,
|
|
31
|
+
DownloadSource,
|
|
27
32
|
Holder,
|
|
28
33
|
Host,
|
|
34
|
+
Load,
|
|
35
|
+
LoadStep,
|
|
36
|
+
MemoryPressure,
|
|
29
37
|
Pool,
|
|
30
38
|
Problem,
|
|
31
39
|
Row,
|
|
@@ -189,6 +197,75 @@ def card(model: Model, vision_on: bool) -> Row:
|
|
|
189
197
|
return cast(Row, {k: v for k, v in found.items() if v})
|
|
190
198
|
|
|
191
199
|
|
|
200
|
+
def _apply_live_fit(
|
|
201
|
+
lib: Library,
|
|
202
|
+
found: Row,
|
|
203
|
+
model: Model,
|
|
204
|
+
priced: Priced,
|
|
205
|
+
record: Record | None,
|
|
206
|
+
state: str,
|
|
207
|
+
memory: int,
|
|
208
|
+
) -> None:
|
|
209
|
+
if record is None:
|
|
210
|
+
fits = False if priced.fit == "none" else priced.fits_now
|
|
211
|
+
load_need, load_free = priced.load_need_bytes, priced.load_free_bytes
|
|
212
|
+
elif state in ("loaded", "loading"):
|
|
213
|
+
fits, load_need, load_free = True, 0, 0
|
|
214
|
+
else:
|
|
215
|
+
fits, load_need, load_free = library_pricing.live_fit(
|
|
216
|
+
lib.facts,
|
|
217
|
+
model,
|
|
218
|
+
record["pool"],
|
|
219
|
+
lib.base_dir,
|
|
220
|
+
lib.catalog,
|
|
221
|
+
lib.reserved(),
|
|
222
|
+
fallback_need=memory,
|
|
223
|
+
)
|
|
224
|
+
found["fits_now"] = fits
|
|
225
|
+
if not fits and found["pool"]:
|
|
226
|
+
found["load_need_bytes"] = load_need
|
|
227
|
+
found["load_free_bytes"] = load_free
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _downloading(job: Job) -> Download:
|
|
231
|
+
dl: Download = {
|
|
232
|
+
"step": "verify" if job["phase"] == "verify" else "download",
|
|
233
|
+
"done_bytes": job["done"],
|
|
234
|
+
"total_bytes": job["total"],
|
|
235
|
+
"bytes_per_second": job["bytes_per_second"],
|
|
236
|
+
}
|
|
237
|
+
if job["phase"] != "verify":
|
|
238
|
+
src = job.get("source")
|
|
239
|
+
if isinstance(src, str) and src in DOWNLOAD_SOURCES:
|
|
240
|
+
dl["source"] = cast(DownloadSource, src)
|
|
241
|
+
conns = job.get("connections")
|
|
242
|
+
if isinstance(conns, int) and not isinstance(conns, bool) and conns >= 0:
|
|
243
|
+
dl["connections"] = conns
|
|
244
|
+
return dl
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _loading(job: Job) -> Load:
|
|
248
|
+
if job["phase"] == "warm":
|
|
249
|
+
return {
|
|
250
|
+
"step": "warm",
|
|
251
|
+
"done_steps": min(7, 5 + max(0, job["done"])),
|
|
252
|
+
"total_steps": 7,
|
|
253
|
+
}
|
|
254
|
+
raw_total = job["total"] if job["total"] > 0 else 5
|
|
255
|
+
total_steps = raw_total + 2
|
|
256
|
+
done_steps = min(total_steps, max(0, job["done"]))
|
|
257
|
+
raw_step = job.get("load_step")
|
|
258
|
+
if isinstance(raw_step, str) and raw_step in LOAD_STEPS_PUBLIC:
|
|
259
|
+
step = cast(LoadStep, raw_step)
|
|
260
|
+
elif done_steps < 3:
|
|
261
|
+
step = "prepare"
|
|
262
|
+
elif done_steps == 3:
|
|
263
|
+
step = "start"
|
|
264
|
+
else:
|
|
265
|
+
step = "load"
|
|
266
|
+
return {"step": step, "done_steps": done_steps, "total_steps": total_steps}
|
|
267
|
+
|
|
268
|
+
|
|
192
269
|
def row(lib: Library, model: Model) -> Row:
|
|
193
270
|
record = lib.records.get(model.id)
|
|
194
271
|
priced = lib.judge(model)
|
|
@@ -229,14 +306,12 @@ def row(lib: Library, model: Model) -> Row:
|
|
|
229
306
|
else priced.pool,
|
|
230
307
|
"state": state, # type: ignore[typeddict-item]
|
|
231
308
|
}
|
|
309
|
+
_apply_live_fit(lib, found, model, priced, record, state, memory)
|
|
232
310
|
job, alive = lib.jobs.get(model.id, (None, False))
|
|
233
311
|
if state == "downloading" and job is not None and alive:
|
|
234
|
-
found["download"] =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
"total_bytes": job["total"],
|
|
238
|
-
"bytes_per_second": job["bytes_per_second"],
|
|
239
|
-
}
|
|
312
|
+
found["download"] = _downloading(job)
|
|
313
|
+
elif state == "loading" and job is not None and alive:
|
|
314
|
+
found["load"] = _loading(job)
|
|
240
315
|
found.update(card(model, found["vision"]))
|
|
241
316
|
if state != "absent":
|
|
242
317
|
if (selector := pi_model_of(model, record)) is not None:
|
|
@@ -300,22 +375,34 @@ def pools(lib: Library, rows: list[Row]) -> list[Pool]:
|
|
|
300
375
|
"bytes": _component_bytes(plan, pool),
|
|
301
376
|
}
|
|
302
377
|
)
|
|
303
|
-
|
|
378
|
+
now = library_pricing.live(lib.facts, lib.reserved())
|
|
304
379
|
found: list[Pool] = []
|
|
305
380
|
for pool, held in holders.items():
|
|
306
381
|
total = library_pricing.pool_total(lib.facts, pool)
|
|
307
|
-
|
|
382
|
+
free = library_pricing.pool_free(now, pool)
|
|
383
|
+
used = min(total, max(0, total - free))
|
|
308
384
|
found.append(
|
|
309
385
|
{
|
|
310
386
|
"id": pool,
|
|
311
387
|
"total_bytes": total,
|
|
312
|
-
"used_bytes":
|
|
388
|
+
"used_bytes": used,
|
|
313
389
|
"holders": held,
|
|
390
|
+
"reserve_bytes": library_pricing.pool_reserve(now, pool),
|
|
314
391
|
}
|
|
315
392
|
)
|
|
316
393
|
return found
|
|
317
394
|
|
|
318
395
|
|
|
396
|
+
def _pressure_label(level: object) -> MemoryPressure | None:
|
|
397
|
+
if not isinstance(level, int) or isinstance(level, bool):
|
|
398
|
+
return None
|
|
399
|
+
if level == 1:
|
|
400
|
+
return "normal"
|
|
401
|
+
if level == metal.PRESSURE_WARN:
|
|
402
|
+
return "warn"
|
|
403
|
+
return "critical"
|
|
404
|
+
|
|
405
|
+
|
|
319
406
|
def host(lib: Library) -> Host:
|
|
320
407
|
facts = lib.facts
|
|
321
408
|
shown = library_pricing.visible(facts) # the cards the pools may use
|
|
@@ -331,12 +418,13 @@ def host(lib: Library) -> Host:
|
|
|
331
418
|
engine_label = f"llama.cpp {engine.get('build') or ''}".strip()
|
|
332
419
|
if (kind := engine.get("backend")) in backend:
|
|
333
420
|
engine_label += f" · {backend[str(kind)]}"
|
|
334
|
-
|
|
421
|
+
found: Host = {
|
|
335
422
|
"platform": platform_name(facts),
|
|
336
423
|
"arch": ARCH.get(str(facts.get("arch")), str(facts.get("arch"))),
|
|
337
424
|
"os_label": os_label,
|
|
338
425
|
"engine_label": engine_label,
|
|
339
426
|
"ram_total_bytes": facts["ram"]["total_bytes"],
|
|
427
|
+
"ram_available_bytes": facts["ram"]["available_bytes"],
|
|
340
428
|
"disk_free_bytes": library_pricing.base_free(lib.base_dir),
|
|
341
429
|
"gpus": [
|
|
342
430
|
{
|
|
@@ -350,17 +438,25 @@ def host(lib: Library) -> Host:
|
|
|
350
438
|
if g.get("vendor") == "nvidia" and (shown is None or g["index"] in shown)
|
|
351
439
|
],
|
|
352
440
|
}
|
|
441
|
+
if (ws := metal.read_working_set(facts)) is not None and ws > 0:
|
|
442
|
+
found["metal_working_set_bytes"] = ws
|
|
443
|
+
if (pressure := _pressure_label(facts["ram"].get("pressure_level"))) is not None:
|
|
444
|
+
found["memory_pressure"] = pressure
|
|
445
|
+
return found
|
|
353
446
|
|
|
354
447
|
|
|
355
448
|
def build(lib: Library) -> Status:
|
|
356
449
|
models = lib.models()
|
|
357
450
|
rows = [row(lib, m) for m in models]
|
|
451
|
+
now = library_pricing.live(lib.facts, lib.reserved())
|
|
358
452
|
candidates = [
|
|
359
|
-
|
|
453
|
+
m
|
|
360
454
|
for m, r in zip(models, rows, strict=True)
|
|
361
|
-
if r["state"] == "absent"
|
|
455
|
+
if r["state"] == "absent"
|
|
456
|
+
and r["availability"]["downloadable"]
|
|
457
|
+
and r.get("fits_now") is True
|
|
362
458
|
]
|
|
363
|
-
chosen = library_pricing.recommend(
|
|
459
|
+
chosen = library_pricing.recommend(now, candidates)
|
|
364
460
|
for r in rows:
|
|
365
461
|
r["recommended"] = r["id"] == chosen
|
|
366
462
|
return {
|
|
@@ -16,11 +16,9 @@ from dataclasses import dataclass
|
|
|
16
16
|
from localmodels import metal, vision
|
|
17
17
|
from localmodels.budget import HARNESS_RAM, RAM_FLOOR, host_ram
|
|
18
18
|
from localmodels.catalog import (
|
|
19
|
-
PLEASANT_FLOOR_TOK_S,
|
|
20
19
|
CatalogEntry,
|
|
21
20
|
DecisionRecipe,
|
|
22
21
|
QuantVariant,
|
|
23
|
-
VariantChoice,
|
|
24
22
|
decision_components,
|
|
25
23
|
hardware_key,
|
|
26
24
|
predicted_decode_tok_s,
|
|
@@ -77,16 +75,14 @@ PRODUCT_DEFAULTS = {
|
|
|
77
75
|
# every 16 GB Mac, stays on the ladder rather than a lower-scored model such as Qwen3.6-35B-A3B.
|
|
78
76
|
MAC_DEFAULT_YIELD_SCORE = 50
|
|
79
77
|
|
|
80
|
-
# The Mac small-memory ladder (roadmap
|
|
81
|
-
#
|
|
82
|
-
#
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
|
|
78
|
+
# The Mac small-memory ladder (roadmap decisions 57 and 61, user-selected; replaces decision
|
|
79
|
+
# 39's LFM3-1.7B): on every Apple Silicon Mac of MAC_LADDER_MIN_BYTES or more, while no validated
|
|
80
|
+
# model scoring MAC_DEFAULT_YIELD_SCORE or more fits, Spark-X2.6-4B Q4_K_M is the sole rung and
|
|
81
|
+
# minimum automatic floor (1.7B is below the 4B floor, so Macs with less free memory refuse
|
|
82
|
+
# rather than dropping to 1.7B). The rung is a candidate outside SimplexAI ranking: its catalog
|
|
83
|
+
# score is unranked (0) and never competes with installed scores.
|
|
84
|
+
MAC_LADDER = ("spark-x2.6-4b-q4km",)
|
|
86
85
|
MAC_LADDER_MIN_BYTES = 16 * metal.GIB
|
|
87
|
-
# --prefer fastest on a Mac below this much memory tries the small rung first (16 GB: the 1.7B);
|
|
88
|
-
# larger Macs try the 4B first (24 GB: Spark-X2.6-4B Q4_K_M), beside any validated model.
|
|
89
|
-
MAC_SMALL_BELOW_BYTES = 20 * metal.GIB
|
|
90
86
|
# Validated darwin entries the ladder replaces in automatic selection (decision 57): Ling-3.0-tiny
|
|
91
87
|
# (25) was the 32 GB+ fallback. Explicit --llm still installs it.
|
|
92
88
|
MAC_LADDER_REPLACES = frozenset({"ling-3.0-tiny"})
|
|
@@ -109,11 +105,10 @@ class MacLadder:
|
|
|
109
105
|
|
|
110
106
|
|
|
111
107
|
def mac_ladder(facts: HostFacts) -> MacLadder | None:
|
|
112
|
-
"""This Mac's ladder (
|
|
108
|
+
"""This Mac's ladder (decisions 57 and 61), or None off Apple Silicon and below 16 GB."""
|
|
113
109
|
if not metal.supported(facts) or facts["ram"]["total_bytes"] < MAC_LADDER_MIN_BYTES:
|
|
114
110
|
return None
|
|
115
|
-
|
|
116
|
-
return MacLadder(MAC_LADDER, tuple(reversed(MAC_LADDER)) if small else MAC_LADDER)
|
|
111
|
+
return MacLadder(MAC_LADDER, MAC_LADDER)
|
|
117
112
|
|
|
118
113
|
|
|
119
114
|
def mac_rung(entry: CatalogEntry, facts: HostFacts) -> bool:
|
|
@@ -348,11 +343,10 @@ def recommended_entry(
|
|
|
348
343
|
backend: str = "auto",
|
|
349
344
|
ladder: tuple[str, ...] = (),
|
|
350
345
|
) -> tuple[CatalogEntry, str] | None:
|
|
351
|
-
"""
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
remain available for explicit selection."""
|
|
346
|
+
"""Pick among resident entries that pass ``agent_ready`` (64K shared by two requests).
|
|
347
|
+
|
|
348
|
+
Speed breaks capability ties; the slow-decode advisory is not a gate.
|
|
349
|
+
"""
|
|
356
350
|
fitting = [
|
|
357
351
|
(e, c)
|
|
358
352
|
for e in entries
|
|
@@ -361,9 +355,6 @@ def recommended_entry(
|
|
|
361
355
|
if not fitting:
|
|
362
356
|
return None
|
|
363
357
|
|
|
364
|
-
def speed(t: tuple[CatalogEntry, VariantChoice]) -> float:
|
|
365
|
-
return predicted_decode_tok_s(t[0], t[1].variant, budget, backend=backend)
|
|
366
|
-
|
|
367
358
|
resident = [(e, c) for e, c in fitting if c.zero_spill and agent_ready(e, c.variant, budget)]
|
|
368
359
|
rungs = {e.id: e for e, _ in resident if e.id in ladder}
|
|
369
360
|
resident = [(e, c) for e, c in resident if e.id not in rungs]
|
|
@@ -373,9 +364,7 @@ def recommended_entry(
|
|
|
373
364
|
for entry, _ in resident:
|
|
374
365
|
if entry.id == product_default:
|
|
375
366
|
return (entry, "product-default")
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
pick
|
|
379
|
-
floor_gated = any(e.quality > pick.quality for e, _ in resident)
|
|
380
|
-
return (pick, "speed-gated-quality" if floor_gated else "best-quality-resident")
|
|
367
|
+
if resident:
|
|
368
|
+
pick = max(resident, key=lambda t: rank_key(t[0], t[1].variant, budget, backend=backend))[0]
|
|
369
|
+
return pick, "best-quality-resident"
|
|
381
370
|
return None
|
|
@@ -20,7 +20,7 @@ from collections.abc import Mapping
|
|
|
20
20
|
from typing import TypedDict
|
|
21
21
|
|
|
22
22
|
from localmodels.contracts import decode
|
|
23
|
-
from localmodels.probe import GPU, HostFacts
|
|
23
|
+
from localmodels.probe import GPU, ComputeProcess, HostFacts
|
|
24
24
|
|
|
25
25
|
GIB = 1 << 30
|
|
26
26
|
METAL_UUID = "metal-0" # service_probe.METAL_UUID labels the processes it finds on the GPU
|
|
@@ -228,26 +228,43 @@ def conflicts(facts: HostFacts) -> list[str]:
|
|
|
228
228
|
return found
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
def
|
|
232
|
-
"""Resident memory of this tool's own servers on the GPU (service discovery's ``ps``)."""
|
|
231
|
+
def _metal_processes(facts: HostFacts) -> list[ComputeProcess]:
|
|
233
232
|
services = facts.get("services")
|
|
234
233
|
processes = (services.get("compute_processes") if services else None) or []
|
|
234
|
+
return [p for p in processes if p["gpu_uuid"] == METAL_UUID]
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def owned_bytes(facts: HostFacts) -> int:
|
|
238
|
+
"""What stopping this tool's own servers on the GPU gives back (service discovery's
|
|
239
|
+
``ps``): their resident memory less their file cache, which the RAM available already
|
|
240
|
+
counts (``cached_bytes``)."""
|
|
241
|
+
return sum(
|
|
242
|
+
max(0, int(p.get("used_bytes") or 0) - int(p.get("cached_bytes") or 0))
|
|
243
|
+
for p in _metal_processes(facts)
|
|
244
|
+
if p["owned"] is True
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def foreign_cached_bytes(facts: HostFacts) -> int:
|
|
249
|
+
"""The file-cached weights of inference servers this tool does not own: an upstream server
|
|
250
|
+
unwires its weights a few minutes into idling, and macOS then counts them as available.
|
|
251
|
+
They are still that server's model (decision 43), so they are not free for a plan."""
|
|
235
252
|
return sum(
|
|
236
|
-
int(p.get("
|
|
237
|
-
for p in processes
|
|
238
|
-
if p["gpu_uuid"] == METAL_UUID and p["owned"] is True
|
|
253
|
+
int(p.get("cached_bytes") or 0) for p in _metal_processes(facts) if p["owned"] is not True
|
|
239
254
|
)
|
|
240
255
|
|
|
241
256
|
|
|
242
257
|
def reclaimed(facts: HostFacts) -> HostFacts:
|
|
243
|
-
"""``facts`` with this tool's own servers' memory back in the RAM available
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
258
|
+
"""``facts`` with this tool's own servers' memory back in the RAM available, as a fresh plan
|
|
259
|
+
would price them (as the Linux suite slice is reclaimed, budget.host_ram), and another
|
|
260
|
+
server's file-cached weights out of it."""
|
|
261
|
+
owned, foreign = owned_bytes(facts), foreign_cached_bytes(facts)
|
|
262
|
+
if not owned and not foreign:
|
|
247
263
|
return facts
|
|
248
264
|
seen = copy.deepcopy(facts)
|
|
249
|
-
seen["ram"]
|
|
250
|
-
|
|
265
|
+
ram = seen["ram"]
|
|
266
|
+
ram["available_bytes"] = max(
|
|
267
|
+
0, min(ram["total_bytes"], ram["available_bytes"] + owned) - foreign
|
|
251
268
|
)
|
|
252
269
|
return seen
|
|
253
270
|
|
|
@@ -101,6 +101,10 @@ class CgroupMemory(TypedDict):
|
|
|
101
101
|
|
|
102
102
|
class _ComputeSince20261024(TypedDict, total=False):
|
|
103
103
|
in_suite: bool # verified current-user deployment in the suite; never just a cgroup label
|
|
104
|
+
# A Mac process's resident file cache: its resident memory less its physical footprint
|
|
105
|
+
# (mapped GGUF weights that are not wired). The RAM available already counts these pages
|
|
106
|
+
# (metal_probe.available_memory), so a stop gives back only the rest. Absent: unknown.
|
|
107
|
+
cached_bytes: int
|
|
104
108
|
|
|
105
109
|
|
|
106
110
|
class ComputeProcess(_ComputeSince20261024):
|
|
@@ -10,7 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
from typing import Literal, TypedDict
|
|
11
11
|
|
|
12
12
|
from localmodels import catalog as cat
|
|
13
|
-
from localmodels import llm_rank
|
|
13
|
+
from localmodels import llm_rank, stack_warm_store
|
|
14
14
|
from localmodels.budget import Placement, agent_budget, gib, placements
|
|
15
15
|
from localmodels.context_policy import AGENT, window_k
|
|
16
16
|
from localmodels.estimator import PhysicsRefusal
|
|
@@ -86,10 +86,6 @@ RECOMMENDED_REASONS = {
|
|
|
86
86
|
"Candidates that pass the agent capacity gate are ranked by capability score first, "
|
|
87
87
|
"predicted decode speed second; not a measurement of quality or latency on this computer."
|
|
88
88
|
),
|
|
89
|
-
"speed-gated-quality": (
|
|
90
|
-
"Candidates with higher capability scores failed the predicted decode gate; resident "
|
|
91
|
-
"candidates that pass it are ranked by capability score first. Not a latency measurement."
|
|
92
|
-
),
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
|
|
@@ -316,13 +312,34 @@ def catalog_rows(
|
|
|
316
312
|
}
|
|
317
313
|
for p in host
|
|
318
314
|
],
|
|
319
|
-
"recommendation": None
|
|
320
|
-
if rec is None
|
|
321
|
-
else {
|
|
322
|
-
"id": rec[0].id,
|
|
323
|
-
"reason": rec[1],
|
|
324
|
-
"reason_text": RECOMMENDED_REASONS[rec[1]],
|
|
325
|
-
"placement": rec[2].id,
|
|
326
|
-
},
|
|
315
|
+
"recommendation": _recommendation_payload(facts, *rec) if rec is not None else None,
|
|
327
316
|
"models": rows,
|
|
328
317
|
}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _recommendation_payload(
|
|
321
|
+
facts: HostFacts, entry: cat.CatalogEntry, reason: str, placement: Placement
|
|
322
|
+
) -> dict[str, str]:
|
|
323
|
+
payload = {
|
|
324
|
+
"id": entry.id,
|
|
325
|
+
"reason": reason,
|
|
326
|
+
"reason_text": RECOMMENDED_REASONS[reason],
|
|
327
|
+
"placement": placement.id,
|
|
328
|
+
}
|
|
329
|
+
choice = cat.select_variant(entry, placement.budget)
|
|
330
|
+
if choice is not None:
|
|
331
|
+
variant = choice.variant
|
|
332
|
+
indices = (0,) if placement.backend == "metal" else placement.gpu_indices
|
|
333
|
+
seen = (
|
|
334
|
+
stack_warm_store.lookup(facts, indices[0], entry.id, variant.quant)
|
|
335
|
+
if len(indices) == 1
|
|
336
|
+
else None
|
|
337
|
+
)
|
|
338
|
+
speed = cat.decode_estimate(entry, variant, placement.budget, backend=placement.backend)
|
|
339
|
+
warning = cat.decode_advisory(
|
|
340
|
+
speed.tok_s if seen is None else seen,
|
|
341
|
+
measured=seen is not None or speed.basis == "measured-decode",
|
|
342
|
+
)
|
|
343
|
+
if warning:
|
|
344
|
+
payload["speed_warning"] = warning
|
|
345
|
+
return payload
|
|
@@ -135,7 +135,7 @@ def _show_parts(
|
|
|
135
135
|
"Bifrost" if harness.gateway_kind(plan["harness"]["gateway"]) == "bifrost" else "Magpie"
|
|
136
136
|
)
|
|
137
137
|
print("默认组合:" + " + ".join([*pieces, gateway, "pi"]))
|
|
138
|
-
print("
|
|
138
|
+
print(" 按上面的硬件快照规划,不是已批准的安装计划。")
|
|
139
139
|
print(
|
|
140
140
|
f" LLM 窗口 {stack_summary.window_label(llm['launch']['window'])},"
|
|
141
141
|
+ (stack_hardware.agent_label(llm) or f"{llm['launch']['slots']} 路,")
|
|
@@ -164,12 +164,14 @@ def _show_parts(
|
|
|
164
164
|
print(f" 注意 {warning}")
|
|
165
165
|
for warning in facts:
|
|
166
166
|
print(f" 说明 {warning}")
|
|
167
|
+
if advisory := plan.get("hardware", {}).get("llm_decode_advisory"):
|
|
168
|
+
print(f" 注意 {advisory}")
|
|
167
169
|
_show_evidence(plan, detailed=all_models)
|
|
168
170
|
for line in [
|
|
169
|
-
"
|
|
170
|
-
"
|
|
171
|
+
"容量和整栈预算是估算,不是本机推理实测;解码速度区分估算与同设备测量",
|
|
172
|
+
"目录历史实测与本机已保存的 warm 记录分开标注;当前窗口、并发和全组件共存仍须验收",
|
|
171
173
|
"工具安装状态与本地权重复用未核实,下载按全新安装估算;端口只参考该快照",
|
|
172
|
-
"CPU
|
|
174
|
+
"首 token 尚无独立估算;CPU 竞争与整栈并发延迟未实测",
|
|
173
175
|
*(unknowns or []),
|
|
174
176
|
]:
|
|
175
177
|
print(f" 估算 {line}")
|
|
@@ -9,6 +9,7 @@ private-name imports.
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
+
import contextlib
|
|
12
13
|
import http.client
|
|
13
14
|
import json
|
|
14
15
|
import os
|
|
@@ -62,27 +63,80 @@ def act_engine(p: remote_ops.EngineParams) -> None:
|
|
|
62
63
|
remote_ops.emit("result", binary=binary, reused=False)
|
|
63
64
|
|
|
64
65
|
|
|
65
|
-
def
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
def _verified_reuse_source(source: str, sha256: str, label: str) -> bool:
|
|
67
|
+
receipt = source + ".sha256"
|
|
68
|
+
try:
|
|
69
|
+
if os.path.isfile(receipt) and remote_ops._read(receipt).strip() == sha256:
|
|
70
|
+
return True
|
|
71
|
+
except (OSError, UnicodeError):
|
|
72
|
+
pass
|
|
73
|
+
if remote_ops._sha256(source, label) != sha256:
|
|
72
74
|
remote_ops.emit(
|
|
73
75
|
"log",
|
|
74
|
-
message=
|
|
76
|
+
message=(
|
|
77
|
+
f"the existing copy of {label} has a SHA256 mismatch; downloading instead: {source}"
|
|
78
|
+
),
|
|
75
79
|
)
|
|
80
|
+
return False
|
|
81
|
+
return True
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _link_copy(source: str, dest: str, sha256: str, size: int, label: str) -> None:
|
|
85
|
+
"""Hard-link (same device) or copy (cross-device) a verified copy the host already has;
|
|
86
|
+
any mismatch or error falls back to downloading."""
|
|
87
|
+
if os.path.exists(dest) or not os.path.isfile(source) or os.path.getsize(source) != size:
|
|
76
88
|
return
|
|
77
|
-
|
|
89
|
+
dest_dir = os.path.dirname(dest) or "."
|
|
90
|
+
os.makedirs(dest_dir, exist_ok=True)
|
|
91
|
+
if not _verified_reuse_source(source, sha256, label):
|
|
92
|
+
return
|
|
93
|
+
same_dev = os.stat(source).st_dev == os.stat(dest_dir).st_dev
|
|
94
|
+
if not same_dev:
|
|
95
|
+
free = shutil.disk_usage(dest_dir).free
|
|
96
|
+
if free < size:
|
|
97
|
+
remote_ops.emit(
|
|
98
|
+
"log",
|
|
99
|
+
message=(
|
|
100
|
+
f"not enough disk space to copy {label} "
|
|
101
|
+
f"({size} bytes needed, {free} free); downloading instead"
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
return
|
|
105
|
+
tmp = f"{dest}.reuse.{os.getpid()}"
|
|
106
|
+
with contextlib.suppress(OSError):
|
|
107
|
+
os.unlink(tmp)
|
|
108
|
+
try:
|
|
109
|
+
if same_dev:
|
|
110
|
+
os.link(source, tmp)
|
|
111
|
+
else:
|
|
112
|
+
shutil.copyfile(source, tmp)
|
|
113
|
+
os.replace(tmp, dest)
|
|
114
|
+
except OSError as exc:
|
|
115
|
+
with contextlib.suppress(OSError):
|
|
116
|
+
os.unlink(tmp)
|
|
78
117
|
remote_ops.emit(
|
|
79
118
|
"log",
|
|
80
|
-
message=f"
|
|
119
|
+
message=f"could not reuse {source} for {label} ({exc}); downloading instead",
|
|
81
120
|
)
|
|
82
121
|
return
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
except BaseException:
|
|
123
|
+
with contextlib.suppress(OSError):
|
|
124
|
+
os.unlink(tmp)
|
|
125
|
+
raise
|
|
126
|
+
remote_ops._write(dest + ".sha256", sha256)
|
|
127
|
+
remote_ops._store_cached(dest, sha256, size)
|
|
128
|
+
remote_ops.emit(
|
|
129
|
+
"progress",
|
|
130
|
+
phase="download",
|
|
131
|
+
file=label,
|
|
132
|
+
done=size,
|
|
133
|
+
total=size,
|
|
134
|
+
bytes_per_s=size,
|
|
135
|
+
source="cache",
|
|
136
|
+
connections=0,
|
|
137
|
+
**remote_ops.step_fields(size),
|
|
138
|
+
)
|
|
139
|
+
remote_ops.emit("log", message="verified and reused the local file " + source)
|
|
86
140
|
|
|
87
141
|
|
|
88
142
|
def act_download(p: remote_ops.DownloadParams) -> None:
|
|
@@ -258,6 +312,9 @@ def probe(url: str, size: int) -> tuple[float, bool] | None:
|
|
|
258
312
|
return got / max(1e-3, time.monotonic() - start), ranged
|
|
259
313
|
|
|
260
314
|
|
|
315
|
+
LONE_SMALL_BYTES = 1 << 20
|
|
316
|
+
|
|
317
|
+
|
|
261
318
|
def rank(
|
|
262
319
|
sources: list[remote_ops.Source],
|
|
263
320
|
size: int,
|
|
@@ -266,7 +323,11 @@ def rank(
|
|
|
266
323
|
) -> list[_Ranked]:
|
|
267
324
|
"""The sources fastest first, each with whether it serves ranges; ones that failed the probe
|
|
268
325
|
go last in plan order (and into ``unreachable``), so a passing hiccup still leaves them as
|
|
269
|
-
a fallback.
|
|
326
|
+
a fallback. A lone source of a small file is not probed: there is nothing to rank, the
|
|
327
|
+
probe would download the whole file a second time (most of pi's ~120 module tarballs),
|
|
328
|
+
and one plain stream reads it in about the time a resume would save."""
|
|
329
|
+
if len(sources) == 1 and size <= min(PROBE_BYTES, LONE_SMALL_BYTES):
|
|
330
|
+
return [(sources[0], False)]
|
|
270
331
|
measured: list[tuple[float, int, _Ranked]] = []
|
|
271
332
|
failed: list[_Ranked] = []
|
|
272
333
|
notes = []
|
|
@@ -35,6 +35,20 @@ def _purgeable(p: remote_ops.RemoveParams, preparation: list[str]) -> list[list[
|
|
|
35
35
|
return [[f, st.st_size, st.st_nlink] for f, st in stats if not os.path.isdir(f)]
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
def _delete_prompt_caches(root: str) -> None:
|
|
39
|
+
"""The kept prompt starts, which hold prompt text: slot_cache.py's prefix.json,
|
|
40
|
+
prefix-tally.json and saved slots (prefix-<hash>.bin) under ``slots``, and a temporary
|
|
41
|
+
file a stop may have left of them."""
|
|
42
|
+
slots = os.path.join(root, "slots")
|
|
43
|
+
if not os.path.isdir(slots):
|
|
44
|
+
return
|
|
45
|
+
for name in os.listdir(slots):
|
|
46
|
+
if name.startswith("prefix") and name.endswith((".json", ".bin", ".tmp")):
|
|
47
|
+
_delete(os.path.join(slots, name))
|
|
48
|
+
if not os.listdir(slots):
|
|
49
|
+
_delete(slots, os.rmdir)
|
|
50
|
+
|
|
51
|
+
|
|
38
52
|
def _delete(path: str, remove: Callable[[str], None] = os.remove) -> None:
|
|
39
53
|
"""Delete one of a stopped service's files or emptied directories. Windows refuses while
|
|
40
54
|
another process still has it open, and a server that was just ended keeps its log and its
|
|
@@ -105,6 +119,7 @@ def _remove(p: remote_ops.RemoveParams, preparation: list[str]) -> None:
|
|
|
105
119
|
]:
|
|
106
120
|
if os.path.exists(remote_ops._expand(path)):
|
|
107
121
|
_delete(remote_ops._expand(path))
|
|
122
|
+
_delete_prompt_caches(paths["root"])
|
|
108
123
|
approved = set(p.get("purge") or []) & {str(f[0]) for f in listed}
|
|
109
124
|
for path in approved:
|
|
110
125
|
if os.path.lexists(path): # the service files above may be listed too
|