@simplexai/localmodels-linux-arm64 0.1.0-dev.110 → 0.1.0-dev.112
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/README.md +1 -1
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +52 -52
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +482 -103
- package/modules/localmodels/catalog_recipes.py +10 -1
- package/modules/localmodels/custom_hub.py +66 -2
- package/modules/localmodels/custom_hub_http.py +18 -0
- package/modules/localmodels/deploy.py +70 -5
- package/modules/localmodels/download-mirrors.json +70 -0
- package/modules/localmodels/engine_adapters/strata_poly.py +20 -4
- package/modules/localmodels/engine_adapters/suite_plan.py +7 -0
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.10.json +132 -0
- package/modules/localmodels/engines.json +96 -91
- package/modules/localmodels/engines.py +9 -2
- package/modules/localmodels/http_local.py +46 -0
- package/modules/localmodels/library_cli.py +2 -1
- package/modules/localmodels/library_custom.py +73 -0
- package/modules/localmodels/library_jobs.py +47 -23
- package/modules/localmodels/library_model.py +3 -1
- package/modules/localmodels/library_poly.py +78 -33
- package/modules/localmodels/library_presentation.py +28 -0
- package/modules/localmodels/library_pricing.py +125 -20
- package/modules/localmodels/library_serve.py +90 -27
- package/modules/localmodels/library_smoke.py +1 -1
- package/modules/localmodels/library_state.py +23 -1
- package/modules/localmodels/library_status.py +57 -56
- package/modules/localmodels/mirrors.py +217 -21
- package/modules/localmodels/npm_transport.py +46 -35
- package/modules/localmodels/plan_envelope.py +8 -1
- package/modules/localmodels/region.py +90 -23
- package/modules/localmodels/remote_ops_common.py +1 -0
- package/modules/localmodels/remote_ops_download.py +583 -126
- package/modules/localmodels/remote_ops_prepare.py +8 -2
- package/modules/localmodels/remote_ops_ranges.py +80 -44
- package/modules/localmodels/remote_ops_redirect.py +3 -1
- package/modules/localmodels/remote_ops_remove.py +4 -2
- package/modules/localmodels/runtime_index.py +3 -1
- package/modules/localmodels/stack.py +1 -6
- package/modules/localmodels/stack_suite.py +15 -2
- package/modules/localmodels/{strata-poly-serve-0.2.20-poly.9.txt → strata-poly-serve-0.2.20-poly.10.txt} +1 -1
- package/modules/localmodels/suite.py +110 -8
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/view.js +11 -3
- package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/RECORD +48 -48
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +0 -132
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/LICENSE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev110.dist-info → simplex_localmodels-0.1.0.dev112.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -264,7 +264,8 @@ def _generate_from_hubs(
|
|
|
264
264
|
region: str | None,
|
|
265
265
|
) -> None:
|
|
266
266
|
"""Generate one group; a group that reads the Hub (the MTP head) is retried from the other
|
|
267
|
-
Hub when the first fails
|
|
267
|
+
Hub when the first fails. Switching from hf-mirror to huggingface in cn does not emit
|
|
268
|
+
``region_fallback`` because hf-mirror is not an independent CN source."""
|
|
268
269
|
hubs = hub_endpoints(spec["hf_endpoint"], region) if group != spec["pack"] else [""]
|
|
269
270
|
for index, hub in enumerate(hubs):
|
|
270
271
|
if hub:
|
|
@@ -279,7 +280,12 @@ def _generate_from_hubs(
|
|
|
279
280
|
continue
|
|
280
281
|
if index:
|
|
281
282
|
side = "cn" if hub == HF_MIRROR else "global"
|
|
282
|
-
|
|
283
|
+
only_hf_mirror_failed = region == "cn" and all(
|
|
284
|
+
prev.rstrip("/") == HF_MIRROR for prev in hubs[:index]
|
|
285
|
+
)
|
|
286
|
+
switch = (
|
|
287
|
+
{"region_fallback": side} if side != region and not only_hf_mirror_failed else {}
|
|
288
|
+
)
|
|
283
289
|
remote_ops_common.emit("log", phase="prepare", message="read the other Hub", **switch)
|
|
284
290
|
return
|
|
285
291
|
|
|
@@ -390,6 +390,39 @@ def _threads(job: Transfer, ranged: bool) -> list[threading.Thread]:
|
|
|
390
390
|
]
|
|
391
391
|
|
|
392
392
|
|
|
393
|
+
def _promote_or_emit(
|
|
394
|
+
job: Transfer,
|
|
395
|
+
source: remote_ops_common.Source,
|
|
396
|
+
label: str,
|
|
397
|
+
*,
|
|
398
|
+
done: int,
|
|
399
|
+
size: int,
|
|
400
|
+
rate: int,
|
|
401
|
+
ranged: bool,
|
|
402
|
+
promote: Any,
|
|
403
|
+
) -> bool:
|
|
404
|
+
"""Emit one progress tick. Return True when ``promote`` asked to leave this source."""
|
|
405
|
+
if promote is not None and not job.stop.is_set() and job.remaining() > 0:
|
|
406
|
+
decision = promote(done, size, rate)
|
|
407
|
+
if isinstance(decision, BaseException) and job.remaining() > 0:
|
|
408
|
+
job.fail(decision)
|
|
409
|
+
return True
|
|
410
|
+
remote_ops_common.emit(
|
|
411
|
+
"progress",
|
|
412
|
+
phase="download",
|
|
413
|
+
file=label,
|
|
414
|
+
done=done,
|
|
415
|
+
total=size,
|
|
416
|
+
bytes_per_s=rate,
|
|
417
|
+
source=source["source"],
|
|
418
|
+
connections=max(1, job.active()) if ranged else 1,
|
|
419
|
+
**remote_ops_common.step_fields(done),
|
|
420
|
+
)
|
|
421
|
+
if ranged:
|
|
422
|
+
remote_ops_common.save_ranges(job.part, size, job.snapshot())
|
|
423
|
+
return False
|
|
424
|
+
|
|
425
|
+
|
|
393
426
|
def run_transfer(
|
|
394
427
|
job: Transfer,
|
|
395
428
|
source: remote_ops_common.Source,
|
|
@@ -397,6 +430,7 @@ def run_transfer(
|
|
|
397
430
|
*,
|
|
398
431
|
ranged: bool,
|
|
399
432
|
allow_slow_switch: bool = False,
|
|
433
|
+
promote: Any = None,
|
|
400
434
|
) -> None:
|
|
401
435
|
threads = _threads(job, ranged)
|
|
402
436
|
for thread in threads:
|
|
@@ -406,51 +440,53 @@ def run_transfer(
|
|
|
406
440
|
initial_done = size - job.remaining()
|
|
407
441
|
meter = remote_ops_mirrors.Rate(mark, initial_done)
|
|
408
442
|
slow_window_start, slow_window_done = mark, initial_done
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
443
|
+
try:
|
|
444
|
+
while True:
|
|
445
|
+
alive = [
|
|
446
|
+
t for t in threads if t.is_alive()
|
|
447
|
+
] # the connections open during this interval
|
|
448
|
+
if not alive or not job.remaining(): # a stalled thief's victim may still be blocked
|
|
449
|
+
break
|
|
450
|
+
for t in alive:
|
|
451
|
+
t.join(timeout=remote_ops_common.PROGRESS_EVERY_S / len(alive))
|
|
452
|
+
now, done = time.monotonic(), size - job.remaining()
|
|
453
|
+
if allow_slow_switch and not job.stop.is_set():
|
|
454
|
+
window_elapsed = now - slow_window_start
|
|
455
|
+
if window_elapsed >= SLOW_WINDOW_S:
|
|
456
|
+
window_rate = int((done - slow_window_done) / max(1e-3, window_elapsed))
|
|
457
|
+
remaining = max(0, size - done)
|
|
458
|
+
near_done = remaining <= SLOW_BYTES_PER_S * SLOW_MIN_REMAINING_S
|
|
459
|
+
if window_rate < SLOW_BYTES_PER_S and not near_done:
|
|
460
|
+
job.fail(SlowTransferError(window_rate))
|
|
461
|
+
break
|
|
462
|
+
slow_window_start, slow_window_done = now, done
|
|
463
|
+
if now - mark >= remote_ops_common.PROGRESS_EVERY_S:
|
|
464
|
+
if _promote_or_emit(
|
|
465
|
+
job,
|
|
466
|
+
source,
|
|
467
|
+
label,
|
|
468
|
+
done=done,
|
|
469
|
+
size=size,
|
|
470
|
+
rate=meter.add(now, done),
|
|
471
|
+
ranged=ranged,
|
|
472
|
+
promote=promote,
|
|
473
|
+
):
|
|
424
474
|
break
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
remote_ops_common.save_ranges(job.part, size, job.snapshot())
|
|
441
|
-
if job.errors or any(t.is_alive() for t in threads):
|
|
442
|
-
job.stop_and_close()
|
|
443
|
-
deadline = time.monotonic() + 2.0
|
|
444
|
-
for t in threads:
|
|
445
|
-
if t.is_alive():
|
|
446
|
-
t.join(timeout=max(0.0, deadline - time.monotonic()))
|
|
447
|
-
if ranged:
|
|
448
|
-
remote_ops_common.save_ranges(job.part, size, job.snapshot())
|
|
449
|
-
if job.steals:
|
|
450
|
-
remote_ops_common.emit(
|
|
451
|
-
"log",
|
|
452
|
-
message=f"{label}: {len(threads)} connections, {job.steals} ranges rebalanced",
|
|
453
|
-
)
|
|
475
|
+
mark = now
|
|
476
|
+
finally:
|
|
477
|
+
if job.errors or any(t.is_alive() for t in threads):
|
|
478
|
+
job.stop_and_close()
|
|
479
|
+
deadline = time.monotonic() + 2.0
|
|
480
|
+
for t in threads:
|
|
481
|
+
if t.is_alive():
|
|
482
|
+
t.join(timeout=max(0.0, deadline - time.monotonic()))
|
|
483
|
+
if ranged:
|
|
484
|
+
remote_ops_common.save_ranges(job.part, size, job.snapshot())
|
|
485
|
+
if ranged and job.steals:
|
|
486
|
+
remote_ops_common.emit(
|
|
487
|
+
"log",
|
|
488
|
+
message=f"{label}: {len(threads)} connections, {job.steals} ranges rebalanced",
|
|
489
|
+
)
|
|
454
490
|
|
|
455
491
|
|
|
456
492
|
def _plain(job: Transfer) -> None:
|
|
@@ -350,6 +350,7 @@ class SafeRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
|
350
350
|
"""Enforce HTTPS + proxy/Fake-IP-aware anti-SSRF and strip credentials on origin change."""
|
|
351
351
|
|
|
352
352
|
max_redirections = MAX_REDIRECTS
|
|
353
|
+
http_error_308 = urllib.request.HTTPRedirectHandler.http_error_307
|
|
353
354
|
|
|
354
355
|
def __init__(self, *, allow_insecure_loopback: bool = False) -> None:
|
|
355
356
|
self._allow_insecure_loopback = allow_insecure_loopback
|
|
@@ -381,7 +382,8 @@ class SafeRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
|
381
382
|
source_url=req.full_url,
|
|
382
383
|
allow_insecure_loopback=self.allow_loopback(),
|
|
383
384
|
)
|
|
384
|
-
|
|
385
|
+
super_code = 307 if code == 308 and req.get_method() in ("GET", "HEAD") else code
|
|
386
|
+
redirected = super().redirect_request(req, fp, super_code, msg, headers, resolved)
|
|
385
387
|
if redirected is None:
|
|
386
388
|
return None
|
|
387
389
|
redirected.__dict__["_safe_redirect_hops"] = hops + 1
|
|
@@ -120,8 +120,9 @@ def _remove(p: remote_ops_common.RemoveParams, preparation: list[str]) -> None:
|
|
|
120
120
|
): # the slice _write_slice wrote
|
|
121
121
|
os.remove(suite)
|
|
122
122
|
remote_ops_common.systemctl("daemon-reload")
|
|
123
|
+
drop_keys = ("script", "pid", "spec") if p.get("keep_key") else ("script", "pid", "spec", "key")
|
|
123
124
|
for path in [
|
|
124
|
-
*(paths[k] for k in
|
|
125
|
+
*(paths[k] for k in drop_keys),
|
|
125
126
|
paths["pid"] + ".identity.json",
|
|
126
127
|
*p.get("config_files", []),
|
|
127
128
|
]:
|
|
@@ -135,5 +136,6 @@ def _remove(p: remote_ops_common.RemoveParams, preparation: list[str]) -> None:
|
|
|
135
136
|
for root, _, _ in sorted(os.walk(paths["root"]), reverse=True) if approved else []:
|
|
136
137
|
if not os.listdir(root):
|
|
137
138
|
_delete(root, os.rmdir)
|
|
138
|
-
|
|
139
|
+
kept_candidates = (paths["log"], paths["key"]) if p.get("keep_key") else (paths["log"],)
|
|
140
|
+
kept = [path for path in kept_candidates if os.path.exists(path)]
|
|
139
141
|
remote_ops_common.emit("result", removed=True, purged=len(approved), kept=kept)
|
|
@@ -183,7 +183,9 @@ def _model_entry(
|
|
|
183
183
|
engine = _engine_of(record, catalog_by_id)
|
|
184
184
|
entry: ModelIndexEntry = {
|
|
185
185
|
"id": record["id"],
|
|
186
|
-
"state":
|
|
186
|
+
"state": "failed"
|
|
187
|
+
if record["state"] == "idle" and library_state.files_missing(record["plan"])
|
|
188
|
+
else record["state"],
|
|
187
189
|
"pool": record.get("pool") or None,
|
|
188
190
|
"engine": engine,
|
|
189
191
|
"pi_model": _pi_model_of(record),
|
|
@@ -4,8 +4,6 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import copy
|
|
6
6
|
import json
|
|
7
|
-
import os
|
|
8
|
-
import secrets
|
|
9
7
|
import subprocess
|
|
10
8
|
import sys
|
|
11
9
|
import time
|
|
@@ -161,10 +159,7 @@ def load(path: Path) -> StackPlan:
|
|
|
161
159
|
|
|
162
160
|
def service_key(plan: Plan) -> str:
|
|
163
161
|
"""Reuse the key of a previous run so a running service and the gateway keep agreeing."""
|
|
164
|
-
|
|
165
|
-
if path.is_file():
|
|
166
|
-
return path.read_text(encoding="utf-8").strip()
|
|
167
|
-
return secrets.token_urlsafe(24)
|
|
162
|
+
return deploy.resolve_api_key(plan)
|
|
168
163
|
|
|
169
164
|
|
|
170
165
|
Log = Callable[[str], None]
|
|
@@ -253,7 +253,7 @@ def unified_bytes(
|
|
|
253
253
|
) -> int:
|
|
254
254
|
"""What a strata-poly LLM holds on a Mac, where every expert stays in unified memory.
|
|
255
255
|
|
|
256
|
-
Recipes carrying explicit KV geometry (e.g. Inkling 2 Mini ``poly.
|
|
256
|
+
Recipes carrying explicit KV geometry (e.g. Inkling 2 Mini ``poly.10``) use compositional sizing
|
|
257
257
|
(weights + KV + resident Metal vision + Metal overhead); legacy recipes without KV geometry
|
|
258
258
|
fall back to ``weights + METAL_BESIDE_BYTES`` (PS219, M5 Ultra)."""
|
|
259
259
|
total, _ = suite.poly_unified_footprint(
|
|
@@ -382,6 +382,19 @@ def _free_to_plan(recipe: suite.SuiteRecipe, card: GPU, options: StackOptions) -
|
|
|
382
382
|
return max(int(recipe.get("vram_bytes", 0)), start_need(vram, floor, card, options))
|
|
383
383
|
|
|
384
384
|
|
|
385
|
+
def strata_card_need(recipe: suite.SuiteRecipe, options: StackOptions) -> int:
|
|
386
|
+
"""The card size ``--llm`` needs for ``recipe``.
|
|
387
|
+
|
|
388
|
+
``--llm auto`` only offers a recipe where its full expert cache fits (``vram_bytes``), so a
|
|
389
|
+
slower offload of a bigger quant never displaces the compact recipe a small card is meant
|
|
390
|
+
to run. Naming the recipe explicitly may use its hybrid-offload floor (``min_vram_bytes``),
|
|
391
|
+
where the engine keeps the experts it cannot fit in host RAM.
|
|
392
|
+
"""
|
|
393
|
+
if options.get("llm") == "auto":
|
|
394
|
+
return int(recipe.get("vram_bytes", 0))
|
|
395
|
+
return suite.poly_min_vram_bytes(recipe)
|
|
396
|
+
|
|
397
|
+
|
|
385
398
|
def strata_parts(
|
|
386
399
|
facts: HostFacts,
|
|
387
400
|
options: StackOptions,
|
|
@@ -416,7 +429,7 @@ def strata_parts(
|
|
|
416
429
|
),
|
|
417
430
|
)
|
|
418
431
|
if unified
|
|
419
|
-
else
|
|
432
|
+
else strata_card_need(llm_recipe, options)
|
|
420
433
|
)
|
|
421
434
|
gpu = _suite_gpu(
|
|
422
435
|
facts,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# PolyStrata 0.2.20-poly.
|
|
1
|
+
# PolyStrata 0.2.20-poly.10's Python server (terminal/serve/server.py, MIT) for strata-poly LLM
|
|
2
2
|
# recipes: jinja2 3.1.6 (BSD-3-Clause) with markupsafe 3.0.3 (BSD-3-Clause) renders the chat
|
|
3
3
|
# template, regex 2026.9.10 (Apache-2.0 and CNRI-Python) drives its tokenizer, psutil 7.2.2
|
|
4
4
|
# (BSD-3-Clause) reads memory for its status page, and pillow (MIT-CMU; 13.0.0 on Python 3.11+,
|
|
@@ -87,6 +87,12 @@ class CardArgs(TypedDict, total=False):
|
|
|
87
87
|
at_least_free_bytes: int # optional live free VRAM less reserve floor (shared-GPU safety)
|
|
88
88
|
platforms: list[str] # only on these (facts["platform"]); every platform when absent
|
|
89
89
|
args: list[str]
|
|
90
|
+
# Flags this card turns off the recipe's base profile carries (with their value), such as
|
|
91
|
+
# ``--basinkv`` on a card with room to batch requests natively.
|
|
92
|
+
remove_args: list[str]
|
|
93
|
+
# Drop every ``--basinkv*`` flag from the base profile and keep native KV: BasinKV's single
|
|
94
|
+
# pinned hot slab cannot serve concurrent slots, so a card that opts out batches instead.
|
|
95
|
+
disable_basinkv: bool
|
|
90
96
|
context: int # optional larger context window (--max-context and launch.window) on this card
|
|
91
97
|
parallel: int # optional higher slot concurrency (--batch / profile.parallel) on this card
|
|
92
98
|
|
|
@@ -105,6 +111,13 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
|
|
|
105
111
|
port: int
|
|
106
112
|
threads: int # 0: decided from the host's logical cores
|
|
107
113
|
vram_bytes: int # what the component holds on its GPU, measured
|
|
114
|
+
# strata-poly recipes that can also run with experts spilled to host RAM: the least VRAM a
|
|
115
|
+
# card needs to start them (`vram_bytes` stays the full expert-cache ceiling).
|
|
116
|
+
min_vram_bytes: int
|
|
117
|
+
# strata-poly recipes: the context and concurrency Apple Silicon plans and prices by (their
|
|
118
|
+
# CUDA tiers may start at a shorter offload window or BasinKV's single hot slab).
|
|
119
|
+
metal_context: int
|
|
120
|
+
metal_parallel: int
|
|
108
121
|
# strata-poly recipes: what the engine keeps free of the card (--vram-reserve-mib) for the
|
|
109
122
|
# display and its own overshoot of that reserve.
|
|
110
123
|
vram_reserve_mib: int
|
|
@@ -147,6 +160,10 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
|
|
|
147
160
|
library: bool # list candidate in library status without entering --llm auto
|
|
148
161
|
decode_fraction: float # active weight fraction per decoded token when full VRAM-resident
|
|
149
162
|
embd_table_bytes: int # host-RAM-resident embedding table bytes excluded from GPU weights
|
|
163
|
+
# PolyStrata recipes: expert bytes the host-RAM estimate reserves for cards that cannot hold
|
|
164
|
+
# them all in VRAM; ``library_poly._calibrate_host_ram`` discounts the part a roomier card
|
|
165
|
+
# keeps resident (Qwen4's 8 GB tier spills ~14 GiB, its 24 GB tier ~2 GiB).
|
|
166
|
+
host_ram_spill_bytes: int
|
|
150
167
|
capabilities: list[str]
|
|
151
168
|
quant_fidelity: str
|
|
152
169
|
bits_per_weight: float
|
|
@@ -223,10 +240,10 @@ def slice_memory() -> int:
|
|
|
223
240
|
def cuda_decision_engine(
|
|
224
241
|
facts: HostFacts, argv: list[str], base_dir: str, notes: list[str], *, metal: bool = False
|
|
225
242
|
) -> ReleaseEngine:
|
|
226
|
-
"""The CUDA build of the decision models
|
|
227
|
-
|
|
243
|
+
"""The CUDA build of the llama.cpp engine the decision models pin (their Metal build on a
|
|
244
|
+
Mac), else a llama-server already here that is that build with CUDA
|
|
228
245
|
(engines.host_engine)."""
|
|
229
|
-
lock_path = engine_lock_path(
|
|
246
|
+
lock_path = engine_lock_path(None)
|
|
230
247
|
backend = "metal" if metal else "cuda"
|
|
231
248
|
try:
|
|
232
249
|
return release_engine(select_engine_build(facts, backend, lock_path), base_dir.rstrip("/"))
|
|
@@ -288,6 +305,17 @@ def poly_weight_bytes(r: SuiteRecipe) -> int:
|
|
|
288
305
|
return sum(int(f["size_bytes"]) for f in r["files"] if not f.get("vision"))
|
|
289
306
|
|
|
290
307
|
|
|
308
|
+
def poly_min_vram_bytes(r: SuiteRecipe) -> int:
|
|
309
|
+
"""The least VRAM a PolyStrata recipe starts in.
|
|
310
|
+
|
|
311
|
+
``vram_bytes`` is the full expert-cache ceiling. A recipe that can also run with experts
|
|
312
|
+
spilled to host RAM declares ``min_vram_bytes``: the hybrid-offload floor a card needs to
|
|
313
|
+
start at, below the ceiling (``inkling-2-mini-q4-poly`` and ``qwen4-35b-a3b-q4-poly`` on
|
|
314
|
+
8-16 GB cards). Recipes without it run only where their ceiling fits.
|
|
315
|
+
"""
|
|
316
|
+
return int(r.get("min_vram_bytes") or r.get("vram_bytes") or 0)
|
|
317
|
+
|
|
318
|
+
|
|
291
319
|
def matched_card_args(
|
|
292
320
|
facts: HostFacts, r: SuiteRecipe, gpu: GPU | None, vram_reserve_mib: int
|
|
293
321
|
) -> list[CardArgs]:
|
|
@@ -325,6 +353,65 @@ def effective_parallel(r: SuiteRecipe, matched: Sequence[CardArgs]) -> int:
|
|
|
325
353
|
return max((base, *(int(group.get("parallel") or 0) for group in matched)), default=base)
|
|
326
354
|
|
|
327
355
|
|
|
356
|
+
# PolyStrata's sparse long-context KV paths (``--basinkv`` and legacy ``--kv-sparse``) keep one
|
|
357
|
+
# shared hot slab plus a pinned host copy; a serve profile that batches >1 request over them
|
|
358
|
+
# either corrupts the slab or cannot honour the contexts, so they are single-slot only.
|
|
359
|
+
SPARSE_KV_FLAGS = ("--basinkv", "--kv-sparse")
|
|
360
|
+
SPARSE_KV_VALUE_FLAGS = ("--basinkv-index", "--basinkv-kv-quant")
|
|
361
|
+
# Native KV flags BasinKV is mutually exclusive with (the engine refuses the combination).
|
|
362
|
+
NATIVE_KV_VALUE_FLAGS = ("--kv", "--kv-resident")
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def sparse_kv(args: Sequence[object]) -> bool:
|
|
366
|
+
"""True when ``args`` enable PolyStrata's sparse long-context KV (BasinKV or ``--kv-sparse``)."""
|
|
367
|
+
return any(str(token) in SPARSE_KV_FLAGS for token in args)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def drop_flag(args: Sequence[object], flag: str) -> list[str]:
|
|
371
|
+
"""``args`` without every ``flag`` and the value that follows it.
|
|
372
|
+
|
|
373
|
+
A flag keeps no value, so the token after it is only dropped when it does not itself start
|
|
374
|
+
with ``--``. ``--flag=value`` spellings are dropped whole.
|
|
375
|
+
"""
|
|
376
|
+
out: list[str] = []
|
|
377
|
+
skip = False
|
|
378
|
+
for token in (str(item) for item in args):
|
|
379
|
+
if skip:
|
|
380
|
+
skip = False
|
|
381
|
+
if not token.startswith("--"):
|
|
382
|
+
continue
|
|
383
|
+
if token == flag:
|
|
384
|
+
skip = True
|
|
385
|
+
continue
|
|
386
|
+
if token.startswith(f"{flag}="):
|
|
387
|
+
continue
|
|
388
|
+
out.append(token)
|
|
389
|
+
return out
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def drop_flags(args: Sequence[object], flags: Sequence[str]) -> list[str]:
|
|
393
|
+
out = [str(item) for item in args]
|
|
394
|
+
for flag in flags:
|
|
395
|
+
out = drop_flag(out, flag)
|
|
396
|
+
return out
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def apply_card_args(args: Sequence[object], matched: Sequence[CardArgs]) -> list[str]:
|
|
400
|
+
"""The base profile args after the matched ``card_args`` groups turn flags off.
|
|
401
|
+
|
|
402
|
+
``remove_args`` drops named flags with their values; ``disable_basinkv`` drops every
|
|
403
|
+
``--basinkv*`` flag and the legacy ``--kv-sparse`` (with values). Removal never adds flags:
|
|
404
|
+
widening a window or the slot count stays ``context`` / ``parallel``'s job.
|
|
405
|
+
"""
|
|
406
|
+
out = [str(item) for item in args]
|
|
407
|
+
for group in matched:
|
|
408
|
+
for flag in group.get("remove_args") or ():
|
|
409
|
+
out = drop_flag(out, str(flag))
|
|
410
|
+
if group.get("disable_basinkv"):
|
|
411
|
+
out = drop_flags(out, (*SPARSE_KV_FLAGS, *SPARSE_KV_VALUE_FLAGS))
|
|
412
|
+
return out
|
|
413
|
+
|
|
414
|
+
|
|
328
415
|
def poly_gpu_resident(
|
|
329
416
|
r: SuiteRecipe,
|
|
330
417
|
gpu: GPU | None,
|
|
@@ -484,12 +571,20 @@ def poly_unified_footprint(
|
|
|
484
571
|
"""Return ``(unified_bytes, wired_bytes)`` for a ``strata-poly`` recipe on Apple Silicon Metal.
|
|
485
572
|
|
|
486
573
|
When KV geometry is available, prices compositionally:
|
|
487
|
-
``
|
|
488
|
-
``wired_bytes`` covers
|
|
574
|
+
``resident_weights + kv(window, slots, kv_fmt) + resident_vision + metal_overhead_bytes``.
|
|
575
|
+
``wired_bytes`` covers Metal-resident weights, KV cache and Metal vision encoder;
|
|
489
576
|
``unified_bytes`` adds Metal runtime/compute and Python server overhead (default 1.80 GiB,
|
|
490
577
|
overridable via ``recipe["metal_overhead_bytes"]``).
|
|
578
|
+
|
|
579
|
+
``embd_table_bytes`` (Qwen4's 11.52 GB ``per_layer_token_embd`` shard, kept mmap'd off the
|
|
580
|
+
hot path the way llama.cpp's ``lazy_bytes`` is) is subtracted: it is faulted from disk on
|
|
581
|
+
demand instead of being wired, so charging it as resident would refuse Macs that run it.
|
|
491
582
|
"""
|
|
492
|
-
weights =
|
|
583
|
+
weights = max(
|
|
584
|
+
0,
|
|
585
|
+
sum(int(f["size_bytes"]) for f in recipe["files"] if not f.get("vision"))
|
|
586
|
+
- int(recipe.get("embd_table_bytes") or 0),
|
|
587
|
+
)
|
|
493
588
|
geom = poly_kv_geometry(recipe, allow_catalog_fallback=allow_catalog_fallback)
|
|
494
589
|
if geom is None:
|
|
495
590
|
total = weights + fallback_beside_bytes
|
|
@@ -499,10 +594,17 @@ def poly_unified_footprint(
|
|
|
499
594
|
profile_args = profile.get("args") if isinstance(profile, dict) else None
|
|
500
595
|
raw_args: Sequence[object] = profile_args if isinstance(profile_args, list) else ()
|
|
501
596
|
eff_window = (
|
|
502
|
-
window
|
|
597
|
+
window
|
|
598
|
+
if window is not None and window > 0
|
|
599
|
+
else int(recipe.get("metal_context") or recipe.get("context") or 65536)
|
|
503
600
|
)
|
|
504
601
|
eff_kv = (kv_fmt or poly_kv_format(raw_args)).strip().lower()
|
|
505
|
-
|
|
602
|
+
# Metal runs its own slot count: a recipe whose CUDA tier is the offload one (parallel: 1)
|
|
603
|
+
# still batches on Apple Silicon, and ``metal_parallel`` states that (see suite_plan).
|
|
604
|
+
raw_parallel = recipe.get("metal_parallel") or (
|
|
605
|
+
profile.get("parallel") if isinstance(profile, dict) else None
|
|
606
|
+
)
|
|
607
|
+
default_slots = int(str(raw_parallel or 2))
|
|
506
608
|
eff_slots = max(1, slots if slots is not None and slots > 0 else default_slots)
|
|
507
609
|
if eff_kv in _POLY_SINGLE_SLOT_KV:
|
|
508
610
|
eff_slots = 1
|
|
@@ -41,7 +41,7 @@ const WORDS = {
|
|
|
41
41
|
"vram.p": "The LLM's memory comes in parts: the weights are fixed, the KV cache grows linearly with the context; Jev shares the LLM's card. Dashed tiles are planned but not running. Hover a tile to see what it is.",
|
|
42
42
|
"vram.none": "No NVIDIA card found; this stack's decision model runs on a GPU only.",
|
|
43
43
|
"start.h": "No stack on this computer yet: start here", "start.p": "The board is read-only and runs nothing. Run one of these in a terminal; once installed, the flow, memory and live speeds appear here.", "start.copy": "Copy", "start.copied": "Copied", "start.select": "Press Ctrl+C", "start.aria": "Copy command {c}", "mem.free": "{f} free",
|
|
44
|
-
"vram.aside": "not used by this stack", "meas.h": "Plan and measured", "meas.p": "What this tool's running services hold now, beside what the plan priced: host memory is the private resident memory of each service and its children (/proc, mapped files excluded), GPU memory is nvidia-smi's figure per process. The maps above stay sized by the plan.", "meas.comp": "Component", "meas.plan": "Plan", "meas.got": "Measured", "meas.diff": "Difference", "meas.host": "host memory", "meas.over": "well over the plan: it may crowd other services", "mem.planned": "This stack plans", "mem.used.demo": "In use now (demo)", "mem.used.smi": "In use now (nvidia-smi)", "mem.used.ram": "In use now (/proc/meminfo)",
|
|
44
|
+
"vram.aside": "not used by this stack", "meas.h": "Plan and measured", "meas.p": "What this tool's running services hold now, beside what the plan priced: host memory is the private resident memory of each service and its children (/proc, mapped files excluded), GPU memory is nvidia-smi's figure per process. The maps above stay sized by the plan.", "meas.comp": "Component", "meas.plan": "Plan", "meas.got": "Measured", "meas.diff": "Difference", "meas.host": "host memory", "meas.over": "well over the plan: it may crowd other services", "mem.planned": "This stack plans", "mem.used.demo": "In use now (demo)", "mem.used.smi": "In use now (nvidia-smi)", "mem.used.unified": "In use now (unified memory)", "mem.used.ram": "In use now (/proc/meminfo)",
|
|
45
45
|
"fits": "Still fits on this card now (at least 64K shared pool × 2 sessions; decode speeds are estimates):",
|
|
46
46
|
"tiles.more": "{n} more",
|
|
47
47
|
"zoom": "Only this stack is drawn: it holds {p}% of the total, too thin to read at full scale; the bar above is the whole machine.",
|
|
@@ -1083,9 +1083,12 @@ function renderGpus(v) {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
const holders = g.holders.length ? ` · ${g.holders.join("; ")}` : "";
|
|
1085
1085
|
const aside = gpuAside(v, g);
|
|
1086
|
+
// The in-use figure is nvidia-smi's on an NVIDIA host and the Mac's own unified-memory
|
|
1087
|
+
// accounting on Apple Silicon (every other reading in this panel is NVIDIA-only too).
|
|
1088
|
+
const usedKey = v.source === "demo" ? "mem.used.demo" : /^NVIDIA/i.test(g.name || "") ? "mem.used.smi" : "mem.used.unified";
|
|
1086
1089
|
box.children[0].replaceChildren(
|
|
1087
1090
|
h("div", { class: "dev", style: { "margin-bottom": "8px" } }, devIcon("GPU"), h("b", {}, `GPU ${g.index}`), aside ? h("span", { class: "tag" }, t("vram.aside")) : null, h("span", { class: "mono" }, `${g.name}${g.bandwidth_gb_s ? ` · ${g.bandwidth_gb_s} GB/s` : ""}${holders}`)),
|
|
1088
|
-
memHead(hasPlan(v) && !aside ? ours : null, g.total_bytes, g.used_bytes,
|
|
1091
|
+
memHead(hasPlan(v) && !aside ? ours : null, g.total_bytes, g.used_bytes, usedKey));
|
|
1089
1092
|
box.classList.toggle("bare", !hasPlan(v) || aside);
|
|
1090
1093
|
const zoom = zoomed(g.segments);
|
|
1091
1094
|
treemap(box.querySelector(".tree"), zoom ? zoom.segments : g.segments, states);
|
|
@@ -1350,8 +1353,9 @@ function renderSpeed(v) {
|
|
|
1350
1353
|
}
|
|
1351
1354
|
if (S.prefill) {
|
|
1352
1355
|
if (rebuilt) paintPrefill(S.prefill, false);
|
|
1353
|
-
} else
|
|
1354
|
-
const
|
|
1356
|
+
} else {
|
|
1357
|
+
const prompt = lastPrompt(v.events);
|
|
1358
|
+
const seed = prompt ? prefillPlan(prompt.tokens_in, preV) : null;
|
|
1355
1359
|
if (seed) paintPrefill((S.prefill = seed), false);
|
|
1356
1360
|
}
|
|
1357
1361
|
T.per = decodeStep(T.rate);
|
|
@@ -1663,7 +1667,11 @@ function lastPrompt(events) {
|
|
|
1663
1667
|
return (events || []).find((e) => e.kind === "chat" && e.tokens_in > 0);
|
|
1664
1668
|
}
|
|
1665
1669
|
|
|
1670
|
+
// ``e`` is the chat turn whose prompt sizes the grid. The services' counters can say a request
|
|
1671
|
+
// went by before any gateway turn is in the document (no gateway log yet, or a page opened mid
|
|
1672
|
+
// session): there is no prompt to sweep then, and the lanes keep the plan's estimate.
|
|
1666
1673
|
function sweep(e) {
|
|
1674
|
+
if (!e) return;
|
|
1667
1675
|
const llm = S.view && comp(S.view, "llm");
|
|
1668
1676
|
const speed = (S.recent.llm || {}).prefill ?? (llm && llm.perf.prefill_tok_s.value);
|
|
1669
1677
|
const plan = prefillPlan(e.tokens_in, speed);
|