@simplexai/localmodels-darwin-x64 0.1.0-dev.103 → 0.1.0-dev.104

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 (139) 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 +126 -127
  6. package/modules/localmodels/__init__.py +1 -1
  7. package/modules/localmodels/catalog.json +130 -127
  8. package/modules/localmodels/catalog.py +7 -3
  9. package/modules/localmodels/catalog_recipes.py +3 -3
  10. package/modules/localmodels/cli_parser.py +3 -3
  11. package/modules/localmodels/component.py +1 -1
  12. package/modules/localmodels/console.py +1 -1
  13. package/modules/localmodels/context_policy.py +6 -5
  14. package/modules/localmodels/debug_cli.py +0 -12
  15. package/modules/localmodels/debug_mode.py +0 -6
  16. package/modules/localmodels/decode_calibration.json +3 -4
  17. package/modules/localmodels/decode_calibration.py +5 -2
  18. package/modules/localmodels/deployment_lifecycle.py +1 -1
  19. package/modules/localmodels/download-mirrors.json +1 -1
  20. package/modules/localmodels/engine_adapters/base.py +11 -1
  21. package/modules/localmodels/engine_adapters/strata_poly.py +65 -3
  22. package/modules/localmodels/engine_adapters/suite_plan.py +57 -20
  23. package/modules/localmodels/engines-b11583.json +6 -26
  24. package/modules/localmodels/engines-b12588-mix-c0c3de8.json +3 -15
  25. package/modules/localmodels/engines-b12757-mix-ef2df21.json +3 -15
  26. package/modules/localmodels/engines-prism-b12178-03ec600.json +3 -15
  27. package/modules/localmodels/engines-speechcpp-v0.11.3.json +4 -20
  28. package/modules/localmodels/engines-strata-0.1.47.json +1 -5
  29. package/modules/localmodels/engines-strata-0.1.49.2.json +1 -5
  30. package/modules/localmodels/engines-strata-0.1.59.1.json +1 -5
  31. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +6 -30
  32. package/modules/localmodels/engines-strata-poly-0.2.20-poly.9.json +129 -0
  33. package/modules/localmodels/engines-whisper-b5454.json +6 -30
  34. package/modules/localmodels/engines.json +13 -61
  35. package/modules/localmodels/estimator.py +10 -5
  36. package/modules/localmodels/gpu_specs.py +1 -1
  37. package/modules/localmodels/hosts.py +12 -16
  38. package/modules/localmodels/kokoro-tts-0.6.1.txt +1 -1
  39. package/modules/localmodels/library_elastic.py +135 -6
  40. package/modules/localmodels/library_kept.py +9 -1
  41. package/modules/localmodels/library_model.py +28 -1
  42. package/modules/localmodels/library_poly.py +109 -11
  43. package/modules/localmodels/library_pricing.py +12 -3
  44. package/modules/localmodels/library_serve.py +134 -67
  45. package/modules/localmodels/library_smoke.py +63 -5
  46. package/modules/localmodels/library_state.py +3 -2
  47. package/modules/localmodels/library_status.py +8 -1
  48. package/modules/localmodels/llm_rank.py +13 -8
  49. package/modules/localmodels/metal.py +1 -2
  50. package/modules/localmodels/plan_envelope.py +29 -11
  51. package/modules/localmodels/planning/budget.py +14 -12
  52. package/modules/localmodels/planning/memory_pools.py +7 -1
  53. package/modules/localmodels/privacy_acceptance.py +6 -5
  54. package/modules/localmodels/py.typed +0 -0
  55. package/modules/localmodels/quant_formats.py +1 -1
  56. package/modules/localmodels/recommend_cli.py +1 -1
  57. package/modules/localmodels/remote_ops_launchd.py +8 -1
  58. package/modules/localmodels/runtime_process.py +1 -1
  59. package/modules/localmodels/service_deployment.py +2 -4
  60. package/modules/localmodels/service_probe.py +59 -13
  61. package/modules/localmodels/setup_inspection.py +72 -70
  62. package/modules/localmodels/setup_text.py +7 -56
  63. package/modules/localmodels/sidecar_downloads.py +34 -0
  64. package/modules/localmodels/sidecar_http.py +61 -5
  65. package/modules/localmodels/sidecar_state.py +52 -2
  66. package/modules/localmodels/speech_admission.py +20 -4
  67. package/modules/localmodels/speech_catalog.py +23 -0
  68. package/modules/localmodels/speech_cli.py +10 -2
  69. package/modules/localmodels/speech_jobs.py +42 -17
  70. package/modules/localmodels/speech_server.py +182 -81
  71. package/modules/localmodels/speech_state.py +4 -1
  72. package/modules/localmodels/speech_workers.py +11 -0
  73. package/modules/localmodels/stack.py +1 -1
  74. package/modules/localmodels/stack_args.py +6 -6
  75. package/modules/localmodels/stack_auto.py +1 -1
  76. package/modules/localmodels/stack_aux_gpu.py +1 -1
  77. package/modules/localmodels/stack_cleanup.py +21 -18
  78. package/modules/localmodels/stack_cli.py +6 -2
  79. package/modules/localmodels/stack_compose.py +11 -4
  80. package/modules/localmodels/stack_debug.py +1 -2
  81. package/modules/localmodels/stack_decision.py +4 -4
  82. package/modules/localmodels/stack_doctor.py +2 -2
  83. package/modules/localmodels/stack_events.py +1 -1
  84. package/modules/localmodels/stack_gpu_memory.py +1 -1
  85. package/modules/localmodels/stack_hardware.py +3 -3
  86. package/modules/localmodels/stack_mcp.py +1 -2
  87. package/modules/localmodels/stack_picks.py +1 -1
  88. package/modules/localmodels/stack_plan.py +9 -9
  89. package/modules/localmodels/stack_ports.py +31 -4
  90. package/modules/localmodels/stack_rollback.py +1 -1
  91. package/modules/localmodels/stack_run.py +1 -1
  92. package/modules/localmodels/stack_suite.py +61 -12
  93. package/modules/localmodels/stack_view_agent.py +1 -1
  94. package/modules/localmodels/stack_view_serve.py +0 -2
  95. package/modules/localmodels/stack_view_words.py +2 -2
  96. package/modules/localmodels/stack_warm.py +2 -2
  97. package/modules/localmodels/stack_whatif.py +524 -41
  98. package/modules/localmodels/stack_whatif_html.py +903 -0
  99. package/modules/localmodels/startlux-decide-83fe6c7d.txt +2 -2
  100. package/modules/localmodels/{strata-poly-serve-0.2.20-poly.7.txt → strata-poly-serve-0.2.20-poly.9.txt} +1 -1
  101. package/modules/localmodels/strata_poly_server.py +114 -3
  102. package/modules/localmodels/suite.py +137 -5
  103. package/modules/localmodels/tts_admission.py +2 -17
  104. package/modules/localmodels/tts_catalog.py +29 -1
  105. package/modules/localmodels/tts_cli.py +23 -4
  106. package/modules/localmodels/tts_http.py +10 -4
  107. package/modules/localmodels/tts_jobs.py +49 -19
  108. package/modules/localmodels/tts_server.py +1 -1
  109. package/modules/localmodels/tts_sidecar.py +66 -28
  110. package/modules/localmodels/tts_state.py +7 -2
  111. package/modules/localmodels/vision.py +5 -3
  112. package/modules/localmodels/web/view/ASSET-SOURCES.md +4 -7
  113. package/modules/localmodels/web/view/view.css +0 -1
  114. package/modules/localmodels/web/view/view.js +2 -5
  115. package/modules/localmodels/web/whatif/app.js +730 -0
  116. package/modules/localmodels/web/whatif/page.html +1172 -0
  117. package/modules/localmodels/web/whatif/sim.js +303 -0
  118. package/modules/localmodels/windows_job.py +179 -11
  119. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/METADATA +14 -0
  120. package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/RECORD +118 -114
  121. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/LICENSE +201 -0
  122. package/modules/simplex_localmodels-0.1.0.dev104.dist-info/licenses/NOTICE +126 -0
  123. package/package.json +11 -2
  124. package/tool.json +1 -1
  125. package/modules/localmodels/engines-strata-poly-0.2.20-poly.7.json +0 -94
  126. package/modules/localmodels/fixtures/stack-research-demo-plan.json +0 -1059
  127. package/modules/localmodels/stack_research.py +0 -716
  128. package/modules/localmodels/stack_research_demo.py +0 -125
  129. package/modules/localmodels/stack_research_plan.py +0 -146
  130. package/modules/localmodels/web/index.html +0 -2605
  131. package/modules/localmodels/web/sizecalc/app.js +0 -1306
  132. package/modules/localmodels/web/sizecalc/calc.js +0 -269
  133. package/modules/localmodels/web/sizecalc/page.html +0 -520
  134. package/modules/localmodels/web/view/logo-claude.svg +0 -3
  135. package/modules/localmodels/web/view/logo-codex.png +0 -0
  136. package/modules/simplex_localmodels-0.1.0.dev103.dist-info/METADATA +0 -9
  137. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/WHEEL +0 -0
  138. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/entry_points.txt +0 -0
  139. /package/modules/{simplex_localmodels-0.1.0.dev103.dist-info → simplex_localmodels-0.1.0.dev104.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -12,6 +12,7 @@ import copy
12
12
  import json
13
13
  import sys
14
14
  from concurrent.futures import ThreadPoolExecutor
15
+ from dataclasses import dataclass
15
16
  from pathlib import Path
16
17
  from typing import Literal, TypeAlias, TypedDict
17
18
 
@@ -20,6 +21,8 @@ from localmodels import (
20
21
  catalog,
21
22
  cli_help,
22
23
  deploy,
24
+ engines,
25
+ llm_rank,
23
26
  metal,
24
27
  probe,
25
28
  service_probe,
@@ -34,11 +37,82 @@ from localmodels.planning.memcalc import parse_size
34
37
  from localmodels.probe import GPU, HostFacts, Services
35
38
  from localmodels.stack_compose import agent_posture, choose_parts, ram_budget
36
39
  from localmodels.stack_memory import Machine
37
- from localmodels.stack_plan import StackError, StackOptions, default_options
40
+ from localmodels.stack_plan import (
41
+ PREFERENCES,
42
+ StackError,
43
+ StackOptions,
44
+ default_options,
45
+ platform_error,
46
+ )
38
47
 
39
48
  SCHEMA = "localmodels.stack-what-if/v1"
40
49
  GIB = 1 << 30
41
50
  RAM_STEPS_GIB = (16, 32, 64)
51
+ PLATFORM_ALIASES = {
52
+ "linux": "linux",
53
+ "windows": "win32",
54
+ "win32": "win32",
55
+ "macos": "darwin",
56
+ "mac": "darwin",
57
+ "darwin": "darwin",
58
+ }
59
+ PRESSURE_LEVELS = (metal.PRESSURE_NORMAL, metal.PRESSURE_WARN, metal.PRESSURE_CRITICAL)
60
+ DECISIONS = ("none", "auto")
61
+ OTHER_UNIFIED_VENDORS = ("amd", "intel", "cuda-uma")
62
+
63
+
64
+ @dataclass(frozen=True)
65
+ class Simulation:
66
+ """Optional cross-platform simulation knobs layered on ``Machine``."""
67
+
68
+ platform: str | None = None # "linux" | "win32" | "darwin" (or alias)
69
+ cuda: str | None = None # e.g. "13.0", "12.8", "12.4"
70
+ vram_used: int | None = None # bytes already held on card 0
71
+ ram_available: int | None = None # bytes available now
72
+ pressure: int | None = None # macOS pressure_level: 1 (Normal), 2 (Warning), 4 (Critical)
73
+ gpu_vendor: str | None = None # "nvidia" | "amd" | "intel" | "cuda-uma"
74
+
75
+
76
+ class EvalResult(TypedDict):
77
+ """Single-configuration evaluation result from the real planner."""
78
+
79
+ ok: bool
80
+ id: str | None
81
+ display_name: str | None
82
+ quant: str | None
83
+ quality: int | None
84
+ engine: str | None
85
+ window: int | None
86
+ slots: int | None
87
+ kv_types: list[str]
88
+ vision: str | None
89
+ decode_tok_s: float | None
90
+ decode_basis: str
91
+ speed_kind: str # estimated | measured | unavailable
92
+ vram_bytes: int
93
+ ram_needed_bytes: int
94
+ ram_parts: dict[str, int]
95
+ download_bytes: int
96
+ decision_id: str | None
97
+ decision_vram_bytes: int
98
+ candidate_fallback: bool
99
+ mac_ladder: bool
100
+ reasons: list[str]
101
+ refusal: str | None
102
+ cause_code: str | None
103
+
104
+
105
+ def normalize_platform(raw: str) -> str:
106
+ """Normalize CLI platform names (linux, windows, macos) to HostFacts platform keys."""
107
+ found = PLATFORM_ALIASES.get(raw.strip().lower())
108
+ if found is None:
109
+ raise StackError(f"unknown platform {raw!r}; choose linux, windows or macos")
110
+ return found
111
+
112
+
113
+ def driver_for_cuda(cuda: str) -> str:
114
+ """Minimum NVIDIA display driver branch for ``cuda``, or empty string if unmapped."""
115
+ return engines.min_driver_for_cuda(cuda)
42
116
 
43
117
 
44
118
  class Choice(TypedDict):
@@ -169,8 +243,7 @@ def _unified(facts: HostFacts, total: int) -> HostFacts:
169
243
  return seen
170
244
 
171
245
 
172
- def starting_facts(machine: Machine, facts: HostFacts | None = None) -> HostFacts:
173
- """Override supplied readings, or create a complete simulation without touching hardware."""
246
+ def _validate_machine(machine: Machine) -> None:
174
247
  if machine.unified is not None and (machine.vram is not None or machine.ram is not None):
175
248
  raise StackError("--unified-memory cannot be combined with --vram or --ram")
176
249
  sizes = (machine.vram, machine.ram, machine.unified)
@@ -178,30 +251,334 @@ def starting_facts(machine: Machine, facts: HostFacts | None = None) -> HostFact
178
251
  raise StackError("memory sizes must be greater than zero")
179
252
  if machine.unified is not None and machine.unified < 8 * GIB:
180
253
  raise StackError("--unified-memory must be at least 8 GiB")
181
- complete = machine.unified is not None or (machine.vram is not None and machine.ram is not None)
182
- if facts is None:
183
- facts = _simulated() if complete else read_host()
184
- seen = copy.deepcopy(facts)
185
- if machine.unified is not None:
186
- return _unified(seen, machine.unified)
187
- if metal.supported(seen) and (machine.vram is not None or machine.ram is not None):
188
- raise StackError("Apple Silicon shares one memory pool; use --unified-memory")
254
+
255
+
256
+ def _validate_sim(machine: Machine, sim: Simulation, facts: HostFacts | None) -> str | None:
257
+ platform = normalize_platform(sim.platform) if sim.platform is not None else None
258
+ if sim.pressure is not None and sim.pressure not in PRESSURE_LEVELS:
259
+ raise StackError(f"--pressure must be one of {', '.join(str(p) for p in PRESSURE_LEVELS)}")
260
+ if sim.vram_used is not None and sim.vram_used < 0:
261
+ raise StackError("--vram-used cannot be negative")
262
+ if sim.ram_available is not None and sim.ram_available < 0:
263
+ raise StackError("--ram-available cannot be negative")
264
+ if sim.gpu_vendor is not None and sim.gpu_vendor not in ("nvidia", *OTHER_UNIFIED_VENDORS):
265
+ raise StackError(f"unknown GPU vendor {sim.gpu_vendor!r}")
266
+ is_mac = (
267
+ (machine.unified is not None and sim.gpu_vendor not in OTHER_UNIFIED_VENDORS)
268
+ or platform == "darwin"
269
+ or (
270
+ facts is not None
271
+ and metal.supported(facts)
272
+ and platform is None
273
+ and sim.gpu_vendor is None
274
+ )
275
+ )
276
+ if is_mac:
277
+ if machine.vram is not None or machine.ram is not None:
278
+ raise StackError("Apple Silicon shares one memory pool; use --unified-memory")
279
+ if sim.vram_used is not None:
280
+ raise StackError("--vram-used applies to discrete GPU simulations only")
281
+ if sim.cuda is not None:
282
+ raise StackError("--cuda applies to NVIDIA simulations only")
283
+ elif sim.pressure is not None:
284
+ raise StackError("--pressure applies to Apple Silicon Macs only")
285
+ return platform
286
+
287
+
288
+ def _apply_unified(seen: HostFacts, total: int, sim: Simulation | None) -> HostFacts:
289
+ mac = _unified(seen, total)
290
+ if sim is not None and sim.ram_available is not None:
291
+ if sim.ram_available > total:
292
+ raise StackError("--ram-available cannot exceed --unified-memory")
293
+ mac["ram"]["available_bytes"] = sim.ram_available
294
+ if sim is not None and sim.pressure is not None:
295
+ mac["ram"]["pressure_level"] = sim.pressure
296
+ return mac
297
+
298
+
299
+ def _apply_other_unified(seen: HostFacts, total: int, sim: Simulation) -> HostFacts:
300
+ platform = normalize_platform(sim.platform) if sim.platform is not None else "linux"
301
+ avail = (
302
+ sim.ram_available
303
+ if sim.ram_available is not None
304
+ else max(0, total - min(4 * GIB, total // 4))
305
+ )
306
+ if avail > total:
307
+ raise StackError("--ram-available cannot exceed total memory")
308
+ seen.update({"platform": platform, "arch": "x64", "metal": None, "cgroup_memory": None})
309
+ seen["ram"] = {"total_bytes": total, "available_bytes": avail}
310
+ seen["services"] = _simulated()["services"]
311
+ if sim.gpu_vendor == "cuda-uma":
312
+ cuda = sim.cuda or "13.0"
313
+ driver = driver_for_cuda(cuda)
314
+ card = _card(0, 0, 0)
315
+ card["name"] = "Simulated NVIDIA Unified GPU"
316
+ card["driver_version"] = driver
317
+ seen["gpu_vendor_class"] = "nvidia"
318
+ seen["nvidia"] = {"cuda_version": cuda, "driver_version": driver}
319
+ seen["gpus"] = [card]
320
+ seen["cuda_pool"] = {"total_bytes": total, "integrated": True}
321
+ else:
322
+ seen["gpu_vendor_class"] = sim.gpu_vendor or "unknown"
323
+ seen["nvidia"] = None
324
+ seen["gpus"] = []
325
+ seen["cuda_pool"] = None
326
+ return seen
327
+
328
+
329
+ def _apply_discrete(
330
+ seen: HostFacts, machine: Machine, sim: Simulation | None, platform: str | None
331
+ ) -> HostFacts:
332
+ if platform is not None:
333
+ seen["platform"] = platform
334
+ seen["arch"] = "x64"
335
+ cuda = sim.cuda if sim is not None else None
336
+ if cuda is not None:
337
+ seen["nvidia"] = {"cuda_version": cuda, "driver_version": driver_for_cuda(cuda)}
189
338
  if machine.vram is not None:
190
- seen["gpus"] = [_card(0, machine.vram)]
339
+ used = sim.vram_used if (sim is not None and sim.vram_used is not None) else 0
340
+ if used > machine.vram:
341
+ raise StackError("--vram-used cannot exceed --vram")
342
+ card = _card(0, machine.vram, used)
343
+ if cuda is not None:
344
+ card["driver_version"] = driver_for_cuda(cuda)
345
+ seen["gpus"] = [card]
191
346
  seen["cuda_pool"] = None
192
347
  seen["metal"] = None
193
348
  seen["gpu_vendor_class"] = "nvidia"
194
349
  seen["services"] = _simulated()["services"]
350
+ elif sim is not None and sim.vram_used is not None and seen["gpus"]:
351
+ card0 = seen["gpus"][0]
352
+ if sim.vram_used > card0["total_bytes"]:
353
+ raise StackError("--vram-used cannot exceed card VRAM")
354
+ card0["used_bytes"] = sim.vram_used
355
+ card0["free_bytes"] = max(0, card0["total_bytes"] - sim.vram_used)
195
356
  if machine.ram is not None:
196
- used = seen["ram"]["total_bytes"] - seen["ram"]["available_bytes"]
357
+ used_ram = seen["ram"]["total_bytes"] - seen["ram"]["available_bytes"]
197
358
  seen["ram"] = {
198
359
  "total_bytes": machine.ram,
199
- "available_bytes": max(0, machine.ram - used),
360
+ "available_bytes": max(0, machine.ram - used_ram),
200
361
  }
201
362
  seen["cgroup_memory"] = None
363
+ if sim is not None and sim.ram_available is not None:
364
+ if sim.ram_available > seen["ram"]["total_bytes"]:
365
+ raise StackError("--ram-available cannot exceed total RAM")
366
+ seen["ram"]["available_bytes"] = sim.ram_available
202
367
  return seen
203
368
 
204
369
 
370
+ def starting_facts(
371
+ machine: Machine,
372
+ facts: HostFacts | None = None,
373
+ sim: Simulation | None = None,
374
+ ) -> HostFacts:
375
+ """Override supplied readings, or create a complete simulation without touching hardware."""
376
+ _validate_machine(machine)
377
+ platform = _validate_sim(machine, sim, facts) if sim is not None else None
378
+ other_unified = sim is not None and sim.gpu_vendor in OTHER_UNIFIED_VENDORS
379
+ complete = (
380
+ machine.unified is not None
381
+ or (machine.vram is not None and machine.ram is not None)
382
+ or (other_unified and (machine.unified is not None or machine.ram is not None))
383
+ )
384
+ if facts is None:
385
+ facts = _simulated() if complete else read_host()
386
+ seen = copy.deepcopy(facts)
387
+ if other_unified:
388
+ assert sim is not None
389
+ total = machine.unified or machine.ram or seen["ram"]["total_bytes"]
390
+ return _apply_other_unified(seen, total, sim)
391
+ if machine.unified is not None:
392
+ return _apply_unified(seen, machine.unified, sim)
393
+ if metal.supported(seen):
394
+ if machine.vram is not None or machine.ram is not None:
395
+ raise StackError("Apple Silicon shares one memory pool; use --unified-memory")
396
+ if sim is not None and sim.ram_available is not None:
397
+ if sim.ram_available > seen["ram"]["total_bytes"]:
398
+ raise StackError("--ram-available cannot exceed total memory")
399
+ seen["ram"]["available_bytes"] = sim.ram_available
400
+ if sim is not None and sim.pressure is not None:
401
+ seen["ram"]["pressure_level"] = sim.pressure
402
+ return seen
403
+ return _apply_discrete(seen, machine, sim, platform)
404
+
405
+
406
+ def simulate_facts(
407
+ machine: Machine,
408
+ sim: Simulation | None = None,
409
+ facts: HostFacts | None = None,
410
+ ) -> HostFacts:
411
+ """Public simulation entry point for cross-platform facts (wraps ``starting_facts``)."""
412
+ return starting_facts(machine, facts=facts, sim=sim)
413
+
414
+
415
+ def _eval_refused(
416
+ message: str,
417
+ *,
418
+ cause_code: str | None = None,
419
+ reasons: list[str] | None = None,
420
+ ) -> EvalResult:
421
+ return {
422
+ "ok": False,
423
+ "id": None,
424
+ "display_name": None,
425
+ "quant": None,
426
+ "quality": None,
427
+ "engine": None,
428
+ "window": None,
429
+ "slots": None,
430
+ "kv_types": [],
431
+ "vision": None,
432
+ "decode_tok_s": None,
433
+ "decode_basis": "unavailable",
434
+ "speed_kind": "unavailable",
435
+ "vram_bytes": 0,
436
+ "ram_needed_bytes": 0,
437
+ "ram_parts": {},
438
+ "download_bytes": 0,
439
+ "decision_id": None,
440
+ "decision_vram_bytes": 0,
441
+ "candidate_fallback": False,
442
+ "mac_ladder": False,
443
+ "reasons": list(reasons or ()),
444
+ "refusal": message,
445
+ "cause_code": cause_code,
446
+ }
447
+
448
+
449
+ def _eval_from_parts(
450
+ priced: HostFacts,
451
+ options: StackOptions,
452
+ parts: dict[str, object],
453
+ ram_parts: dict[str, int],
454
+ pressure_notes: list[str],
455
+ ) -> EvalResult:
456
+ llm = decode(parts["llm"], dict[str, object])
457
+ model = decode(llm["model"], dict[str, object])
458
+ launch = decode(llm["launch"], dict[str, object])
459
+ placement = decode(llm["placement"], dict[str, object])
460
+ llm_id = str(model["id"])
461
+ gpus = decode(placement.get("gpus") or [], list[dict[str, object]])
462
+ index = decode(gpus[0]["index"], int) if gpus else 0
463
+ vram_bytes = int(str(launch.get("unified_bytes") or launch.get("vram_bytes") or 0))
464
+ download_bytes = int(str(model.get("download_bytes") or 0))
465
+ vision_mode = str(launch.get("vision") or "off")
466
+ dec_choice = decode(parts["decision"], dict[str, object])
467
+ dec_plan_raw = dec_choice.get("plan")
468
+ decision_id: str | None = None
469
+ decision_vram_bytes = 0
470
+ if isinstance(dec_plan_raw, dict):
471
+ dec_model = decode(dec_plan_raw["model"], dict[str, object])
472
+ dec_launch = decode(dec_plan_raw["launch"], dict[str, object])
473
+ decision_id = str(dec_model["id"])
474
+ decision_vram_bytes = int(str(dec_launch.get("vram_bytes") or 0))
475
+ part_warnings = decode(parts["warnings"], list[str])
476
+ reasons = list(dict.fromkeys([*pressure_notes, *part_warnings]))
477
+ if recipe := next((r for r in suite.recipes("llm") if r["id"] == llm_id), None):
478
+ return {
479
+ "ok": True,
480
+ "id": recipe["id"],
481
+ "display_name": str(recipe.get("display_name") or recipe["id"]),
482
+ "quant": recipe["version"],
483
+ "quality": recipe["quality"]["score"],
484
+ "engine": recipe["runtime"],
485
+ "window": int(str(launch["window"])),
486
+ "slots": int(str(launch.get("slots", 1))),
487
+ "kv_types": [],
488
+ "vision": vision_mode,
489
+ "decode_tok_s": None,
490
+ "decode_basis": "unavailable",
491
+ "speed_kind": "unavailable",
492
+ "vram_bytes": vram_bytes,
493
+ "ram_needed_bytes": sum(ram_parts.values()),
494
+ "ram_parts": ram_parts,
495
+ "download_bytes": download_bytes,
496
+ "decision_id": decision_id,
497
+ "decision_vram_bytes": decision_vram_bytes,
498
+ "candidate_fallback": False,
499
+ "mac_ladder": False,
500
+ "reasons": reasons,
501
+ "refusal": None,
502
+ "cause_code": None,
503
+ }
504
+ entry = next(e for e in catalog.load_catalog_file() if e.id == llm_id)
505
+ posture = agent_posture(options)
506
+ if metal.supported(priced):
507
+ posture = posture_for(posture, "metal")
508
+ budget, _ = hardware.llm_budget(priced, index, options, entry=entry, posture=posture)
509
+ speed = catalog.decode_estimate(entry, entry.variants[-1], budget)
510
+ is_fb = llm_rank.windows_fallback(entry, priced)
511
+ is_mac = llm_rank.mac_rung(entry, priced)
512
+ return {
513
+ "ok": True,
514
+ "id": entry.id,
515
+ "display_name": entry.display_name,
516
+ "quant": entry.variants[-1].quant,
517
+ "quality": None if (is_fb or is_mac) else entry.quality,
518
+ "engine": entry.runtime,
519
+ "window": int(str(launch["window"])),
520
+ "slots": int(str(launch["slots"])),
521
+ "kv_types": decode(launch["kv_types"], list[str]),
522
+ "vision": vision_mode,
523
+ "decode_tok_s": round(speed.tok_s, 1),
524
+ "decode_basis": speed.basis,
525
+ "speed_kind": "measured" if speed.basis == "measured-decode" else "estimated",
526
+ "vram_bytes": vram_bytes,
527
+ "ram_needed_bytes": sum(ram_parts.values()),
528
+ "ram_parts": ram_parts,
529
+ "download_bytes": download_bytes,
530
+ "decision_id": decision_id,
531
+ "decision_vram_bytes": decision_vram_bytes,
532
+ "candidate_fallback": is_fb,
533
+ "mac_ladder": is_mac,
534
+ "reasons": reasons,
535
+ "refusal": None,
536
+ "cause_code": None,
537
+ }
538
+
539
+
540
+ def evaluate(
541
+ facts: HostFacts,
542
+ *,
543
+ prefer: str = "smartest",
544
+ decision: str = "none",
545
+ reuse_from: tuple[str, ...] = (),
546
+ base_dir: str = deploy.DEFAULT_BASE_DIR,
547
+ ) -> EvalResult:
548
+ """Evaluate one configuration through the real ``stack plan --llm auto`` planner."""
549
+ if error := platform_error(facts["platform"], arch=facts.get("arch")):
550
+ return _eval_refused(error)
551
+ if error := metal.problem(facts):
552
+ return _eval_refused(error, cause_code="MEMORY_INSUFFICIENT")
553
+ priced, pressure_notes = metal.pressured(
554
+ metal.reclaimed(facts) if metal.supported(facts) else facts
555
+ )
556
+ options = default_options()
557
+ options["reuse_from"] = list(reuse_from)
558
+ options["base_dir"] = base_dir
559
+ options["prefer"] = prefer
560
+ options["decision"] = decision
561
+ options["offline"] = True
562
+ try:
563
+ parts, selected = choose_parts(
564
+ priced,
565
+ options,
566
+ resolver=deploy.catalog_pins,
567
+ listening=lambda _: False,
568
+ previous=lambda *_: None,
569
+ existing=lambda _: [],
570
+ owned_ram=lambda: 0,
571
+ )
572
+ ram_parts = ram_budget(parts)
573
+ except (StackError, PlanError) as exc:
574
+ return _eval_refused(
575
+ str(exc),
576
+ cause_code=getattr(exc, "cause_code", None),
577
+ reasons=pressure_notes,
578
+ )
579
+ return _eval_from_parts(priced, selected, dict(parts), ram_parts, pressure_notes)
580
+
581
+
205
582
  def _choice(facts: HostFacts, options: StackOptions, role: str) -> tuple[Choice | None, list[str]]:
206
583
  try:
207
584
  parts, _ = choose_parts(
@@ -262,35 +639,60 @@ def _choice(facts: HostFacts, options: StackOptions, role: str) -> tuple[Choice
262
639
  }, notes
263
640
 
264
641
 
642
+ def _simulated_note(facts: HostFacts) -> str | None:
643
+ if facts["hostname"] != "simulated" or facts["platform"] not in ("linux", "win32"):
644
+ return None
645
+ cuda = ((facts.get("nvidia") or {}).get("cuda_version") or "13.0").strip()
646
+ os_name = "Windows" if facts["platform"] == "win32" else "Linux"
647
+ return (
648
+ f"Fully simulated {os_name} hardware assumes x64 and a CUDA {cuda} compatible driver; "
649
+ "runtime and system libraries have not been probed."
650
+ )
651
+
652
+
653
+ def _roles(prefer: str | None) -> tuple[str, ...]:
654
+ if prefer in ("concurrent", "fast"):
655
+ return (*stack_picks.ROLES, prefer)
656
+ return stack_picks.ROLES
657
+
658
+
265
659
  def snapshot(
266
660
  facts: HostFacts,
267
661
  *,
268
662
  reuse_from: tuple[str, ...] = (),
269
663
  base_dir: str = deploy.DEFAULT_BASE_DIR,
664
+ decision: str = "none",
665
+ prefer: str | None = None,
270
666
  ) -> Snapshot:
271
667
  options = default_options()
272
668
  options["reuse_from"] = list(reuse_from)
273
669
  options["base_dir"] = base_dir
670
+ options["decision"] = decision
274
671
  seen = hardware.view(facts, options, None)
275
- priced, _ = metal.pressured(metal.reclaimed(facts) if metal.supported(facts) else facts)
276
- choices: Choices = {"smartest": None, "fastest": None}
672
+ roles = _roles(prefer)
673
+ choices: Choices = dict.fromkeys(roles)
277
674
  notes = list(seen["notes"])
278
- if facts["hostname"] == "simulated" and facts["platform"] == "linux":
279
- notes.append(
280
- "Fully simulated Linux hardware assumes x64 and a CUDA 13.0 compatible driver; "
281
- "runtime and system libraries have not been probed."
675
+ if sim_note := _simulated_note(facts):
676
+ notes.append(sim_note)
677
+ if problem := metal.problem(facts):
678
+ if problem not in notes:
679
+ notes.append(problem)
680
+ else:
681
+ priced, pressure_notes = metal.pressured(
682
+ metal.reclaimed(facts) if metal.supported(facts) else facts
282
683
  )
283
- for role in stack_picks.ROLES:
284
- choices[role], warnings = _choice(priced, {**options, "prefer": role}, role)
285
- notes.extend(w for w in warnings if w not in notes)
286
- smart, fast = choices["smartest"], choices["fastest"]
287
- if smart is not None and fast is not None:
288
- if fast["id"] == smart["id"] or (
289
- fast["decode_tok_s"] is not None
290
- and smart["decode_tok_s"] is not None
291
- and fast["decode_tok_s"] < smart["decode_tok_s"] * stack_picks.WORTH_FASTER
292
- ):
293
- choices["fastest"] = None
684
+ notes.extend(n for n in pressure_notes if n not in notes)
685
+ for role in roles:
686
+ choices[role], warnings = _choice(priced, {**options, "prefer": role}, role)
687
+ notes.extend(w for w in warnings if w not in notes)
688
+ smart, fast = choices["smartest"], choices["fastest"]
689
+ if smart is not None and fast is not None:
690
+ if fast["id"] == smart["id"] or (
691
+ fast["decode_tok_s"] is not None
692
+ and smart["decode_tok_s"] is not None
693
+ and fast["decode_tok_s"] < smart["decode_tok_s"] * stack_picks.WORTH_FASTER
694
+ ):
695
+ choices["fastest"] = None
294
696
  return {
295
697
  "capacity": {
296
698
  "platform": facts["platform"],
@@ -308,9 +710,14 @@ def report(
308
710
  *,
309
711
  reuse_from: tuple[str, ...] = (),
310
712
  base_dir: str = deploy.DEFAULT_BASE_DIR,
713
+ decision: str = "none",
714
+ prefer: str | None = None,
311
715
  ) -> Report:
312
716
  """Compare every independent upgrade with the baseline, never with the preceding step."""
313
- baseline = snapshot(facts, reuse_from=reuse_from, base_dir=base_dir)
717
+ roles = _roles(prefer)
718
+ baseline = snapshot(
719
+ facts, reuse_from=reuse_from, base_dir=base_dir, decision=decision, prefer=prefer
720
+ )
314
721
  upgrades: list[Upgrade] = []
315
722
 
316
723
  def add(
@@ -321,9 +728,11 @@ def report(
321
728
  seen: HostFacts,
322
729
  card: int | None = None,
323
730
  ) -> None:
324
- result = snapshot(seen, reuse_from=reuse_from, base_dir=base_dir)
731
+ result = snapshot(
732
+ seen, reuse_from=reuse_from, base_dir=base_dir, decision=decision, prefer=prefer
733
+ )
325
734
  changes = {}
326
- for role in stack_picks.ROLES:
735
+ for role in roles:
327
736
  old, new = baseline["choices"].get(role), result["choices"].get(role)
328
737
  if new is None:
329
738
  changes[role] = ["available"] if old is not None else []
@@ -373,6 +782,7 @@ def report(
373
782
  held = gpu["total_bytes"] - gpu["free_bytes"]
374
783
  replacement = _card(gpu["index"], size * GIB, held)
375
784
  replacement["uuid"] = gpu["uuid"]
785
+ replacement["driver_version"] = gpu.get("driver_version", "")
376
786
  seen["gpus"] = [
377
787
  replacement if g["index"] == gpu["index"] else g for g in seen["gpus"]
378
788
  ]
@@ -391,7 +801,7 @@ def report(
391
801
  "upgrades": upgrades,
392
802
  "notes": [
393
803
  "Each upgrade is independent and compared with the starting hardware.",
394
- "Choices use stack plan --llm auto, with decision none and the default stack options. "
804
+ f"Choices use stack plan --llm auto, with decision {decision} and the default stack options. "
395
805
  "Strata-generated packs must already exist; --reuse-from reads an existing directory. "
396
806
  "Ports and previously running deployments are not assumed.",
397
807
  "Hypothetical devices use class bandwidth estimates, without speculative decoding. "
@@ -430,6 +840,7 @@ def _label(choice: Choice | None) -> str:
430
840
  def render(data: Report) -> str:
431
841
  start = data["baseline"]
432
842
  capacity = start["capacity"]
843
+ roles = list(start["choices"])
433
844
  lines = [
434
845
  f"Starting hardware: {capacity['ram_total_bytes'] / GIB:g} GiB RAM "
435
846
  f"({capacity['ram_available_bytes'] / GIB:g} GiB available)"
@@ -439,7 +850,7 @@ def render(data: Report) -> str:
439
850
  f" GPU {gpu['index']}: {gpu['name']}, {gpu['total_bytes'] / GIB:g} GiB "
440
851
  f"({'Metal working set' if gpu['vendor'] == 'apple' else 'VRAM'})"
441
852
  )
442
- for role in stack_picks.ROLES:
853
+ for role in roles:
443
854
  lines.append(f" {role}: {_label(start['choices'].get(role))}")
444
855
  if (choice := start["choices"].get(role)) is not None and choice["engine"] != "llama.cpp":
445
856
  lines.append(f" {choice['reason']}")
@@ -463,7 +874,7 @@ def render(data: Report) -> str:
463
874
  continue
464
875
  shown.append((step["result"]["choices"], step["label"]))
465
876
  lines.append(step["label"])
466
- for role in stack_picks.ROLES:
877
+ for role in roles:
467
878
  before, after = start["choices"].get(role), step["result"]["choices"].get(role)
468
879
  if before != after:
469
880
  lines.append(f" {role}: {_label(before)} -> {_label(after)}")
@@ -481,6 +892,24 @@ def render(data: Report) -> str:
481
892
  return "\n".join(lines)
482
893
 
483
894
 
895
+ def simulation_from_args(args: argparse.Namespace) -> Simulation | None:
896
+ """Build a ``Simulation`` from parsed CLI arguments, or None when no extra knobs were set."""
897
+ platform = getattr(args, "platform", None)
898
+ cuda = getattr(args, "cuda", None)
899
+ raw_vram_used = getattr(args, "vram_used", None)
900
+ raw_ram_avail = getattr(args, "ram_available", None)
901
+ pressure = getattr(args, "pressure", None)
902
+ if all(v is None for v in (platform, cuda, raw_vram_used, raw_ram_avail, pressure)):
903
+ return None
904
+ return Simulation(
905
+ platform=platform,
906
+ cuda=cuda,
907
+ vram_used=parse_size(raw_vram_used) if raw_vram_used is not None else None,
908
+ ram_available=parse_size(raw_ram_avail) if raw_ram_avail is not None else None,
909
+ pressure=pressure,
910
+ )
911
+
912
+
484
913
  def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
485
914
  parser = actions.add_parser(
486
915
  "what-if", help="compare hardware upgrades and what they unlock (read-only)"
@@ -491,6 +920,43 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
491
920
  "--unified-memory", metavar="SIZE", help="simulate an Apple Silicon Mac, e.g. 24GiB"
492
921
  )
493
922
  parser.add_argument("--ram", metavar="SIZE", help="simulate host RAM, e.g. 64GiB")
923
+ parser.add_argument(
924
+ "--platform",
925
+ choices=("linux", "windows", "macos"),
926
+ help="simulate target OS platform (linux, windows or macos)",
927
+ )
928
+ parser.add_argument(
929
+ "--cuda",
930
+ metavar="VER",
931
+ help="simulate NVIDIA driver CUDA capability, e.g. 13.0 or 12.8",
932
+ )
933
+ parser.add_argument(
934
+ "--vram-used",
935
+ metavar="SIZE",
936
+ help="simulate VRAM already held by desktop/WDDM or other apps, e.g. 2GiB",
937
+ )
938
+ parser.add_argument(
939
+ "--ram-available",
940
+ metavar="SIZE",
941
+ help="simulate currently available host or unified memory, e.g. 18GiB",
942
+ )
943
+ parser.add_argument(
944
+ "--pressure",
945
+ type=int,
946
+ choices=PRESSURE_LEVELS,
947
+ help="simulate macOS VM memory pressure (1 normal, 2 warning, 4 critical)",
948
+ )
949
+ parser.add_argument(
950
+ "--prefer",
951
+ choices=PREFERENCES,
952
+ help="focus preference (smartest, fastest, concurrent or fast)",
953
+ )
954
+ parser.add_argument(
955
+ "--decision",
956
+ default="none",
957
+ choices=DECISIONS,
958
+ help="include GPU decision model reservation (default %(default)s)",
959
+ )
494
960
  parser.add_argument(
495
961
  "--facts", type=Path, metavar="FILE", help="read saved facts without probing"
496
962
  )
@@ -508,15 +974,29 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
508
974
  help="existing Strata model directory (read-only; repeatable)",
509
975
  )
510
976
  parser.add_argument("--json", action="store_true", help=f"print {SCHEMA} JSON")
977
+ parser.add_argument(
978
+ "--html",
979
+ metavar="PATH",
980
+ help="write a self-contained interactive recommendation simulator HTML page and exit",
981
+ )
511
982
  cli_help.document(
512
983
  parser,
513
984
  "Compare independent RAM +16/+32/+64 GiB and larger VRAM tiers, or the next Mac "
514
985
  "unified-memory tier, using stack plan's auto LLM selection. "
515
- "Fully specified simulations need no probe. No facts or plans are saved.",
986
+ "Fully specified simulations need no probe. No facts or plans are saved. "
987
+ "--html generates an offline interactive simulator backed by the live planner.",
516
988
  examples=[
517
989
  ("%(prog)s", "compare upgrades from this computer's readings"),
518
990
  ("%(prog)s --vram 24GiB --ram 64GiB", "simulate a card and RAM without probing"),
519
- ("%(prog)s --unified-memory 24GiB --json", "simulate a Mac without probing"),
991
+ (
992
+ "%(prog)s --platform windows --vram 8GiB --ram 32GiB --vram-used 2GiB",
993
+ "simulate Windows 8 GiB NVIDIA with WDDM overhead",
994
+ ),
995
+ (
996
+ "%(prog)s --unified-memory 24GiB --ram-available 18GiB --pressure 2 --json",
997
+ "simulate a 24 GiB Mac under warning memory pressure",
998
+ ),
999
+ ("%(prog)s --html whatif-simulator.html", "write the interactive HTML simulator"),
520
1000
  ("%(prog)s --facts host.json", "compare from saved hardware facts"),
521
1001
  (
522
1002
  "%(prog)s --vram 24GiB --ram 32GiB --reuse-from DIR",
@@ -524,7 +1004,7 @@ def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) ->
524
1004
  ),
525
1005
  ],
526
1006
  sections=[
527
- ("output", f"changes in both choices; --json: {SCHEMA}, sizes in bytes"),
1007
+ ("output", f"changes in both choices; --json: {SCHEMA}, sizes in bytes; --html: page"),
528
1008
  ("exit status", "0 printed, even when no model fits; 2 bad input or unreadable facts"),
529
1009
  ],
530
1010
  )
@@ -537,15 +1017,18 @@ def cli(args: argparse.Namespace) -> int:
537
1017
  ram=parse_size(args.ram) if args.ram else None,
538
1018
  unified=parse_size(args.unified_memory) if args.unified_memory else None,
539
1019
  )
1020
+ sim = simulation_from_args(args)
540
1021
  facts = (
541
1022
  decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
542
1023
  if args.facts
543
1024
  else None
544
1025
  )
545
1026
  data = report(
546
- starting_facts(machine, facts),
1027
+ starting_facts(machine, facts, sim),
547
1028
  reuse_from=tuple(args.reuse_from),
548
1029
  base_dir=args.base_dir,
1030
+ decision=getattr(args, "decision", "none"),
1031
+ prefer=getattr(args, "prefer", None),
549
1032
  )
550
1033
  except (OSError, ValueError, StackError) as exc:
551
1034
  print(f"stack what-if: {exc}", file=sys.stderr)