@simplexai/localmodels-darwin-arm64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.36

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 (143) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +141 -99
  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 +7 -1
  11. package/modules/localmodels/catalog.json +286 -12
  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-strata-0.1.59.1.json +31 -0
  22. package/modules/localmodels/engines.json +57 -1
  23. package/modules/localmodels/engines.py +6 -2
  24. package/modules/localmodels/estimator.py +21 -7
  25. package/modules/localmodels/frontend.py +4 -4
  26. package/modules/localmodels/gateway.py +14 -4
  27. package/modules/localmodels/gateway_app_bifrost.py +4 -3
  28. package/modules/localmodels/gateway_bifrost.py +70 -57
  29. package/modules/localmodels/gateway_probe.py +3 -4
  30. package/modules/localmodels/gguf.py +7 -0
  31. package/modules/localmodels/harness.py +24 -25
  32. package/modules/localmodels/harness_gateway.py +19 -10
  33. package/modules/localmodels/harness_probe.py +33 -6
  34. package/modules/localmodels/hosts.py +73 -9
  35. package/modules/localmodels/install.py +36 -6
  36. package/modules/localmodels/library_cli.py +179 -0
  37. package/modules/localmodels/library_convert.py +132 -0
  38. package/modules/localmodels/library_gateway.py +471 -0
  39. package/modules/localmodels/library_jobs.py +314 -0
  40. package/modules/localmodels/library_model.py +246 -0
  41. package/modules/localmodels/library_pricing.py +347 -0
  42. package/modules/localmodels/library_serve.py +348 -0
  43. package/modules/localmodels/library_state.py +373 -0
  44. package/modules/localmodels/library_status.py +349 -0
  45. package/modules/localmodels/llm_rank.py +77 -8
  46. package/modules/localmodels/memcalc.py +7 -30
  47. package/modules/localmodels/metal.py +26 -0
  48. package/modules/localmodels/metal_probe.py +11 -7
  49. package/modules/localmodels/plan_envelope.py +4 -1
  50. package/modules/localmodels/preparation.py +49 -0
  51. package/modules/localmodels/probe.py +8 -8
  52. package/modules/localmodels/process_identity.py +536 -9
  53. package/modules/localmodels/quant_formats.py +123 -0
  54. package/modules/localmodels/recommend.py +32 -3
  55. package/modules/localmodels/recommend_cli.py +8 -4
  56. package/modules/localmodels/records.py +1 -0
  57. package/modules/localmodels/remote_ops.py +104 -6
  58. package/modules/localmodels/remote_ops_download.py +17 -2
  59. package/modules/localmodels/remote_ops_prepare.py +425 -0
  60. package/modules/localmodels/remote_ops_remove.py +40 -7
  61. package/modules/localmodels/remote_ops_service.py +110 -8
  62. package/modules/localmodels/remote_ops_verify.py +15 -2
  63. package/modules/localmodels/runtime_auth.py +31 -1
  64. package/modules/localmodels/runtime_cli.py +3 -4
  65. package/modules/localmodels/runtime_io.py +50 -6
  66. package/modules/localmodels/service_autostart.py +45 -1
  67. package/modules/localmodels/service_control.py +13 -0
  68. package/modules/localmodels/service_deployment.py +12 -3
  69. package/modules/localmodels/service_jobs.py +33 -4
  70. package/modules/localmodels/service_probe.py +67 -13
  71. package/modules/localmodels/service_stop.py +152 -0
  72. package/modules/localmodels/service_worker.py +9 -1
  73. package/modules/localmodels/services_cli.py +50 -6
  74. package/modules/localmodels/setup_inspection.py +34 -25
  75. package/modules/localmodels/setup_text.py +118 -0
  76. package/modules/localmodels/sizecalc.py +625 -0
  77. package/modules/localmodels/sizecalc_cli.py +249 -0
  78. package/modules/localmodels/stack.py +69 -17
  79. package/modules/localmodels/stack_args.py +91 -19
  80. package/modules/localmodels/stack_auto.py +78 -0
  81. package/modules/localmodels/stack_binding.py +23 -35
  82. package/modules/localmodels/stack_card.py +195 -0
  83. package/modules/localmodels/stack_cleanup.py +379 -0
  84. package/modules/localmodels/stack_clients.py +4 -1
  85. package/modules/localmodels/stack_compose.py +173 -206
  86. package/modules/localmodels/stack_console.py +2 -0
  87. package/modules/localmodels/stack_decision.py +3 -2
  88. package/modules/localmodels/stack_down.py +189 -0
  89. package/modules/localmodels/stack_events.py +54 -0
  90. package/modules/localmodels/stack_hardware.py +30 -34
  91. package/modules/localmodels/stack_journal.py +29 -8
  92. package/modules/localmodels/stack_ledger.py +411 -0
  93. package/modules/localmodels/stack_lifecycle.py +162 -167
  94. package/modules/localmodels/stack_llm_ram.py +57 -5
  95. package/modules/localmodels/stack_memory.py +721 -0
  96. package/modules/localmodels/stack_picks.py +147 -0
  97. package/modules/localmodels/stack_plan.py +143 -25
  98. package/modules/localmodels/stack_ports.py +22 -0
  99. package/modules/localmodels/stack_preflight.py +699 -0
  100. package/modules/localmodels/stack_review.py +123 -5
  101. package/modules/localmodels/stack_rollback.py +2 -0
  102. package/modules/localmodels/stack_route.py +256 -0
  103. package/modules/localmodels/stack_run.py +11 -0
  104. package/modules/localmodels/stack_suite.py +107 -20
  105. package/modules/localmodels/stack_summary.py +65 -4
  106. package/modules/localmodels/stack_try.py +354 -0
  107. package/modules/localmodels/stack_try_client.py +194 -0
  108. package/modules/localmodels/stack_try_docs.py +139 -0
  109. package/modules/localmodels/stack_up.py +8 -1
  110. package/modules/localmodels/stack_update.py +29 -4
  111. package/modules/localmodels/stack_verify.py +3 -1
  112. package/modules/localmodels/stack_view.py +10 -11
  113. package/modules/localmodels/stack_view_apply.py +4 -2
  114. package/modules/localmodels/stack_view_events.py +2 -1
  115. package/modules/localmodels/stack_view_serve.py +3 -0
  116. package/modules/localmodels/stack_view_text.py +1 -1
  117. package/modules/localmodels/stack_view_words.py +4 -1
  118. package/modules/localmodels/stack_warm.py +574 -0
  119. package/modules/localmodels/stack_whatif.py +558 -0
  120. package/modules/localmodels/suite.py +48 -39
  121. package/modules/localmodels/tool_archive.py +40 -0
  122. package/modules/localmodels/tools.json +8 -0
  123. package/modules/localmodels/transport.py +1 -0
  124. package/modules/localmodels/vision.py +8 -1
  125. package/modules/localmodels/web/sizecalc/app.js +431 -0
  126. package/modules/localmodels/web/sizecalc/calc.js +269 -0
  127. package/modules/localmodels/web/sizecalc/page.html +362 -0
  128. package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
  129. package/modules/localmodels/web/view/i18n.js +1 -1
  130. package/modules/localmodels/web/view/logo-claude.svg +3 -0
  131. package/modules/localmodels/web/view/logo-codex.png +0 -0
  132. package/modules/localmodels/web/view/logo-pi.svg +6 -0
  133. package/modules/localmodels/web/view/view.css +4 -0
  134. package/modules/localmodels/web/view/view.js +15 -6
  135. package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/METADATA +1 -1
  136. package/modules/simplex_localmodels-0.1.0.dev36.dist-info/RECORD +242 -0
  137. package/package.json +1 -1
  138. package/tool.json +1 -1
  139. package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
  140. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/WHEEL +0 -0
  141. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/entry_points.txt +0 -0
  142. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/NOTICE +0 -0
  143. /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -7,9 +7,10 @@ from pathlib import Path
7
7
  from typing import TypedDict
8
8
  from urllib.parse import urlsplit, urlunsplit
9
9
 
10
- from localmodels import catalog_license, harness, stack
10
+ from localmodels import budget, catalog_license, harness, stack
11
11
  from localmodels.contracts import decode
12
- from localmodels.stack_plan import deployments
12
+ from localmodels.setup_text import Lang, join, text
13
+ from localmodels.stack_plan import StackPlan, deployments
13
14
 
14
15
  # The gateway the plan installs, as the approval screen names it (harness.gateway_kind).
15
16
  GATEWAY_NAMES = {"bifrost": "Bifrost", "magpie": "Magpie"}
@@ -20,10 +21,34 @@ class SelectedGPU(TypedDict):
20
21
  name: str
21
22
 
22
23
 
23
- class StackReview(TypedDict):
24
+ class PlanGPU(TypedDict):
25
+ index: int
26
+ name: str
27
+ totalBytes: int | None # the card's memory, when the plan recorded it
28
+ roles: list[str] # llm, llm_fast, decision: the models the plan places on this card
29
+
30
+
31
+ class PlanSummary(TypedDict):
32
+ """What a plan installs and needs, read from the plan alone: the recommendation an installer
33
+ shows. ``gpus`` lists every card the plan places a model on, the LLM's first."""
34
+
35
+ llm: str # catalog model ID
36
+ llmName: str # display name and quantization
37
+ contextWindow: int
38
+ gpus: list[PlanGPU] # empty when the plan runs on the CPU or unified memory only
39
+ placement: str # the LLM placement's label, e.g. "GPU 0 · RTX 4090" or "CPU"
40
+ memoryKind: str # discrete (GPU memory apart from RAM) or unified
41
+ vramBytes: int # GPU memory all planned deployments reserve; 0 on unified memory
42
+ memoryBytes: int # RAM the stack needs (on unified memory, everything)
43
+ downloadBytes: int
44
+ diskBytes: int
45
+ text: str # one sentence in the requested language
46
+
47
+
48
+ class _StackReview(TypedDict):
24
49
  schema: str
25
50
  planId: str
26
- gpuIndex: int
51
+ gpuIndex: int # the LLM's first GPU; every one is in gpus
27
52
  gpuName: str
28
53
  llm: str
29
54
  contextWindow: int
@@ -34,6 +59,11 @@ class StackReview(TypedDict):
34
59
  warnings: list[str]
35
60
 
36
61
 
62
+ class StackReview(_StackReview, total=False):
63
+ gpus: list[PlanGPU] # since 2026-11-13
64
+ summary: PlanSummary
65
+
66
+
37
67
  def _public_warning(text: str) -> str:
38
68
  def public_url(match: re.Match[str]) -> str:
39
69
  try:
@@ -54,7 +84,93 @@ def _public_warning(text: str) -> str:
54
84
  return "".join(char for char in text if ord(char) >= 32 or char in "\t\n")
55
85
 
56
86
 
57
- def review_plan(path: Path) -> StackReview:
87
+ def _gpus(plan: StackPlan) -> list[PlanGPU]:
88
+ hardware = plan.get("hardware")
89
+ cards = hardware["cards"] if hardware else []
90
+ totals = {c["index"]: c["total_bytes"] for c in cards}
91
+ found: dict[int, PlanGPU] = {}
92
+ placed = [
93
+ (role, decode(part["placement"].get("gpus"), list[SelectedGPU]))
94
+ for role, part in (
95
+ ("llm", plan["llm"]),
96
+ ("llm_fast", plan.get("llm_fast")),
97
+ ("decision", plan["decision"]),
98
+ )
99
+ if part is not None
100
+ ]
101
+ existing = plan.get("decision_existing")
102
+ if existing and existing["devices"] is not None:
103
+ devices = {device.strip() for device in existing["devices"].split(",")}
104
+ placed.append(
105
+ (
106
+ "decision",
107
+ [
108
+ {"index": card["index"], "name": card["name"]}
109
+ for card in cards
110
+ if str(card["index"]) in devices or card.get("uuid") in devices
111
+ ],
112
+ )
113
+ )
114
+ for role, selected in placed:
115
+ for gpu in selected:
116
+ row = found.setdefault(
117
+ gpu["index"],
118
+ {
119
+ "index": gpu["index"],
120
+ "name": gpu["name"],
121
+ "totalBytes": totals.get(gpu["index"]),
122
+ "roles": [],
123
+ },
124
+ )
125
+ if role not in row["roles"]:
126
+ row["roles"].append(role)
127
+ return list(found.values())
128
+
129
+
130
+ def summarize(plan: StackPlan, lang: Lang = "zh") -> PlanSummary:
131
+ llm, need = plan["llm"], plan["budget"]
132
+ model = llm["model"]
133
+ name = " ".join(filter(None, (model["display_name"], model.get("quant")))) or model["id"]
134
+ gpus = _gpus(plan)
135
+ unified = need.get("memory_kind") == "unified"
136
+ vram = 0
137
+ if not unified:
138
+ vram = sum(
139
+ decode(part["launch"].get("vram_bytes") or 0, int)
140
+ for part in deployments(plan)
141
+ if part["placement"].get("gpus")
142
+ )
143
+ where = join([f"GPU {g['index']} · {g['name']}" for g in gpus], lang) or str(
144
+ llm["placement"].get("label") or "CPU"
145
+ )
146
+ ram, download = decode(need["ram_needed_bytes"], int), decode(need["download_bytes"], int)
147
+ disk = decode(need["disk_needed_bytes"], int)
148
+ gib = budget.gib
149
+ return {
150
+ "llm": model["id"],
151
+ "llmName": name,
152
+ "contextWindow": decode(llm["launch"]["window"], int),
153
+ "gpus": gpus,
154
+ "placement": str(llm["placement"].get("label") or ""),
155
+ "memoryKind": "unified" if unified else "discrete",
156
+ "vramBytes": vram,
157
+ "memoryBytes": ram,
158
+ "downloadBytes": download,
159
+ "diskBytes": disk,
160
+ "text": text(
161
+ "summary-unified" if unified else "summary",
162
+ lang,
163
+ llm=name,
164
+ where=where,
165
+ vram=gib(vram),
166
+ ram=gib(ram),
167
+ download=gib(download),
168
+ disk=gib(disk),
169
+ ),
170
+ }
171
+
172
+
173
+ def review_plan(path: Path, lang: Lang = "zh") -> StackReview:
58
174
  if not path.is_absolute():
59
175
  raise ValueError("Plan path must be absolute")
60
176
  plan = stack.load(path)
@@ -82,4 +198,6 @@ def review_plan(path: Path) -> StackReview:
82
198
  "memoryBytes": decode(budget["ram_needed_bytes"], int),
83
199
  "components": [*components, GATEWAY_NAMES[harness.gateway_kind(gateway)], "Pi"],
84
200
  "warnings": list(dict.fromkeys(warnings)),
201
+ "gpus": _gpus(plan),
202
+ "summary": summarize(plan, lang),
85
203
  }
@@ -102,6 +102,8 @@ def find() -> Rollback:
102
102
  def _role(plan: StackPlan, part: Plan) -> str:
103
103
  if part is plan["llm"]:
104
104
  return "llm"
105
+ if part is plan.get("llm_fast"):
106
+ return "llm_fast"
105
107
  if part is plan["decision"] or part is plan.get("decision_front"):
106
108
  return "decision"
107
109
  return part["endpoint"].get("contract") or part["model"]["id"]
@@ -0,0 +1,256 @@
1
+ """Opt-in second LLM, priced after the primary's window and optional components are fixed."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import copy
6
+ from collections.abc import Callable
7
+ from dataclasses import replace
8
+ from pathlib import Path
9
+ from typing import Any, cast
10
+
11
+ from localmodels import catalog as cat
12
+ from localmodels import (
13
+ component,
14
+ deploy,
15
+ hosts,
16
+ metal,
17
+ stack_hardware,
18
+ stack_llm_ram,
19
+ stack_picks,
20
+ stack_ports,
21
+ stack_suite,
22
+ suite,
23
+ vision,
24
+ )
25
+ from localmodels.budget import gib
26
+ from localmodels.context_policy import AgentPosture
27
+ from localmodels.probe import HostFacts
28
+ from localmodels.records import PinnedFile, Plan
29
+ from localmodels.stack_plan import Parts, StackError, StackOptions, own_name
30
+
31
+
32
+ def validate(options: StackOptions, facts: HostFacts) -> None:
33
+ """Normalize the disabled route and refuse unsupported routing before planning components."""
34
+ if options.get("route", "none") == "none":
35
+ options.pop("route", None)
36
+ options.pop("llm_fast_port", None)
37
+ return
38
+ if options["route"] != "fastest":
39
+ raise StackError("--route accepts fastest")
40
+ if metal.supported(facts):
41
+ raise StackError("--route fastest is not supported on Metal yet; use one LLM on this Mac")
42
+ if options.get("gateway", "magpie") != "bifrost":
43
+ raise StackError("--route fastest requires --gateway bifrost; Magpie is not supported")
44
+ if options["decision"] == "none":
45
+ raise StackError("--route fastest requires a decision model; use --decision auto or ID")
46
+ if options.get("prefer", "smartest") != "smartest":
47
+ raise StackError("--route fastest requires --prefer smartest for the primary LLM")
48
+ if options.get("defer_services"):
49
+ raise StackError(
50
+ "--route fastest requires an active decision model, without --defer-services"
51
+ )
52
+
53
+
54
+ def add(
55
+ facts: HostFacts,
56
+ options: StackOptions,
57
+ parts: Parts,
58
+ posture: AgentPosture,
59
+ *,
60
+ resolver: Callable[[list[tuple[str, cat.AssetFile]], str], list[PinnedFile]],
61
+ listening: Callable[[int], bool],
62
+ previous: Callable[[str, int], Plan | None],
63
+ approved: Plan | None = None,
64
+ ) -> None:
65
+ """Add exactly the hardware's fastest pick, refusing rather than shrinking the primary."""
66
+ choice = parts["decision"]
67
+ if choice["plan"] is None and choice["existing"] is None:
68
+ raise StackError("--route fastest requires an available decision model in the plan")
69
+ seen = stack_hardware.view(facts, options, posture)
70
+ offered = seen.get("picks", [])
71
+ if options.get("gpu") is not None:
72
+ offered = stack_picks.picks([c for c in seen["cards"] if c["index"] == options["gpu"]])
73
+ pick = next((p for p in offered if p["role"] == "fastest"), None)
74
+ if pick is None or pick["id"] == parts["llm"]["model"]["id"]:
75
+ raise StackError("--route fastest has no distinct, worthwhile fastest pick on this device")
76
+ window = int(str(parts["llm"]["launch"]["window"]))
77
+ posture = replace(
78
+ posture,
79
+ floor=max(posture.floor, window),
80
+ preferred=max(posture.preferred, window),
81
+ target=max(posture.target, window),
82
+ )
83
+ occupied = [
84
+ p for p in (parts["llm"], choice["plan"], choice["front"], *parts["aux"]) if p is not None
85
+ ]
86
+ reserved = [p["service"]["port"] for p in occupied]
87
+
88
+ def eligible(name: str, port: int) -> Plan | None:
89
+ found = previous(name, port)
90
+ return (
91
+ found
92
+ if found is not None and reusable(found, parts["llm"], posture, approved)
93
+ else None
94
+ )
95
+
96
+ running = (
97
+ stack_ports.private_previous([pick["id"]], options["base_dir"], eligible)
98
+ if not options.get("llm_fast_port")
99
+ else None
100
+ )
101
+ port = (
102
+ options.get("llm_fast_port")
103
+ or (running["service"]["port"] if running else None)
104
+ or stack_ports.default_port(facts, stack_ports.AUTO_PORTS, listening, reserved=reserved)
105
+ )
106
+ if port in reserved:
107
+ raise StackError(f"fastest LLM port {port} conflicts with another planned component")
108
+ options["llm_fast_port"] = port
109
+ name = own_name(pick["id"], port, options["base_dir"])
110
+ running = eligible(name, port)
111
+ held = remaining_memory(facts, parts, occupied, reclaimed=approved is not None)
112
+ placement = (
113
+ f"gpu:{options['gpu']}"
114
+ if options.get("gpu") is not None
115
+ else f"gpu:{pick['card']}"
116
+ if options.get("share_gpu")
117
+ else "auto"
118
+ )
119
+ try:
120
+ fast = running or deploy.build_plan(
121
+ hosts.LOCAL_ID,
122
+ held,
123
+ deploy.PlanOptions(
124
+ model_id=pick["id"],
125
+ placement_id=placement,
126
+ port=port,
127
+ base_dir=options["base_dir"],
128
+ hf_download_endpoint=options["hf_endpoint"],
129
+ hf_api_endpoint=options["hf_endpoint"],
130
+ agent=posture,
131
+ ),
132
+ resolver=resolver,
133
+ )
134
+ except deploy.AgentMemoryError as exc:
135
+ needed, usable = exc.needed_bytes, exc.available_bytes
136
+ capacity = (
137
+ "the primary Strata expert cache retains its approved allocation"
138
+ if _strata(parts["llm"]) is not None
139
+ else f"only {gib(usable)} remains"
140
+ )
141
+ raise StackError(
142
+ f"--route fastest: {pick['id']} needs at least about {gib(needed)} {exc.memory} "
143
+ f"including KV/runtime; {capacity}, short about "
144
+ f"{gib(max(0, needed - usable))}; primary window is unchanged; "
145
+ "use a second idle card or a larger memory tier"
146
+ ) from None
147
+ _, ram = stack_suite.fit_llama_ram(
148
+ facts,
149
+ options,
150
+ fast,
151
+ {**choice, "notes": []},
152
+ parts["aux"],
153
+ cat.load_catalog_file(),
154
+ (running is not None, 0, parts["ram_available"]),
155
+ parts["warnings"],
156
+ posture=posture,
157
+ approved_mib=stack_llm_ram.approved_cache_mib(approved, fast),
158
+ reserved_bytes=parts["llm_ram"],
159
+ fixed_aux=True,
160
+ )
161
+ parts["llm_fast"] = fast
162
+ parts["llm_fast_running"] = running is not None
163
+ parts["llm_fast_ram"] = ram
164
+ parts["warnings"].append(
165
+ f"routing: estimated joint budget includes {pick['id']}; easy turns use fastest, "
166
+ "COMPLEX turns use the primary LLM; its window is unchanged"
167
+ )
168
+
169
+
170
+ def reusable(
171
+ part: Plan, primary: Plan, posture: AgentPosture, approved: Plan | None = None
172
+ ) -> bool:
173
+ """Respect fast's own posture; automatic KV and reader placement can differ from the primary."""
174
+ launch = part["launch"]
175
+ entry = next(e for e in cat.load_catalog_file() if e.id == part["model"]["id"])
176
+ kv_matches = (
177
+ launch.get("kv_types") == approved["launch"].get("kv_types")
178
+ if approved is not None
179
+ else not posture.kv_pinned or launch.get("kv_types") == list(posture.kv_types[0])
180
+ )
181
+ return (
182
+ int(str(launch.get("window") or 0)) >= int(str(primary["launch"]["window"]))
183
+ and launch.get("slots") == posture.slots
184
+ and (launch.get("vision") not in (None, "", "off"))
185
+ == vision.llama_reader_enabled(entry.mmproj, posture.vision)
186
+ and kv_matches
187
+ )
188
+
189
+
190
+ def key_file(part: Plan) -> str:
191
+ return str(Path(part["service"]["deploy_dir"]) / "api-key")
192
+
193
+
194
+ def _strata(part: Plan) -> suite.SuiteRecipe | None:
195
+ return next(
196
+ (
197
+ r
198
+ for r in suite.recipes("llm")
199
+ if r["id"] == part["model"]["id"] and r["runtime"] in suite.STRATA_RUNTIMES
200
+ ),
201
+ None,
202
+ )
203
+
204
+
205
+ def _primary_vram(part: Plan, available: int) -> int:
206
+ """A Strata cache keeps its approved allocation, including slots beyond the recipe baseline."""
207
+ measured = int(str(part["launch"].get("vram_bytes") or 0))
208
+ recipe = _strata(part)
209
+ if recipe is None:
210
+ return measured
211
+ sizing = recipe.get("expert_cache_sizing")
212
+ argv = part["service"]["argv"]
213
+ if sizing and "--expert-cache" in argv:
214
+ slots = argv[argv.index("--expert-cache") + 1]
215
+ if slots.isdigit():
216
+ cache = int(stack_suite.expert_cache_mib(recipe, int(slots)) * (1 << 20))
217
+ reader = (
218
+ vision.strata_gpu_mib(
219
+ recipe.get("vision") or {}, str(part["launch"].get("vision") or "off")
220
+ )
221
+ << 20
222
+ )
223
+ return max(measured, cache + reader)
224
+ # Auto caches grow into the free card. Their static recipe peak is not an allocation cap.
225
+ return max(measured, available)
226
+
227
+
228
+ def remaining_memory(
229
+ facts: HostFacts,
230
+ parts: Parts,
231
+ occupied: list[Plan],
232
+ *,
233
+ reclaimed: bool = False,
234
+ ) -> HostFacts:
235
+ """The existing budget facts after the unchanged primary and foundations take their share."""
236
+ held = copy.deepcopy(facts)
237
+ choice = parts["decision"]
238
+ for part in occupied:
239
+ if part is parts["llm"] and parts["llm_running"] and not reclaimed:
240
+ continue
241
+ if part in (choice["plan"], choice["front"]) and choice["running"] and not reclaimed:
242
+ continue
243
+ amount = int(str(part["launch"].get("vram_bytes") or 0))
244
+ if part is choice["plan"]:
245
+ amount += component.VRAM_MARGIN
246
+ for gpu in held.get("gpus") or []:
247
+ if any(
248
+ g["uuid"] == gpu["uuid"]
249
+ for g in cast(list[dict[str, Any]], part["placement"].get("gpus") or [])
250
+ ):
251
+ allocated = (
252
+ _primary_vram(part, gpu["free_bytes"]) if part is parts["llm"] else amount
253
+ )
254
+ gpu["free_bytes"] = max(0, gpu["free_bytes"] - allocated)
255
+ gpu["used_bytes"] += allocated
256
+ return held
@@ -127,6 +127,8 @@ def report(record: StackRecord, timing: Mapping[str, float] | None = None) -> in
127
127
 
128
128
  def _planned_components(plan: StackPlan) -> list[str]:
129
129
  required = ["tools", "llm"]
130
+ if plan.get("llm_fast"):
131
+ required.append("llm_fast")
130
132
  if plan["decision"] is not None or plan["decision_existing"] is not None:
131
133
  required.append("decision")
132
134
  required.extend(part["endpoint"].get("contract", "aux") for part in plan.get("aux", []))
@@ -532,6 +534,8 @@ def _required_from_saved_plan(plan: object, plan_id: str) -> list[str] | None:
532
534
  except (TypeError, ValueError, RecursionError):
533
535
  return None
534
536
  result = ["tools", "llm"]
537
+ if plan.get("llm_fast"):
538
+ result.append("llm_fast")
535
539
  if plan["decision"] is not None or plan["decision_existing"] is not None:
536
540
  result.append("decision")
537
541
  for item in plan["aux"]:
@@ -593,6 +597,13 @@ def capabilities() -> None:
593
597
  "clients_schema": "localmodels.stack-clients/v1",
594
598
  "run_schema": "localmodels.stack-run/v1",
595
599
  "progress_schema": "localmodels.stack-progress/v1",
600
+ "hardware_picks": True, # stack hardware --json: picks (smartest, fastest)
601
+ "prefer_fastest": True,
602
+ "warm_json": True,
603
+ "warm_schema": "localmodels.stack-warm/v1",
604
+ "remove_dry_run": True, # remove keeps only model files; --purge: none
605
+ "memory_json": True, # stack memory MODEL --json: VRAM and RAM estimate
606
+ "memory_schema": "localmodels.stack-memory/v1",
596
607
  },
597
608
  },
598
609
  separators=(",", ":"),
@@ -12,22 +12,29 @@ import argparse
12
12
  from collections.abc import Callable
13
13
  from dataclasses import replace
14
14
 
15
+ from localmodels import catalog as cat
15
16
  from localmodels import cli_help, hosts, metal, stack_ports, suite, vision
16
17
  from localmodels import stack_decision as decide
17
18
  from localmodels import stack_gpu_memory as gpu_memory
19
+ from localmodels import stack_hardware as hardware
20
+ from localmodels import stack_llm_ram as llm_ram
18
21
  from localmodels.budget import gib, holders, host_ram, idle_cards, sharing_cards
22
+ from localmodels.context_policy import AgentPosture
19
23
  from localmodels.plan_envelope import PlanError
20
24
  from localmodels.probe import GPU, HostFacts
21
25
  from localmodels.records import Plan
26
+ from localmodels.stack_llm_ram import prompt_cache_bytes, prompt_cache_fit
22
27
  from localmodels.stack_plan import (
23
28
  HARNESS_RAM,
24
29
  RAM_FLOOR,
30
+ DecisionChoice,
25
31
  Parts,
26
32
  StackError,
27
33
  StackOptions,
28
34
  StackPlan,
29
35
  is_redeploy,
30
36
  own_name,
37
+ ram_floor,
31
38
  )
32
39
  from localmodels.suite import bounded_ram
33
40
 
@@ -131,6 +138,12 @@ def _aux(value: str) -> str:
131
138
  return "auto" if len(tasks) == len(AUX_TASKS) else ",".join(tasks)
132
139
 
133
140
 
141
+ def expert_cache_mib(recipe: suite.SuiteRecipe, slots: int = 0) -> float:
142
+ """The fixed cache footprint shared by Strata allocation and whole-stack routing budgets."""
143
+ sizing = recipe["expert_cache_sizing"]
144
+ return sizing["base_mib"] + sizing["draft_head_mib"] + slots * sizing["slot_mib"]
145
+
146
+
134
147
  def expert_cache(
135
148
  recipe: suite.SuiteRecipe, gpu: GPU, reserve_mib: int, reader_mib: int = 0
136
149
  ) -> tuple[str, int]:
@@ -141,19 +154,15 @@ def expert_cache(
141
154
  top of its reservation: lab241-rsi (2026-10-23) found 4.1 GiB idle. A fixed slot count takes
142
155
  the same VRAM in either start order; the decision model's share stays out of it, and Strata
143
156
  keeps only its own free margin. ``reader_mib`` is the GPU picture reader's VRAM (decision 31),
144
- held back from the cache like the decision model's."""
157
+ held back from the cache like the decision model's. Auto also reserves the real card's
158
+ memory excluded by ``--gpu-memory``. Fixed-slot sizing below uses the priced card's total."""
159
+ auto_reserve = reserve_mib + reader_mib + (gpu_memory.left_out_bytes(gpu) >> 20)
145
160
  sizing = recipe.get("expert_cache_sizing")
146
161
  if not sizing:
147
- return "auto", reserve_mib + reader_mib
148
- room = (
149
- (gpu["total_bytes"] >> 20)
150
- - reserve_mib
151
- - reader_mib
152
- - sizing["base_mib"]
153
- - sizing["draft_head_mib"]
154
- )
162
+ return "auto", auto_reserve
163
+ room = (gpu["total_bytes"] >> 20) - reserve_mib - reader_mib - expert_cache_mib(recipe)
155
164
  slots = int(room / sizing["slot_mib"])
156
- return (str(slots), STRATA_FREE_MIB) if slots > 0 else ("auto", reserve_mib + reader_mib)
165
+ return (str(slots), STRATA_FREE_MIB) if slots > 0 else ("auto", auto_reserve)
157
166
 
158
167
 
159
168
  def strata_recipes() -> list[suite.SuiteRecipe]:
@@ -543,19 +552,25 @@ def aux_plans(
543
552
  try:
544
553
  chosen = opts
545
554
  if task in stack_ports.AUXILIARY_PORTS:
546
- port = stack_ports.default_port(
547
- facts,
548
- stack_ports.AUXILIARY_PORTS[task],
549
- listening,
550
- reserved=(
551
- options["llm_port"],
552
- options["decision_port"],
553
- options["decision_port"] + 1000,
554
- ),
555
+ reserved = (
556
+ options["llm_port"],
557
+ options["decision_port"],
558
+ options["decision_port"] + 1000,
559
+ )
560
+ retry = stack_ports.failed_own_port(
561
+ [recipe["id"] for recipe in suite.recipes(task)], options["base_dir"]
562
+ )
563
+ port = (
564
+ retry
565
+ if retry is not None and retry not in reserved
566
+ else stack_ports.default_port(
567
+ facts, stack_ports.AUXILIARY_PORTS[task], listening, reserved=reserved
568
+ )
555
569
  )
556
570
  chosen = replace(opts, port=port)
557
571
  part = suite.build_plan(hosts.LOCAL_ID, facts, r, chosen)
558
- if metal.supported(facts): # no cgroups on macOS: priced by the estimate
572
+ # No cgroups on macOS or Windows: priced by the estimate, no slice promised.
573
+ if metal.supported(facts) or facts["platform"] == "win32":
559
574
  part = suite.unbounded(part)
560
575
  except PlanError as why:
561
576
  warnings.append(
@@ -611,3 +626,75 @@ def fit_aux(
611
626
  host_used += need
612
627
  slice_used += need
613
628
  return kept
629
+
630
+
631
+ def fit_llama_ram(
632
+ facts: HostFacts,
633
+ options: StackOptions,
634
+ llm: Plan,
635
+ choice: DecisionChoice,
636
+ candidates: list[Plan],
637
+ entries: tuple[cat.CatalogEntry, ...],
638
+ host: tuple[bool, int, int],
639
+ warnings: list[str],
640
+ *,
641
+ posture: AgentPosture,
642
+ approved_mib: int | None = None,
643
+ reserved_bytes: int = 0,
644
+ fixed_aux: bool = False,
645
+ ) -> tuple[list[Plan], int]:
646
+ """(the auxiliaries kept, the LLM's host RAM) once the LLM, its prompt cache, the decision
647
+ model and the auxiliaries share the ``available`` RAM; ``host`` is (the LLM already runs,
648
+ RAM held for unified-memory foundations, RAM available). ``reserved_bytes`` holds another
649
+ LLM's unchanged host budget; ``fixed_aux`` keeps its already chosen foundations."""
650
+ running, held, available = host
651
+ metal = hardware.on_metal(llm)
652
+ spill = llm_ram.own_bytes(llm, entries, running=running, metal=metal)
653
+ decision_ram = decide.host_ram(choice)
654
+ # The prompt cache is what lets an agent session pushed out of the shared KV pool resume
655
+ # without prefilling its history again; its RAM is budgeted, not left to chance. Its minimum
656
+ # comes first and the rest of it last (below). On a Mac that minimum is the floor deploy
657
+ # reserved inside the LLM's unified bytes before the window and decision model were chosen.
658
+ floor = int(str(llm["launch"].get("cache_floor_bytes") or 0)) if metal else 0
659
+ if floor: # never shrink below what deploy reserved, nor demand more than that
660
+ posture = replace(posture, prompt_cache_min_mib=floor >> 20)
661
+ if running and metal: # a running Mac LLM's cache beyond the floor is the same RAM
662
+ spill += prompt_cache_bytes(llm) - floor
663
+ if not running and not metal:
664
+ # Swapped-out LLM memory turns every token slow; like the suite services, it never swaps.
665
+ # It stays outside the suite slice: its cgroup holds the page cache of mmapped weights,
666
+ # which the slice's re-plan accounting would count as free memory.
667
+ llm["service"]["limits"] = {**(llm["service"].get("limits") or {}), "MemorySwapMax": "0"}
668
+ warnings += choice["notes"]
669
+ minimum = min(prompt_cache_bytes(llm), posture.prompt_cache_min_mib << 20)
670
+ aux = (
671
+ candidates
672
+ if fixed_aux
673
+ else fit_aux(
674
+ candidates,
675
+ reserved_bytes
676
+ + spill
677
+ + (0 if running or metal else minimum)
678
+ + decision_ram
679
+ + HARNESS_RAM,
680
+ decision_ram,
681
+ suite.size_bytes(options["suite_memory"]),
682
+ available,
683
+ warnings,
684
+ floor=ram_floor(metal),
685
+ )
686
+ )
687
+ if not running: # the cache shrinks to its minimum before an auxiliary is given up (product.md)
688
+ room = (
689
+ available
690
+ - ram_floor(metal)
691
+ - HARNESS_RAM
692
+ - decision_ram
693
+ - spill
694
+ - held
695
+ - reserved_bytes
696
+ )
697
+ left = room - sum(map(suite.bounded_ram, aux)) + floor
698
+ warnings += prompt_cache_fit(llm, left, posture, approved_mib=approved_mib)
699
+ spill += prompt_cache_bytes(llm) - floor
700
+ return aux, spill