@simplexai/localmodels-linux-x64 0.1.0-dev.35 → 0.1.0-dev.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +124 -102
- package/kit.py +1 -0
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +9 -3
- package/modules/localmodels/bifrost_config.py +188 -0
- package/modules/localmodels/budget.py +15 -2
- package/modules/localmodels/catalog.json +235 -2
- package/modules/localmodels/catalog.py +51 -320
- package/modules/localmodels/catalog_add.py +2 -8
- package/modules/localmodels/catalog_recipes.py +321 -0
- package/modules/localmodels/cli_parser.py +4 -1
- package/modules/localmodels/console.py +5 -4
- package/modules/localmodels/contracts.py +13 -3
- package/modules/localmodels/debug_cli.py +158 -0
- package/modules/localmodels/debug_mode.py +727 -0
- package/modules/localmodels/debug_stub_server.py +192 -0
- package/modules/localmodels/decode_calibration.json +1 -1
- package/modules/localmodels/decode_calibration.py +34 -17
- package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
- package/modules/localmodels/gateway.py +21 -155
- package/modules/localmodels/gateway_accept.py +201 -0
- package/modules/localmodels/gateway_bifrost.py +19 -184
- package/modules/localmodels/gateway_cli.py +11 -4
- package/modules/localmodels/gateway_foundations.py +2 -4
- package/modules/localmodels/gateway_probe.py +0 -1
- package/modules/localmodels/gateway_server.py +2 -3
- package/modules/localmodels/gpu_specs.py +12 -0
- package/modules/localmodels/guard.py +2 -7
- package/modules/localmodels/harness.py +16 -129
- package/modules/localmodels/harness_cleanup.py +135 -0
- package/modules/localmodels/harness_gateway.py +16 -14
- package/modules/localmodels/harness_probe.py +12 -4
- package/modules/localmodels/hosts.py +25 -2
- package/modules/localmodels/http_local.py +59 -0
- package/modules/localmodels/install.py +23 -8
- package/modules/localmodels/library_gateway.py +9 -9
- package/modules/localmodels/library_jobs.py +76 -27
- package/modules/localmodels/library_serve.py +12 -1
- package/modules/localmodels/library_state.py +6 -1
- package/modules/localmodels/llm_rank.py +155 -7
- package/modules/localmodels/metal_probe.py +11 -7
- package/modules/localmodels/probe.py +108 -174
- package/modules/localmodels/process_identity.py +109 -154
- package/modules/localmodels/process_windows.py +86 -0
- package/modules/localmodels/recommend.py +32 -3
- package/modules/localmodels/recommend_cli.py +14 -6
- package/modules/localmodels/remote_ops.py +65 -0
- package/modules/localmodels/remote_ops_download.py +2 -2
- package/modules/localmodels/remote_ops_prepare.py +19 -0
- package/modules/localmodels/remote_ops_service.py +14 -2
- package/modules/localmodels/runtime_args.py +10 -3
- package/modules/localmodels/runtime_auth.py +5 -9
- package/modules/localmodels/runtime_cli.py +128 -129
- package/modules/localmodels/runtime_discovery.py +84 -0
- package/modules/localmodels/runtime_install.py +101 -0
- package/modules/localmodels/runtime_releases.py +302 -0
- package/modules/localmodels/service_stop.py +8 -108
- package/modules/localmodels/service_upgrade.py +394 -63
- package/modules/localmodels/services_cli.py +24 -14
- package/modules/localmodels/setup_inspection.py +97 -9
- package/modules/localmodels/setup_text.py +7 -0
- package/modules/localmodels/sizecalc.py +0 -1
- package/modules/localmodels/stack.py +14 -221
- package/modules/localmodels/stack_arena.py +732 -0
- package/modules/localmodels/stack_args.py +15 -9
- package/modules/localmodels/stack_auto.py +384 -3
- package/modules/localmodels/stack_aux_gpu.py +4 -3
- package/modules/localmodels/stack_capacity.py +138 -0
- package/modules/localmodels/stack_cleanup.py +9 -4
- package/modules/localmodels/stack_cli.py +286 -0
- package/modules/localmodels/stack_compose.py +76 -32
- package/modules/localmodels/stack_console.py +9 -6
- package/modules/localmodels/stack_hardware.py +96 -270
- package/modules/localmodels/stack_hardware_text.py +263 -0
- package/modules/localmodels/stack_journal.py +3 -9
- package/modules/localmodels/stack_ledger.py +48 -18
- package/modules/localmodels/stack_lifecycle.py +33 -312
- package/modules/localmodels/stack_mcp.py +729 -0
- package/modules/localmodels/stack_memory.py +0 -2
- package/modules/localmodels/stack_picks.py +73 -18
- package/modules/localmodels/stack_plan.py +23 -5
- package/modules/localmodels/stack_preflight.py +11 -19
- package/modules/localmodels/stack_remove.py +373 -0
- package/modules/localmodels/stack_route.py +101 -17
- package/modules/localmodels/stack_suite.py +16 -10
- package/modules/localmodels/stack_summary.py +14 -0
- package/modules/localmodels/stack_try.py +238 -24
- package/modules/localmodels/stack_try_client.py +53 -15
- package/modules/localmodels/stack_try_docs.py +2 -2
- package/modules/localmodels/stack_view.py +24 -171
- package/modules/localmodels/stack_view_access.py +114 -1
- package/modules/localmodels/stack_view_agent.py +3 -13
- package/modules/localmodels/stack_view_hub.py +9 -10
- package/modules/localmodels/stack_view_llm.py +1 -1
- package/modules/localmodels/stack_view_sandbox.py +2 -2
- package/modules/localmodels/stack_view_schema.py +183 -0
- package/modules/localmodels/stack_view_serve.py +7 -1
- package/modules/localmodels/stack_view_service.py +1 -2
- package/modules/localmodels/stack_view_text.py +13 -9
- package/modules/localmodels/stack_warm.py +3 -0
- package/modules/localmodels/stack_warm_store.py +517 -0
- package/modules/localmodels/tui.py +28 -4
- package/modules/localmodels/tui_dialogs.py +136 -0
- package/modules/localmodels/tui_modals.py +279 -0
- package/modules/localmodels/tui_screen.py +113 -154
- package/modules/localmodels/tui_views.py +134 -203
- package/modules/localmodels/web/index.html +510 -101
- package/modules/localmodels/web/sizecalc/app.js +363 -10
- package/modules/localmodels/web/sizecalc/page.html +27 -3
- package/modules/localmodels/web/view/fleet.html +11 -2
- package/modules/localmodels/web/view/fleet.js +191 -17
- package/modules/localmodels/web/view/i18n.js +3 -2
- package/modules/localmodels/web/view/index.html +1 -1
- package/modules/localmodels/web/view/nav.js +22 -3
- package/modules/localmodels/web/view/view.css +63 -18
- package/modules/localmodels/web/view/view.js +169 -32
- package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
- package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +120 -98
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -15,10 +15,12 @@ from localmodels import (
|
|
|
15
15
|
cli_help,
|
|
16
16
|
deploy,
|
|
17
17
|
harness,
|
|
18
|
+
stack_arena,
|
|
18
19
|
stack_card,
|
|
19
20
|
stack_debug,
|
|
20
21
|
stack_down,
|
|
21
22
|
stack_ledger,
|
|
23
|
+
stack_mcp,
|
|
22
24
|
stack_memory,
|
|
23
25
|
stack_ports,
|
|
24
26
|
stack_rollback,
|
|
@@ -50,6 +52,7 @@ GROUPS = (
|
|
|
50
52
|
"status",
|
|
51
53
|
"warm",
|
|
52
54
|
"try",
|
|
55
|
+
"arena",
|
|
53
56
|
"ledger",
|
|
54
57
|
"card",
|
|
55
58
|
"view",
|
|
@@ -60,13 +63,12 @@ GROUPS = (
|
|
|
60
63
|
),
|
|
61
64
|
),
|
|
62
65
|
("clean up", ("remove", "prune")),
|
|
63
|
-
("for installers and agents", ("capabilities", "commands", "clients")),
|
|
66
|
+
("for installers and agents", ("capabilities", "commands", "clients", "mcp")),
|
|
64
67
|
)
|
|
65
68
|
STACK = """\
|
|
66
69
|
Plan, install and run the local agent stack on this computer: the smartest LLM that fits,
|
|
67
|
-
a gateway (Bifrost by default)
|
|
68
|
-
|
|
69
|
-
--no-search leaves search out.
|
|
70
|
+
a gateway (Bifrost by default) and the pi agent. A GPU decision model, embedding/reranker/STT,
|
|
71
|
+
TTS and free web search are optional and off by default (--decision, --aux, --tts, --search).
|
|
70
72
|
Nothing is downloaded or started until you approve a saved plan.
|
|
71
73
|
|
|
72
74
|
typical flow:
|
|
@@ -83,13 +85,15 @@ typical flow:
|
|
|
83
85
|
6. remove uninstall everything but the downloads (--purge: those too)"""
|
|
84
86
|
AGENTS = """\
|
|
85
87
|
Read-only: hardware, memory, what-if, decisions, plan (saves a file), status, view, verify, doctor,
|
|
86
|
-
commands, clients,
|
|
87
|
-
--approve. warm sends
|
|
88
|
-
macOS purge)
|
|
88
|
+
commands, clients, mcp (read-only stdio JSON-RPC), ledger, arena leaderboard, card (writes a local
|
|
89
|
+
SVG), remove --dry-run, and rollback without --approve. warm sends each installed LLM two short
|
|
90
|
+
requests (--sudo also runs macOS purge); try sends one demo request through the local gateway (try
|
|
91
|
+
search queries public search engines) and changes nothing installed. arena compares two local LLMs
|
|
92
|
+
blindly and writes only model IDs and Elo counts.
|
|
89
93
|
Installs only an approved plan: apply PLAN --approve ID, rollback --approve ID; install asks
|
|
90
94
|
y/N (--yes skips). Also changes things: up (starts what was installed), down (stops it), remove, prune --yes.
|
|
91
95
|
Machine output: --json on plan, hardware, memory, what-if, status, view, verify, doctor, up, down, apply,
|
|
92
|
-
clients, warm, ledger.
|
|
96
|
+
clients, warm, ledger, arena.
|
|
93
97
|
`%(prog)s commands --json` describes every subcommand and option as JSON.
|
|
94
98
|
Progress bars draw only on a terminal; piped output is plain lines (NO_COLOR also honored)."""
|
|
95
99
|
EXIT = (
|
|
@@ -397,7 +401,7 @@ def _plan(actions: Parsers) -> None:
|
|
|
397
401
|
("%(prog)s", "recommended stack for this computer"),
|
|
398
402
|
("%(prog)s --llm qwen3.8-27b --decision none", "pin the LLM, no decision model"),
|
|
399
403
|
("%(prog)s --aux embedding,reranker", "opt in to some auxiliaries"),
|
|
400
|
-
("%(prog)s --
|
|
404
|
+
("%(prog)s --search", "add the free web search"),
|
|
401
405
|
("%(prog)s --gpu 1 --share-gpu", "a card that already runs something"),
|
|
402
406
|
("%(prog)s --update", "replace only what changed in the installed stack"),
|
|
403
407
|
("%(prog)s --facts host.json --offline --json", "price saved facts, no network"),
|
|
@@ -503,6 +507,7 @@ def _helpers(actions: Parsers) -> None:
|
|
|
503
507
|
"value, default, choices, help) and the examples, for agents and completion scripts.",
|
|
504
508
|
examples=[("%(prog)s", "one line per command"), ("%(prog)s --json", "")],
|
|
505
509
|
)
|
|
510
|
+
stack_mcp.add_parser(actions)
|
|
506
511
|
|
|
507
512
|
|
|
508
513
|
def _clients(actions: Parsers) -> None:
|
|
@@ -525,6 +530,7 @@ def _day2(actions: Parsers) -> None:
|
|
|
525
530
|
stack_down.add_parser(actions)
|
|
526
531
|
stack_warm.add_parser(actions)
|
|
527
532
|
stack_try.add_parser(actions)
|
|
533
|
+
stack_arena.add_parser(actions)
|
|
528
534
|
stack_ledger.add_parser(actions)
|
|
529
535
|
stack_card.add_parser(actions)
|
|
530
536
|
stack_rollback.add_parser(actions)
|
|
@@ -8,12 +8,56 @@ are supplied through the planner's readers and suite.build_plan. No state is sav
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
from collections.abc import Callable
|
|
11
|
+
from dataclasses import replace
|
|
12
|
+
from typing import Any, cast
|
|
11
13
|
|
|
12
|
-
from localmodels import
|
|
14
|
+
from localmodels import (
|
|
15
|
+
catalog as cat,
|
|
16
|
+
)
|
|
17
|
+
from localmodels import (
|
|
18
|
+
deploy,
|
|
19
|
+
hosts,
|
|
20
|
+
llm_rank,
|
|
21
|
+
metal,
|
|
22
|
+
preparation,
|
|
23
|
+
reuse,
|
|
24
|
+
stack_llm_ram,
|
|
25
|
+
stack_ports,
|
|
26
|
+
stack_suite,
|
|
27
|
+
stack_warm_store,
|
|
28
|
+
)
|
|
29
|
+
from localmodels import stack_aux_gpu as aux_gpu
|
|
30
|
+
from localmodels import stack_decision as decide
|
|
31
|
+
from localmodels import stack_gpu_memory as gpu_memory
|
|
32
|
+
from localmodels import stack_hardware as hardware
|
|
33
|
+
from localmodels.budget import HARNESS_RAM, RAM_FLOOR, gpu_conflicts, host_ram
|
|
34
|
+
from localmodels.context_policy import AgentPosture
|
|
35
|
+
from localmodels.estimator import HardwareBudget
|
|
13
36
|
from localmodels.plan_envelope import PlanError
|
|
14
37
|
from localmodels.probe import HostFacts
|
|
15
|
-
from localmodels.records import Plan
|
|
16
|
-
from localmodels.stack_plan import
|
|
38
|
+
from localmodels.records import PinnedFile, Plan
|
|
39
|
+
from localmodels.stack_plan import (
|
|
40
|
+
DecisionChoice,
|
|
41
|
+
LlmFit,
|
|
42
|
+
Parts,
|
|
43
|
+
StackError,
|
|
44
|
+
StackOptions,
|
|
45
|
+
StackPlan,
|
|
46
|
+
default_options,
|
|
47
|
+
download_budget,
|
|
48
|
+
own_name,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
PreviousFn = Callable[[str, int], Plan | None]
|
|
52
|
+
ExistingFn = Callable[[list[cat.LlamaComponentRecipe]], list[reuse.ExistingService]]
|
|
53
|
+
LlamaReads = tuple[Callable[[int], bool], PreviousFn, ExistingFn, bool]
|
|
54
|
+
|
|
55
|
+
DEFAULT_READS: LlamaReads = (
|
|
56
|
+
lambda _: False,
|
|
57
|
+
lambda *_: None,
|
|
58
|
+
lambda _: [],
|
|
59
|
+
False,
|
|
60
|
+
)
|
|
17
61
|
|
|
18
62
|
|
|
19
63
|
def strata_parts(
|
|
@@ -76,3 +120,340 @@ def strata_parts(
|
|
|
76
120
|
return parts
|
|
77
121
|
passed_over.extend(skipped)
|
|
78
122
|
return None
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def maybe_capped(facts: HostFacts, options: StackOptions) -> HostFacts | None:
|
|
126
|
+
"""``facts`` with ``--gpu-memory`` applied when not already capped; ``None`` if invalid."""
|
|
127
|
+
if not options.get("gpu_memory") or any(
|
|
128
|
+
gpu_memory.LEFT_OUT in g for g in facts.get("gpus") or []
|
|
129
|
+
):
|
|
130
|
+
return facts
|
|
131
|
+
try:
|
|
132
|
+
return gpu_memory.capped(facts, options)[0]
|
|
133
|
+
except StackError:
|
|
134
|
+
return None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def card_fits(
|
|
138
|
+
facts: HostFacts, index: int, options: StackOptions, llama_score: int
|
|
139
|
+
) -> list[LlmFit]:
|
|
140
|
+
"""Validated Strata/PolyStrata recipes that fit ``index`` under ``--llm auto``'s rules."""
|
|
141
|
+
if options.get("kv") or options.get("quant"):
|
|
142
|
+
return []
|
|
143
|
+
prefer = "concurrent" if options.get("prefer") == "concurrent" else "smartest"
|
|
144
|
+
probe_opts: StackOptions = {**options, "llm": "auto", "prefer": prefer}
|
|
145
|
+
capped = maybe_capped(facts, probe_opts)
|
|
146
|
+
if capped is None:
|
|
147
|
+
return []
|
|
148
|
+
facts = capped
|
|
149
|
+
if not stack_suite.auto_strata_wanted(facts, probe_opts):
|
|
150
|
+
return []
|
|
151
|
+
gpu = next((g for g in facts.get("gpus") or [] if g["index"] == index), None)
|
|
152
|
+
if gpu is None or gpu.get("vendor") != "nvidia" or gpu.get("mig_mode") == "enabled":
|
|
153
|
+
return []
|
|
154
|
+
share = bool(options.get("share_gpu", False) or gpu_conflicts(facts).get(gpu["uuid"]))
|
|
155
|
+
bar = llm_rank.strata_bar(llama_score, probe_opts)
|
|
156
|
+
fits: list[LlmFit] = []
|
|
157
|
+
for recipe in stack_suite.auto_strata_candidates(facts, bar):
|
|
158
|
+
candidate_options: StackOptions = {
|
|
159
|
+
**probe_opts,
|
|
160
|
+
"gpu": index,
|
|
161
|
+
"share_gpu": share,
|
|
162
|
+
"llm_port": 0,
|
|
163
|
+
"decision_port": 0,
|
|
164
|
+
}
|
|
165
|
+
try:
|
|
166
|
+
parts = stack_suite.strata_parts(
|
|
167
|
+
facts,
|
|
168
|
+
candidate_options,
|
|
169
|
+
recipe,
|
|
170
|
+
[],
|
|
171
|
+
listening=lambda _: False,
|
|
172
|
+
previous=lambda *_: None,
|
|
173
|
+
owned_ram=lambda: 0,
|
|
174
|
+
)
|
|
175
|
+
if (
|
|
176
|
+
share
|
|
177
|
+
and int(str(parts["budget"].get("vram_needed_bytes") or 0)) > gpu["free_bytes"]
|
|
178
|
+
):
|
|
179
|
+
continue
|
|
180
|
+
if any(f.get("generated") and not preparation.ready(f) for f in parts["llm"]["files"]):
|
|
181
|
+
continue
|
|
182
|
+
fresh = [
|
|
183
|
+
p
|
|
184
|
+
for p in (
|
|
185
|
+
parts["llm"],
|
|
186
|
+
parts["decision"]["plan"],
|
|
187
|
+
parts["decision"]["front"],
|
|
188
|
+
*parts["aux"],
|
|
189
|
+
)
|
|
190
|
+
if p is not None
|
|
191
|
+
]
|
|
192
|
+
download_budget(
|
|
193
|
+
facts,
|
|
194
|
+
fresh,
|
|
195
|
+
cast(Any, {"download_bytes": 0}),
|
|
196
|
+
parts["decision"]["front"],
|
|
197
|
+
lambda _: {},
|
|
198
|
+
)
|
|
199
|
+
except (StackError, PlanError):
|
|
200
|
+
continue
|
|
201
|
+
fits.append(
|
|
202
|
+
{
|
|
203
|
+
"id": recipe["id"],
|
|
204
|
+
"quant": str(parts["llm"]["model"]["quant"]),
|
|
205
|
+
"quality": recipe["quality"]["score"],
|
|
206
|
+
"decode_tok_s": None,
|
|
207
|
+
"decode_basis": "unavailable",
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
return fits
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def _synthetic_pins(assets: list[tuple[str, cat.AssetFile]], _api: str) -> list[PinnedFile]:
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
"repo": repo,
|
|
217
|
+
"path": asset.path,
|
|
218
|
+
"revision": asset.revision or ("0" * 40),
|
|
219
|
+
"size_bytes": asset.size_bytes,
|
|
220
|
+
"sha256": asset.sha256 or ("0" * 64),
|
|
221
|
+
"local_name": asset.local_name,
|
|
222
|
+
}
|
|
223
|
+
for repo, asset in assets
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _running_on_card(running: Plan, facts: HostFacts, index: int) -> bool:
|
|
228
|
+
gpus = cast(list[dict[str, object]], running["placement"].get("gpus") or [])
|
|
229
|
+
if not gpus:
|
|
230
|
+
return True
|
|
231
|
+
uuid = next((g.get("uuid") for g in facts.get("gpus") or [] if g["index"] == index), None)
|
|
232
|
+
return any(
|
|
233
|
+
(uuid and g.get("uuid") == uuid) or (not g.get("uuid") and g.get("index") == index)
|
|
234
|
+
for g in gpus
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _probe_port(
|
|
239
|
+
facts: HostFacts,
|
|
240
|
+
merged: StackOptions,
|
|
241
|
+
entry_id: str,
|
|
242
|
+
listening: Callable[[int], bool],
|
|
243
|
+
previous: PreviousFn,
|
|
244
|
+
) -> int:
|
|
245
|
+
try:
|
|
246
|
+
return stack_ports.llm_port(facts, merged, entry_id, listening, previous)
|
|
247
|
+
except (PlanError, StackError):
|
|
248
|
+
return deploy.DEFAULT_PORT
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _aux_placed_llm(
|
|
252
|
+
facts: HostFacts,
|
|
253
|
+
ram_facts: HostFacts,
|
|
254
|
+
merged: StackOptions,
|
|
255
|
+
final_llm: Plan,
|
|
256
|
+
choice: DecisionChoice,
|
|
257
|
+
listening: Callable[[int], bool],
|
|
258
|
+
previous: PreviousFn,
|
|
259
|
+
price_llm: decide.PriceLLM,
|
|
260
|
+
) -> Plan:
|
|
261
|
+
if not any(
|
|
262
|
+
t in stack_suite.FOUNDATION_TASKS for t in stack_suite.wanted_tasks(merged, unified=False)
|
|
263
|
+
):
|
|
264
|
+
return final_llm
|
|
265
|
+
aux_candidates = stack_suite.aux_plans(facts, merged, listening, previous, [], approved=None)
|
|
266
|
+
_, final_llm = aux_gpu.place(
|
|
267
|
+
ram_facts,
|
|
268
|
+
final_llm,
|
|
269
|
+
choice,
|
|
270
|
+
aux_candidates,
|
|
271
|
+
stack_suite.suite_options(merged),
|
|
272
|
+
price_llm,
|
|
273
|
+
[],
|
|
274
|
+
)
|
|
275
|
+
return final_llm
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def llama_ram_fits(
|
|
279
|
+
facts: HostFacts,
|
|
280
|
+
options: StackOptions,
|
|
281
|
+
entry: cat.CatalogEntry,
|
|
282
|
+
index: int,
|
|
283
|
+
posture: AgentPosture,
|
|
284
|
+
*,
|
|
285
|
+
budget: HardwareBudget | None = None,
|
|
286
|
+
reads: LlamaReads = DEFAULT_READS,
|
|
287
|
+
reclaimed_ram: int | Callable[[], int] = 0,
|
|
288
|
+
ram_refused: list[bool] | None = None,
|
|
289
|
+
) -> bool:
|
|
290
|
+
"""Whether ``entry`` on discrete card ``index`` fits host RAM beside its decision choice."""
|
|
291
|
+
if budget is not None and budget.uma:
|
|
292
|
+
return llm_rank.automatic_fit(entry, facts, budget, posture, options)
|
|
293
|
+
merged: StackOptions = {**default_options(), **options}
|
|
294
|
+
capped = maybe_capped(facts, merged)
|
|
295
|
+
if capped is None:
|
|
296
|
+
return False
|
|
297
|
+
if capped is not facts:
|
|
298
|
+
facts = capped
|
|
299
|
+
if budget is not None:
|
|
300
|
+
budget = hardware.llm_budget(facts, index, merged, entry=entry, posture=posture)[0]
|
|
301
|
+
listening, previous, existing, qa_cpu_decision = reads
|
|
302
|
+
port = _probe_port(facts, merged, entry.id, listening, previous)
|
|
303
|
+
merged["llm_port"] = port
|
|
304
|
+
running_llm = previous(own_name(entry.id, port, merged["base_dir"]), port)
|
|
305
|
+
if running_llm is not None and _running_on_card(running_llm, facts, index):
|
|
306
|
+
return True
|
|
307
|
+
if budget is not None and not llm_rank.agent_ready(entry, entry.variants[-1], budget, posture):
|
|
308
|
+
return False
|
|
309
|
+
placement_id = "host" if metal.device(facts) is not None else f"gpu:{index}"
|
|
310
|
+
ram_facts = cast(
|
|
311
|
+
HostFacts,
|
|
312
|
+
{
|
|
313
|
+
**facts,
|
|
314
|
+
"disk": {**(facts.get("disk") or {}), "free_bytes": None},
|
|
315
|
+
"llama_servers": [],
|
|
316
|
+
},
|
|
317
|
+
)
|
|
318
|
+
entries = (entry,)
|
|
319
|
+
|
|
320
|
+
def price_llm(seen: HostFacts, placement: str | None = None, /, *, mtp: bool = True) -> Plan:
|
|
321
|
+
return deploy.build_plan(
|
|
322
|
+
hosts.LOCAL_ID,
|
|
323
|
+
seen,
|
|
324
|
+
deploy.PlanOptions(
|
|
325
|
+
model_id=entry.id,
|
|
326
|
+
placement_id=placement or placement_id,
|
|
327
|
+
port=port,
|
|
328
|
+
base_dir=merged["base_dir"],
|
|
329
|
+
hf_download_endpoint=merged["hf_endpoint"],
|
|
330
|
+
hf_api_endpoint=merged["hf_endpoint"],
|
|
331
|
+
engine_path="llama-server",
|
|
332
|
+
agent=posture if mtp else replace(posture, mtp_draft_depth=0),
|
|
333
|
+
quant=str(merged.get("quant") or ""),
|
|
334
|
+
),
|
|
335
|
+
entries=entries,
|
|
336
|
+
resolver=_synthetic_pins,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
try:
|
|
340
|
+
llm = price_llm(ram_facts)
|
|
341
|
+
choice = decide.choose(
|
|
342
|
+
ram_facts,
|
|
343
|
+
merged,
|
|
344
|
+
llm,
|
|
345
|
+
False,
|
|
346
|
+
price_llm,
|
|
347
|
+
previous,
|
|
348
|
+
existing,
|
|
349
|
+
qa_cpu_decision,
|
|
350
|
+
listening=lambda _: False,
|
|
351
|
+
resource_template=bool(merged.get("defer_services", False)),
|
|
352
|
+
)
|
|
353
|
+
final_llm = _aux_placed_llm(
|
|
354
|
+
facts,
|
|
355
|
+
ram_facts,
|
|
356
|
+
merged,
|
|
357
|
+
choice["llm"] or llm,
|
|
358
|
+
choice,
|
|
359
|
+
listening,
|
|
360
|
+
previous,
|
|
361
|
+
price_llm,
|
|
362
|
+
)
|
|
363
|
+
except (PlanError, StackError):
|
|
364
|
+
return False
|
|
365
|
+
decision_ram = 0 if merged.get("defer_services") else decide.host_ram(choice)
|
|
366
|
+
min_cache_bytes = (posture.prompt_cache_min_mib << 20) if posture.prompt_cache_mib > 0 else 0
|
|
367
|
+
needed = (
|
|
368
|
+
stack_llm_ram.own_bytes(final_llm, entries, running=False, metal=False)
|
|
369
|
+
+ min_cache_bytes
|
|
370
|
+
+ decision_ram
|
|
371
|
+
+ HARNESS_RAM
|
|
372
|
+
+ RAM_FLOOR
|
|
373
|
+
)
|
|
374
|
+
reclaimed = reclaimed_ram() if callable(reclaimed_ram) else reclaimed_ram
|
|
375
|
+
if needed <= host_ram(facts, reclaimed_bytes=reclaimed)[1]:
|
|
376
|
+
return True
|
|
377
|
+
if ram_refused is not None:
|
|
378
|
+
ram_refused.append(True)
|
|
379
|
+
return False
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def auto_llama_fits(
|
|
383
|
+
facts: HostFacts,
|
|
384
|
+
cards: list[int],
|
|
385
|
+
options: StackOptions,
|
|
386
|
+
posture: AgentPosture,
|
|
387
|
+
*,
|
|
388
|
+
reads: LlamaReads = DEFAULT_READS,
|
|
389
|
+
reclaimed_ram: int | Callable[[], int] = 0,
|
|
390
|
+
) -> tuple[list[tuple[tuple[int, float], str, int]], set[str], bool]:
|
|
391
|
+
"""Rankable (key, model_id, card_index) tuples, fallback ids, and whether RAM rejected a fit."""
|
|
392
|
+
capped = maybe_capped(facts, {**default_options(), **options})
|
|
393
|
+
if capped is None:
|
|
394
|
+
return [], set(), False
|
|
395
|
+
facts = capped
|
|
396
|
+
fitting: list[tuple[tuple[int, float], str, int]] = []
|
|
397
|
+
fallback_ids: set[str] = set()
|
|
398
|
+
ram_refused: list[bool] = []
|
|
399
|
+
for entry in cat.load_catalog_file():
|
|
400
|
+
if not (llm_rank.automatic_here(entry, facts) and entry.runtime == "llama.cpp"):
|
|
401
|
+
continue
|
|
402
|
+
variant = entry.variants[-1]
|
|
403
|
+
for index in cards:
|
|
404
|
+
card = hardware.llm_budget(facts, index, options, entry=entry, posture=posture)[0]
|
|
405
|
+
fits = (
|
|
406
|
+
llm_rank.automatic_fit(entry, facts, card, posture, options)
|
|
407
|
+
if card.uma
|
|
408
|
+
else llama_ram_fits(
|
|
409
|
+
facts,
|
|
410
|
+
options,
|
|
411
|
+
entry,
|
|
412
|
+
index,
|
|
413
|
+
posture,
|
|
414
|
+
budget=card,
|
|
415
|
+
reads=reads,
|
|
416
|
+
reclaimed_ram=reclaimed_ram,
|
|
417
|
+
ram_refused=ram_refused,
|
|
418
|
+
)
|
|
419
|
+
)
|
|
420
|
+
if fits:
|
|
421
|
+
measured = stack_warm_store.lookup(facts, index, entry.id, variant.quant)
|
|
422
|
+
tok_s = (
|
|
423
|
+
round(measured, 1)
|
|
424
|
+
if measured is not None
|
|
425
|
+
else round(cat.decode_estimate(entry, variant, card).tok_s, 1)
|
|
426
|
+
)
|
|
427
|
+
score = 0 if llm_rank.windows_fallback(entry, facts) else entry.quality
|
|
428
|
+
fitting.append(((score, tok_s), entry.id, index))
|
|
429
|
+
if llm_rank.windows_fallback(entry, facts):
|
|
430
|
+
fallback_ids.add(entry.id)
|
|
431
|
+
break
|
|
432
|
+
return fitting, fallback_ids, bool(ram_refused)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def approved_keeps_llama(facts: HostFacts, approved: StackPlan | None) -> bool:
|
|
436
|
+
"""True when rebuilding an approved auto llama.cpp plan (never flip to Strata on rebuild)."""
|
|
437
|
+
if approved is None:
|
|
438
|
+
return False
|
|
439
|
+
llm_id = approved["llm"]["model"]["id"]
|
|
440
|
+
return bool(llm_id) and stack_suite.strata_recipe(facts, llm_id)[0] is None
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def approved_llama_choice(
|
|
444
|
+
fitting: list[tuple[tuple[int, float], str, int]], approved: StackPlan | None
|
|
445
|
+
) -> tuple[str, int] | None:
|
|
446
|
+
"""Preserve an approved auto LLM target while it still passes current admission."""
|
|
447
|
+
if approved is None:
|
|
448
|
+
return None
|
|
449
|
+
llm: Plan = approved["llm"]
|
|
450
|
+
approved_id = llm["model"]["id"]
|
|
451
|
+
if not approved_id:
|
|
452
|
+
return None
|
|
453
|
+
matches = [(entry_id, idx) for _, entry_id, idx in fitting if entry_id == approved_id]
|
|
454
|
+
if not matches:
|
|
455
|
+
return None
|
|
456
|
+
gpus = llm["placement"].get("gpus")
|
|
457
|
+
first_gpu = gpus[0] if isinstance(gpus, list) and gpus else None
|
|
458
|
+
preferred = first_gpu.get("index") if isinstance(first_gpu, dict) else None
|
|
459
|
+
return next((m for m in matches if m[1] == preferred), matches[0])
|
|
@@ -39,9 +39,9 @@ def _decision_vram(choice: DecisionChoice) -> int:
|
|
|
39
39
|
|
|
40
40
|
def _degrades(llm: Plan, again: Plan) -> bool:
|
|
41
41
|
"""An auxiliary must not cost the LLM anything it already had beside the decision model:
|
|
42
|
-
a narrower window, fewer slots, a smaller KV type (q8_0 V dropping to q4_0)
|
|
43
|
-
draft context. Only the decision model may trade those away for its
|
|
44
|
-
decision model first)."""
|
|
42
|
+
a narrower window, fewer slots, a smaller KV type (q8_0 V dropping to q4_0), its MTP
|
|
43
|
+
draft context or its GPU picture reader. Only the decision model may trade those away for its
|
|
44
|
+
index (2026-10-30: decision model first)."""
|
|
45
45
|
before, after = llm["launch"], again["launch"]
|
|
46
46
|
return (
|
|
47
47
|
int(str(after["window"])) < int(str(before["window"]))
|
|
@@ -49,6 +49,7 @@ def _degrades(llm: Plan, again: Plan) -> bool:
|
|
|
49
49
|
or str(after.get("kv_types")) != str(before.get("kv_types"))
|
|
50
50
|
or int(str(after.get("mtp_draft_depth") or 0))
|
|
51
51
|
< int(str(before.get("mtp_draft_depth") or 0))
|
|
52
|
+
or str(after.get("vision") or "off") != str(before.get("vision") or "off")
|
|
52
53
|
)
|
|
53
54
|
|
|
54
55
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Explain discrete-GPU capacity without changing automatic catalog admission.
|
|
2
|
+
|
|
3
|
+
References use the stack's budget and launch physics, including its KV/runtime/vision
|
|
4
|
+
costs. Total capacity is hypothetical; current free capacity grants no sharing consent.
|
|
5
|
+
Neither proves that the whole stack fits host RAM/disk or works on this platform.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import replace
|
|
11
|
+
|
|
12
|
+
from localmodels import catalog as cat
|
|
13
|
+
from localmodels import llm_rank
|
|
14
|
+
from localmodels.budget import gib
|
|
15
|
+
from localmodels.context_policy import AgentPosture
|
|
16
|
+
from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES, PhysicsRefusal
|
|
17
|
+
from localmodels.probe import HostFacts
|
|
18
|
+
from localmodels.stack_plan import CapacityFit, Hardware, StackOptions
|
|
19
|
+
|
|
20
|
+
WDDM_NOTE = (
|
|
21
|
+
"Windows WDDM GPU contexts can include desktop C+G apps; their presence does not "
|
|
22
|
+
"identify an inference service, and per-process VRAM may be unavailable. "
|
|
23
|
+
"Use current free VRAM for plans; sharing still needs explicit consent and known owners."
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def rows(
|
|
28
|
+
facts: HostFacts, index: int, options: StackOptions, posture: AgentPosture
|
|
29
|
+
) -> list[CapacityFit]:
|
|
30
|
+
from localmodels import stack_hardware as hardware
|
|
31
|
+
|
|
32
|
+
gpu = hardware.device(facts, index)
|
|
33
|
+
if gpu["vendor"] != "nvidia" or gpu.get("mig_mode") == "enabled":
|
|
34
|
+
return []
|
|
35
|
+
total: HostFacts = {
|
|
36
|
+
**facts,
|
|
37
|
+
"gpus": [
|
|
38
|
+
{**g, "free_bytes": g["total_bytes"], "used_bytes": 0} if g["index"] == index else g
|
|
39
|
+
for g in facts.get("gpus") or []
|
|
40
|
+
],
|
|
41
|
+
}
|
|
42
|
+
found = []
|
|
43
|
+
for entry in cat.load_catalog_file():
|
|
44
|
+
if entry.runtime != "llama.cpp" or entry.status not in ("candidate", "validated"):
|
|
45
|
+
continue
|
|
46
|
+
variant = entry.variants[-1]
|
|
47
|
+
choices = []
|
|
48
|
+
# Keep the requested posture when possible; a one-slot trial is always explicit.
|
|
49
|
+
for slots in dict.fromkeys((posture.slots, 1)):
|
|
50
|
+
bounded = replace(posture, target=posture.floor, preferred=posture.floor, slots=slots)
|
|
51
|
+
full, reserve = hardware.llm_budget(total, index, options, entry=entry, posture=bounded)
|
|
52
|
+
decision = entry.launch_plan(variant, full, agent=bounded).decision
|
|
53
|
+
if isinstance(decision, PhysicsRefusal):
|
|
54
|
+
continue
|
|
55
|
+
current, _ = hardware.llm_budget(facts, index, options, entry=entry, posture=bounded)
|
|
56
|
+
current_decision = entry.launch_plan(variant, current, agent=bounded).decision
|
|
57
|
+
fits_now = not isinstance(current_decision, PhysicsRefusal)
|
|
58
|
+
if not isinstance(current_decision, PhysicsRefusal):
|
|
59
|
+
decision = current_decision
|
|
60
|
+
row: CapacityFit = {
|
|
61
|
+
"id": entry.id,
|
|
62
|
+
"quant": variant.quant,
|
|
63
|
+
"status": entry.status,
|
|
64
|
+
"validated_on": list(entry.validated_on),
|
|
65
|
+
"admission": "windows-candidate-fallback"
|
|
66
|
+
if llm_rank.windows_fallback(entry, facts)
|
|
67
|
+
else "validated"
|
|
68
|
+
if cat.validated_here(entry, facts["platform"])
|
|
69
|
+
else "candidate"
|
|
70
|
+
if entry.status == "candidate"
|
|
71
|
+
else "platform-not-validated",
|
|
72
|
+
"fits_now": fits_now,
|
|
73
|
+
"fits_total": True,
|
|
74
|
+
"window": decision.window,
|
|
75
|
+
"slots": slots,
|
|
76
|
+
"vision": decision.vision_reader or "off",
|
|
77
|
+
"kv_types": list(decision.kv_types),
|
|
78
|
+
"needed_free_bytes": decision.vram_bytes + AGENT_VRAM_RESERVE_BYTES + reserve,
|
|
79
|
+
}
|
|
80
|
+
choices.append(row)
|
|
81
|
+
if choices:
|
|
82
|
+
chosen = next((r for r in choices if r["fits_now"]), choices[0])
|
|
83
|
+
found.append((chosen["fits_now"], llm_rank.rank_key(entry, variant, full), chosen))
|
|
84
|
+
return [r for _, _, r in sorted(found, key=lambda t: (t[0], t[1]), reverse=True)]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def lines(hw: Hardware, command: str) -> list[str]:
|
|
88
|
+
out = []
|
|
89
|
+
for card in hw["cards"]:
|
|
90
|
+
references = card.get("capacity", [])
|
|
91
|
+
if not references:
|
|
92
|
+
continue
|
|
93
|
+
out.append(f" GPU {card['index']} capacity only (not installation-ready):")
|
|
94
|
+
for row in references[:3]:
|
|
95
|
+
available = (
|
|
96
|
+
"fits current free VRAM"
|
|
97
|
+
if row["fits_now"]
|
|
98
|
+
else "total capacity only; free VRAM too low"
|
|
99
|
+
)
|
|
100
|
+
out.append(
|
|
101
|
+
f" {row['id']} {row['quant']} [{row['admission']}]: {available}; "
|
|
102
|
+
f"{row['window'] // 1024}K / {row['slots']} slot(s), "
|
|
103
|
+
f"KV={'/'.join(row['kv_types'])}, vision={row['vision']}, "
|
|
104
|
+
f"needs {gib(row['needed_free_bytes'])} free incl. reserves"
|
|
105
|
+
)
|
|
106
|
+
out.append(
|
|
107
|
+
f" {command} stack plan --llm {row['id']} --gpu {card['index']} "
|
|
108
|
+
f"--context {row['window']} --slots {row['slots']} --vision {row['vision']} "
|
|
109
|
+
f"--kv {'/'.join(row['kv_types'])} --offline"
|
|
110
|
+
)
|
|
111
|
+
out.append(
|
|
112
|
+
" GPU estimates include weights, KV, runtime and vision; host RAM, cache, disk, "
|
|
113
|
+
"ports and whole-stack acceptance still require stack plan and real verification. "
|
|
114
|
+
"Capacity references do not change automatic eligibility; the existing Windows "
|
|
115
|
+
"candidate fallback policy is labelled separately."
|
|
116
|
+
)
|
|
117
|
+
if card["held_by"]:
|
|
118
|
+
out.append(
|
|
119
|
+
" Other GPU work is preserved. Explicit sharing needs --share-gpu; "
|
|
120
|
+
"unknown process owners or service discovery still block installation."
|
|
121
|
+
)
|
|
122
|
+
return out
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def no_default_reason(facts: HostFacts, options: StackOptions, posture: AgentPosture) -> str:
|
|
126
|
+
"""Explain a catalog admission gap independently of transient free VRAM or conflicts."""
|
|
127
|
+
references = [
|
|
128
|
+
r for g in facts.get("gpus") or [] for r in rows(facts, g["index"], options, posture)
|
|
129
|
+
]
|
|
130
|
+
if not references or any(
|
|
131
|
+
r["admission"] in ("validated", "windows-candidate-fallback") for r in references
|
|
132
|
+
):
|
|
133
|
+
return ""
|
|
134
|
+
ids = list(dict.fromkeys(f"{r['id']} [{r['admission']}]" for r in references))
|
|
135
|
+
return (
|
|
136
|
+
"catalog admission gap: no verified LLM fits even the total GPU capacity at this "
|
|
137
|
+
"agent floor; capacity-only alternatives: " + ", ".join(ids[:3]) + "; "
|
|
138
|
+
)
|
|
@@ -26,8 +26,10 @@ from localmodels.stack_plan import StackError, platform_error
|
|
|
26
26
|
|
|
27
27
|
Out = Callable[[str], None]
|
|
28
28
|
# State this tool writes for a stack and nothing else reads: saved plans, run records, the
|
|
29
|
-
# apply lock and journal (stacks/), the cached probe (facts/)
|
|
30
|
-
|
|
29
|
+
# apply lock and journal (stacks/), the cached probe (facts/), the view window's profile,
|
|
30
|
+
# measured per-device decode speeds (warm_speeds.json), and the blind Elo board (arena.json;
|
|
31
|
+
# its empty arena.lock stays per WHI-317).
|
|
32
|
+
STACK_STATE = ("stacks", "facts", "view-app", "warm_speeds.json", "arena.json")
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
Engines = dict[Path, set[str]] # engine directory -> the archive names it was unpacked from
|
|
@@ -186,6 +188,9 @@ def sweep(
|
|
|
186
188
|
for path in doomed:
|
|
187
189
|
if path.is_dir() and not path.is_symlink():
|
|
188
190
|
shutil.rmtree(path)
|
|
191
|
+
elif path.name == "arena.json":
|
|
192
|
+
with hosts.file_lock(path.parent / "arena.lock"):
|
|
193
|
+
path.unlink(missing_ok=True)
|
|
189
194
|
else:
|
|
190
195
|
path.unlink(missing_ok=True)
|
|
191
196
|
if state:
|
|
@@ -200,8 +205,8 @@ def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) ->
|
|
|
200
205
|
A directory someone else made there stays, empty or not. The manifest's empty
|
|
201
206
|
``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
|
|
202
207
|
.agents/skills/owned-manifest-lock), so it is the one file an uninstall leaves."""
|
|
203
|
-
root = Path(tools_dir).expanduser()
|
|
204
|
-
private = root / "gateway-home"
|
|
208
|
+
root = Path(hosts.tools_dir(tools_dir)).expanduser()
|
|
209
|
+
private = root.resolve() / "gateway-home"
|
|
205
210
|
if not hosts.owned_path(tools_dir).exists() and private.is_dir():
|
|
206
211
|
# Windows has no uid: the directory sits in this user's profile under a private ACL.
|
|
207
212
|
uid = os.getuid() if hasattr(os, "getuid") else None
|