@simplexai/localmodels-linux-x64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.35

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 (140) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +138 -97
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +4 -0
  5. package/modules/localmodels/app.py +7 -2
  6. package/modules/localmodels/approval.py +4 -4
  7. package/modules/localmodels/bifrost_checks.py +121 -3
  8. package/modules/localmodels/bifrost_provider.py +53 -0
  9. package/modules/localmodels/bifrost_unit.py +32 -1
  10. package/modules/localmodels/budget.py +5 -1
  11. package/modules/localmodels/catalog.json +51 -10
  12. package/modules/localmodels/catalog.py +30 -29
  13. package/modules/localmodels/catalog_add.py +1 -0
  14. package/modules/localmodels/cli_parser.py +10 -2
  15. package/modules/localmodels/component.py +7 -1
  16. package/modules/localmodels/decode_calibration.json +6 -0
  17. package/modules/localmodels/decode_calibration.py +104 -0
  18. package/modules/localmodels/deploy.py +44 -7
  19. package/modules/localmodels/deploy_steps.py +10 -1
  20. package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
  21. package/modules/localmodels/engines.json +57 -1
  22. package/modules/localmodels/engines.py +6 -2
  23. package/modules/localmodels/estimator.py +21 -7
  24. package/modules/localmodels/frontend.py +4 -4
  25. package/modules/localmodels/gateway.py +14 -4
  26. package/modules/localmodels/gateway_app_bifrost.py +4 -3
  27. package/modules/localmodels/gateway_bifrost.py +70 -57
  28. package/modules/localmodels/gateway_probe.py +3 -4
  29. package/modules/localmodels/gguf.py +7 -0
  30. package/modules/localmodels/harness.py +24 -25
  31. package/modules/localmodels/harness_gateway.py +19 -10
  32. package/modules/localmodels/harness_probe.py +33 -6
  33. package/modules/localmodels/hosts.py +73 -9
  34. package/modules/localmodels/install.py +36 -6
  35. package/modules/localmodels/library_cli.py +179 -0
  36. package/modules/localmodels/library_convert.py +132 -0
  37. package/modules/localmodels/library_gateway.py +471 -0
  38. package/modules/localmodels/library_jobs.py +314 -0
  39. package/modules/localmodels/library_model.py +246 -0
  40. package/modules/localmodels/library_pricing.py +347 -0
  41. package/modules/localmodels/library_serve.py +348 -0
  42. package/modules/localmodels/library_state.py +373 -0
  43. package/modules/localmodels/library_status.py +349 -0
  44. package/modules/localmodels/llm_rank.py +16 -2
  45. package/modules/localmodels/memcalc.py +7 -30
  46. package/modules/localmodels/metal.py +26 -0
  47. package/modules/localmodels/plan_envelope.py +4 -1
  48. package/modules/localmodels/preparation.py +49 -0
  49. package/modules/localmodels/probe.py +8 -8
  50. package/modules/localmodels/process_identity.py +536 -9
  51. package/modules/localmodels/quant_formats.py +123 -0
  52. package/modules/localmodels/recommend_cli.py +8 -4
  53. package/modules/localmodels/records.py +1 -0
  54. package/modules/localmodels/remote_ops.py +104 -6
  55. package/modules/localmodels/remote_ops_download.py +17 -2
  56. package/modules/localmodels/remote_ops_prepare.py +406 -0
  57. package/modules/localmodels/remote_ops_remove.py +40 -7
  58. package/modules/localmodels/remote_ops_service.py +110 -8
  59. package/modules/localmodels/remote_ops_verify.py +15 -2
  60. package/modules/localmodels/runtime_auth.py +31 -1
  61. package/modules/localmodels/runtime_cli.py +3 -4
  62. package/modules/localmodels/runtime_io.py +50 -6
  63. package/modules/localmodels/service_autostart.py +45 -1
  64. package/modules/localmodels/service_control.py +13 -0
  65. package/modules/localmodels/service_deployment.py +12 -3
  66. package/modules/localmodels/service_jobs.py +33 -4
  67. package/modules/localmodels/service_probe.py +67 -13
  68. package/modules/localmodels/service_stop.py +152 -0
  69. package/modules/localmodels/service_worker.py +9 -1
  70. package/modules/localmodels/services_cli.py +50 -6
  71. package/modules/localmodels/setup_inspection.py +34 -25
  72. package/modules/localmodels/setup_text.py +118 -0
  73. package/modules/localmodels/sizecalc.py +625 -0
  74. package/modules/localmodels/sizecalc_cli.py +249 -0
  75. package/modules/localmodels/stack.py +69 -17
  76. package/modules/localmodels/stack_args.py +91 -19
  77. package/modules/localmodels/stack_auto.py +78 -0
  78. package/modules/localmodels/stack_binding.py +23 -35
  79. package/modules/localmodels/stack_card.py +195 -0
  80. package/modules/localmodels/stack_cleanup.py +379 -0
  81. package/modules/localmodels/stack_clients.py +4 -1
  82. package/modules/localmodels/stack_compose.py +150 -194
  83. package/modules/localmodels/stack_console.py +2 -0
  84. package/modules/localmodels/stack_decision.py +3 -2
  85. package/modules/localmodels/stack_down.py +189 -0
  86. package/modules/localmodels/stack_events.py +54 -0
  87. package/modules/localmodels/stack_hardware.py +22 -23
  88. package/modules/localmodels/stack_journal.py +29 -8
  89. package/modules/localmodels/stack_ledger.py +411 -0
  90. package/modules/localmodels/stack_lifecycle.py +162 -167
  91. package/modules/localmodels/stack_llm_ram.py +57 -5
  92. package/modules/localmodels/stack_memory.py +721 -0
  93. package/modules/localmodels/stack_picks.py +139 -0
  94. package/modules/localmodels/stack_plan.py +140 -22
  95. package/modules/localmodels/stack_ports.py +22 -0
  96. package/modules/localmodels/stack_preflight.py +699 -0
  97. package/modules/localmodels/stack_review.py +123 -5
  98. package/modules/localmodels/stack_rollback.py +2 -0
  99. package/modules/localmodels/stack_route.py +256 -0
  100. package/modules/localmodels/stack_run.py +11 -0
  101. package/modules/localmodels/stack_suite.py +102 -17
  102. package/modules/localmodels/stack_summary.py +65 -4
  103. package/modules/localmodels/stack_try.py +354 -0
  104. package/modules/localmodels/stack_try_client.py +194 -0
  105. package/modules/localmodels/stack_try_docs.py +139 -0
  106. package/modules/localmodels/stack_up.py +8 -1
  107. package/modules/localmodels/stack_update.py +29 -4
  108. package/modules/localmodels/stack_verify.py +3 -1
  109. package/modules/localmodels/stack_view.py +10 -11
  110. package/modules/localmodels/stack_view_apply.py +4 -2
  111. package/modules/localmodels/stack_view_events.py +2 -1
  112. package/modules/localmodels/stack_view_serve.py +3 -0
  113. package/modules/localmodels/stack_view_text.py +1 -1
  114. package/modules/localmodels/stack_view_words.py +4 -1
  115. package/modules/localmodels/stack_warm.py +574 -0
  116. package/modules/localmodels/stack_whatif.py +558 -0
  117. package/modules/localmodels/suite.py +48 -39
  118. package/modules/localmodels/tool_archive.py +40 -0
  119. package/modules/localmodels/tools.json +8 -0
  120. package/modules/localmodels/transport.py +1 -0
  121. package/modules/localmodels/vision.py +8 -1
  122. package/modules/localmodels/web/sizecalc/app.js +431 -0
  123. package/modules/localmodels/web/sizecalc/calc.js +269 -0
  124. package/modules/localmodels/web/sizecalc/page.html +362 -0
  125. package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
  126. package/modules/localmodels/web/view/i18n.js +1 -1
  127. package/modules/localmodels/web/view/logo-claude.svg +3 -0
  128. package/modules/localmodels/web/view/logo-codex.png +0 -0
  129. package/modules/localmodels/web/view/logo-pi.svg +6 -0
  130. package/modules/localmodels/web/view/view.css +4 -0
  131. package/modules/localmodels/web/view/view.js +15 -6
  132. package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/METADATA +1 -1
  133. package/modules/simplex_localmodels-0.1.0.dev35.dist-info/RECORD +241 -0
  134. package/package.json +1 -1
  135. package/tool.json +1 -1
  136. package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
  137. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/WHEEL +0 -0
  138. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/entry_points.txt +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/NOTICE +0 -0
  140. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev35.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -16,6 +16,7 @@ import os
16
16
  import sys
17
17
  from collections.abc import Callable
18
18
  from dataclasses import replace
19
+ from functools import cache
19
20
  from pathlib import Path
20
21
 
21
22
  from localmodels import (
@@ -31,9 +32,11 @@ from localmodels import (
31
32
  process_identity,
32
33
  remote_ops_launchd,
33
34
  reuse,
35
+ stack_auto,
34
36
  stack_debug,
35
37
  stack_mlx,
36
38
  stack_ports,
39
+ stack_route,
37
40
  stack_suite,
38
41
  suite,
39
42
  )
@@ -49,26 +52,21 @@ from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_
49
52
  from localmodels.plan_envelope import PlanError, require_free_port, utc_now
50
53
  from localmodels.probe import HostFacts
51
54
  from localmodels.records import PinnedFile, Plan
52
- from localmodels.stack_llm_ram import prompt_cache_bytes, prompt_cache_fit
53
55
  from localmodels.stack_plan import (
54
56
  HARNESS_RAM,
55
57
  SCHEMA,
56
- DecisionChoice,
57
58
  Parts,
58
59
  StackError,
59
60
  StackOptions,
60
61
  StackPlan,
61
62
  command,
63
+ download_budget,
62
64
  is_redeploy,
63
65
  own_name,
64
66
  platform_error,
65
67
  ram_floor,
66
- reuse_copies,
67
68
  )
68
69
 
69
- FRONT_ENV_BYTES = 200 << 20 # a decision front's environment: 110 MB source archive plus wheels
70
-
71
-
72
70
  loopback_listening = stack_ports.loopback_listening
73
71
 
74
72
 
@@ -136,6 +134,8 @@ def compose(
136
134
  the local lookups each keyword stands for (tests replace them); who holds a GPU comes from
137
135
  the facts' service discovery alone, so saved facts price the host they describe."""
138
136
  options = options.copy()
137
+ owned_ram = cache(owned_ram)
138
+ stack_route.validate(options, facts)
139
139
  if error := platform_error(facts["platform"], options.get("profile"), facts["arch"]):
140
140
  raise StackError(error)
141
141
  if not qa_cpu_decision and options.get("profile") != "macos-mlx-preview":
@@ -154,6 +154,73 @@ def compose(
154
154
  and options["llm_port"] == options["decision_port"]
155
155
  ):
156
156
  raise StackError("the LLM and the decision model cannot use the same port")
157
+
158
+ def check_strata(candidate: Parts, selected: StackOptions) -> None:
159
+ assemble(facts, tools, selected, candidate, listening=listening, copies=copies)
160
+
161
+ parts, options = choose_parts(
162
+ facts,
163
+ options,
164
+ resolver=resolver,
165
+ listening=listening,
166
+ previous=previous,
167
+ existing=existing,
168
+ owned_ram=owned_ram,
169
+ qa_cpu_decision=qa_cpu_decision,
170
+ approved=approved,
171
+ check_strata=check_strata,
172
+ )
173
+ parts["warnings"] = pressure_notes + capped_notes + parts["warnings"]
174
+ if options.get("route") == "fastest":
175
+ stack_route.add(
176
+ facts,
177
+ options,
178
+ parts,
179
+ agent_posture(options),
180
+ resolver=resolver,
181
+ listening=listening,
182
+ previous=previous,
183
+ approved=approved.get("llm_fast") if approved else None,
184
+ )
185
+ deferred = None
186
+ if options.get("defer_services"):
187
+ choice = parts["decision"]
188
+ deferred = {"decision": choice["plan"], "decision_front": choice["front"]}
189
+ parts["decision"] = {**choice, "plan": None, "front": None, "existing": None, "options": []}
190
+ # Named foundations priced and reserved on unified memory (stack_suite.aux_plans): the
191
+ # background worker installs these exact plans once the chat Runtime is ready.
192
+ named = stack_suite.named_foundations(options)
193
+ for part in [p for p in parts["aux"] if stack_suite.task_of(p) in named]:
194
+ deferred[stack_suite.task_of(part)] = part
195
+ parts["aux"] = [p for p in parts["aux"] if stack_suite.task_of(p) not in deferred]
196
+ plan = assemble(facts, tools, options, parts, listening=listening, copies=copies)
197
+ if deferred is not None:
198
+ plan["deferred_services"] = deferred
199
+ plan["plan_id"] = digest(plan)
200
+ return plan
201
+
202
+
203
+ def choose_parts(
204
+ facts: HostFacts,
205
+ options: StackOptions,
206
+ *,
207
+ resolver: Callable[[list[tuple[str, cat.AssetFile]], str], list[PinnedFile]],
208
+ listening: Callable[[int], bool],
209
+ previous: Callable[[str, int], Plan | None],
210
+ existing: Callable[[list[cat.LlamaComponentRecipe]], list[reuse.ExistingService]],
211
+ owned_ram: Callable[[], int],
212
+ qa_cpu_decision: bool = False,
213
+ approved: StackPlan | None = None,
214
+ check_strata: Callable[[Parts, StackOptions], None] | None = None,
215
+ ) -> tuple[Parts, StackOptions]:
216
+ """The planner's LLM selection and priced parts, shared with read-only upgrade advice.
217
+
218
+ Linux auto compares the llama.cpp pick with Strata/PolyStrata, including whole-stack RAM
219
+ and local generated-pack requirements. Pure apart from the supplied readers and the suite's
220
+ local pack-file checks; no assembly, persistence or execution. The caller's options stay
221
+ unchanged; the returned copy carries allocated ports, just as compose did before extraction.
222
+ """
223
+ options = options.copy()
157
224
  strata, notes = stack_suite.strata_recipe(facts, options["llm"])
158
225
  if strata is not None and options.get("context"):
159
226
  raise StackError(
@@ -177,28 +244,21 @@ def compose(
177
244
  )
178
245
  passed_over: list[str] = []
179
246
  if parts is None and strata is None and stack_suite.auto_strata_wanted(facts, options):
180
- parts = _auto_strata_parts(facts, options, listening, previous, owned_ram, passed_over)
247
+ parts = stack_auto.strata_parts(
248
+ facts,
249
+ options,
250
+ _llama_quality(facts, options),
251
+ listening,
252
+ previous,
253
+ owned_ram,
254
+ passed_over,
255
+ check=check_strata,
256
+ )
181
257
  if parts is None:
182
258
  reads = (resolver, listening, previous, existing, owned_ram)
183
259
  parts = _llama_parts(facts, options, *reads, qa_cpu_decision, approved)
184
260
  parts["warnings"] = passed_over + parts["warnings"]
185
- parts["warnings"] = pressure_notes + capped_notes + parts["warnings"]
186
- deferred = None
187
- if options.get("defer_services"):
188
- choice = parts["decision"]
189
- deferred = {"decision": choice["plan"], "decision_front": choice["front"]}
190
- parts["decision"] = {**choice, "plan": None, "front": None, "existing": None, "options": []}
191
- # Named foundations priced and reserved on unified memory (stack_suite.aux_plans): the
192
- # background worker installs these exact plans once the chat Runtime is ready.
193
- named = stack_suite.named_foundations(options)
194
- for part in [p for p in parts["aux"] if stack_suite.task_of(p) in named]:
195
- deferred[stack_suite.task_of(part)] = part
196
- parts["aux"] = [p for p in parts["aux"] if stack_suite.task_of(p) not in deferred]
197
- plan = assemble(facts, tools, options, parts, listening=listening, copies=copies)
198
- if deferred is not None:
199
- plan["deferred_services"] = deferred
200
- plan["plan_id"] = digest(plan)
201
- return plan
261
+ return parts, options
202
262
 
203
263
 
204
264
  def _llama_quality(facts: HostFacts, options: StackOptions) -> tuple[int, str]:
@@ -212,53 +272,6 @@ def _llama_quality(facts: HostFacts, options: StackOptions) -> tuple[int, str]:
212
272
  return entry.quality, llm_id
213
273
 
214
274
 
215
- def _auto_strata_parts(
216
- facts: HostFacts,
217
- options: StackOptions,
218
- listening: Callable[[int], bool],
219
- previous: Callable[[str, int], Plan | None],
220
- owned_ram: Callable[[], int],
221
- passed_over: list[str],
222
- ) -> Parts | None:
223
- """The best validated Strata recipe whose installed SimplexAI score beats the llama.cpp
224
- pick by at least llm_rank.TIE_BAND and that fits this host, priced as if ``--llm`` named
225
- it (roadmap decisions 26 and 33: Strata keeps the experts in RAM, so a 24 GB card with 64 GB runs
226
- Flash-Next). None leaves the choice to llama.cpp; why each better recipe was passed over is
227
- added to ``passed_over`` for the llama.cpp plan's warnings."""
228
- bar, llama_id = _llama_quality(facts, options)
229
- skipped: list[str] = []
230
- for recipe in stack_suite.auto_strata_candidates(facts, bar + llm_rank.TIE_BAND):
231
- score = recipe["quality"]["score"]
232
- why = (
233
- f"LLM: auto picks Strata {recipe['id']} (installed SimplexAI score {score}"
234
- + (
235
- f", best llama.cpp {llama_id} scores {bar}"
236
- if llama_id
237
- else ", no llama.cpp model fits"
238
- )
239
- + f", --prefer {options.get('prefer') or 'smartest'})"
240
- )
241
- try:
242
- parts = stack_suite.strata_parts(
243
- facts,
244
- options,
245
- recipe,
246
- [why, *skipped],
247
- listening=listening,
248
- previous=previous,
249
- owned_ram=owned_ram,
250
- )
251
- except (StackError, PlanError) as exc: # PlanError: its Strata pack is not on this host
252
- skipped.append(
253
- f"LLM: auto passed over the smarter Strata {recipe['id']} "
254
- f"(installed SimplexAI score {score}): {exc}"
255
- )
256
- continue
257
- return parts
258
- passed_over.extend(skipped)
259
- return None
260
-
261
-
262
275
  def agent_posture(options: StackOptions) -> AgentPosture:
263
276
  """The stack's agent posture with the operator's slot count. One slot is allowed since
264
277
  roadmap decision 26 (the smartest model does not have to serve two requests at once);
@@ -498,7 +511,8 @@ def _llama_parts(
498
511
  # (decision 21; 2026-10-30 order: decision index before GPU auxiliaries).
499
512
  opts = stack_suite.suite_options(options)
500
513
  candidates, llm = aux_gpu.place(facts, llm, choice, candidates, opts, price_llm, warnings)
501
- aux, spill = _fit_ram(
514
+ approved_mib = llm_ram.approved_cache_mib(approved.get("llm") if approved else None, llm)
515
+ aux, spill = stack_suite.fit_llama_ram(
502
516
  facts,
503
517
  options,
504
518
  llm,
@@ -507,6 +521,8 @@ def _llama_parts(
507
521
  entries,
508
522
  (running_llm is not None, held, available),
509
523
  warnings,
524
+ posture=posture,
525
+ approved_mib=approved_mib,
510
526
  )
511
527
  return {
512
528
  "llm": llm,
@@ -520,86 +536,33 @@ def _llama_parts(
520
536
  }
521
537
 
522
538
 
523
- def _fit_ram(
524
- facts: HostFacts,
525
- options: StackOptions,
526
- llm: Plan,
527
- choice: DecisionChoice,
528
- candidates: list[Plan],
529
- entries: tuple[cat.CatalogEntry, ...],
530
- host: tuple[bool, int, int],
531
- warnings: list[str],
532
- ) -> tuple[list[Plan], int]:
533
- """(the auxiliaries kept, the LLM's host RAM) once the LLM, its prompt cache, the decision
534
- model and the auxiliaries share the ``available`` RAM; ``host`` is (the LLM already runs,
535
- RAM held for unified-memory foundations, RAM available)."""
536
- running, held, available = host
537
- metal = hardware.on_metal(llm)
538
- spill = llm_ram.own_bytes(llm, entries, running=running, metal=metal)
539
- decision_ram = decide.host_ram(choice)
540
- posture = agent_posture(options)
541
- # The prompt cache is what lets an agent session pushed out of the shared KV pool resume
542
- # without prefilling its history again; its RAM is budgeted, not left to chance. Its minimum
543
- # comes first and the rest of it last (below). On a Mac that minimum is the floor deploy
544
- # reserved inside the LLM's unified bytes before the window and decision model were chosen.
545
- floor = int(str(llm["launch"].get("cache_floor_bytes") or 0)) if metal else 0
546
- if floor: # never shrink below what deploy reserved, nor demand more than that
547
- posture = replace(posture, prompt_cache_min_mib=floor >> 20)
548
- if running and metal: # a running Mac LLM's cache beyond the floor is the same RAM
549
- spill += prompt_cache_bytes(llm) - floor
550
- if not running and not metal:
551
- # Swapped-out LLM memory turns every token slow; like the suite services, it never swaps.
552
- # It stays outside the suite slice: its cgroup holds the page cache of mmapped weights,
553
- # which the slice's re-plan accounting would count as free memory.
554
- llm["service"]["limits"] = {**(llm["service"].get("limits") or {}), "MemorySwapMax": "0"}
555
- warnings += choice["notes"]
556
- minimum = min(prompt_cache_bytes(llm), posture.prompt_cache_min_mib << 20)
557
- aux = stack_suite.fit_aux(
558
- candidates,
559
- spill + (0 if running or metal else minimum) + decision_ram + HARNESS_RAM,
560
- decision_ram,
561
- suite.size_bytes(options["suite_memory"]),
562
- available,
563
- warnings,
564
- floor=ram_floor(metal),
565
- )
566
- if not running: # the cache shrinks to its minimum before an auxiliary is given up (product.md)
567
- room = available - ram_floor(metal) - HARNESS_RAM - decision_ram - spill - held
568
- warnings += prompt_cache_fit(llm, room - sum(map(suite.bounded_ram, aux)) + floor, posture)
569
- spill += prompt_cache_bytes(llm) - floor
570
- return aux, spill
571
-
572
-
573
- def engine_download_bytes(parts: list[Plan]) -> int:
574
- """Engine archives to fetch, once per engine directory (several components share a build)."""
575
- by_dir = {
576
- str(p["engine"].get("dir") or id(p)): sum(a["size_bytes"] for a in p["engine"]["assets"])
577
- for p in parts
578
- if p["engine"].get("assets")
539
+ def ram_budget(parts: Parts) -> dict[str, int]:
540
+ """The whole-stack RAM budget, refusing the same shortfall in plans and upgrade advice."""
541
+ llm, choice, aux = parts["llm"], parts["decision"], parts["aux"]
542
+ fast = parts.get("llm_fast")
543
+ ram_parts = {
544
+ "llm": parts["llm_ram"],
545
+ **({"llm_fast": parts["llm_fast_ram"]} if fast is not None else {}),
546
+ "decision": decide.host_ram(choice),
547
+ **{p["endpoint"].get("contract", p["model"]["id"]): suite.bounded_ram(p) for p in aux},
548
+ "harness": HARNESS_RAM,
549
+ "floor": (floor := ram_floor(hardware.on_metal(llm))),
579
550
  }
580
- return sum(by_dir.values())
581
-
582
-
583
- def _memory_note(llm: Plan, parts: list[Plan], options: StackOptions) -> list[str]:
584
- if hardware.on_metal(llm):
585
- return [
586
- "memory: macOS has no cgroups, so the system does not enforce each service's memory "
587
- "limit or disable swap; the whole stack is estimated against one unified memory pool "
588
- "(the LLM's and decision model's VRAM is that memory). Watch other programs' memory "
589
- "use before and after apply; memory pressure slows inference"
590
- ]
591
- if llm["service"].get("slice"):
592
- return [
593
- f"memory: each service has its own cgroup limit with swap disabled; the stack sits "
594
- f"in {suite.SLICE}, limit {options['suite_memory']}"
595
- ]
596
- if any(p["service"].get("slice") for p in parts):
597
- return [
598
- f"memory: the decision and auxiliary models each have a cgroup limit with swap "
599
- f"disabled, in {suite.SLICE}, limit {options['suite_memory']}; the LLM is outside "
600
- "it but also has swap disabled"
601
- ]
602
- return []
551
+ ram_needed = sum(ram_parts.values())
552
+ available = parts["ram_available"]
553
+ if (
554
+ fast is not None or not parts["llm_running"] or hardware.on_metal(llm)
555
+ ) and ram_needed > available:
556
+ raise StackError(
557
+ f"not enough available RAM: the stack needs about {gib(ram_needed)} (with "
558
+ f"{gib(floor)} system headroom), this computer has {gib(available)} available"
559
+ + (
560
+ f", short about {gib(ram_needed - available)}; primary window is unchanged"
561
+ if fast is not None
562
+ else ""
563
+ )
564
+ )
565
+ return ram_parts
603
566
 
604
567
 
605
568
  def assemble(
@@ -619,38 +582,42 @@ def assemble(
619
582
  warnings = list(parts["warnings"]) + hardware.decision_elsewhere(
620
583
  choice, options.get("gpu"), facts
621
584
  )
585
+ fast = parts.get("llm_fast")
622
586
  kept = [llm] if parts["llm_running"] else []
587
+ if fast is not None and parts.get("llm_fast_running"):
588
+ kept.append(fast)
623
589
  kept += [p for p in (decision, front) if p is not None and choice["running"]]
624
- own = [p for p in (llm, decision, front, *aux) if p is not None]
590
+ own = [p for p in (llm, fast, decision, front, *aux) if p is not None]
625
591
  fresh = [p for p in own if all(p is not k for k in kept)]
626
592
  for part in fresh:
627
593
  # aux_plans already left out an auxiliary whose port another program holds.
628
594
  if all(part is not a for a in aux):
629
595
  if listening(part["service"]["port"]) and (part is llm or not is_redeploy(part)):
630
596
  port = part["service"]["port"]
631
- flag = "--llm-port" if part is llm else "--decision-port"
597
+ role, fix = (
598
+ ("the fastest LLM", "Plan again to choose a free port")
599
+ if part is fast
600
+ else (
601
+ "the LLM" if part is llm else "the decision model",
602
+ "Pick a free port with "
603
+ + ("--llm-port" if part is llm else "--decision-port"),
604
+ )
605
+ )
632
606
  held = harness_probe.port_holder(port) if sys.platform.startswith("linux") else None
633
607
  raise StackError(
634
- f"port {port} for {'the LLM' if part is llm else 'the decision model'} "
608
+ f"port {port} for {role} "
635
609
  + (f"is taken by {held}" if held else "is taken by another program")
636
- + f"; this tool will not stop it. Pick a free port with {flag}"
610
+ + f"; this tool will not stop it. {fix}"
637
611
  )
638
612
 
639
- ram_parts = {
640
- "llm": parts["llm_ram"],
641
- "decision": decide.host_ram(choice),
642
- **{p["endpoint"].get("contract", p["model"]["id"]): suite.bounded_ram(p) for p in aux},
643
- "harness": HARNESS_RAM,
644
- "floor": (floor := ram_floor(hardware.on_metal(llm))),
645
- }
613
+ ram_parts = ram_budget(parts)
646
614
  ram_needed = sum(ram_parts.values())
647
615
  available = parts["ram_available"]
648
- if (not parts["llm_running"] or hardware.on_metal(llm)) and ram_needed > available:
649
- raise StackError(
650
- f"not enough available RAM: the stack needs about {gib(ram_needed)} (with "
651
- f"{gib(floor)} system headroom), this computer has {gib(available)} available"
652
- )
653
- warnings += _memory_note(llm, own, options)
616
+ metal = hardware.on_metal(llm)
617
+ windows = facts["platform"] == "win32"
618
+ warnings += llm_ram.memory_note(
619
+ llm, own, options["suite_memory"], suite.SLICE, metal=metal, windows=windows
620
+ )
654
621
 
655
622
  served = front or decision
656
623
  gateway_decision: harness.Endpoint | None = (
@@ -676,6 +643,17 @@ def assemble(
676
643
  gateway_kind=options.get("gateway", "magpie"),
677
644
  context=int(str(llm["launch"].get("window") or 0)) or None,
678
645
  )
646
+ if fast is not None:
647
+ tools_plan["gateway"]["llm_fast"] = {
648
+ "url": fast["endpoint"]["base_url"],
649
+ "model": fast["endpoint"]["model"],
650
+ }
651
+ tools_plan["gateway"]["llm_fast_key_file"] = stack_route.key_file(fast)
652
+ tools_plan["gateway"]["llm_key_file"] = stack_route.key_file(llm)
653
+ tools_plan["warnings"] = [
654
+ w.replace("so all hit one LLM at client effort", "each LLM uses client effort")
655
+ for w in tools_plan["warnings"]
656
+ ]
679
657
  if harness.gateway_kind(tools_plan["gateway"]) == "bifrost":
680
658
  if any(p["endpoint"].get("contract") == "search" for p in aux):
681
659
  tools_plan["warnings"].append(
@@ -687,29 +665,8 @@ def assemble(
687
665
  tools_plan = gateway_keys.with_caller_key(tools_plan)
688
666
  warnings += tools_plan["warnings"]
689
667
 
690
- front_env = FRONT_ENV_BYTES if any(front is p for p in fresh) else 0
691
- # A TTS venv: its installed size counts as download (an upper bound) and twice on disk,
692
- # once installed and once in the installer's cache.
693
- venvs = sum(int(str(p["launch"].get("frontend_bytes", 0))) for p in fresh)
694
- engine_bytes = engine_download_bytes(fresh)
695
- saved, reuse_notes = reuse_copies(fresh, copies)
668
+ disk, reuse_notes = download_budget(facts, fresh, tools_plan, front, copies)
696
669
  warnings += reuse_notes
697
- downloads = (
698
- sum(p["model"]["download_bytes"] for p in fresh)
699
- + engine_bytes
700
- + tools_plan["download_bytes"]
701
- + front_env
702
- + venvs
703
- - saved
704
- )
705
- # Archives stay beside what they unpack to, so engines and tools count about twice.
706
- disk_needed = downloads + engine_bytes + tools_plan["download_bytes"] + 3 * front_env + venvs
707
- free = facts["disk"]["free_bytes"]
708
- if free is not None and disk_needed > free:
709
- raise StackError(
710
- f"not enough disk space: the stack needs about {gib(disk_needed)}, "
711
- f"{facts['disk']['path']} has only {gib(free)} free"
712
- )
713
670
  budget: dict[str, object] = {
714
671
  "kind": "estimate",
715
672
  "memory_kind": "unified" if hardware.on_metal(llm) else "discrete",
@@ -717,10 +674,7 @@ def assemble(
717
674
  "ram_needed_bytes": ram_needed,
718
675
  "ram_parts": ram_parts,
719
676
  "suite_memory": options["suite_memory"],
720
- "disk_free_bytes": free,
721
- "disk_needed_bytes": disk_needed,
722
- "download_bytes": downloads,
723
- "reused_bytes": saved,
677
+ **disk,
724
678
  "decision_vram_bytes": int(str(decision["launch"].get("vram_bytes") or 0))
725
679
  if decision
726
680
  else 0,
@@ -746,5 +700,7 @@ def assemble(
746
700
  "hardware": hardware.snapshot(facts, options),
747
701
  "plan_id": "",
748
702
  }
703
+ if fast is not None:
704
+ plan["llm_fast"] = fast
749
705
  plan["plan_id"] = digest(plan)
750
706
  return plan
@@ -69,6 +69,8 @@ def labels(plan: StackPlan) -> list[tuple[str, str]]:
69
69
  rows = [("tools", " · ".join(tools) or "keeps the existing tools")]
70
70
  llm = plan["llm"]["model"]
71
71
  rows.append(("llm", f"{llm['display_name']} {llm['quant']}".strip()))
72
+ if fast := plan.get("llm_fast"):
73
+ rows.append(("llm_fast", f"Fast LLM {fast['model']['display_name']}"))
72
74
  if plan["decision"] is not None:
73
75
  rows.append(("decision", plan["decision"]["model"]["id"]))
74
76
  elif plan["decision_existing"] is not None:
@@ -569,11 +569,12 @@ def gpu_plans(
569
569
  notes: list[str] = []
570
570
  mac = card["uuid"] == metal.METAL_UUID
571
571
  engine = suite.cuda_decision_engine(facts, probe_argv, opts.base_dir, notes, metal=mac)
572
+ cgroups = not mac and facts["platform"] != "win32"
572
573
  server = component.gpu_plan(
573
574
  hosts.LOCAL_ID, facts, opts, pick, card, engine, resource_template=resource_template
574
575
  )
575
576
  server["warnings"] += notes
576
- if mac: # no cgroups on macOS: nothing to bound the services with
577
+ if not cgroups: # macOS and Windows: nothing to bound the services with
577
578
  server = suite.unbounded(server)
578
579
  else:
579
580
  server = suite.bounded(server, DECISION_LIMITS, slice_limits)
@@ -582,7 +583,7 @@ def gpu_plans(
582
583
  front = component.front_plan(
583
584
  hosts.LOCAL_ID, facts, server, opts, resource_template=resource_template
584
585
  )
585
- if mac:
586
+ if not cgroups:
586
587
  return server, suite.unbounded(front)
587
588
  return server, suite.bounded(front, FRONT_LIMITS, slice_limits)
588
589