@simplexai/localmodels-darwin-arm64 0.1.0-dev.36 → 0.1.0-dev.38

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.
Files changed (134) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +132 -110
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_checks.py +9 -6
  7. package/modules/localmodels/bifrost_config.py +203 -0
  8. package/modules/localmodels/bifrost_datasheet.py +12 -2
  9. package/modules/localmodels/budget.py +13 -2
  10. package/modules/localmodels/catalog.json +137 -2
  11. package/modules/localmodels/catalog.py +70 -321
  12. package/modules/localmodels/catalog_add.py +2 -8
  13. package/modules/localmodels/catalog_recipes.py +352 -0
  14. package/modules/localmodels/cli_parser.py +4 -1
  15. package/modules/localmodels/console.py +5 -4
  16. package/modules/localmodels/contracts.py +13 -3
  17. package/modules/localmodels/debug_cli.py +158 -0
  18. package/modules/localmodels/debug_mode.py +727 -0
  19. package/modules/localmodels/debug_stub_server.py +192 -0
  20. package/modules/localmodels/decode_calibration.json +1 -1
  21. package/modules/localmodels/decode_calibration.py +34 -17
  22. package/modules/localmodels/gateway.py +21 -155
  23. package/modules/localmodels/gateway_accept.py +201 -0
  24. package/modules/localmodels/gateway_bifrost.py +30 -193
  25. package/modules/localmodels/gateway_cli.py +15 -6
  26. package/modules/localmodels/gateway_foundations.py +2 -4
  27. package/modules/localmodels/gateway_probe.py +0 -1
  28. package/modules/localmodels/gateway_server.py +2 -3
  29. package/modules/localmodels/gpu_specs.py +12 -0
  30. package/modules/localmodels/guard.py +2 -7
  31. package/modules/localmodels/harness.py +16 -129
  32. package/modules/localmodels/harness_cleanup.py +135 -0
  33. package/modules/localmodels/harness_gateway.py +16 -14
  34. package/modules/localmodels/harness_probe.py +12 -4
  35. package/modules/localmodels/hosts.py +25 -2
  36. package/modules/localmodels/http_local.py +59 -0
  37. package/modules/localmodels/install.py +23 -8
  38. package/modules/localmodels/library_gateway.py +20 -9
  39. package/modules/localmodels/library_jobs.py +125 -28
  40. package/modules/localmodels/library_model.py +10 -0
  41. package/modules/localmodels/library_pricing.py +29 -22
  42. package/modules/localmodels/library_serve.py +17 -1
  43. package/modules/localmodels/library_state.py +15 -2
  44. package/modules/localmodels/library_status.py +30 -0
  45. package/modules/localmodels/llm_rank.py +185 -39
  46. package/modules/localmodels/probe.py +108 -174
  47. package/modules/localmodels/process_identity.py +120 -154
  48. package/modules/localmodels/process_windows.py +86 -0
  49. package/modules/localmodels/recommend.py +6 -3
  50. package/modules/localmodels/recommend_cli.py +14 -6
  51. package/modules/localmodels/remote_ops.py +65 -0
  52. package/modules/localmodels/remote_ops_service.py +14 -2
  53. package/modules/localmodels/runtime_args.py +10 -3
  54. package/modules/localmodels/runtime_auth.py +5 -9
  55. package/modules/localmodels/runtime_cli.py +128 -129
  56. package/modules/localmodels/runtime_discovery.py +84 -0
  57. package/modules/localmodels/runtime_install.py +101 -0
  58. package/modules/localmodels/runtime_releases.py +302 -0
  59. package/modules/localmodels/search_server.py +5 -1
  60. package/modules/localmodels/service_stop.py +8 -108
  61. package/modules/localmodels/service_upgrade.py +394 -63
  62. package/modules/localmodels/services_cli.py +24 -14
  63. package/modules/localmodels/setup_inspection.py +97 -9
  64. package/modules/localmodels/setup_text.py +7 -0
  65. package/modules/localmodels/sizecalc.py +0 -1
  66. package/modules/localmodels/stack.py +45 -235
  67. package/modules/localmodels/stack_arena.py +732 -0
  68. package/modules/localmodels/stack_args.py +21 -12
  69. package/modules/localmodels/stack_auto.py +384 -3
  70. package/modules/localmodels/stack_aux_gpu.py +4 -3
  71. package/modules/localmodels/stack_capacity.py +138 -0
  72. package/modules/localmodels/stack_cleanup.py +9 -4
  73. package/modules/localmodels/stack_cli.py +288 -0
  74. package/modules/localmodels/stack_compose.py +63 -30
  75. package/modules/localmodels/stack_console.py +9 -6
  76. package/modules/localmodels/stack_hardware.py +95 -265
  77. package/modules/localmodels/stack_hardware_text.py +263 -0
  78. package/modules/localmodels/stack_journal.py +3 -9
  79. package/modules/localmodels/stack_ledger.py +48 -18
  80. package/modules/localmodels/stack_lifecycle.py +33 -312
  81. package/modules/localmodels/stack_llm_ram.py +16 -6
  82. package/modules/localmodels/stack_mcp.py +729 -0
  83. package/modules/localmodels/stack_memory.py +0 -2
  84. package/modules/localmodels/stack_picks.py +62 -15
  85. package/modules/localmodels/stack_plan.py +19 -1
  86. package/modules/localmodels/stack_preflight.py +11 -19
  87. package/modules/localmodels/stack_progress.py +9 -1
  88. package/modules/localmodels/stack_remove.py +373 -0
  89. package/modules/localmodels/stack_route.py +101 -17
  90. package/modules/localmodels/stack_run.py +29 -0
  91. package/modules/localmodels/stack_suite.py +21 -10
  92. package/modules/localmodels/stack_summary.py +14 -0
  93. package/modules/localmodels/stack_try.py +238 -24
  94. package/modules/localmodels/stack_try_client.py +53 -15
  95. package/modules/localmodels/stack_try_docs.py +2 -2
  96. package/modules/localmodels/stack_view.py +24 -171
  97. package/modules/localmodels/stack_view_access.py +114 -1
  98. package/modules/localmodels/stack_view_agent.py +3 -13
  99. package/modules/localmodels/stack_view_hub.py +9 -10
  100. package/modules/localmodels/stack_view_llm.py +1 -1
  101. package/modules/localmodels/stack_view_sandbox.py +2 -2
  102. package/modules/localmodels/stack_view_schema.py +183 -0
  103. package/modules/localmodels/stack_view_serve.py +7 -1
  104. package/modules/localmodels/stack_view_service.py +1 -2
  105. package/modules/localmodels/stack_view_text.py +13 -9
  106. package/modules/localmodels/stack_warm.py +48 -4
  107. package/modules/localmodels/stack_warm_store.py +517 -0
  108. package/modules/localmodels/tools.json +32 -18
  109. package/modules/localmodels/transport.py +38 -13
  110. package/modules/localmodels/tui.py +28 -4
  111. package/modules/localmodels/tui_dialogs.py +136 -0
  112. package/modules/localmodels/tui_modals.py +279 -0
  113. package/modules/localmodels/tui_screen.py +113 -154
  114. package/modules/localmodels/tui_views.py +134 -203
  115. package/modules/localmodels/web/index.html +510 -101
  116. package/modules/localmodels/web/sizecalc/app.js +363 -10
  117. package/modules/localmodels/web/sizecalc/page.html +27 -3
  118. package/modules/localmodels/web/view/fleet.html +11 -2
  119. package/modules/localmodels/web/view/fleet.js +191 -17
  120. package/modules/localmodels/web/view/i18n.js +3 -2
  121. package/modules/localmodels/web/view/index.html +1 -1
  122. package/modules/localmodels/web/view/nav.js +22 -3
  123. package/modules/localmodels/web/view/view.css +63 -18
  124. package/modules/localmodels/web/view/view.js +169 -32
  125. package/modules/localmodels/windows_job.py +69 -0
  126. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/METADATA +1 -1
  127. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/RECORD +128 -106
  128. package/package.json +1 -1
  129. package/tool.json +1 -1
  130. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  131. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/WHEEL +0 -0
  132. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/entry_points.txt +0 -0
  133. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.dist-info}/licenses/NOTICE +0 -0
  134. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev38.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), free web search and the pi agent. A GPU decision model,
68
- embedding/reranker/STT and TTS are optional and off by default (--decision, --aux, --tts);
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, ledger, card (writes a local SVG), remove --dry-run, and rollback without
87
- --approve. warm sends the LLM two short requests and changes nothing else (--sudo also runs
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 = (
@@ -185,9 +189,12 @@ def add_plan_arguments(plan: argparse.ArgumentParser) -> None:
185
189
  choices=PREFERENCES,
186
190
  default="smartest",
187
191
  help="what auto optimizes (roadmap decision 26): smartest, the highest installed "
188
- "SimplexAI score that fits (default); concurrent, at least two requests decoding "
189
- "together; fast, the fastest model within a few points of the smartest; fastest, the "
190
- "highest decode speed that fits whatever its score (the second choice `stack hardware` "
192
+ "SimplexAI score that fits (default), except that a Mac of 16 GB or more takes its "
193
+ "Spark-X2.6 ladder while no validated model scoring 50 fits, and Windows NVIDIA falls "
194
+ "back to Spark-X2.6-4B Q8_0 when no validated model fits; concurrent, at least two "
195
+ "requests decoding together; fast, the fastest model within a few points of the "
196
+ "smartest; fastest, the highest decode speed that fits whatever its score, the Mac "
197
+ "ladder's rung and the Windows fallback included (the second choice `stack hardware` "
191
198
  "and `install` offer)",
192
199
  )
193
200
  choose.add_argument(
@@ -397,7 +404,7 @@ def _plan(actions: Parsers) -> None:
397
404
  ("%(prog)s", "recommended stack for this computer"),
398
405
  ("%(prog)s --llm qwen3.8-27b --decision none", "pin the LLM, no decision model"),
399
406
  ("%(prog)s --aux embedding,reranker", "opt in to some auxiliaries"),
400
- ("%(prog)s --no-search", "leave out the free web search"),
407
+ ("%(prog)s --search", "add the free web search"),
401
408
  ("%(prog)s --gpu 1 --share-gpu", "a card that already runs something"),
402
409
  ("%(prog)s --update", "replace only what changed in the installed stack"),
403
410
  ("%(prog)s --facts host.json --offline --json", "price saved facts, no network"),
@@ -503,6 +510,7 @@ def _helpers(actions: Parsers) -> None:
503
510
  "value, default, choices, help) and the examples, for agents and completion scripts.",
504
511
  examples=[("%(prog)s", "one line per command"), ("%(prog)s --json", "")],
505
512
  )
513
+ stack_mcp.add_parser(actions)
506
514
 
507
515
 
508
516
  def _clients(actions: Parsers) -> None:
@@ -525,6 +533,7 @@ def _day2(actions: Parsers) -> None:
525
533
  stack_down.add_parser(actions)
526
534
  stack_warm.add_parser(actions)
527
535
  stack_try.add_parser(actions)
536
+ stack_arena.add_parser(actions)
528
537
  stack_ledger.add_parser(actions)
529
538
  stack_card.add_parser(actions)
530
539
  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 llm_rank, preparation, stack_suite
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 Parts, StackError, StackOptions
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) or its MTP
43
- draft context. Only the decision model may trade those away for its index (2026-10-30:
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
+ )