@simplexai/localmodels-linux-arm64 0.1.0-dev.63 → 0.1.0-dev.64

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 (72) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +71 -64
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/app.py +15 -2
  5. package/modules/localmodels/catalog.json +34 -0
  6. package/modules/localmodels/catalog.py +26 -4
  7. package/modules/localmodels/catalog_recipes.py +37 -1
  8. package/modules/localmodels/context_policy.py +6 -1
  9. package/modules/localmodels/debug_mode.py +85 -103
  10. package/modules/localmodels/deploy.py +41 -6
  11. package/modules/localmodels/download-mirrors.json +126 -6
  12. package/modules/localmodels/draft_spec.py +122 -0
  13. package/modules/localmodels/engine_adapters/__init__.py +4 -0
  14. package/modules/localmodels/engine_adapters/auxiliary.py +27 -0
  15. package/modules/localmodels/engine_adapters/base.py +40 -0
  16. package/modules/localmodels/engine_adapters/strata_poly.py +57 -0
  17. package/modules/localmodels/engine_adapters/suite_plan.py +394 -0
  18. package/modules/localmodels/engines-prism-b12178-03ec600.json +7 -7
  19. package/modules/localmodels/install.py +15 -0
  20. package/modules/localmodels/library_convert.py +2 -8
  21. package/modules/localmodels/library_elastic.py +2 -118
  22. package/modules/localmodels/library_jobs.py +1 -2
  23. package/modules/localmodels/library_poly.py +3 -2
  24. package/modules/localmodels/library_pricing.py +122 -13
  25. package/modules/localmodels/library_serve.py +4 -6
  26. package/modules/localmodels/memcalc_cli.py +2 -2
  27. package/modules/localmodels/planning/__init__.py +3 -0
  28. package/modules/localmodels/{memcalc_load.py → planning/memcalc_load.py} +1 -1
  29. package/modules/localmodels/{sizecalc.py → planning/sizecalc.py} +1 -1
  30. package/modules/localmodels/service_deployment.py +2 -1
  31. package/modules/localmodels/sizecalc_cli.py +10 -2
  32. package/modules/localmodels/speech_worker_sensevoice.py +30 -0
  33. package/modules/localmodels/stack.py +2 -4
  34. package/modules/localmodels/stack_arena.py +2 -2
  35. package/modules/localmodels/stack_auto.py +1 -1
  36. package/modules/localmodels/stack_aux_gpu.py +4 -2
  37. package/modules/localmodels/stack_card.py +2 -2
  38. package/modules/localmodels/stack_cleanup.py +3 -2
  39. package/modules/localmodels/stack_compose.py +9 -1
  40. package/modules/localmodels/stack_ledger.py +2 -1
  41. package/modules/localmodels/stack_mcp.py +1 -1
  42. package/modules/localmodels/stack_memory.py +3 -3
  43. package/modules/localmodels/stack_run.py +16 -0
  44. package/modules/localmodels/stack_suite.py +4 -3
  45. package/modules/localmodels/stack_try.py +2 -1
  46. package/modules/localmodels/stack_up.py +15 -30
  47. package/modules/localmodels/stack_view_llm.py +12 -7
  48. package/modules/localmodels/stack_warm.py +6 -3
  49. package/modules/localmodels/stack_whatif.py +1 -1
  50. package/modules/localmodels/suite.py +6 -334
  51. package/modules/localmodels/tui_views.py +17 -2
  52. package/modules/localmodels/web/index.html +595 -226
  53. package/modules/localmodels/web/sizecalc/app.js +34 -40
  54. package/modules/localmodels/web/sizecalc/calc.js +3 -3
  55. package/modules/localmodels/web/sizecalc/page.html +4 -3
  56. package/modules/localmodels/web/view/fleet.html +18 -3
  57. package/modules/localmodels/web/view/fleet.js +135 -14
  58. package/modules/localmodels/web/view/i18n.js +4 -0
  59. package/modules/localmodels/web/view/index.html +16 -0
  60. package/modules/localmodels/web/view/nav.js +49 -0
  61. package/modules/localmodels/web/view/theme.js +1 -1
  62. package/modules/localmodels/web/view/view.css +51 -15
  63. package/modules/localmodels/web/view/view.js +22 -4
  64. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/METADATA +1 -1
  65. package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/RECORD +68 -61
  66. package/package.json +1 -1
  67. package/tool.json +1 -1
  68. /package/modules/localmodels/{memcalc.py → planning/memcalc.py} +0 -0
  69. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/WHEEL +0 -0
  70. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/entry_points.txt +0 -0
  71. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/NOTICE +0 -0
  72. /package/modules/{simplex_localmodels-0.1.0.dev63.dist-info → simplex_localmodels-0.1.0.dev64.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -3,7 +3,7 @@
3
3
  "tag": "prism-b12178-03ec600",
4
4
  "commit": "03ec60072cdd32a03ae931969af62e57bfb0c8dc",
5
5
  "source": "https://github.com/PrismML-Eng/llama.cpp/releases/tag/prism-b12178-03ec600",
6
- "note": "Release asset digests from the GitHub release API (PrismML-Eng/llama.cpp prism-b12178-03ec600, commit 03ec60072cdd32a03ae931969af62e57bfb0c8dc, read 2026-11-26). Required for Ternary Bonsai 2.5 27B (PTQ1_0, PQ2_0, and PQ2_0M ggml tensor types 142/143/145, unsupported in upstream llama.cpp). Linux x64 CUDA 12.8 archive imports up to GLIBC_2.34 plus libgomp.so.1, libcudart.so.12, and libcublas.so.12 (verified via readelf -V -d) and pairs with the pinned CUDA 12.8 cudart companion archive from ggml-org/llama.cpp b11370. Linux and macOS tarballs unpack with a single top directory llama-prism-b12178-03ec600/ stripped by remote_ops.unpack; Windows CUDA 12.4, CUDA 13.3, and CPU zips unpack flat with llama-server.exe beside their DLLs and pair with PrismML's pinned cudart companion zips.",
6
+ "note": "Release asset digests from the GitHub release API (PrismML-Eng/llama.cpp prism-b12178-03ec600, commit 03ec60072cdd32a03ae931969af62e57bfb0c8dc, read 2026-11-26). Required for Ternary Bonsai 2.5 27B (PTQ1_0, PQ2_0, and PQ2_0M ggml tensor types 142/143/145, unsupported in upstream llama.cpp). Linux x64 CUDA 12.8 archive imports up to GLIBC_2.34 plus libgomp.so.1, libcudart.so.12, and libcublas.so.12 (verified via readelf -V -d) and pairs with the pinned CUDA 12.8 cudart companion archive from ggml-org/llama.cpp b11370. Linux and macOS tarballs unpack with a single top directory llama-prism-b12178-03ec600/ stripped by remote_ops.unpack; Windows CUDA 12.4, CUDA 13.3, and CPU zips unpack flat with llama-server.exe beside their DLLs and pair with PrismML's pinned cudart companion zips. Archives over 200 MiB (the Linux CUDA 12.8 build, the Windows CUDA 12.4 and 13.3 builds and their cudart companions) are fetched from byte-identical copies on the project CloudFront under cli/localmodels/engines/prism/, uploaded 2026-11-28 with S3 sha256 metadata and read back: GitHub release downloads crawl from mainland China (home-win 2026-11-27: 48.6 KB/s GitHub against ~8 MB/s CloudFront) and npm copies stop at 200 MiB. The originals keep the same file names in the GitHub release above (the Linux cudart companion in ggml-org/llama.cpp b11370).",
7
7
  "builds": [
8
8
  {
9
9
  "platform": "linux",
@@ -17,13 +17,13 @@
17
17
  "assets": [
18
18
  {
19
19
  "name": "llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
20
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
20
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-linux-cuda-12.8-x64.tar.gz",
21
21
  "sha256": "a50997fb29bb0684c00cdf21bb1382923c6bc70085a74c9c3d913dcf76af1899",
22
22
  "size_bytes": 225887048
23
23
  },
24
24
  {
25
25
  "name": "cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
26
- "url": "https://github.com/ggml-org/llama.cpp/releases/download/b11370/cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
26
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-b11370-bin-ubuntu-cuda-12.8-x64.tar.gz",
27
27
  "sha256": "7807b4fc01958fc11db9894b2ab791e664b4da999017e70f7b5a7147f6c770e3",
28
28
  "size_bytes": 594375807
29
29
  }
@@ -76,13 +76,13 @@
76
76
  "assets": [
77
77
  {
78
78
  "name": "llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
79
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
79
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-12.4-x64.zip",
80
80
  "sha256": "f1bef85254012f0e6f25502ee86696c7de6ccc76a922f05c3f23ab2e5719c531",
81
81
  "size_bytes": 341653677
82
82
  },
83
83
  {
84
84
  "name": "cudart-llama-bin-win-cuda-12.4-x64.zip",
85
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/cudart-llama-bin-win-cuda-12.4-x64.zip",
85
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-bin-win-cuda-12.4-x64.zip",
86
86
  "sha256": "8c79a9b226de4b3cacfd1f83d24f962d0773be79f1e7b75c6af4ded7e32ae1d6",
87
87
  "size_bytes": 391443627
88
88
  }
@@ -97,13 +97,13 @@
97
97
  "assets": [
98
98
  {
99
99
  "name": "llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
100
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
100
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/prism-b12178-03ec600/llama-prism-b12178-03ec600-bin-win-cuda-13.3-x64.zip",
101
101
  "sha256": "a34bdb817e797243f86c5e2dd1bdf118d17ea32b6eaa4e6f32c41533b13bc2d8",
102
102
  "size_bytes": 216516289
103
103
  },
104
104
  {
105
105
  "name": "cudart-llama-bin-win-cuda-13.3-x64.zip",
106
- "url": "https://github.com/PrismML-Eng/llama.cpp/releases/download/prism-b12178-03ec600/cudart-llama-bin-win-cuda-13.3-x64.zip",
106
+ "url": "https://d2ikbbcl3j6jz9.cloudfront.net/cli/localmodels/engines/prism/cudart/cudart-llama-bin-win-cuda-13.3-x64.zip",
107
107
  "sha256": "1462a050eb4c684921ba51dcc4cc488a036674c3e73e9945ee705b854808d03e",
108
108
  "size_bytes": 390970417
109
109
  }
@@ -86,6 +86,8 @@ def cli(args: argparse.Namespace) -> int:
86
86
  if plan.get("llm_fast")
87
87
  else stack_picks.second(offered, str(plan["llm"]["model"]["id"]))
88
88
  )
89
+ if other is not None and not args.yes:
90
+ print("\n".join(_choice_comparison(offered, str(plan["llm"]["model"]["id"]), other)))
89
91
  answer = "y" if args.yes else _confirm(other)
90
92
  if other is not None and answer == OTHER:
91
93
  # The second choice gets its own plan, shown in full: approval binds to what was shown.
@@ -119,6 +121,19 @@ def cli(args: argparse.Namespace) -> int:
119
121
  OTHER = "2" # the answer that asks for the second choice's plan
120
122
 
121
123
 
124
+ def _choice_comparison(
125
+ offered: list[stack_picks.Pick], chosen_id: str, other: stack_picks.Pick
126
+ ) -> list[str]:
127
+ """Compact two-line comparison of the shown plan's LLM and the second pick, keeping the
128
+ measured-vs-estimated basis from stack_picks.label."""
129
+ shown = next((p for p in offered if p["id"] == chosen_id), None)
130
+ rows: list[str] = []
131
+ if shown is not None:
132
+ rows.append(f" this plan ({shown['role']:<8}) {stack_picks.label(shown)}")
133
+ rows.append(f" option {OTHER} ({other['role']:<8}) {stack_picks.label(other)}")
134
+ return rows
135
+
136
+
122
137
  def _confirm(other: stack_picks.Pick | None) -> str:
123
138
  """The operator's answer: "y", OTHER when a second choice is offered and asked for, else "n"."""
124
139
  choice = f"/{OTHER}: see the {other['role']} plan instead" if other else ""
@@ -27,7 +27,7 @@ from localmodels import (
27
27
  library_state,
28
28
  library_status,
29
29
  stack_run,
30
- stack_up,
30
+ stack_verify,
31
31
  )
32
32
  from localmodels.contracts import decode
33
33
  from localmodels.library_model import library_id
@@ -131,8 +131,6 @@ def _planned_stack_llms(plan: StackPlan | None) -> dict[str, str]:
131
131
  """``library_id -> stack_provider`` for every LLM declared by ``plan`` (running or unloaded)."""
132
132
  if plan is None:
133
133
  return {}
134
- from localmodels import stack_verify
135
-
136
134
  found: dict[str, str] = {}
137
135
  for component, part in stack_verify.parts(plan):
138
136
  if component not in STACK_LLMS:
@@ -149,8 +147,6 @@ def adopted_components(plan: StackPlan) -> set[str]:
149
147
  stays when ``library remove`` deletes the model's record; a converted record (an earlier
150
148
  one may lack ``stack_provider``: the main LLM's) names them too. Read only; it never
151
149
  converts."""
152
- from localmodels import stack_verify
153
-
154
150
  try:
155
151
  marker = json.loads((library_state.root() / MARKER).read_text("utf-8"))
156
152
  except (OSError, ValueError):
@@ -178,8 +174,6 @@ def _active_stack_llms(plan: StackPlan | None) -> dict[str, tuple[str, Plan]]:
178
174
  """Accepted stack LLM deployments still present and ok on disk: ``library_id -> (provider, plan)``."""
179
175
  if plan is None:
180
176
  return {}
181
- from localmodels import stack_verify
182
-
183
177
  found: dict[str, tuple[str, Plan]] = {}
184
178
  for component, part in stack_verify.parts(plan):
185
179
  if component not in STACK_LLMS:
@@ -580,7 +574,7 @@ def convert_once() -> list[str]:
580
574
  if accepted is not None:
581
575
  plan, attempt_id, _ = accepted
582
576
  elif not hosts.stack_runs():
583
- plan = stack_up.accepted()
577
+ plan = stack_run.accepted()
584
578
  adopted = _sync_with_plan(plan, attempt_id)
585
579
  return adopted or _reconcile_live_bifrost()
586
580
  marker_doc = _read_marker(marker)
@@ -10,8 +10,6 @@ non-critical VM pressure, admission succeeds at the floor posture with a pressur
10
10
 
11
11
  from __future__ import annotations
12
12
 
13
- import copy
14
- import math
15
13
  from dataclasses import dataclass, replace
16
14
  from typing import cast
17
15
 
@@ -31,8 +29,6 @@ from localmodels import (
31
29
  from localmodels import catalog as cat
32
30
  from localmodels.context_policy import AgentPosture
33
31
  from localmodels.estimator import (
34
- AGENT_VRAM_RESERVE_BYTES,
35
- METAL_VRAM_RESERVE_BYTES,
36
32
  PhysicsRefusal,
37
33
  )
38
34
  from localmodels.library_model import (
@@ -182,76 +178,6 @@ def elastic_posture_ladder(
182
178
  return tuple(rungs)
183
179
 
184
180
 
185
- def _project_cuda_uma(
186
- facts: HostFacts, unified: int, target: int, *, bypass_working_set: bool
187
- ) -> HostFacts:
188
- seen = copy.deepcopy(facts)
189
- need = target + AGENT_VRAM_RESERVE_BYTES
190
- raw = int(math.ceil(need / (1 - budget._UMA_HEADROOM_FRACTION)))
191
- while int(raw * (1 - budget._UMA_HEADROOM_FRACTION)) < need:
192
- raw += 1
193
- raw = raw if bypass_working_set else min(unified, raw)
194
- if bypass_working_set and isinstance(cuda_pool := seen.get("cuda_pool"), dict):
195
- cuda_pool["total_bytes"], cuda_pool["integrated"] = max(unified, raw), True
196
- for gpu in seen.get("gpus") or []:
197
- if gpu.get("vendor") == "nvidia" and gpu.get("mig_mode") != "enabled":
198
- gpu["free_bytes"], gpu["used_bytes"] = 0, gpu["total_bytes"]
199
- break
200
- ram = seen["ram"]
201
- if bypass_working_set:
202
- ram["total_bytes"] = max(int(ram["total_bytes"]), raw)
203
- if (cgroup := seen.get("cgroup_memory")) is not None:
204
- if (limit := cgroup.get("limit_bytes")) is not None and limit < raw:
205
- cgroup["limit_bytes"] = raw
206
- cgroup["usage_bytes"] = 0
207
- ram["available_bytes"] = min(int(ram["total_bytes"]), raw)
208
- return seen
209
-
210
-
211
- def facts_for_budget(
212
- facts: HostFacts,
213
- pool: str,
214
- target_bytes: int,
215
- *,
216
- wired_cap_bytes: int | None = None,
217
- bypass_working_set: bool = False,
218
- ) -> HostFacts:
219
- """Project ``facts`` so ``deploy.build_plan`` prices ``pool`` against ``target_bytes``
220
- (unified/total) and optional ``wired_cap_bytes`` (Metal GPU wired headroom)."""
221
- target = max(0, target_bytes)
222
- if pool == "unified" and metal.supported(facts):
223
- seen = copy.deepcopy(facts)
224
- ram = seen["ram"]
225
- needed_avail = target + metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
226
- ram["available_bytes"] = (
227
- needed_avail if bypass_working_set else min(int(ram["total_bytes"]), needed_avail)
228
- )
229
- ram["pressure_level"] = metal.PRESSURE_NORMAL
230
- ram.pop("pressure_kept_bytes", None)
231
- if isinstance(metal_doc := seen.get("metal"), dict):
232
- ceiling = (
233
- max(0, wired_cap_bytes) + METAL_VRAM_RESERVE_BYTES
234
- if wired_cap_bytes is not None
235
- else max(metal.wired_ceiling_bytes(facts), target + METAL_VRAM_RESERVE_BYTES)
236
- if bypass_working_set
237
- else metal.wired_ceiling_bytes(facts)
238
- )
239
- metal_doc["recommended_max_working_set_bytes"] = ceiling
240
- return seen
241
- if pool == "unified" and (unified := budget.unified_pool_bytes(facts)) is not None:
242
- return _project_cuda_uma(facts, unified, target, bypass_working_set=bypass_working_set)
243
- if (idx := library_pricing.gpu_index(pool)) is not None:
244
- seen = copy.deepcopy(facts)
245
- for gpu in seen.get("gpus") or []:
246
- if gpu["index"] == idx:
247
- free = target + AGENT_VRAM_RESERVE_BYTES
248
- gpu["free_bytes"] = free if bypass_working_set else min(gpu["total_bytes"], free)
249
- gpu["used_bytes"] = max(0, gpu["total_bytes"] - gpu["free_bytes"])
250
- break
251
- return seen
252
- return facts
253
-
254
-
255
181
  def _plan_posture(plan: Plan) -> PostureSpec:
256
182
  launch = plan["launch"]
257
183
  window = int(str(launch.get("window") or 0))
@@ -336,48 +262,6 @@ def minimum_memory_bytes(facts: HostFacts, model: Model, pool: str) -> int | Non
336
262
  return min_need
337
263
 
338
264
 
339
- def validate_plan_bounds(
340
- facts: HostFacts,
341
- model: Model,
342
- pool: str,
343
- plan: Plan,
344
- catalog: tuple[cat.CatalogEntry, ...],
345
- *,
346
- check_pool_total: bool = True,
347
- check_host_ram: bool = True,
348
- ) -> None:
349
- """Reject a plan exceeding ``pool``'s total capacity or host RAM on a discrete GPU."""
350
- if check_pool_total:
351
- total = library_pricing.pool_total(facts, pool)
352
- used = memory_bytes(plan)
353
- if used > total:
354
- refused = PhysicsRefusal(
355
- needed_bytes=used,
356
- available_bytes=total,
357
- message=f"{model.id} needs {used} bytes, exceeding pool {pool} total {total} bytes",
358
- )
359
- raise deploy.AgentMemoryError(
360
- refused.message,
361
- refused,
362
- "unified memory" if pool == "unified" else "GPU memory",
363
- )
364
- if check_host_ram and library_pricing.gpu_index(pool) is not None:
365
- needed_ram = (
366
- library_pricing.host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
367
- )
368
- _, avail_ram = budget.host_ram(facts)
369
- if needed_ram > avail_ram:
370
- refused = PhysicsRefusal(
371
- needed_bytes=needed_ram,
372
- available_bytes=avail_ram,
373
- message=(
374
- f"{model.id} needs {needed_ram} bytes of system memory, "
375
- f"exceeding {avail_ram} bytes available"
376
- ),
377
- )
378
- raise deploy.AgentMemoryError(refused.message, refused, "system memory")
379
-
380
-
381
265
  @dataclass(frozen=True)
382
266
  class _PriceCtx:
383
267
  facts: HostFacts
@@ -400,7 +284,7 @@ def _price_rung(
400
284
  check_host_ram: bool = True,
401
285
  bypass_working_set: bool = False,
402
286
  ) -> Plan:
403
- priced_facts = facts_for_budget(
287
+ priced_facts = library_pricing.facts_for_budget(
404
288
  ctx.facts,
405
289
  ctx.pool,
406
290
  budget_bytes,
@@ -424,7 +308,7 @@ def _price_rung(
424
308
  entries=ctx.catalog,
425
309
  resolver=deploy.catalog_pins,
426
310
  )
427
- validate_plan_bounds(
311
+ library_pricing.validate_plan_bounds(
428
312
  ctx.facts,
429
313
  ctx.model,
430
314
  ctx.pool,
@@ -23,6 +23,7 @@ from localmodels import (
23
23
  deploy_steps,
24
24
  frontend,
25
25
  hosts,
26
+ library_convert,
26
27
  library_gateway,
27
28
  library_pricing,
28
29
  library_state,
@@ -537,8 +538,6 @@ def download(
537
538
  load: Callable[[str, str, list[str]], Row],
538
539
  ) -> Row:
539
540
  """Fetch the model into ``base_dir``, record it, then load it when its pool has room."""
540
- from localmodels import library_convert
541
-
542
541
  library_convert.convert_once()
543
542
  lib = library_status.Library.read(probe(), base_dir)
544
543
  model = library_pricing.find(model_id, lib.catalog)
@@ -3,7 +3,7 @@
3
3
  Validated ``strata-poly`` chat recipes that declare model-card metadata (``display_name``,
4
4
  ``description``, ``family``, ``publisher``, ``parameters``) join ``localmodels library`` on
5
5
  supported NVIDIA Linux and Windows hosts alongside ``llama.cpp`` models. Pricing runs
6
- ``suite.build_plan`` so CUDA 13 driver checks, glibc checks, vision reader placement and host
6
+ ``suite_plan.build_plan`` so CUDA 13 driver checks, glibc checks, vision reader placement and host
7
7
  RAM ceilings stay identical to ``stack plan``.
8
8
  """
9
9
 
@@ -22,6 +22,7 @@ from localmodels import (
22
22
  )
23
23
  from localmodels import catalog as cat
24
24
  from localmodels.context_policy import AgentPosture
25
+ from localmodels.engine_adapters import suite_plan
25
26
  from localmodels.estimator import PhysicsRefusal
26
27
  from localmodels.library_model import Reason, split_id
27
28
  from localmodels.probe import GPU, HostFacts
@@ -297,7 +298,7 @@ def price(
297
298
  vram_reserve_mib=reserve,
298
299
  vision_reader=reader,
299
300
  )
300
- plan = suite.build_plan(hosts.LOCAL_ID, facts, recipe, opts)
301
+ plan = suite_plan.build_plan(hosts.LOCAL_ID, facts, recipe, opts)
301
302
  if facts["platform"] == "win32":
302
303
  plan = suite.unbounded(plan)
303
304
  _calibrate_host_ram(plan, recipe, gpu)
@@ -14,6 +14,7 @@ from __future__ import annotations
14
14
 
15
15
  import copy
16
16
  import functools
17
+ import math
17
18
  import os
18
19
  import shutil
19
20
  from collections.abc import Iterable, Mapping
@@ -24,6 +25,7 @@ from typing import Any, Literal
24
25
  from localmodels import (
25
26
  budget,
26
27
  context_policy,
28
+ debug_mode,
27
29
  deploy,
28
30
  engines,
29
31
  hosts,
@@ -33,6 +35,8 @@ from localmodels import (
33
35
  llm_rank,
34
36
  metal,
35
37
  plan_envelope,
38
+ remote_ops_download,
39
+ stack_compose,
36
40
  stack_hardware,
37
41
  stack_llm_ram,
38
42
  suite,
@@ -43,13 +47,14 @@ from localmodels.context_policy import AgentPosture
43
47
  from localmodels.estimator import (
44
48
  AGENT_VRAM_RESERVE_BYTES,
45
49
  METAL_VRAM_RESERVE_BYTES,
50
+ PhysicsRefusal,
46
51
  agent_footprint_bytes,
47
52
  eager,
48
53
  )
49
54
  from localmodels.library_model import LibraryError, Reason, display_name, split_id
50
55
  from localmodels.probe import HostFacts
51
56
  from localmodels.records import Plan
52
- from localmodels.stack_plan import platform_error
57
+ from localmodels.stack_plan import default_options, platform_error
53
58
 
54
59
  POOL_RAM_FRACTION = 0.8 # a "system" pool's budget: RAM x 0.8 (contract v2)
55
60
  UNIFIED_RESERVE_BYTES = metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
@@ -59,9 +64,7 @@ DESKTOP_VRAM_BASELINE_CAP_BYTES = budget.DESKTOP_VRAM_BASELINE_CAP_BYTES
59
64
  @functools.cache
60
65
  def posture() -> AgentPosture:
61
66
  """The default stack plan's agent posture: its slots, image input and thinking cap."""
62
- from localmodels import stack, stack_compose
63
-
64
- return stack_compose.agent_posture(stack.default_options())
67
+ return stack_compose.agent_posture(default_options())
65
68
 
66
69
 
67
70
  @dataclass(frozen=True)
@@ -363,6 +366,116 @@ def _required_host_ram(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int
363
366
  return host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
364
367
 
365
368
 
369
+ def _project_cuda_uma(
370
+ facts: HostFacts, unified: int, target: int, *, bypass_working_set: bool
371
+ ) -> HostFacts:
372
+ seen = copy.deepcopy(facts)
373
+ need = target + AGENT_VRAM_RESERVE_BYTES
374
+ raw = int(math.ceil(need / (1 - budget._UMA_HEADROOM_FRACTION)))
375
+ while int(raw * (1 - budget._UMA_HEADROOM_FRACTION)) < need:
376
+ raw += 1
377
+ raw = raw if bypass_working_set else min(unified, raw)
378
+ if bypass_working_set and isinstance(cuda_pool := seen.get("cuda_pool"), dict):
379
+ cuda_pool["total_bytes"], cuda_pool["integrated"] = max(unified, raw), True
380
+ for gpu in seen.get("gpus") or []:
381
+ if gpu.get("vendor") == "nvidia" and gpu.get("mig_mode") != "enabled":
382
+ gpu["free_bytes"], gpu["used_bytes"] = 0, gpu["total_bytes"]
383
+ break
384
+ ram = seen["ram"]
385
+ if bypass_working_set:
386
+ ram["total_bytes"] = max(int(ram["total_bytes"]), raw)
387
+ if (cgroup := seen.get("cgroup_memory")) is not None:
388
+ if (limit := cgroup.get("limit_bytes")) is not None and limit < raw:
389
+ cgroup["limit_bytes"] = raw
390
+ cgroup["usage_bytes"] = 0
391
+ ram["available_bytes"] = min(int(ram["total_bytes"]), raw)
392
+ return seen
393
+
394
+
395
+ def facts_for_budget(
396
+ facts: HostFacts,
397
+ pool: str,
398
+ target_bytes: int,
399
+ *,
400
+ wired_cap_bytes: int | None = None,
401
+ bypass_working_set: bool = False,
402
+ ) -> HostFacts:
403
+ """Project ``facts`` so ``deploy.build_plan`` prices ``pool`` against ``target_bytes``
404
+ (unified/total) and optional ``wired_cap_bytes`` (Metal GPU wired headroom)."""
405
+ target = max(0, target_bytes)
406
+ if pool == "unified" and metal.supported(facts):
407
+ seen = copy.deepcopy(facts)
408
+ ram = seen["ram"]
409
+ needed_avail = target + metal.HOST_KEEP_BYTES + METAL_VRAM_RESERVE_BYTES
410
+ ram["available_bytes"] = (
411
+ needed_avail if bypass_working_set else min(int(ram["total_bytes"]), needed_avail)
412
+ )
413
+ ram["pressure_level"] = metal.PRESSURE_NORMAL
414
+ ram.pop("pressure_kept_bytes", None)
415
+ if isinstance(metal_doc := seen.get("metal"), dict):
416
+ ceiling = (
417
+ max(0, wired_cap_bytes) + METAL_VRAM_RESERVE_BYTES
418
+ if wired_cap_bytes is not None
419
+ else max(metal.wired_ceiling_bytes(facts), target + METAL_VRAM_RESERVE_BYTES)
420
+ if bypass_working_set
421
+ else metal.wired_ceiling_bytes(facts)
422
+ )
423
+ metal_doc["recommended_max_working_set_bytes"] = ceiling
424
+ return seen
425
+ if pool == "unified" and (unified := budget.unified_pool_bytes(facts)) is not None:
426
+ return _project_cuda_uma(facts, unified, target, bypass_working_set=bypass_working_set)
427
+ if (idx := gpu_index(pool)) is not None:
428
+ seen = copy.deepcopy(facts)
429
+ for gpu in seen.get("gpus") or []:
430
+ if gpu["index"] == idx:
431
+ free = target + AGENT_VRAM_RESERVE_BYTES
432
+ gpu["free_bytes"] = free if bypass_working_set else min(gpu["total_bytes"], free)
433
+ gpu["used_bytes"] = max(0, gpu["total_bytes"] - gpu["free_bytes"])
434
+ break
435
+ return seen
436
+ return facts
437
+
438
+
439
+ def validate_plan_bounds(
440
+ facts: HostFacts,
441
+ model: Model,
442
+ pool: str,
443
+ plan: Plan,
444
+ catalog: tuple[cat.CatalogEntry, ...],
445
+ *,
446
+ check_pool_total: bool = True,
447
+ check_host_ram: bool = True,
448
+ ) -> None:
449
+ """Reject a plan exceeding ``pool``'s total capacity or host RAM on a discrete GPU."""
450
+ if check_pool_total:
451
+ total = pool_total(facts, pool)
452
+ used = memory_bytes(plan)
453
+ if used > total:
454
+ refused = PhysicsRefusal(
455
+ needed_bytes=used,
456
+ available_bytes=total,
457
+ message=f"{model.id} needs {used} bytes, exceeding pool {pool} total {total} bytes",
458
+ )
459
+ raise deploy.AgentMemoryError(
460
+ refused.message,
461
+ refused,
462
+ "unified memory" if pool == "unified" else "GPU memory",
463
+ )
464
+ if check_host_ram and gpu_index(pool) is not None:
465
+ needed_ram = host_ram_bytes(plan, catalog) + budget.HARNESS_RAM + budget.RAM_FLOOR
466
+ _, avail_ram = budget.host_ram(facts)
467
+ if needed_ram > avail_ram:
468
+ refused = PhysicsRefusal(
469
+ needed_bytes=needed_ram,
470
+ available_bytes=avail_ram,
471
+ message=(
472
+ f"{model.id} needs {needed_ram} bytes of system memory, "
473
+ f"exceeding {avail_ram} bytes available"
474
+ ),
475
+ )
476
+ raise deploy.AgentMemoryError(refused.message, refused, "system memory")
477
+
478
+
366
479
  def price(
367
480
  facts: HostFacts,
368
481
  model: Model,
@@ -374,8 +487,6 @@ def price(
374
487
  require_live: bool = False,
375
488
  ) -> Plan:
376
489
  """The deployment plan on ``pool``; AgentMemoryError when it does not fit there."""
377
- from localmodels import library_elastic
378
-
379
490
  placement = pools(facts).get(pool)
380
491
  if placement is None:
381
492
  raise plan_envelope.PlanError(f"this computer has no pool {pool}")
@@ -390,7 +501,7 @@ def price(
390
501
  raise LiveMemoryUnavailable(problem)
391
502
  adm = budget.admission_budget(facts, "unified")
392
503
  if adm is not None:
393
- facts = library_elastic.facts_for_budget(
504
+ facts = facts_for_budget(
394
505
  facts, "unified", adm.soft_budget_bytes, wired_cap_bytes=adm.wired_headroom_bytes
395
506
  )
396
507
  else:
@@ -414,7 +525,7 @@ def price(
414
525
  entries=effective_catalog,
415
526
  resolver=deploy.catalog_pins,
416
527
  )
417
- library_elastic.validate_plan_bounds(facts, model, pool, plan, effective_catalog)
528
+ validate_plan_bounds(facts, model, pool, plan, effective_catalog)
418
529
  return plan
419
530
 
420
531
 
@@ -587,6 +698,8 @@ def judge(
587
698
 
588
699
  def base_free(base_dir: str) -> int:
589
700
  """Free bytes on the filesystem that will hold ``<base_dir>/models``."""
701
+ if (simulated := debug_mode.simulating()) is not None:
702
+ return debug_mode.simulated_disk_free(simulated)
590
703
  path = Path(base_dir).expanduser() / "models"
591
704
  while not path.exists() and path != path.parent:
592
705
  path = path.parent
@@ -598,8 +711,6 @@ def base_free(base_dir: str) -> int:
598
711
 
599
712
  def missing_bytes(plan: Plan) -> int:
600
713
  """Bytes a download still has to fetch: files neither verified in place nor partly kept."""
601
- from localmodels import remote_ops_download
602
-
603
714
  left = 0
604
715
  for f in plan["files"]:
605
716
  if plan_envelope.verified_in_place(f):
@@ -711,13 +822,11 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
711
822
  def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple[str, str] | None:
712
823
  """(catalog id, quant) of the smartest live library pick; falls back to library models when
713
824
  ``stack`` selects Strata/PolyStrata or on CUDA unified-memory hosts."""
714
- from localmodels import stack
715
-
716
825
  seen = copy.deepcopy(facts)
717
826
  if (shown_cards := visible(facts)) is not None:
718
827
  seen["gpus"] = [g for g in seen.get("gpus") or [] if g["index"] in shown_cards]
719
828
  try:
720
- view = stack_hardware.view(seen, stack.default_options(), posture())
829
+ view = stack_hardware.view(seen, default_options(), posture())
721
830
  except (KeyError, ValueError, TypeError, OSError):
722
831
  return None
723
832
  pick = next(
@@ -21,11 +21,13 @@ from typing import cast
21
21
 
22
22
  from localmodels import (
23
23
  app,
24
+ debug_mode,
24
25
  deploy,
25
26
  engines,
26
27
  frontend,
27
28
  harness,
28
29
  hosts,
30
+ library_convert,
29
31
  library_elastic,
30
32
  library_gateway,
31
33
  library_jobs,
@@ -281,6 +283,8 @@ def _room(
281
283
  def _port(facts: HostFacts) -> int:
282
284
  """Under ``locked()``: a free port that no recorded server and no live load holds; the
283
285
  caller reserves it in its load job before releasing the lock."""
286
+ if debug_mode.simulating() is not None:
287
+ return debug_mode.simulated_port()
284
288
  taken = [r["plan"]["service"]["port"] for r in library_state.records() if r["state"] != "idle"]
285
289
  taken += [
286
290
  job.get("port", 0)
@@ -705,8 +709,6 @@ def load(
705
709
  force: bool = False,
706
710
  ctx: int | None = None,
707
711
  ) -> Row:
708
- from localmodels import library_convert
709
-
710
712
  if ctx is not None and (isinstance(ctx, bool) or ctx <= 0):
711
713
  raise LibraryError("INVALID_STATE", "--ctx must be a positive integer")
712
714
  library_convert.convert_once()
@@ -780,8 +782,6 @@ def _claim(model: Model, kind: str) -> tuple[Record, Job]:
780
782
 
781
783
 
782
784
  def unload(model_id: str, base_dir: str) -> Row:
783
- from localmodels import library_convert
784
-
785
785
  library_convert.convert_once()
786
786
  model = library_pricing.find(model_id, library_pricing.entries())
787
787
  record, job = _claim(model, "unload")
@@ -802,8 +802,6 @@ def _clear_removed_source(pi_model: str | None) -> None:
802
802
 
803
803
 
804
804
  def remove(model_id: str, base_dir: str) -> Row:
805
- from localmodels import library_convert
806
-
807
805
  library_convert.convert_once()
808
806
  model = library_pricing.find(model_id, library_pricing.entries())
809
807
  record, job = _claim(model, "remove")
@@ -11,7 +11,7 @@ from pathlib import Path
11
11
  from typing import Any
12
12
 
13
13
  from localmodels import cli_help, vision
14
- from localmodels.memcalc import (
14
+ from localmodels.planning.memcalc import (
15
15
  GIB,
16
16
  KIB,
17
17
  KV_TYPES,
@@ -24,7 +24,7 @@ from localmodels.memcalc import (
24
24
  quant_bits,
25
25
  report,
26
26
  )
27
- from localmodels.memcalc_load import WeightOptions, load_model
27
+ from localmodels.planning.memcalc_load import WeightOptions, load_model
28
28
 
29
29
 
30
30
  def _gib(n: float) -> str:
@@ -0,0 +1,3 @@
1
+ """Memory and capacity pricing as pure functions: per-model memory by context length
2
+ (``memcalc``, read by ``memcalc_load``) and weight size by device class (``sizecalc``).
3
+ See docs/local-models/architecture.md#子包."""
@@ -16,7 +16,7 @@ from typing import Any
16
16
 
17
17
  from localmodels import estimator, remote_ops_redirect
18
18
  from localmodels.gguf import read_gguf_header, split_parts
19
- from localmodels.memcalc import (
19
+ from localmodels.planning.memcalc import (
20
20
  MIB,
21
21
  MemcalcError,
22
22
  Model,
@@ -18,7 +18,7 @@ from dataclasses import dataclass
18
18
  from typing import Any
19
19
 
20
20
  from localmodels import estimator, metal, quant_formats
21
- from localmodels.memcalc import GIB, KIB, MemcalcError
21
+ from localmodels.planning.memcalc import GIB, KIB, MemcalcError
22
22
  from localmodels.quant_formats import QuantFormat
23
23
 
24
24
  SCHEMA = "localmodels.sizecalc/v1"
@@ -30,6 +30,7 @@ from localmodels import (
30
30
  from localmodels import stack_decision as decision
31
31
  from localmodels import stack_lifecycle as lifecycle
32
32
  from localmodels.contracts import decode
33
+ from localmodels.engine_adapters import suite_plan
33
34
  from localmodels.plan_envelope import PlanError, deployment
34
35
  from localmodels.probe import HostFacts, Services
35
36
  from localmodels.records import FinishedRecord, Plan
@@ -86,7 +87,7 @@ def plan_component(
86
87
  )
87
88
  except PlanError as exc:
88
89
  raise WaitingForResourcesError("port") from exc
89
- built = suite.build_plan(
90
+ built = suite_plan.build_plan(
90
91
  "local",
91
92
  facts,
92
93
  recipe,