@simplexai/localmodels-win32-x64 0.1.0-dev.103 → 0.1.0-dev.105

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 (172) hide show
  1. package/LICENSE +201 -0
  2. package/{modules/simplex_localmodels-0.1.0.dev103.dist-info/licenses/NOTICE → NOTICE} +42 -13
  3. package/README.md +10 -0
  4. package/bootstrap.identity +1 -1
  5. package/bootstrap.sha256 +159 -158
  6. package/modules/localmodels/__init__.py +1 -1
  7. package/modules/localmodels/__main__.py +204 -86
  8. package/modules/localmodels/apple_sensors.py +23 -0
  9. package/modules/localmodels/approval.py +25 -2
  10. package/modules/localmodels/catalog.json +584 -158
  11. package/modules/localmodels/catalog.py +18 -3
  12. package/modules/localmodels/catalog_recipes.py +64 -6
  13. package/modules/localmodels/cli_help.py +10 -0
  14. package/modules/localmodels/cli_parser.py +313 -230
  15. package/modules/localmodels/component.py +21 -3
  16. package/modules/localmodels/console.py +1 -1
  17. package/modules/localmodels/context_policy.py +6 -5
  18. package/modules/localmodels/custom_probe.py +4 -2
  19. package/modules/localmodels/debug_cli.py +0 -12
  20. package/modules/localmodels/debug_mode.py +0 -6
  21. package/modules/localmodels/decode_calibration.json +3 -4
  22. package/modules/localmodels/decode_calibration.py +5 -2
  23. package/modules/localmodels/deploy.py +11 -1
  24. package/modules/localmodels/deployment_lifecycle.py +1 -1
  25. package/modules/localmodels/download-mirrors.json +1 -1
  26. package/modules/localmodels/engine_adapters/base.py +11 -1
  27. package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
  28. package/modules/localmodels/engine_adapters/suite_plan.py +61 -24
  29. package/modules/localmodels/engines-b11583.json +6 -26
  30. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
  31. package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
  32. package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
  33. package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
  34. package/modules/localmodels/engines-strata-0.1.47.json +1 -5
  35. package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
  36. package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
  37. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
  38. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
  39. package/modules/localmodels/engines-whisper-b5454.json +6 -30
  40. package/modules/localmodels/engines.json +13 -61
  41. package/modules/localmodels/estimator.py +10 -5
  42. package/modules/localmodels/gpu_specs.py +1 -1
  43. package/modules/localmodels/host_sensors.py +25 -2
  44. package/modules/localmodels/hosts.py +38 -21
  45. package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
  46. package/modules/localmodels/library_cli.py +34 -16
  47. package/modules/localmodels/library_custom.py +9 -1
  48. package/modules/localmodels/library_direct.py +41 -1
  49. package/modules/localmodels/library_elastic.py +135 -6
  50. package/modules/localmodels/library_jobs.py +23 -4
  51. package/modules/localmodels/library_kept.py +9 -1
  52. package/modules/localmodels/library_model.py +174 -2
  53. package/modules/localmodels/library_order.py +175 -69
  54. package/modules/localmodels/library_poly.py +150 -21
  55. package/modules/localmodels/library_presentation.py +485 -0
  56. package/modules/localmodels/library_pricing.py +15 -4
  57. package/modules/localmodels/library_serve.py +342 -70
  58. package/modules/localmodels/library_smoke.py +63 -5
  59. package/modules/localmodels/library_state.py +48 -10
  60. package/modules/localmodels/library_status.py +37 -17
  61. package/modules/localmodels/llm_rank.py +22 -11
  62. package/modules/localmodels/metal.py +1 -2
  63. package/modules/localmodels/plan_envelope.py +40 -13
  64. package/modules/localmodels/planning/budget.py +14 -12
  65. package/modules/localmodels/planning/memory_pools.py +7 -1
  66. package/modules/localmodels/privacy_acceptance.py +6 -5
  67. package/modules/localmodels/probe.py +34 -7
  68. package/modules/localmodels/py.typed +0 -0
  69. package/modules/localmodels/quant_formats.py +10 -3
  70. package/modules/localmodels/recommend_cli.py +1 -1
  71. package/modules/localmodels/records.py +19 -2
  72. package/modules/localmodels/remote_ops_launchd.py +8 -1
  73. package/modules/localmodels/remote_ops_verify.py +91 -24
  74. package/modules/localmodels/runtime_index.py +303 -0
  75. package/modules/localmodels/runtime_process.py +1 -1
  76. package/modules/localmodels/service_deployment.py +2 -4
  77. package/modules/localmodels/service_probe.py +59 -13
  78. package/modules/localmodels/setup_inspection.py +94 -73
  79. package/modules/localmodels/setup_text.py +7 -56
  80. package/modules/localmodels/sidecar_downloads.py +34 -0
  81. package/modules/localmodels/sidecar_http.py +61 -5
  82. package/modules/localmodels/sidecar_state.py +52 -2
  83. package/modules/localmodels/speech_admission.py +20 -4
  84. package/modules/localmodels/speech_catalog.py +23 -0
  85. package/modules/localmodels/speech_cli.py +30 -16
  86. package/modules/localmodels/speech_jobs.py +42 -17
  87. package/modules/localmodels/speech_serve.py +9 -2
  88. package/modules/localmodels/speech_server.py +185 -81
  89. package/modules/localmodels/speech_state.py +4 -1
  90. package/modules/localmodels/speech_workers.py +11 -0
  91. package/modules/localmodels/stack.py +1 -1
  92. package/modules/localmodels/stack_args.py +276 -145
  93. package/modules/localmodels/stack_auto.py +91 -6
  94. package/modules/localmodels/stack_aux_gpu.py +1 -1
  95. package/modules/localmodels/stack_cleanup.py +21 -18
  96. package/modules/localmodels/stack_cli.py +120 -115
  97. package/modules/localmodels/stack_compose.py +16 -5
  98. package/modules/localmodels/stack_debug.py +15 -6
  99. package/modules/localmodels/stack_decision.py +4 -4
  100. package/modules/localmodels/stack_doctor.py +2 -2
  101. package/modules/localmodels/stack_down.py +2 -0
  102. package/modules/localmodels/stack_events.py +1 -1
  103. package/modules/localmodels/stack_gpu_memory.py +1 -1
  104. package/modules/localmodels/stack_hardware.py +17 -15
  105. package/modules/localmodels/stack_mcp.py +1 -2
  106. package/modules/localmodels/stack_mlx.py +8 -1
  107. package/modules/localmodels/stack_picks.py +20 -21
  108. package/modules/localmodels/stack_plan.py +12 -11
  109. package/modules/localmodels/stack_ports.py +31 -4
  110. package/modules/localmodels/stack_review.py +28 -7
  111. package/modules/localmodels/stack_rollback.py +1 -1
  112. package/modules/localmodels/stack_run.py +1 -1
  113. package/modules/localmodels/stack_suite.py +72 -21
  114. package/modules/localmodels/stack_up.py +2 -0
  115. package/modules/localmodels/stack_view.py +180 -35
  116. package/modules/localmodels/stack_view_agent.py +1 -1
  117. package/modules/localmodels/stack_view_demo.py +2 -0
  118. package/modules/localmodels/stack_view_gpu.py +36 -2
  119. package/modules/localmodels/stack_view_schema.py +26 -3
  120. package/modules/localmodels/stack_view_serve.py +0 -2
  121. package/modules/localmodels/stack_view_slots.py +3 -1
  122. package/modules/localmodels/stack_view_telemetry.py +90 -4
  123. package/modules/localmodels/stack_view_tick.py +246 -40
  124. package/modules/localmodels/stack_view_words.py +9 -2
  125. package/modules/localmodels/stack_warm.py +2 -2
  126. package/modules/localmodels/stack_whatif.py +524 -41
  127. package/modules/localmodels/stack_whatif_html.py +900 -0
  128. package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
  129. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
  130. package/modules/localmodels/strata_poly_server.py +114 -3
  131. package/modules/localmodels/suite.py +265 -6
  132. package/modules/localmodels/telemetry_math.py +458 -18
  133. package/modules/localmodels/transport.py +8 -1
  134. package/modules/localmodels/tts_admission.py +2 -17
  135. package/modules/localmodels/tts_catalog.py +29 -1
  136. package/modules/localmodels/tts_cli.py +45 -22
  137. package/modules/localmodels/tts_http.py +10 -4
  138. package/modules/localmodels/tts_jobs.py +49 -19
  139. package/modules/localmodels/tts_serve.py +9 -2
  140. package/modules/localmodels/tts_server.py +1 -1
  141. package/modules/localmodels/tts_sidecar.py +69 -28
  142. package/modules/localmodels/tts_state.py +7 -2
  143. package/modules/localmodels/vision.py +5 -3
  144. package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
  145. package/modules/localmodels/web/view/view.css +0 -1
  146. package/modules/localmodels/web/view/view.js +2 -5
  147. package/modules/localmodels/web/whatif/app.js +730 -0
  148. package/modules/localmodels/web/whatif/page.html +1172 -0
  149. package/modules/localmodels/web/whatif/sim.js +297 -0
  150. package/modules/localmodels/win_probe.py +89 -16
  151. package/modules/localmodels/windows_job.py +179 -11
  152. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/METADATA +14 -0
  153. package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +151 -145
  154. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/LICENSE +201 -0
  155. package/modules/simplex_localmodels-0.1.0.dev105.dist-info/licenses/NOTICE +126 -0
  156. package/package.json +11 -2
  157. package/tool.json +1 -1
  158. package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
  159. package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
  160. package/modules/localmodels/stack_research.py +0 -716
  161. package/modules/localmodels/stack_research_demo.py +0 -125
  162. package/modules/localmodels/stack_research_plan.py +0 -146
  163. package/modules/localmodels/web/index.html +0 -2605
  164. package/modules/localmodels/web/sizecalc/app.js +0 -1306
  165. package/modules/localmodels/web/sizecalc/calc.js +0 -269
  166. package/modules/localmodels/web/sizecalc/page.html +0 -520
  167. package/modules/localmodels/web/view/logo-claude.svg +0 -3
  168. package/modules/localmodels/web/view/logo-codex.png +0 -0
  169. package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
  170. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
  171. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
  172. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  # startlux-decide 1.1.0 (StartLuxLabs/StartLux-Decision@83fe6c7d61a687a6e17f118b4f7d8f429f5d3a01, code
2
2
  # Apache-2.0) for the llama.cpp backend of a StartLux Instant decision front, with the aiohttp and
3
- # transformers versions measured with it on lab-12021 (2026-10-20 and 2026-10-22). Installed by
3
+ # transformers versions verified on reference Linux CUDA hardware. Installed by
4
4
  # localmodels/frontend.py with pip --require-hashes --no-deps. Regenerate the pinned dependencies with
5
5
  # uv pip compile --universal --python-version 3.10 --generate-hashes --no-header --no-annotate
6
6
  # from "aiohttp==3.14.5" and "transformers==5.20.2". The source archive is 110 MB (it carries the
@@ -8,7 +8,7 @@
8
8
  # jinja2 and MarkupSafe were appended on 2026-10-29, compiled the same way from "jinja2" alone:
9
9
  # transformers' apply_chat_template needs jinja2, which neither startlux-decide nor transformers
10
10
  # requires, so without it the front exits on its first request
11
- # (evidence/2026-10-29-stack-macos-metal-tiers).
11
+ # (verified on macOS Metal).
12
12
  startlux-decide @ https://github.com/StartLuxLabs/StartLux-Decision/archive/83fe6c7d61a687a6e17f118b4f7d8f429f5d3a01.tar.gz \
13
13
  --hash=sha256:b1c15f6b2f104f02955008f38a74ebf72b282da8a165ae97dac4b8ce4570ce90
14
14
  aiohappyeyeballs==2.7.1 \
@@ -1,4 +1,4 @@
1
- # PolyStrata 0.2.20-poly.7's Python server (terminal/serve/server.py, MIT) for strata-poly LLM
1
+ # PolyStrata 0.2.20-poly.9's Python server (terminal/serve/server.py, MIT) for strata-poly LLM
2
2
  # recipes: jinja2 3.1.6 (BSD-3-Clause) with markupsafe 3.0.3 (BSD-3-Clause) renders the chat
3
3
  # template, regex 2026.9.10 (Apache-2.0 and CNRI-Python) drives its tokenizer, psutil 7.2.2
4
4
  # (BSD-3-Clause) reads memory for its status page, and pillow (MIT-CMU; 13.0.0 on Python 3.11+,
@@ -24,6 +24,7 @@ the server:
24
24
  from __future__ import annotations
25
25
 
26
26
  import argparse
27
+ import ctypes
27
28
  import json
28
29
  import os
29
30
  import runpy
@@ -31,7 +32,116 @@ import shutil
31
32
  import subprocess
32
33
  import sys
33
34
  from pathlib import Path
34
- from typing import cast
35
+ from typing import Any, cast
36
+
37
+ _JOB_LIMIT_AFFINITY = 0x0010 # JOB_OBJECT_LIMIT_AFFINITY
38
+ _BASIC_LIMITS = 2 # JobObjectBasicLimitInformation
39
+ _AFFINITY_ENV = "LOCALMODELS_POLY_CPU_AFFINITY"
40
+ _DISABLE_VALUES = frozenset(("0", "off", "false", "none"))
41
+ _AFFINITY_JOBS: list[Any] = [] # kept open for the server's lifetime; no kill-on-close
42
+
43
+
44
+ def _reserved_speech_cores(logical_cores: int) -> int:
45
+ """Keep the same core-reservation rule as ``localmodels.windows_job`` (standalone copy)."""
46
+ if logical_cores >= 12:
47
+ return 4
48
+ if logical_cores >= 6:
49
+ return 2
50
+ return 0
51
+
52
+
53
+ def poly_affinity_mask(available_mask: int, override: str | None = None) -> int | None:
54
+ """Return the Windows CPU affinity mask for PolyStrata (excluding reserved speech cores).
55
+
56
+ Reserves the highest-index logical CPUs (keeping CPU 0 and Intel P-cores with PolyStrata
57
+ while guaranteeing a PolyStrata-free slice for CPU speech workers). Returns ``None`` when
58
+ disabled via ``LOCALMODELS_POLY_CPU_AFFINITY=off`` or when fewer than 6 CPUs are available.
59
+ """
60
+ if available_mask <= 0:
61
+ return None
62
+ if override is not None:
63
+ cleaned = override.strip().lower()
64
+ if cleaned:
65
+ if cleaned in _DISABLE_VALUES:
66
+ return None
67
+ try:
68
+ parsed = int(cleaned, 0)
69
+ except ValueError:
70
+ return None
71
+ clamped = parsed & available_mask
72
+ return clamped if clamped > 0 else None
73
+ cpus = [bit for bit in range(available_mask.bit_length()) if available_mask & (1 << bit)]
74
+ reserve = _reserved_speech_cores(len(cpus))
75
+ if reserve <= 0 or len(cpus) <= reserve:
76
+ return None
77
+ speech_mask = sum(1 << bit for bit in cpus[-reserve:])
78
+ poly_mask = available_mask & ~speech_mask
79
+ return poly_mask if poly_mask > 0 else None
80
+
81
+
82
+ def apply_windows_cpu_affinity() -> int | None:
83
+ """Windows: restrict this launcher and its child ``strata-poly.exe`` to ``poly_affinity_mask``.
84
+
85
+ Prefers a Windows Job Object with ``JOB_OBJECT_LIMIT_AFFINITY`` (without kill-on-close) so
86
+ the kernel enforces the mask across the whole process tree, falling back to
87
+ ``SetProcessAffinityMask`` when nested job assignment is rejected. Returns the applied mask
88
+ or ``None`` off Windows / when skipped.
89
+ """
90
+ if sys.platform != "win32":
91
+ return None
92
+ from ctypes import wintypes
93
+
94
+ kernel = ctypes.WinDLL("kernel32", use_last_error=True)
95
+ handle_t, ptr_size_t = wintypes.HANDLE, ctypes.POINTER(ctypes.c_size_t)
96
+ specs: tuple[tuple[str, tuple[Any, ...], Any], ...] = (
97
+ ("GetCurrentProcess", (), handle_t),
98
+ ("GetProcessAffinityMask", (handle_t, ptr_size_t, ptr_size_t), wintypes.BOOL),
99
+ ("SetProcessAffinityMask", (handle_t, ctypes.c_size_t), wintypes.BOOL),
100
+ ("CreateJobObjectW", (ctypes.c_void_p, wintypes.LPCWSTR), handle_t),
101
+ (
102
+ "SetInformationJobObject",
103
+ (handle_t, ctypes.c_int, ctypes.c_void_p, wintypes.DWORD),
104
+ wintypes.BOOL,
105
+ ),
106
+ ("AssignProcessToJobObject", (handle_t, handle_t), wintypes.BOOL),
107
+ ("CloseHandle", (handle_t,), wintypes.BOOL),
108
+ )
109
+ for name, argtypes, restype in specs:
110
+ fn = getattr(kernel, name)
111
+ fn.argtypes, fn.restype = argtypes, restype
112
+
113
+ current = kernel.GetCurrentProcess()
114
+ proc_mask, sys_mask = ctypes.c_size_t(0), ctypes.c_size_t(0)
115
+ if not kernel.GetProcessAffinityMask(current, ctypes.byref(proc_mask), ctypes.byref(sys_mask)):
116
+ return None
117
+ target_mask = poly_affinity_mask(int(proc_mask.value), os.environ.get(_AFFINITY_ENV))
118
+ if target_mask is None:
119
+ return None
120
+
121
+ class _JobBasicLimits(ctypes.Structure):
122
+ _fields_ = [
123
+ ("per_process_user_time", ctypes.c_int64),
124
+ ("per_job_user_time", ctypes.c_int64),
125
+ ("limit_flags", wintypes.DWORD),
126
+ ("min_working_set", ctypes.c_size_t),
127
+ ("max_working_set", ctypes.c_size_t),
128
+ ("active_process_limit", wintypes.DWORD),
129
+ ("affinity", ctypes.c_size_t),
130
+ ("priority_class", wintypes.DWORD),
131
+ ("scheduling_class", wintypes.DWORD),
132
+ ]
133
+
134
+ job = kernel.CreateJobObjectW(None, None)
135
+ if job:
136
+ limits = _JobBasicLimits(limit_flags=_JOB_LIMIT_AFFINITY, affinity=target_mask)
137
+ if kernel.SetInformationJobObject(
138
+ job, _BASIC_LIMITS, ctypes.byref(limits), ctypes.sizeof(limits)
139
+ ) and kernel.AssignProcessToJobObject(job, current):
140
+ _AFFINITY_JOBS.append(job)
141
+ return target_mask
142
+ kernel.CloseHandle(job)
143
+
144
+ return target_mask if kernel.SetProcessAffinityMask(current, target_mask) else None
35
145
 
36
146
 
37
147
  def source_root(engine_dir: Path) -> Path:
@@ -172,7 +282,7 @@ def windows_reserve_mib(planned: int, before: int) -> int:
172
282
 
173
283
  The engine fills its cache (or its ``--vram-pool``) to what CUDA reports free less the
174
284
  reserve. Under WDDM that figure is the process's budget less its own use, not the card's
175
- free memory: on homewin's RTX 4060 Ti 16 GB (2026-12-02) a process holding nothing was told
285
+ free memory: on a reference RTX 4060 Ti 16 GB (Windows WDDM) a process holding nothing was told
176
286
  15,223 MiB both idle and with another program holding 8,000 MiB (NVML: 14,804 and 6,685).
177
287
  With such a program there the budget also shrinks once the process holds about 2.5 GiB, by
178
288
  about a MiB for each MiB more, until Windows moves one of them to system memory (decoding
@@ -180,7 +290,7 @@ def windows_reserve_mib(planned: int, before: int) -> int:
180
290
  a process holding ``before`` (what the engine sees when it fills its cache), less the cache
181
291
  it may have. Without ``before`` it is what CUDA reports to a process holding all the engine
182
292
  may take, which leaves the engine ``before`` over. On a card nothing else uses, the reserve
183
- stays ``planned`` (homewin: 643 MiB computed, 1,280 kept). ``planned`` also when the card
293
+ stays ``planned`` (reference 16 GB WDDM: 643 MiB computed, 1,280 kept). ``planned`` also when the card
184
294
  cannot be read: the plan's reserve stands."""
185
295
  try:
186
296
  done = subprocess.run(
@@ -271,6 +381,7 @@ def main(argv: list[str] | None = None) -> None:
271
381
  if root not in sys.path:
272
382
  sys.path.insert(0, root)
273
383
  seed_expert_profile(args.engine_dir, args.config)
384
+ apply_windows_cpu_affinity()
274
385
  sys.argv = server_argv(args.engine_dir, resolve(args.config), args.host, args.port)
275
386
  runpy.run_path(sys.argv[0], run_name="__main__")
276
387
 
@@ -16,11 +16,13 @@ from __future__ import annotations
16
16
  import copy
17
17
  import json
18
18
  import subprocess
19
+ from collections.abc import Sequence
19
20
  from dataclasses import dataclass, field
20
21
  from pathlib import Path
21
- from typing import TypedDict
22
+ from typing import TypedDict, cast
22
23
 
23
24
  from localmodels import catalog as cat
25
+ from localmodels import catalog_recipes, decode_calibration, gpu_specs
24
26
  from localmodels.contracts import decode
25
27
  from localmodels.engines import (
26
28
  EngineUnavailableError,
@@ -32,7 +34,7 @@ from localmodels.engines import (
32
34
  from localmodels.plan_envelope import MODELSCOPE_URL, PlanError
33
35
  from localmodels.probe import GPU, HostFacts
34
36
  from localmodels.records import Plan, ReleaseEngine
35
- from localmodels.vision import StrataVision, strata_gpu_mib
37
+ from localmodels.vision import StrataVision, strata_gpu_mib, strata_ram_mib
36
38
 
37
39
  GIB = 1 << 30
38
40
  # Engines that keep a MoE model's experts in host RAM beside a GPU cache: Strata, and PolyStrata's
@@ -82,8 +84,11 @@ class ExpertCacheSizing(TypedDict):
82
84
 
83
85
  class CardArgs(TypedDict, total=False):
84
86
  at_least_bytes: int
87
+ at_least_free_bytes: int # optional live free VRAM less reserve floor (shared-GPU safety)
85
88
  platforms: list[str] # only on these (facts["platform"]); every platform when absent
86
89
  args: list[str]
90
+ context: int # optional larger context window (--max-context and launch.window) on this card
91
+ parallel: int # optional higher slot concurrency (--batch / profile.parallel) on this card
87
92
 
88
93
 
89
94
  class SuiteRecipe(cat.ComponentRecipe, total=False):
@@ -103,8 +108,8 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
103
108
  # strata-poly recipes: what the engine keeps free of the card (--vram-reserve-mib) for the
104
109
  # display and its own overshoot of that reserve.
105
110
  vram_reserve_mib: int
106
- # strata-poly recipes: engine flags given only to a card with room to spare (``at_least_bytes``
107
- # of the card less the reserve) or only on some platforms, appended to the profile's args.
111
+ # strata-poly recipes: engine flags or wider context given only to a card with room to spare
112
+ # (``at_least_bytes`` of the card less the reserve) or only on some platforms.
108
113
  card_args: list[CardArgs]
109
114
  limits: dict[str, str]
110
115
  env: dict[str, str]
@@ -119,9 +124,9 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
119
124
  min_ram_total_bytes: int # below this the recipe is not recommended
120
125
  conversation_cache: ConversationCache # Strata recipes: parking when stack plan grants it
121
126
  expert_cache_sizing: ExpertCacheSizing # Strata recipes: a fixed slot count instead of auto
122
- vision: StrataVision # Strata recipes whose model reads pictures (roadmap decision 31)
127
+ vision: StrataVision # Strata recipes whose model reads pictures
123
128
  # Strata recipes since 2026-11-03: the installed SimplexAI score that lets ``--llm auto``
124
- # weigh the recipe against the llama.cpp pick (roadmap decisions 26 and 33; stack_suite).
129
+ # weigh the recipe against the llama.cpp pick (stack_suite).
125
130
  quality: cat.QualityData
126
131
  # PolyStrata recipes that should be preferred over a same-score llama.cpp pick (decision 66).
127
132
  prefer_over_llama: bool
@@ -135,6 +140,18 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
135
140
  parameters: str
136
141
  active_parameters: str
137
142
  moe: bool
143
+ library: bool # list candidate in library status without entering --llm auto
144
+ decode_fraction: float # active weight fraction per decoded token when full VRAM-resident
145
+ embd_table_bytes: int # host-RAM-resident embedding table bytes excluded from GPU weights
146
+ capabilities: list[str]
147
+ quant_fidelity: str
148
+ bits_per_weight: float
149
+ # Optional KV geometry and Metal overhead for compositional Apple Silicon unified-memory pricing.
150
+ full_layers: int
151
+ swa_layers: int
152
+ swa_window: int
153
+ per_layer_f16: int
154
+ metal_overhead_bytes: int
138
155
 
139
156
 
140
157
  @dataclass(frozen=True)
@@ -255,5 +272,247 @@ def size_bytes(text: str) -> int:
255
272
  return int(float(text[:-1]) * units[text[-1]]) if text[-1] in units else int(text)
256
273
 
257
274
 
275
+ # Measured non-expert VRAM overhead (KV cache + compute buffers + CUDA context) for PolyStrata
276
+ # recipes when experts fit in VRAM: SP219 inkling-2-mini-q3-poly on 16 GB peaked at 14,498 MiB
277
+ # for 12.69 GiB of weights (~1.47 GiB overhead); 2 GiB keeps a conservative safety margin when
278
+ # the recipe does not declare an explicit measured ``vram_before_cache_mib``.
279
+ VRAM_NON_EXPERT_BYTES = 2 << 30
280
+
281
+
282
+ def poly_weight_bytes(r: SuiteRecipe) -> int:
283
+ """Total byte size of non-vision weight files in a suite recipe."""
284
+ return sum(int(f["size_bytes"]) for f in r["files"] if not f.get("vision"))
285
+
286
+
287
+ def matched_card_args(
288
+ facts: HostFacts, r: SuiteRecipe, gpu: GPU | None, vram_reserve_mib: int
289
+ ) -> list[CardArgs]:
290
+ """``card_args`` entries matching ``gpu``'s total/free room less ``vram_reserve_mib``."""
291
+ if not gpu or not r.get("card_args"):
292
+ return []
293
+ # Under --gpu-memory the reserve also holds what the share leaves out of the real card
294
+ # (stack_gpu_memory.LEFT_OUT, stack_suite.poly_reserve_mib), so the room is counted on it.
295
+ left_out = int(cast("dict[str, int]", gpu).get("share_left_out_bytes", 0))
296
+ reserve = vram_reserve_mib << 20
297
+ room = gpu["total_bytes"] + left_out - reserve
298
+ free_room = gpu["free_bytes"] + left_out - reserve
299
+ return [
300
+ group
301
+ for group in r["card_args"]
302
+ if room >= group["at_least_bytes"]
303
+ and free_room >= group.get("at_least_free_bytes", 0)
304
+ and facts["platform"] in group.get("platforms", [facts["platform"]])
305
+ ]
306
+
307
+
308
+ def effective_context(r: SuiteRecipe, matched: Sequence[CardArgs]) -> int:
309
+ base = int(r.get("context") or 0)
310
+ return max((base, *(int(group.get("context") or 0) for group in matched)), default=base)
311
+
312
+
313
+ def effective_parallel(r: SuiteRecipe, matched: Sequence[CardArgs]) -> int:
314
+ profile = r.get("profile")
315
+ default = 2 if r.get("runtime") == "strata-poly" else 1
316
+ base = (
317
+ int(str(profile.get("parallel") or default))
318
+ if isinstance(profile, dict) and profile.get("parallel") is not None
319
+ else default
320
+ )
321
+ return max((base, *(int(group.get("parallel") or 0) for group in matched)), default=base)
322
+
323
+
324
+ def poly_gpu_resident(
325
+ r: SuiteRecipe,
326
+ gpu: GPU | None,
327
+ *,
328
+ reserve_mib: int | None = None,
329
+ use_free: bool = False,
330
+ ) -> bool:
331
+ """True when a ``strata-poly`` recipe holds all routed experts in ``gpu`` VRAM without CPU
332
+ expert offloading (using measured ``vram_before_cache_mib`` when declared, else 2 GiB)."""
333
+ if r.get("runtime") != "strata-poly" or gpu is None:
334
+ return False
335
+ weight_bytes = poly_weight_bytes(r)
336
+ if weight_bytes <= 0:
337
+ return False
338
+ gpu_weights = max(0, weight_bytes - int(r.get("embd_table_bytes") or 0))
339
+ profile = r.get("profile")
340
+ raw_before = profile.get("vram_before_cache_mib") if isinstance(profile, dict) else None
341
+ non_expert = (
342
+ int(str(raw_before)) << 20
343
+ if isinstance(raw_before, int) and not isinstance(raw_before, bool) and raw_before > 0
344
+ else VRAM_NON_EXPERT_BYTES
345
+ )
346
+ reserve = (int(r.get("vram_reserve_mib") or 0) if reserve_mib is None else reserve_mib) << 20
347
+ avail = gpu["free_bytes"] if use_free else gpu["total_bytes"]
348
+ need = gpu_weights + non_expert + (0 if use_free else reserve)
349
+ return avail >= need
350
+
351
+
352
+ def strata_smart_tie(r: SuiteRecipe) -> float:
353
+ """Deterministic tie-breaker for Strata/PolyStrata recipes within an equal quality band.
354
+
355
+ Higher is better: ``prefer_over_llama`` recipes outrank non-preferred ones; within those,
356
+ higher ``quant_fidelity`` wins (so 24-48 GB GPUs stay on near-lossless Q4 over Q3); within
357
+ equal fidelity, smaller weight footprint wins (compact-first) instead of larger VRAM floor.
358
+ """
359
+ base = 1e9 if r.get("prefer_over_llama") else -1e9
360
+ f_rank = catalog_recipes.fidelity_rank(
361
+ str(r.get("quant_fidelity") or ""), str(r.get("version") or "")
362
+ )
363
+ fidelity_bonus = (len(catalog_recipes.QUANT_FIDELITIES) - 1 - f_rank) * 1e6
364
+ weight_gib = poly_weight_bytes(r) / (1 << 30)
365
+ return base + fidelity_bonus - weight_gib
366
+
367
+
368
+ def poly_decode_estimate(
369
+ r: SuiteRecipe, gpu: GPU | None, *, reserve_mib: int | None = None
370
+ ) -> cat.DecodeEstimate | None:
371
+ """Bandwidth-based decode tok/s estimate for a full-VRAM-resident ``strata-poly`` recipe.
372
+
373
+ Returns ``None`` for non-PolyStrata recipes, when ``decode_fraction`` is undeclared, or
374
+ whenever routed experts spill to host RAM (``not poly_gpu_resident``).
375
+ """
376
+ raw_df = r.get("decode_fraction")
377
+ if r.get("runtime") != "strata-poly" or gpu is None or raw_df is None:
378
+ return None
379
+ if not poly_gpu_resident(r, gpu, reserve_mib=reserve_mib):
380
+ return None
381
+ gpu_weights = max(0, poly_weight_bytes(r) - int(r.get("embd_table_bytes") or 0))
382
+ if gpu_weights <= 0:
383
+ return None
384
+ bytes_per_token = max(1.0, gpu_weights * float(raw_df))
385
+ spec_bw = gpu_specs.bandwidth_gb_s(gpu["name"])
386
+ if spec_bw:
387
+ basis, bandwidth = "gpu-spec", spec_bw
388
+ else:
389
+ basis, bandwidth = "discrete-class", 1000.0
390
+ return decode_calibration.DecodeEstimate(
391
+ bandwidth * 1e9 / bytes_per_token, basis, bandwidth, bytes_per_token
392
+ )
393
+
394
+
258
395
  def catalog_file(name: str) -> Path:
259
396
  return cat.CATALOG_PATH.parent / name
397
+
398
+
399
+ # PolyStrata KV row bytes relative to FP16 (2048 B/row for Inkling 2 Mini; engine/src/poly/inkling2.cpp).
400
+ POLY_KV_ROW_RATIO: dict[str, float] = {
401
+ "fp16": 1.0,
402
+ "f16": 1.0,
403
+ "fp8": 1056 / 2048,
404
+ "q8_0": 1088 / 2048,
405
+ "q4_0": 576 / 2048,
406
+ }
407
+ _POLY_SINGLE_SLOT_KV = frozenset({"q8_0", "q4_0"})
408
+ # Metal runtime/compute buffers (~1.5 GiB) + Python serve wrapper (~0.3 GiB), overridable per recipe.
409
+ # Calibrated on 24 GB Apple M6 (inkling-2-mini-q3-poly, --metal-memory legacy, 3072/3072 experts):
410
+ # 15.29 GiB post-load and 15.99 GiB after a 9.3K prompt vs 16.38 GiB planned (Metal strata-vision
411
+ # 311 MiB vs 791 MiB CUDA estimate offsets Metal compute overhead).
412
+ DEFAULT_METAL_OVERHEAD_BYTES = 1843 << 20
413
+
414
+
415
+ def poly_kv_format(args: Sequence[object]) -> str:
416
+ """Effective ``--kv`` format from a PolyStrata args list (defaults to ``fp16``)."""
417
+ items = [str(item) for item in args]
418
+ fmt = "fp16"
419
+ for idx, token in enumerate(items):
420
+ if token == "--kv" and idx + 1 < len(items):
421
+ fmt = items[idx + 1].strip().lower()
422
+ return fmt
423
+
424
+
425
+ def plan_kv_format(plan: Plan, recipe: SuiteRecipe) -> str:
426
+ """Effective ``--kv`` format from a rendered plan's ``strata-profile.json``, else the recipe."""
427
+ config_files = plan["service"].get("config_files") or {}
428
+ for path, raw in config_files.items():
429
+ if path.endswith("strata-profile.json"):
430
+ try:
431
+ cfg = json.loads(raw)
432
+ except (TypeError, ValueError):
433
+ break
434
+ args = cfg.get("args") if isinstance(cfg, dict) else None
435
+ if isinstance(args, list):
436
+ return poly_kv_format(args)
437
+ profile = recipe.get("profile")
438
+ raw_args = profile.get("args") if isinstance(profile, dict) else None
439
+ return poly_kv_format(raw_args) if isinstance(raw_args, list) else "fp16"
440
+
441
+
442
+ def poly_kv_geometry(
443
+ recipe: SuiteRecipe, *, allow_catalog_fallback: bool = True
444
+ ) -> tuple[int, int, int, int] | None:
445
+ """``(full_layers, swa_layers, swa_window, per_layer_f16)`` for compositional Metal KV sizing."""
446
+ full = int(recipe.get("full_layers") or 0)
447
+ swa = int(recipe.get("swa_layers") or 0)
448
+ swa_win = int(recipe.get("swa_window") or 0)
449
+ per_layer = int(recipe.get("per_layer_f16") or 0)
450
+ if (full > 0 or swa > 0) and per_layer > 0:
451
+ return full, swa, swa_win, per_layer
452
+ if not allow_catalog_fallback:
453
+ return None
454
+ repo = recipe.get("repo") or ""
455
+ if not repo:
456
+ return None
457
+ twin = next(
458
+ (
459
+ e
460
+ for e in cat.load_catalog_file()
461
+ if e.repo == repo and (e.full_layers > 0 or e.swa_layers > 0) and e.per_layer_f16 > 0
462
+ ),
463
+ None,
464
+ )
465
+ if twin is None:
466
+ return None
467
+ return twin.full_layers, twin.swa_layers, twin.swa_window, twin.per_layer_f16
468
+
469
+
470
+ def poly_unified_footprint(
471
+ recipe: SuiteRecipe,
472
+ *,
473
+ window: int | None = None,
474
+ slots: int | None = None,
475
+ kv_fmt: str | None = None,
476
+ vision_reader: str = "off",
477
+ allow_catalog_fallback: bool = True,
478
+ fallback_beside_bytes: int = 12 * GIB,
479
+ ) -> tuple[int, int]:
480
+ """Return ``(unified_bytes, wired_bytes)`` for a ``strata-poly`` recipe on Apple Silicon Metal.
481
+
482
+ When KV geometry is available, prices compositionally:
483
+ ``weights + kv(window, slots, kv_fmt) + resident_vision + metal_overhead_bytes``.
484
+ ``wired_bytes`` covers GPU-resident weights, KV cache and Metal vision encoder;
485
+ ``unified_bytes`` adds Metal runtime/compute and Python server overhead (default 1.80 GiB,
486
+ overridable via ``recipe["metal_overhead_bytes"]``).
487
+ """
488
+ weights = sum(int(f["size_bytes"]) for f in recipe["files"] if not f.get("vision"))
489
+ geom = poly_kv_geometry(recipe, allow_catalog_fallback=allow_catalog_fallback)
490
+ if geom is None:
491
+ total = weights + fallback_beside_bytes
492
+ return total, total
493
+ full_layers, swa_layers, swa_window, per_layer_f16 = geom
494
+ profile = recipe.get("profile")
495
+ profile_args = profile.get("args") if isinstance(profile, dict) else None
496
+ raw_args: Sequence[object] = profile_args if isinstance(profile_args, list) else ()
497
+ eff_window = (
498
+ window if window is not None and window > 0 else int(recipe.get("context") or 65536)
499
+ )
500
+ eff_kv = (kv_fmt or poly_kv_format(raw_args)).strip().lower()
501
+ default_slots = int(str(profile.get("parallel") or 2)) if isinstance(profile, dict) else 2
502
+ eff_slots = max(1, slots if slots is not None and slots > 0 else default_slots)
503
+ if eff_kv in _POLY_SINGLE_SLOT_KV:
504
+ eff_slots = 1
505
+ ratio = POLY_KV_ROW_RATIO.get(eff_kv, 1.0)
506
+ full_tokens = eff_window * eff_slots
507
+ swa_tokens = min(eff_window, swa_window) * eff_slots if swa_layers and swa_window else 0
508
+ kv_bytes = int((full_layers * full_tokens + swa_layers * swa_tokens) * per_layer_f16 * ratio)
509
+ spec = recipe.get("vision") or {}
510
+ if vision_reader == "gpu" and spec:
511
+ vision_bytes = strata_gpu_mib(spec, "gpu") << 20
512
+ elif vision_reader == "cpu" and spec:
513
+ vision_bytes = strata_ram_mib(spec, "cpu") << 20
514
+ else:
515
+ vision_bytes = 0
516
+ overhead = int(recipe.get("metal_overhead_bytes") or DEFAULT_METAL_OVERHEAD_BYTES)
517
+ wired = weights + kv_bytes + vision_bytes
518
+ return wired + overhead, wired