@simplexai/localmodels-linux-x64 0.1.0-dev.50 → 0.1.0-dev.51
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 +31 -31
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/catalog.json +1988 -16
- package/modules/localmodels/deploy.py +29 -134
- package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +132 -0
- package/modules/localmodels/harness_probe.py +38 -22
- package/modules/localmodels/library_gateway.py +17 -1
- package/modules/localmodels/library_model.py +5 -0
- package/modules/localmodels/library_poly.py +1 -0
- package/modules/localmodels/library_status.py +96 -31
- package/modules/localmodels/plan_envelope.py +234 -3
- package/modules/localmodels/process_identity.py +19 -9
- package/modules/localmodels/process_identity_darwin.py +155 -0
- package/modules/localmodels/remote_ops_service.py +11 -13
- package/modules/localmodels/runtime_cli.py +8 -8
- package/modules/localmodels/runtime_install.py +25 -1
- package/modules/localmodels/stack_cli.py +39 -0
- package/modules/localmodels/stack_compose.py +12 -43
- package/modules/localmodels/stack_plan.py +55 -3
- package/modules/localmodels/stack_suite.py +51 -12
- package/modules/localmodels/{strata-poly-serve-0.1.45-poly.9.txt → strata-poly-serve-0.2.20-poly.1.txt} +2 -2
- package/modules/localmodels/strata_poly_server.py +19 -0
- package/modules/localmodels/suite.py +26 -1
- package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/RECORD +28 -28
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +0 -75
- /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -140,16 +140,16 @@ def _previous_install(
|
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
def _darwin_listener_pids(port: int) -> set[int] | None:
|
|
143
|
-
"""Processes listening on TCP ``port`` (lsof; its warnings about unrelated mounts aside)."""
|
|
144
|
-
argv = ["/usr/sbin/lsof", "-wnP", f"-iTCP:{port}", "-sTCP:LISTEN", "-
|
|
143
|
+
"""Processes listening on loopback TCP ``port`` (lsof; its warnings about unrelated mounts aside)."""
|
|
144
|
+
argv = ["/usr/sbin/lsof", "-wnP", f"-iTCP:{port}", "-sTCP:LISTEN", "-Fpn"]
|
|
145
145
|
try:
|
|
146
146
|
done = subprocess.run(argv, capture_output=True, text=True, timeout=10, check=False)
|
|
147
147
|
except (OSError, subprocess.SubprocessError):
|
|
148
148
|
return None
|
|
149
|
-
|
|
150
|
-
if done.returncode not in (0, 1) or
|
|
149
|
+
parsed = process_identity_darwin.parse_lsof_listeners(done.stdout, port, "127.0.0.1")
|
|
150
|
+
if done.returncode not in (0, 1) or parsed is None:
|
|
151
151
|
return None
|
|
152
|
-
return
|
|
152
|
+
return parsed[0]
|
|
153
153
|
|
|
154
154
|
|
|
155
155
|
def _process_state(pid: int) -> str | None:
|
|
@@ -576,7 +576,7 @@ def _darwin_listener_problem(port: int, pids: list[int]) -> str | None:
|
|
|
576
576
|
unknown = "who holds the port is unknown, not probed"
|
|
577
577
|
try:
|
|
578
578
|
result = subprocess.run(
|
|
579
|
-
["/usr/sbin/lsof", "-wnP", f"-iTCP:{port}", "-sTCP:LISTEN", "-
|
|
579
|
+
["/usr/sbin/lsof", "-wnP", f"-iTCP:{port}", "-sTCP:LISTEN", "-Fpn"],
|
|
580
580
|
capture_output=True,
|
|
581
581
|
text=True,
|
|
582
582
|
timeout=10,
|
|
@@ -584,14 +584,12 @@ def _darwin_listener_problem(port: int, pids: list[int]) -> str | None:
|
|
|
584
584
|
)
|
|
585
585
|
except (OSError, subprocess.SubprocessError):
|
|
586
586
|
return unknown
|
|
587
|
-
|
|
588
|
-
if result.returncode or result.stderr or not
|
|
589
|
-
return unknown
|
|
590
|
-
if any(line[:1] not in ("p", "f") or not line[1:].isdecimal() for line in lines):
|
|
591
|
-
return unknown # -Fp: a p line per process, an f line per listening descriptor
|
|
592
|
-
owners = {int(line[1:]) for line in lines if line[:1] == "p"}
|
|
593
|
-
if 0 in owners:
|
|
587
|
+
parsed = process_identity_darwin.parse_lsof_listeners(result.stdout, port, "127.0.0.1")
|
|
588
|
+
if result.returncode or result.stderr or parsed is None or not parsed[2]:
|
|
594
589
|
return unknown
|
|
590
|
+
owners = parsed[0]
|
|
591
|
+
if not owners:
|
|
592
|
+
return "the port is not listening"
|
|
595
593
|
return None if owners <= set(pids) else "another process holds the port, not probed"
|
|
596
594
|
|
|
597
595
|
|
|
@@ -9,7 +9,6 @@ import os
|
|
|
9
9
|
import re
|
|
10
10
|
import subprocess
|
|
11
11
|
import sys
|
|
12
|
-
import tempfile
|
|
13
12
|
import time
|
|
14
13
|
from pathlib import Path
|
|
15
14
|
from typing import Any
|
|
@@ -60,9 +59,11 @@ def _active_profile(runtime: str, env: dict[str, str]) -> Path:
|
|
|
60
59
|
return Path(env.get(PROFILE_KEYS[runtime], str(Path.home() / PROFILE_DIRS[runtime])))
|
|
61
60
|
|
|
62
61
|
|
|
63
|
-
def _probe(
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
def _probe(
|
|
63
|
+
argv: list[str], env: dict[str, str] | None = None, *, timeout: float = 5
|
|
64
|
+
) -> tuple[int, str]:
|
|
65
|
+
retry_timeout = argv[-1:] == ["--version"]
|
|
66
|
+
return runtime_process.probe(argv, env, timeout=timeout, retry_timeout=retry_timeout)
|
|
66
67
|
|
|
67
68
|
|
|
68
69
|
class RuntimeVersionVerificationError(ValueError):
|
|
@@ -566,9 +567,7 @@ def apply_plan(plan: dict[str, Any], approve: str, event: Event = lambda _: None
|
|
|
566
567
|
replace = True
|
|
567
568
|
private_directory(target.parent)
|
|
568
569
|
event({"kind": "stage", "stage": "install", "state": "running"})
|
|
569
|
-
|
|
570
|
-
with tempfile.TemporaryDirectory(prefix=".s", dir=target.parent) as temporary:
|
|
571
|
-
stage = Path(temporary)
|
|
570
|
+
with runtime_install.install_stage(target.parent) as stage:
|
|
572
571
|
private_permissions(stage, created=True)
|
|
573
572
|
tree = _install_tree(plan, stage, event)
|
|
574
573
|
command = (
|
|
@@ -577,7 +576,8 @@ def apply_plan(plan: dict[str, Any], approve: str, event: Event = lambda _: None
|
|
|
577
576
|
else [str(tree / ("pi.exe" if os.name == "nt" else "pi"))]
|
|
578
577
|
)
|
|
579
578
|
event({"kind": "stage", "stage": "verify", "state": "running"})
|
|
580
|
-
|
|
579
|
+
timeout = 10 if runtime == "pi" and plan["platform"].startswith("win32-") else 5
|
|
580
|
+
code, version = _probe(command + ["--version"], timeout=timeout)
|
|
581
581
|
try:
|
|
582
582
|
_require_installed_version(code, version, plan["version"])
|
|
583
583
|
if runtime == "pi" and not pi_loads_extensions(command):
|
|
@@ -5,8 +5,10 @@ from __future__ import annotations
|
|
|
5
5
|
import contextlib
|
|
6
6
|
import os
|
|
7
7
|
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
8
10
|
import threading
|
|
9
|
-
from collections.abc import Callable
|
|
11
|
+
from collections.abc import Callable, Iterator
|
|
10
12
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
11
13
|
from functools import partial
|
|
12
14
|
from pathlib import Path
|
|
@@ -25,6 +27,28 @@ from localmodels.runtime_io import (
|
|
|
25
27
|
)
|
|
26
28
|
|
|
27
29
|
|
|
30
|
+
@contextlib.contextmanager
|
|
31
|
+
def install_stage(parent: Path) -> Iterator[Path]:
|
|
32
|
+
"""Remove the stage while preserving an install failure if its files are still busy."""
|
|
33
|
+
# Keep the stage name short for the Windows Pi dependency tree.
|
|
34
|
+
temporary = tempfile.TemporaryDirectory(prefix=".s", dir=parent)
|
|
35
|
+
try:
|
|
36
|
+
yield Path(temporary.name)
|
|
37
|
+
except BaseException:
|
|
38
|
+
try:
|
|
39
|
+
temporary.cleanup()
|
|
40
|
+
except OSError as error:
|
|
41
|
+
print(
|
|
42
|
+
"localmodels harness: stage cleanup failed"
|
|
43
|
+
f" errno={error.errno} winerror={getattr(error, 'winerror', None)}",
|
|
44
|
+
file=sys.stderr,
|
|
45
|
+
flush=True,
|
|
46
|
+
)
|
|
47
|
+
raise
|
|
48
|
+
else:
|
|
49
|
+
temporary.cleanup()
|
|
50
|
+
|
|
51
|
+
|
|
28
52
|
def bootstrap(path: Path, destination: str) -> dict[str, str]:
|
|
29
53
|
if path.is_symlink():
|
|
30
54
|
raise ValueError("Unsafe bootstrap executable")
|
|
@@ -6,6 +6,7 @@ import argparse
|
|
|
6
6
|
import contextlib
|
|
7
7
|
import json
|
|
8
8
|
import os
|
|
9
|
+
import re
|
|
9
10
|
import sys
|
|
10
11
|
from collections.abc import Callable
|
|
11
12
|
from pathlib import Path
|
|
@@ -14,6 +15,7 @@ from typing import Any
|
|
|
14
15
|
from localmodels import (
|
|
15
16
|
app,
|
|
16
17
|
console,
|
|
18
|
+
deploy,
|
|
17
19
|
harness,
|
|
18
20
|
hosts,
|
|
19
21
|
stack_arena,
|
|
@@ -210,6 +212,41 @@ def apply_cli(
|
|
|
210
212
|
return report(record, timing=shown.timing() if shown else None)
|
|
211
213
|
|
|
212
214
|
|
|
215
|
+
_PLAN_ERROR_CODES = frozenset(
|
|
216
|
+
{
|
|
217
|
+
"HUB_UNREACHABLE",
|
|
218
|
+
"MEMORY_INSUFFICIENT",
|
|
219
|
+
"DISK_INSUFFICIENT",
|
|
220
|
+
"GPU_CONFLICT",
|
|
221
|
+
}
|
|
222
|
+
)
|
|
223
|
+
_SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _plan_error_payload(exc: BaseException) -> dict[str, object]:
|
|
227
|
+
"""Structured, path-free error document for ``stack plan --json`` failures."""
|
|
228
|
+
raw_code = getattr(exc, "cause_code", None)
|
|
229
|
+
code = (
|
|
230
|
+
raw_code
|
|
231
|
+
if isinstance(raw_code, str) and raw_code in _PLAN_ERROR_CODES
|
|
232
|
+
else "STACK_PLAN_FAILED"
|
|
233
|
+
)
|
|
234
|
+
payload: dict[str, object] = {
|
|
235
|
+
"schema": "localmodels.stack-plan-error/v1",
|
|
236
|
+
"event": "error",
|
|
237
|
+
"code": code,
|
|
238
|
+
}
|
|
239
|
+
if isinstance(exc, deploy.HubUnreachableError):
|
|
240
|
+
hosts_tried = [
|
|
241
|
+
host
|
|
242
|
+
for host, _ in exc.failures
|
|
243
|
+
if isinstance(host, str) and len(host) <= 253 and _SAFE_HOST.fullmatch(host)
|
|
244
|
+
]
|
|
245
|
+
if hosts_tried:
|
|
246
|
+
payload["hosts"] = list(dict.fromkeys(hosts_tried))
|
|
247
|
+
return payload
|
|
248
|
+
|
|
249
|
+
|
|
213
250
|
def run_cli(
|
|
214
251
|
args: argparse.Namespace,
|
|
215
252
|
*,
|
|
@@ -284,5 +321,7 @@ def run_cli(
|
|
|
284
321
|
) as exc:
|
|
285
322
|
if getattr(args, "jsonl", False):
|
|
286
323
|
return stack_progress.error(2, guard_details(exc))
|
|
324
|
+
if args.stack_command == "plan" and getattr(args, "json", False):
|
|
325
|
+
print(json.dumps(_plan_error_payload(exc), separators=(",", ":")))
|
|
287
326
|
print(f"stack: {exc}", file=sys.stderr)
|
|
288
327
|
return 2
|
|
@@ -48,7 +48,7 @@ from localmodels import stack_gpu_memory as gpu_memory
|
|
|
48
48
|
from localmodels import stack_hardware as hardware
|
|
49
49
|
from localmodels import stack_llm_ram as llm_ram
|
|
50
50
|
from localmodels.approval import digest
|
|
51
|
-
from localmodels.budget import gib, host_ram
|
|
51
|
+
from localmodels.budget import gib, host_ram
|
|
52
52
|
from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
|
|
53
53
|
from localmodels.plan_envelope import PlanError, require_free_port, utc_now
|
|
54
54
|
from localmodels.probe import HostFacts
|
|
@@ -63,6 +63,7 @@ from localmodels.stack_plan import (
|
|
|
63
63
|
command,
|
|
64
64
|
download_budget,
|
|
65
65
|
is_redeploy,
|
|
66
|
+
no_fit_reason,
|
|
66
67
|
own_name,
|
|
67
68
|
platform_error,
|
|
68
69
|
ram_floor,
|
|
@@ -360,53 +361,17 @@ def _choose_llm(
|
|
|
360
361
|
" (with the smallest decision reserve)" if options.get("decision", "none") != "none" else ""
|
|
361
362
|
)
|
|
362
363
|
avail = (reclaimed_ram() if callable(reclaimed_ram) else reclaimed_ram) if vram_fit else 0
|
|
363
|
-
reason =
|
|
364
|
+
reason, cause_code = no_fit_reason(facts, cards, mac, vram_fit=vram_fit, reclaimed_ram=avail)
|
|
364
365
|
raise StackError(
|
|
365
366
|
stack_capacity.no_default_reason(facts, options, posture)
|
|
366
367
|
+ f"no verified LLM fits {where} in the agent posture "
|
|
367
368
|
f"({window_k(posture.floor)} floor){reserve}{reason}; "
|
|
368
369
|
"name a catalog model with --llm (other candidates are not ranked automatically), "
|
|
369
|
-
f"see each card with {command()} stack hardware"
|
|
370
|
+
f"see each card with {command()} stack hardware",
|
|
371
|
+
cause_code=cause_code,
|
|
370
372
|
)
|
|
371
373
|
|
|
372
374
|
|
|
373
|
-
def _no_fit_reason(
|
|
374
|
-
facts: HostFacts,
|
|
375
|
-
cards: list[int],
|
|
376
|
-
mac: bool,
|
|
377
|
-
*,
|
|
378
|
-
vram_fit: bool = False,
|
|
379
|
-
reclaimed_ram: int = 0,
|
|
380
|
-
) -> str:
|
|
381
|
-
gpus = {g["index"]: g for g in facts.get("gpus") or []}
|
|
382
|
-
if mac or not gpus:
|
|
383
|
-
return ""
|
|
384
|
-
if not cards:
|
|
385
|
-
eligible = [
|
|
386
|
-
p
|
|
387
|
-
for p in placements(facts)
|
|
388
|
-
if not p.pooled and not p.budget.uma and len(p.gpu_indices) == 1
|
|
389
|
-
]
|
|
390
|
-
if not eligible:
|
|
391
|
-
return ": no supported single-card GPU placement"
|
|
392
|
-
if not all(p.conflicts for p in eligible):
|
|
393
|
-
return ": no GPU meets automatic selection requirements; check GPU service discovery"
|
|
394
|
-
free = ", ".join(
|
|
395
|
-
f"GPU {p.gpu_indices[0]} {gib(gpus[p.gpu_indices[0]]['free_bytes'])} free"
|
|
396
|
-
for p in eligible
|
|
397
|
-
)
|
|
398
|
-
return (
|
|
399
|
-
f": every placeable card has other GPU work ({free}), and --llm auto skips "
|
|
400
|
-
"such cards; plan again once they end, or, if sharing is fine and that card has "
|
|
401
|
-
"room, use --gpu N --share-gpu"
|
|
402
|
-
)
|
|
403
|
-
if vram_fit:
|
|
404
|
-
avail = gib(host_ram(facts, reclaimed_bytes=reclaimed_ram)[1])
|
|
405
|
-
return f": not enough available RAM ({avail} available)"
|
|
406
|
-
best = gpus[cards[0]]
|
|
407
|
-
return f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free"
|
|
408
|
-
|
|
409
|
-
|
|
410
375
|
def _foundation_reserve(facts: HostFacts, options: StackOptions, aux: list[Plan]) -> int:
|
|
411
376
|
"""The RAM the named foundations hold back before the LLM is chosen: on unified memory only,
|
|
412
377
|
where they share the pool with the LLM and its cache; a CPU auxiliary beside an NVIDIA card
|
|
@@ -452,7 +417,10 @@ def _gpu_conflicts(llm: Plan, facts: HostFacts, share_gpu: bool) -> list[str]:
|
|
|
452
417
|
"""Another program holding or serving on the LLM's card needs the operator's consent."""
|
|
453
418
|
busy = approval.busy_gpus(llm, facts)
|
|
454
419
|
if busy and not share_gpu:
|
|
455
|
-
raise StackError(
|
|
420
|
+
raise StackError(
|
|
421
|
+
"; ".join(busy) + "; if sharing is fine, plan again with --share-gpu",
|
|
422
|
+
cause_code="GPU_CONFLICT",
|
|
423
|
+
)
|
|
456
424
|
return [f"sharing per --share-gpu: {b}" for b in busy]
|
|
457
425
|
|
|
458
426
|
|
|
@@ -543,7 +511,7 @@ def _llama_parts(
|
|
|
543
511
|
resource_template=options.get("defer_services", False),
|
|
544
512
|
)
|
|
545
513
|
except PlanError as exc:
|
|
546
|
-
raise StackError(str(exc)) from None
|
|
514
|
+
raise StackError(str(exc), cause_code=getattr(exc, "cause_code", None)) from None
|
|
547
515
|
llm = choice["llm"] or llm
|
|
548
516
|
served = choice["front"] or choice["plan"]
|
|
549
517
|
if served is not None and not options.get("defer_services"):
|
|
@@ -609,7 +577,8 @@ def ram_budget(parts: Parts) -> dict[str, int]:
|
|
|
609
577
|
f", short about {gib(ram_needed - available)}; primary window is unchanged"
|
|
610
578
|
if fast is not None
|
|
611
579
|
else ""
|
|
612
|
-
)
|
|
580
|
+
),
|
|
581
|
+
cause_code="MEMORY_INSUFFICIENT",
|
|
613
582
|
)
|
|
614
583
|
return ram_parts
|
|
615
584
|
|
|
@@ -15,7 +15,7 @@ from typing import Literal, TypedDict, cast
|
|
|
15
15
|
from localmodels import approval, deploy, gateway, harness, hosts, preparation, reuse, vision
|
|
16
16
|
from localmodels.budget import HARNESS_RAM as HARNESS_RAM
|
|
17
17
|
from localmodels.budget import RAM_FLOOR as RAM_FLOOR
|
|
18
|
-
from localmodels.budget import gib
|
|
18
|
+
from localmodels.budget import gib, host_ram, placements
|
|
19
19
|
from localmodels.gateway_bifrost import FAST_PROVIDER
|
|
20
20
|
from localmodels.plan_envelope import PlanError, resolved_name
|
|
21
21
|
from localmodels.plan_envelope import verified_in_place as verified_in_place
|
|
@@ -49,6 +49,10 @@ def ram_floor(metal: bool) -> int:
|
|
|
49
49
|
class StackError(RuntimeError):
|
|
50
50
|
"""The stack cannot be planned or applied as asked; the message says why."""
|
|
51
51
|
|
|
52
|
+
def __init__(self, message: str, *, cause_code: str | None = None) -> None:
|
|
53
|
+
super().__init__(message)
|
|
54
|
+
self.cause_code = cause_code
|
|
55
|
+
|
|
52
56
|
|
|
53
57
|
class StackGuardError(StackError):
|
|
54
58
|
"""An approval guard with structured, separately sanitized public diagnostics."""
|
|
@@ -61,7 +65,7 @@ class StackGuardError(StackError):
|
|
|
61
65
|
changed_fields: tuple[str, ...] = (),
|
|
62
66
|
public_message: str = "",
|
|
63
67
|
) -> None:
|
|
64
|
-
super().__init__(message)
|
|
68
|
+
super().__init__(message, cause_code=cause_code)
|
|
65
69
|
self.cause_code = cause_code
|
|
66
70
|
self.changed_fields = changed_fields
|
|
67
71
|
# A literal, path-free sentence the machine result may carry; never the message itself.
|
|
@@ -618,7 +622,8 @@ def download_budget(
|
|
|
618
622
|
if free is not None and disk_needed > free:
|
|
619
623
|
raise StackError(
|
|
620
624
|
f"not enough disk space: the stack needs about {gib(disk_needed)}, "
|
|
621
|
-
f"{facts['disk']['path']} has only {gib(free)} free"
|
|
625
|
+
f"{facts['disk']['path']} has only {gib(free)} free",
|
|
626
|
+
cause_code="DISK_INSUFFICIENT",
|
|
622
627
|
)
|
|
623
628
|
return {
|
|
624
629
|
"disk_free_bytes": free,
|
|
@@ -650,3 +655,50 @@ def engine_line(part: Plan) -> str:
|
|
|
650
655
|
f" engine {release['build']} ({release['commit'][:8]}), {release['backend']}"
|
|
651
656
|
+ "".join(f", {n}" for n in needs if n)
|
|
652
657
|
)
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def no_fit_reason(
|
|
661
|
+
facts: HostFacts,
|
|
662
|
+
cards: list[int],
|
|
663
|
+
mac: bool,
|
|
664
|
+
*,
|
|
665
|
+
vram_fit: bool = False,
|
|
666
|
+
reclaimed_ram: int = 0,
|
|
667
|
+
) -> tuple[str, str | None]:
|
|
668
|
+
"""Explain why no verified auto LLM fit and classify the refusal for structured callers."""
|
|
669
|
+
gpus = {g["index"]: g for g in facts.get("gpus") or []}
|
|
670
|
+
if mac:
|
|
671
|
+
return "", "MEMORY_INSUFFICIENT"
|
|
672
|
+
if not gpus:
|
|
673
|
+
return "", None
|
|
674
|
+
if not cards:
|
|
675
|
+
eligible = [
|
|
676
|
+
p
|
|
677
|
+
for p in placements(facts)
|
|
678
|
+
if not p.pooled and not p.budget.uma and len(p.gpu_indices) == 1
|
|
679
|
+
]
|
|
680
|
+
if not eligible:
|
|
681
|
+
return ": no supported single-card GPU placement", None
|
|
682
|
+
if not all(p.conflicts for p in eligible):
|
|
683
|
+
return (
|
|
684
|
+
": no GPU meets automatic selection requirements; check GPU service discovery",
|
|
685
|
+
None,
|
|
686
|
+
)
|
|
687
|
+
free = ", ".join(
|
|
688
|
+
f"GPU {p.gpu_indices[0]} {gib(gpus[p.gpu_indices[0]]['free_bytes'])} free"
|
|
689
|
+
for p in eligible
|
|
690
|
+
)
|
|
691
|
+
return (
|
|
692
|
+
f": every placeable card has other GPU work ({free}), and --llm auto skips "
|
|
693
|
+
"such cards; plan again once they end, or, if sharing is fine and that card has "
|
|
694
|
+
"room, use --gpu N --share-gpu",
|
|
695
|
+
"GPU_CONFLICT",
|
|
696
|
+
)
|
|
697
|
+
if vram_fit:
|
|
698
|
+
avail = gib(host_ram(facts, reclaimed_bytes=reclaimed_ram)[1])
|
|
699
|
+
return f": not enough available RAM ({avail} available)", "MEMORY_INSUFFICIENT"
|
|
700
|
+
best = gpus[cards[0]]
|
|
701
|
+
return (
|
|
702
|
+
f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free",
|
|
703
|
+
"MEMORY_INSUFFICIENT",
|
|
704
|
+
)
|
|
@@ -18,7 +18,7 @@ from localmodels import stack_decision as decide
|
|
|
18
18
|
from localmodels import stack_gpu_memory as gpu_memory
|
|
19
19
|
from localmodels import stack_hardware as hardware
|
|
20
20
|
from localmodels import stack_llm_ram as llm_ram
|
|
21
|
-
from localmodels.budget import gib, holders, host_ram, idle_cards, sharing_cards
|
|
21
|
+
from localmodels.budget import busy_cards, gib, holders, host_ram, idle_cards, sharing_cards
|
|
22
22
|
from localmodels.context_policy import AgentPosture
|
|
23
23
|
from localmodels.engines import engine_lock_path
|
|
24
24
|
from localmodels.plan_envelope import PlanError
|
|
@@ -160,9 +160,9 @@ def poly_reserve_mib(recipe: suite.SuiteRecipe, gpu: GPU, beside_mib: int) -> in
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
def auto_strata_wanted(facts: HostFacts, options: StackOptions) -> bool:
|
|
163
|
-
"""Whether ``--llm auto`` also weighs Strata recipes: on Linux and Windows (
|
|
164
|
-
|
|
165
|
-
auto_strata_candidates), and not for ``--prefer concurrent``, because a Strata recipe whose
|
|
163
|
+
"""Whether ``--llm auto`` also weighs Strata recipes: on Linux and Windows (a Mac runs a
|
|
164
|
+
strata-poly recipe that ``--llm`` names, and none is validated there; on Windows only
|
|
165
|
+
recipes whose engine has a Windows build, see auto_strata_candidates), and not for ``--prefer concurrent``, because a Strata recipe whose
|
|
166
166
|
experts stay in RAM gains nothing from a second request (GY1), nor under ``--context``: a
|
|
167
167
|
Strata recipe fixes its own window."""
|
|
168
168
|
return (
|
|
@@ -230,6 +230,23 @@ def strata_recipe(facts: HostFacts, requested: str) -> tuple[suite.SuiteRecipe |
|
|
|
230
230
|
]
|
|
231
231
|
|
|
232
232
|
|
|
233
|
+
METAL_BESIDE_BYTES = 12 << 30
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def unified_bytes(recipe: suite.SuiteRecipe) -> int:
|
|
237
|
+
"""What a strata-poly LLM holds on a Mac, where every expert stays in unified memory: its
|
|
238
|
+
files and METAL_BESIDE_BYTES (PS219, M5 Ultra, prompts up to 58K tokens: the engine held 1.4
|
|
239
|
+
to 4.4 GiB beside them; --conversation-cache-mib auto parks up to 8 GiB more)."""
|
|
240
|
+
return sum(f["size_bytes"] for f in recipe["files"] if not f.get("vision")) + METAL_BESIDE_BYTES
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _on_unified_memory(llm: Plan, recipe: suite.SuiteRecipe) -> Plan:
|
|
244
|
+
"""The plan on a Mac: priced whole and once (``launch.unified_bytes``), no cgroup ceiling."""
|
|
245
|
+
added = int(str(llm["launch"]["memory_estimate_bytes"])) - recipe["memory_estimate_bytes"]
|
|
246
|
+
llm["launch"]["unified_bytes"] = unified_bytes(recipe) + added
|
|
247
|
+
return suite.unbounded(llm)
|
|
248
|
+
|
|
249
|
+
|
|
233
250
|
def _suite_gpu(
|
|
234
251
|
facts: HostFacts,
|
|
235
252
|
llm: suite.SuiteRecipe,
|
|
@@ -255,6 +272,17 @@ def _suite_gpu(
|
|
|
255
272
|
)
|
|
256
273
|
if found is not None:
|
|
257
274
|
return found
|
|
275
|
+
mac = metal.device(facts) if llm["runtime"] == "strata-poly" else None # Strata is CUDA only
|
|
276
|
+
if mac is not None: # one Metal GPU on unified memory
|
|
277
|
+
if gpu not in (None, 0):
|
|
278
|
+
raise StackError(f"this computer has one Metal GPU (GPU 0), no GPU {gpu}")
|
|
279
|
+
busy = busy_cards(facts, [mac["uuid"]])
|
|
280
|
+
if busy and not share_gpu:
|
|
281
|
+
raise StackError("; ".join(busy) + "; if sharing is fine, plan again with --share-gpu")
|
|
282
|
+
if mac["free_bytes"] < need:
|
|
283
|
+
free = gib(mac["free_bytes"])
|
|
284
|
+
raise StackError(f"{llm['id']} needs {gib(need)} of unified memory, {free} is free")
|
|
285
|
+
return mac
|
|
258
286
|
candidates = sharing_cards(facts, need) if share_gpu else idle_cards(facts, need)
|
|
259
287
|
cards = [g for g in candidates if gpu is None or g["index"] == gpu]
|
|
260
288
|
if not cards:
|
|
@@ -296,7 +324,8 @@ def strata_parts(
|
|
|
296
324
|
except PlanError as exc:
|
|
297
325
|
raise StackError(f"{exc}; cannot share a card with {llm_recipe['id']}") from None
|
|
298
326
|
vram = pick.tier["vram_bytes"] if pick else 0
|
|
299
|
-
|
|
327
|
+
unified = metal.supported(facts) and llm_recipe["runtime"] == "strata-poly"
|
|
328
|
+
need = unified_bytes(llm_recipe) if unified else int(llm_recipe.get("vram_bytes", 0))
|
|
300
329
|
gpu = _suite_gpu(
|
|
301
330
|
facts, llm_recipe, need, running_llm, options.get("gpu"), share_gpu=options["share_gpu"]
|
|
302
331
|
)
|
|
@@ -336,7 +365,9 @@ def strata_parts(
|
|
|
336
365
|
reasoning_budget=int(options.get("reasoning_budget") or 0),
|
|
337
366
|
)
|
|
338
367
|
llm = running_llm or suite.build_plan(hosts.LOCAL_ID, facts, llm_recipe, opts)
|
|
339
|
-
if not running_llm and
|
|
368
|
+
if not running_llm and unified:
|
|
369
|
+
llm = _on_unified_memory(llm, llm_recipe)
|
|
370
|
+
elif not running_llm and facts["platform"] == "win32":
|
|
340
371
|
llm = suite.unbounded(llm) # no cgroups: priced by the recipe's estimate
|
|
341
372
|
if running_llm:
|
|
342
373
|
warnings.append(
|
|
@@ -359,7 +390,12 @@ def strata_parts(
|
|
|
359
390
|
|
|
360
391
|
ceiling = suite.size_bytes(options["suite_memory"])
|
|
361
392
|
available = host_ram(facts, reclaimed_bytes=owned_ram())[1]
|
|
362
|
-
|
|
393
|
+
floor = ram_floor(unified)
|
|
394
|
+
|
|
395
|
+
def held(plan: Plan) -> int:
|
|
396
|
+
return int(str(plan["launch"]["unified_bytes"])) if unified else bounded_ram(plan)
|
|
397
|
+
|
|
398
|
+
used = held(llm) + decide.host_ram(choice) + HARNESS_RAM
|
|
363
399
|
aux = fit_aux(
|
|
364
400
|
aux_plans(facts, options, listening, previous, warnings, approved=approved),
|
|
365
401
|
used,
|
|
@@ -367,21 +403,24 @@ def strata_parts(
|
|
|
367
403
|
ceiling,
|
|
368
404
|
available,
|
|
369
405
|
warnings,
|
|
406
|
+
floor=floor,
|
|
370
407
|
)
|
|
371
|
-
room = min(ceiling, available -
|
|
408
|
+
room = min(ceiling, available - floor) - used - sum(bounded_ram(p) for p in aux)
|
|
372
409
|
llm = _decide_parking(
|
|
373
410
|
llm, llm_recipe, facts, opts, options, running_llm is not None, room, warnings
|
|
374
411
|
)
|
|
375
|
-
|
|
412
|
+
if unified and "unified_bytes" not in llm["launch"]: # parking planned the LLM again
|
|
413
|
+
llm = _on_unified_memory(llm, llm_recipe)
|
|
414
|
+
whole = held(llm) + decide.host_ram(choice) + sum(map(bounded_ram, aux)) + HARNESS_RAM
|
|
376
415
|
if whole > ceiling:
|
|
377
416
|
raise StackError(
|
|
378
417
|
f"the whole-stack estimate {gib(whole)} exceeds --suite-memory {options['suite_memory']}"
|
|
379
418
|
)
|
|
380
|
-
if options["llm"] == "auto" and not running_llm and whole +
|
|
419
|
+
if options["llm"] == "auto" and not running_llm and whole + floor > available:
|
|
381
420
|
# stack_compose.assemble would refuse this plan outright; refusing here lets auto move
|
|
382
421
|
# on to a smaller recipe or to llama.cpp.
|
|
383
422
|
raise StackError(
|
|
384
|
-
f"its stack needs about {gib(whole +
|
|
423
|
+
f"its stack needs about {gib(whole + floor)} of RAM, {gib(available)} is available"
|
|
385
424
|
)
|
|
386
425
|
vram_needed = need + vram
|
|
387
426
|
if vram_needed > gpu["total_bytes"]:
|
|
@@ -392,7 +431,7 @@ def strata_parts(
|
|
|
392
431
|
return {
|
|
393
432
|
"llm": llm,
|
|
394
433
|
"llm_running": running_llm is not None,
|
|
395
|
-
"llm_ram":
|
|
434
|
+
"llm_ram": held(llm),
|
|
396
435
|
"decision": choice,
|
|
397
436
|
"aux": aux,
|
|
398
437
|
"ram_available": available,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# PolyStrata 0.
|
|
1
|
+
# PolyStrata 0.2.20-poly.1's Python server (terminal/serve/server.py, MIT) for strata-poly LLM recipes:
|
|
2
2
|
# jinja2 3.1.6 (BSD-3-Clause) with markupsafe 3.0.3 (BSD-3-Clause) renders the chat template,
|
|
3
3
|
# regex 2026.9.10 (Apache-2.0 and CNRI-Python) drives its tokenizer, psutil 7.2.2 (BSD-3-Clause)
|
|
4
|
-
# reads memory for its status page. The versions are PolyStrata's own requirements.txt pins; its
|
|
4
|
+
# reads memory for its status page. The versions are PolyStrata's own terminal/requirements.txt pins, unchanged since 0.1.45-poly.9; its
|
|
5
5
|
# build tools, numpy, pillow (images are off in these recipes) and download helpers are left out.
|
|
6
6
|
# Installed by localmodels/frontend.py with --require-hashes --no-deps. Regenerate with
|
|
7
7
|
# uv pip compile --universal --python-version 3.10 --generate-hashes --no-header --no-annotate
|
|
@@ -24,6 +24,7 @@ import argparse
|
|
|
24
24
|
import json
|
|
25
25
|
import os
|
|
26
26
|
import runpy
|
|
27
|
+
import shutil
|
|
27
28
|
import subprocess
|
|
28
29
|
import sys
|
|
29
30
|
from pathlib import Path
|
|
@@ -54,6 +55,23 @@ def prepare(engine_dir: Path, gguf: Path, deploy_dir: Path) -> None:
|
|
|
54
55
|
)
|
|
55
56
|
if not tokenizer_ready(deploy_dir):
|
|
56
57
|
raise SystemExit(f"{tool} wrote no tokenizer into {deploy_dir}")
|
|
58
|
+
# A GGUF without a chat template of its own: the recipe ships the model's beside it.
|
|
59
|
+
own, written = (
|
|
60
|
+
gguf.parent / "chat_template.jinja",
|
|
61
|
+
deploy_dir / "tokenizer" / "chat_template.jinja",
|
|
62
|
+
)
|
|
63
|
+
if own.is_file() and not written.exists():
|
|
64
|
+
shutil.copyfile(own, written)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def seed_expert_profile(engine_dir: Path, config: Path) -> None:
|
|
68
|
+
"""The engine keeps its expert counts in the deployment's ``expert-profile.txt``. For a model
|
|
69
|
+
PolyStrata ships counts for (the profile's ``shipped_expert_profile``), that file starts as
|
|
70
|
+
the shipped one, as upstream's setup has it."""
|
|
71
|
+
shipped = json.loads(config.read_text(encoding="utf-8")).get("shipped_expert_profile")
|
|
72
|
+
own = config.parent / "expert-profile.txt"
|
|
73
|
+
if shipped and not own.exists():
|
|
74
|
+
shutil.copyfile(source_root(engine_dir) / shipped, own)
|
|
57
75
|
|
|
58
76
|
|
|
59
77
|
def _expanded(value: object, home: str) -> object:
|
|
@@ -115,6 +133,7 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
115
133
|
root = str(source_root(args.engine_dir).resolve())
|
|
116
134
|
if root not in sys.path:
|
|
117
135
|
sys.path.insert(0, root)
|
|
136
|
+
seed_expert_profile(args.engine_dir, args.config)
|
|
118
137
|
sys.argv = server_argv(args.engine_dir, resolve(args.config), args.host, args.port)
|
|
119
138
|
runpy.run_path(sys.argv[0], run_name="__main__")
|
|
120
139
|
|
|
@@ -91,6 +91,12 @@ class ExpertCacheSizing(TypedDict):
|
|
|
91
91
|
source: str # where the terms were measured
|
|
92
92
|
|
|
93
93
|
|
|
94
|
+
class CardArgs(TypedDict, total=False):
|
|
95
|
+
at_least_bytes: int
|
|
96
|
+
platforms: list[str] # only on these (facts["platform"]); every platform when absent
|
|
97
|
+
args: list[str]
|
|
98
|
+
|
|
99
|
+
|
|
94
100
|
class SuiteRecipe(cat.ComponentRecipe, total=False):
|
|
95
101
|
"""A catalog component the suite launches from a template (see module docstring)."""
|
|
96
102
|
|
|
@@ -108,6 +114,9 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
|
|
|
108
114
|
# strata-poly recipes: what the engine keeps free of the card (--vram-reserve-mib) for the
|
|
109
115
|
# display and its own overshoot of that reserve.
|
|
110
116
|
vram_reserve_mib: int
|
|
117
|
+
# strata-poly recipes: engine flags given only to a card with room to spare (``at_least_bytes``
|
|
118
|
+
# of the card less the reserve) or only on some platforms, appended to the profile's args.
|
|
119
|
+
card_args: list[CardArgs]
|
|
111
120
|
limits: dict[str, str]
|
|
112
121
|
env: dict[str, str]
|
|
113
122
|
argv: list[str]
|
|
@@ -332,6 +341,21 @@ def build_plan(host_id: str, facts: HostFacts, r: SuiteRecipe, options: SuiteOpt
|
|
|
332
341
|
profile_template["vision"] = vision.strata_section(reader, cores, exe="{vision_exe}")
|
|
333
342
|
if r["runtime"] == "strata":
|
|
334
343
|
profile_template["args"] = [*cast("list[str]", profile_template["args"]), "--vision"]
|
|
344
|
+
if options.gpu and r.get("card_args"):
|
|
345
|
+
# Under --gpu-memory the reserve also holds what the share leaves out of the real card
|
|
346
|
+
# (stack_gpu_memory.LEFT_OUT, stack_suite.poly_reserve_mib), so the room is counted on it.
|
|
347
|
+
left_out = int(cast("dict[str, int]", options.gpu).get("share_left_out_bytes", 0))
|
|
348
|
+
room = options.gpu["total_bytes"] + left_out - (options.vram_reserve_mib << 20)
|
|
349
|
+
profile_template["args"] = [
|
|
350
|
+
*cast("list[str]", profile_template["args"]),
|
|
351
|
+
*(
|
|
352
|
+
a
|
|
353
|
+
for group in r["card_args"]
|
|
354
|
+
if room >= group["at_least_bytes"]
|
|
355
|
+
and facts["platform"] in group.get("platforms", [facts["platform"]])
|
|
356
|
+
for a in group["args"]
|
|
357
|
+
),
|
|
358
|
+
]
|
|
335
359
|
if options.reasoning_budget and r["runtime"] == "strata":
|
|
336
360
|
# strata-<model>.json's default for requests that name none (Strata DETAILS, v0.2.4).
|
|
337
361
|
profile_template["reasoning_budget_tokens"] = options.reasoning_budget
|
|
@@ -468,7 +492,8 @@ def _readiness(plan: Plan, r: SuiteRecipe) -> None:
|
|
|
468
492
|
|
|
469
493
|
|
|
470
494
|
def _check_runtime(facts: HostFacts, recipe: SuiteRecipe) -> None:
|
|
471
|
-
|
|
495
|
+
# PolyStrata's strata-poly has a Metal build; Strata's own engine is CUDA only.
|
|
496
|
+
if facts["platform"] == "darwin" and recipe["runtime"] == "strata":
|
|
472
497
|
raise PlanError("Strata recipes need CUDA and cannot run on Apple Silicon Metal")
|
|
473
498
|
|
|
474
499
|
|