@simplexai/localmodels-linux-x64 0.1.0-dev.40 → 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 +38 -39
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +4 -130
- package/modules/localmodels/catalog.py +10 -0
- package/modules/localmodels/debug_mode.py +8 -0
- package/modules/localmodels/download-mirrors.json +0 -8
- package/modules/localmodels/library_jobs.py +56 -5
- package/modules/localmodels/library_model.py +60 -15
- package/modules/localmodels/library_pricing.py +99 -26
- package/modules/localmodels/library_serve.py +64 -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/recommend.py +30 -13
- package/modules/localmodels/recommend_cli.py +6 -4
- package/modules/localmodels/remote_ops_download.py +67 -13
- package/modules/localmodels/reuse.py +31 -5
- package/modules/localmodels/runtime_cli.py +3 -2
- package/modules/localmodels/runtime_pi.py +17 -8
- package/modules/localmodels/sizecalc.py +0 -2
- package/modules/localmodels/stack_card.py +1 -0
- package/modules/localmodels/stack_compose.py +2 -3
- package/modules/localmodels/stack_hardware.py +22 -5
- package/modules/localmodels/stack_hardware_text.py +40 -35
- 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_summary.py +2 -0
- package/modules/localmodels/stack_warm.py +21 -11
- package/modules/localmodels/stack_warm_store.py +5 -16
- package/modules/{simplex_localmodels-0.1.0.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/RECORD +35 -36
- 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.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev40.dist-info → simplex_localmodels-0.1.0.dev42.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -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
|
|
@@ -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:
|
|
@@ -209,11 +209,21 @@ def device(path: str) -> int | None:
|
|
|
209
209
|
return None
|
|
210
210
|
|
|
211
211
|
|
|
212
|
+
def extra_reuse_roots() -> tuple[str, ...]:
|
|
213
|
+
"""Extra directories from ``LOCALMODELS_REUSE_DIRS`` (``os.pathsep``-separated)."""
|
|
214
|
+
raw = os.environ.get("LOCALMODELS_REUSE_DIRS", "")
|
|
215
|
+
return tuple(entry.strip() for entry in raw.split(os.pathsep) if entry.strip())
|
|
216
|
+
|
|
217
|
+
|
|
212
218
|
def find_copies(
|
|
213
|
-
wanted: dict[str, tuple[int, str]],
|
|
219
|
+
wanted: dict[str, tuple[int, str]],
|
|
220
|
+
roots: tuple[str, ...] = SEARCH_ROOTS,
|
|
221
|
+
*,
|
|
222
|
+
allow_cross_device: bool = False,
|
|
214
223
|
) -> dict[str, str]:
|
|
215
224
|
"""{file name: existing path} for each wanted name (-> (size, destination)) found with the
|
|
216
|
-
same size on the destination's filesystem
|
|
225
|
+
same size on the destination's filesystem (or anywhere under ``roots`` when
|
|
226
|
+
``allow_cross_device`` is true), so reuse can replace the download."""
|
|
217
227
|
found: dict[str, str] = {}
|
|
218
228
|
for root in roots:
|
|
219
229
|
for path in _walk(Path(os.path.expanduser(root))):
|
|
@@ -221,12 +231,28 @@ def find_copies(
|
|
|
221
231
|
if spec is None or path.name in found:
|
|
222
232
|
continue
|
|
223
233
|
real = os.path.realpath(path)
|
|
234
|
+
dest = os.path.expanduser(spec[1])
|
|
224
235
|
try:
|
|
225
|
-
same =
|
|
226
|
-
os.path.
|
|
236
|
+
same = (
|
|
237
|
+
os.path.isfile(real)
|
|
238
|
+
and os.path.getsize(real) == spec[0]
|
|
239
|
+
and (allow_cross_device or os.stat(real).st_dev == device(dest))
|
|
227
240
|
)
|
|
228
241
|
except OSError:
|
|
229
242
|
continue
|
|
230
|
-
if same and real != os.path.realpath(
|
|
243
|
+
if same and real != os.path.realpath(dest):
|
|
231
244
|
found[path.name] = real
|
|
232
245
|
return found
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def find_library_copies(wanted: dict[str, tuple[int, str]]) -> dict[str, str]:
|
|
249
|
+
"""Existing copies for library downloads: same-device hard-link candidates under
|
|
250
|
+
``SEARCH_ROOTS`` first, then missing entries from ``LOCALMODELS_REUSE_DIRS`` (allowing
|
|
251
|
+
cross-device copies)."""
|
|
252
|
+
if not wanted:
|
|
253
|
+
return {}
|
|
254
|
+
found = find_copies(wanted, SEARCH_ROOTS, allow_cross_device=False)
|
|
255
|
+
missing = {name: spec for name, spec in wanted.items() if name not in found}
|
|
256
|
+
if missing and (extra := extra_reuse_roots()):
|
|
257
|
+
found.update(find_copies(missing, extra, allow_cross_device=True))
|
|
258
|
+
return found
|
|
@@ -71,6 +71,7 @@ class RuntimeVersionVerificationError(ValueError):
|
|
|
71
71
|
def __init__(self, code: str, message: str) -> None:
|
|
72
72
|
super().__init__(message)
|
|
73
73
|
self.code = code
|
|
74
|
+
self.details: dict[str, int] = {}
|
|
74
75
|
|
|
75
76
|
|
|
76
77
|
def _require_installed_version(code: int, output: str, expected: str) -> None:
|
|
@@ -711,8 +712,8 @@ def run(args: argparse.Namespace) -> int:
|
|
|
711
712
|
try:
|
|
712
713
|
print(json.dumps(_act(args)))
|
|
713
714
|
return 0
|
|
714
|
-
except RuntimeVersionVerificationError as error:
|
|
715
|
-
_report_error(error.code, str(error))
|
|
715
|
+
except (RuntimeVersionVerificationError, runtime_pi.RuntimeRootTooLongError) as error:
|
|
716
|
+
_report_error(error.code, str(error), **error.details)
|
|
716
717
|
return 1
|
|
717
718
|
except RuntimeDownloadError as error:
|
|
718
719
|
_report_error(
|
|
@@ -69,17 +69,26 @@ WINDOWS_MAX_PATH = 259 # MAX_PATH less the terminator, without long paths enabl
|
|
|
69
69
|
STAGED = ("tools", "pi", ".s" + "x" * 8, "t", "package")
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
class RuntimeRootTooLongError(ValueError):
|
|
73
|
+
"""The pinned Pi tree exceeds the Windows path limit under this root."""
|
|
74
|
+
|
|
75
|
+
code = "RUNTIME_ROOT_TOO_LONG"
|
|
76
|
+
|
|
77
|
+
def __init__(self, length: int, limit: int) -> None:
|
|
78
|
+
super().__init__(
|
|
79
|
+
f"The runtime root is {length} characters; Pi needs at most {limit} on Windows. "
|
|
80
|
+
"Choose a shorter install location or enable long paths."
|
|
81
|
+
)
|
|
82
|
+
self.details = {"rootLength": length, "maxRootLength": limit}
|
|
83
|
+
|
|
84
|
+
|
|
72
85
|
def _check_path_budget(root: Path, longest: int) -> None:
|
|
73
86
|
"""Refuse at plan time a Windows runtime root too long for Pi's dependency tree, unless
|
|
74
87
|
long paths are enabled; an unpacked file past 260 characters fails mid-install."""
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
raise ValueError(
|
|
80
|
-
f"The runtime root is {len(str(root))} characters; Pi's dependency tree fits below a"
|
|
81
|
-
f" root of at most {room} on Windows unless long paths are enabled"
|
|
82
|
-
)
|
|
88
|
+
limit = WINDOWS_MAX_PATH - sum(len(part) + 1 for part in STAGED) - 1 - longest
|
|
89
|
+
length = len(str(root))
|
|
90
|
+
if length > limit and not _long_paths_enabled():
|
|
91
|
+
raise RuntimeRootTooLongError(length, limit)
|
|
83
92
|
|
|
84
93
|
|
|
85
94
|
def _long_paths_enabled() -> bool:
|
|
@@ -180,8 +180,6 @@ DEVICE_IDS = {d.id: d for d in DEVICES}
|
|
|
180
180
|
# catalog: the file size of that catalog.json variant and the entry's KV layout, filled in when
|
|
181
181
|
# the page is built.
|
|
182
182
|
EXAMPLES: tuple[dict[str, Any], ...] = (
|
|
183
|
-
{"id": "qwen3-1.7b", "name": "Qwen3 1.7B", "params": 2.03e9, "attention": "full",
|
|
184
|
-
"kv_per_token": 28 * 8 * 256 * 2, "quant": "Q4_K_M"},
|
|
185
183
|
{"id": "llama3.2-3b", "name": "Llama 3.2 3B", "params": 3.21e9, "attention": "full",
|
|
186
184
|
"kv_per_token": 28 * 8 * 256 * 2, "quant": "Q4_K_M"},
|
|
187
185
|
{"id": "qwen3-4b", "name": "Qwen3 4B", "params": 4.02e9, "attention": "full",
|
|
@@ -42,6 +42,7 @@ def warm_speed(path: Path, plan: StackPlan) -> float | None:
|
|
|
42
42
|
not isinstance(llm, dict)
|
|
43
43
|
or llm.get("name") != plan["llm"]["name"]
|
|
44
44
|
or llm.get("ok") is not True
|
|
45
|
+
or llm.get("decode_basis") != stack_warm.DECODE_TIMING
|
|
45
46
|
):
|
|
46
47
|
return None
|
|
47
48
|
speed = llm.get("decode_tok_s")
|
|
@@ -415,7 +415,7 @@ def _llm_warnings(
|
|
|
415
415
|
llm: Plan, llm_id: str, running: bool, facts: HostFacts, options: StackOptions
|
|
416
416
|
) -> list[str]:
|
|
417
417
|
"""What a catalog llama.cpp LLM's plan says about itself: its own warnings, an ignored
|
|
418
|
-
--conversation-cache, and a running one kept as is or a new one's GPU conflicts
|
|
418
|
+
--conversation-cache, and a running one kept as is or a new one's GPU conflicts."""
|
|
419
419
|
warnings = [f"LLM: {w}" for w in llm["warnings"]]
|
|
420
420
|
if (
|
|
421
421
|
llm_id == llm_rank.WINDOWS_FALLBACK_ID
|
|
@@ -439,7 +439,6 @@ def _llm_warnings(
|
|
|
439
439
|
)
|
|
440
440
|
else:
|
|
441
441
|
warnings += _gpu_conflicts(llm, facts, options.get("share_gpu", False))
|
|
442
|
-
warnings += hardware.slow_warning(facts, llm)
|
|
443
442
|
return warnings
|
|
444
443
|
|
|
445
444
|
|
|
@@ -741,7 +740,7 @@ def assemble(
|
|
|
741
740
|
"harness": tools_plan,
|
|
742
741
|
"budget": budget,
|
|
743
742
|
"warnings": warnings,
|
|
744
|
-
"hardware": hardware.snapshot(facts, options),
|
|
743
|
+
"hardware": hardware.snapshot(facts, options, llm),
|
|
745
744
|
"plan_id": "",
|
|
746
745
|
}
|
|
747
746
|
if fast is not None:
|