@simplexai/localmodels-linux-x64 0.1.0-dev.50 → 0.1.0-dev.52

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 (40) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +38 -38
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/catalog.json +1988 -16
  5. package/modules/localmodels/catalog_recipes.py +47 -8
  6. package/modules/localmodels/contracts.py +96 -37
  7. package/modules/localmodels/deploy.py +29 -134
  8. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +132 -0
  9. package/modules/localmodels/engines.py +18 -2
  10. package/modules/localmodels/gateway_bifrost.py +9 -0
  11. package/modules/localmodels/harness_probe.py +38 -22
  12. package/modules/localmodels/library_gateway.py +132 -1
  13. package/modules/localmodels/library_model.py +5 -0
  14. package/modules/localmodels/library_poly.py +59 -0
  15. package/modules/localmodels/library_status.py +96 -31
  16. package/modules/localmodels/plan_envelope.py +234 -3
  17. package/modules/localmodels/process_identity.py +19 -9
  18. package/modules/localmodels/process_identity_darwin.py +155 -0
  19. package/modules/localmodels/remote_ops_service.py +11 -13
  20. package/modules/localmodels/runtime_cli.py +8 -8
  21. package/modules/localmodels/runtime_install.py +25 -1
  22. package/modules/localmodels/source_cli.py +9 -1
  23. package/modules/localmodels/stack.py +0 -5
  24. package/modules/localmodels/stack_binding.py +6 -2
  25. package/modules/localmodels/stack_cli.py +39 -0
  26. package/modules/localmodels/stack_compose.py +12 -43
  27. package/modules/localmodels/stack_plan.py +58 -5
  28. package/modules/localmodels/stack_suite.py +51 -12
  29. package/modules/localmodels/{strata-poly-serve-0.1.45-poly.9.txt → strata-poly-serve-0.2.20-poly.1.txt} +2 -2
  30. package/modules/localmodels/strata_poly_server.py +19 -0
  31. package/modules/localmodels/suite.py +45 -8
  32. package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/METADATA +1 -1
  33. package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/RECORD +35 -35
  34. package/package.json +1 -1
  35. package/tool.json +1 -1
  36. package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +0 -75
  37. /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/WHEEL +0 -0
  38. /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/entry_points.txt +0 -0
  39. /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/licenses/NOTICE +0 -0
  40. /package/modules/{simplex_localmodels-0.1.0.dev50.dist-info → simplex_localmodels-0.1.0.dev52.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -365,7 +365,11 @@ def _library_binding(
365
365
  if not executable.is_absolute() or not profile.is_absolute():
366
366
  raise ValueError("Pi paths must be absolute")
367
367
  fingerprint = _profile_fingerprint(executable, profile)
368
- if any(component not in adopted for component, _ in stack_verify.parts(plan)):
368
+ unadopted = any(component not in adopted for component, _ in stack_verify.parts(plan))
369
+ pi_points_magpie = harness.gateway_kind(gateway) != "bifrost" and (
370
+ bifrost_pi.pi_model(profile) or ""
371
+ ).startswith("magpie/")
372
+ if unadopted or pi_points_magpie:
369
373
  if harness.gateway_kind(gateway) == "bifrost":
370
374
  record = owned["gateway"].get("bifrost")
371
375
  if not record or record["addr"] != gateway["addr"]:
@@ -375,7 +379,7 @@ def _library_binding(
375
379
  ):
376
380
  return _reason("gateway-unavailable", lang)
377
381
  else:
378
- if owned["gateway"]["group"] != gateway["group"]:
382
+ if unadopted and owned["gateway"]["group"] != gateway["group"]:
379
383
  return _reason("gateway-ownership", lang)
380
384
  magpie = harness.tool_path(plan["harness"], "magpie")
381
385
  env = {
@@ -6,6 +6,7 @@ import argparse
6
6
  import contextlib
7
7
  import json
8
8
  import os
9
+ import re
9
10
  import sys
10
11
  from collections.abc import Callable
11
12
  from pathlib import Path
@@ -14,6 +15,7 @@ from typing import Any
14
15
  from localmodels import (
15
16
  app,
16
17
  console,
18
+ deploy,
17
19
  harness,
18
20
  hosts,
19
21
  stack_arena,
@@ -210,6 +212,41 @@ def apply_cli(
210
212
  return report(record, timing=shown.timing() if shown else None)
211
213
 
212
214
 
215
+ _PLAN_ERROR_CODES = frozenset(
216
+ {
217
+ "HUB_UNREACHABLE",
218
+ "MEMORY_INSUFFICIENT",
219
+ "DISK_INSUFFICIENT",
220
+ "GPU_CONFLICT",
221
+ }
222
+ )
223
+ _SAFE_HOST = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?(?::[0-9]{1,5})?$")
224
+
225
+
226
+ def _plan_error_payload(exc: BaseException) -> dict[str, object]:
227
+ """Structured, path-free error document for ``stack plan --json`` failures."""
228
+ raw_code = getattr(exc, "cause_code", None)
229
+ code = (
230
+ raw_code
231
+ if isinstance(raw_code, str) and raw_code in _PLAN_ERROR_CODES
232
+ else "STACK_PLAN_FAILED"
233
+ )
234
+ payload: dict[str, object] = {
235
+ "schema": "localmodels.stack-plan-error/v1",
236
+ "event": "error",
237
+ "code": code,
238
+ }
239
+ if isinstance(exc, deploy.HubUnreachableError):
240
+ hosts_tried = [
241
+ host
242
+ for host, _ in exc.failures
243
+ if isinstance(host, str) and len(host) <= 253 and _SAFE_HOST.fullmatch(host)
244
+ ]
245
+ if hosts_tried:
246
+ payload["hosts"] = list(dict.fromkeys(hosts_tried))
247
+ return payload
248
+
249
+
213
250
  def run_cli(
214
251
  args: argparse.Namespace,
215
252
  *,
@@ -284,5 +321,7 @@ def run_cli(
284
321
  ) as exc:
285
322
  if getattr(args, "jsonl", False):
286
323
  return stack_progress.error(2, guard_details(exc))
324
+ if args.stack_command == "plan" and getattr(args, "json", False):
325
+ print(json.dumps(_plan_error_payload(exc), separators=(",", ":")))
287
326
  print(f"stack: {exc}", file=sys.stderr)
288
327
  return 2
@@ -48,7 +48,7 @@ from localmodels import stack_gpu_memory as gpu_memory
48
48
  from localmodels import stack_hardware as hardware
49
49
  from localmodels import stack_llm_ram as llm_ram
50
50
  from localmodels.approval import digest
51
- from localmodels.budget import gib, host_ram, placements
51
+ from localmodels.budget import gib, host_ram
52
52
  from localmodels.context_policy import AGENT, AgentPosture, posture_for, window_k
53
53
  from localmodels.plan_envelope import PlanError, require_free_port, utc_now
54
54
  from localmodels.probe import HostFacts
@@ -63,6 +63,7 @@ from localmodels.stack_plan import (
63
63
  command,
64
64
  download_budget,
65
65
  is_redeploy,
66
+ no_fit_reason,
66
67
  own_name,
67
68
  platform_error,
68
69
  ram_floor,
@@ -360,53 +361,17 @@ def _choose_llm(
360
361
  " (with the smallest decision reserve)" if options.get("decision", "none") != "none" else ""
361
362
  )
362
363
  avail = (reclaimed_ram() if callable(reclaimed_ram) else reclaimed_ram) if vram_fit else 0
363
- reason = _no_fit_reason(facts, cards, mac, vram_fit=vram_fit, reclaimed_ram=avail)
364
+ reason, cause_code = no_fit_reason(facts, cards, mac, vram_fit=vram_fit, reclaimed_ram=avail)
364
365
  raise StackError(
365
366
  stack_capacity.no_default_reason(facts, options, posture)
366
367
  + f"no verified LLM fits {where} in the agent posture "
367
368
  f"({window_k(posture.floor)} floor){reserve}{reason}; "
368
369
  "name a catalog model with --llm (other candidates are not ranked automatically), "
369
- f"see each card with {command()} stack hardware"
370
+ f"see each card with {command()} stack hardware",
371
+ cause_code=cause_code,
370
372
  )
371
373
 
372
374
 
373
- def _no_fit_reason(
374
- facts: HostFacts,
375
- cards: list[int],
376
- mac: bool,
377
- *,
378
- vram_fit: bool = False,
379
- reclaimed_ram: int = 0,
380
- ) -> str:
381
- gpus = {g["index"]: g for g in facts.get("gpus") or []}
382
- if mac or not gpus:
383
- return ""
384
- if not cards:
385
- eligible = [
386
- p
387
- for p in placements(facts)
388
- if not p.pooled and not p.budget.uma and len(p.gpu_indices) == 1
389
- ]
390
- if not eligible:
391
- return ": no supported single-card GPU placement"
392
- if not all(p.conflicts for p in eligible):
393
- return ": no GPU meets automatic selection requirements; check GPU service discovery"
394
- free = ", ".join(
395
- f"GPU {p.gpu_indices[0]} {gib(gpus[p.gpu_indices[0]]['free_bytes'])} free"
396
- for p in eligible
397
- )
398
- return (
399
- f": every placeable card has other GPU work ({free}), and --llm auto skips "
400
- "such cards; plan again once they end, or, if sharing is fine and that card has "
401
- "room, use --gpu N --share-gpu"
402
- )
403
- if vram_fit:
404
- avail = gib(host_ram(facts, reclaimed_bytes=reclaimed_ram)[1])
405
- return f": not enough available RAM ({avail} available)"
406
- best = gpus[cards[0]]
407
- return f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free"
408
-
409
-
410
375
  def _foundation_reserve(facts: HostFacts, options: StackOptions, aux: list[Plan]) -> int:
411
376
  """The RAM the named foundations hold back before the LLM is chosen: on unified memory only,
412
377
  where they share the pool with the LLM and its cache; a CPU auxiliary beside an NVIDIA card
@@ -452,7 +417,10 @@ def _gpu_conflicts(llm: Plan, facts: HostFacts, share_gpu: bool) -> list[str]:
452
417
  """Another program holding or serving on the LLM's card needs the operator's consent."""
453
418
  busy = approval.busy_gpus(llm, facts)
454
419
  if busy and not share_gpu:
455
- raise StackError("; ".join(busy) + "; if sharing is fine, plan again with --share-gpu")
420
+ raise StackError(
421
+ "; ".join(busy) + "; if sharing is fine, plan again with --share-gpu",
422
+ cause_code="GPU_CONFLICT",
423
+ )
456
424
  return [f"sharing per --share-gpu: {b}" for b in busy]
457
425
 
458
426
 
@@ -543,7 +511,7 @@ def _llama_parts(
543
511
  resource_template=options.get("defer_services", False),
544
512
  )
545
513
  except PlanError as exc:
546
- raise StackError(str(exc)) from None
514
+ raise StackError(str(exc), cause_code=getattr(exc, "cause_code", None)) from None
547
515
  llm = choice["llm"] or llm
548
516
  served = choice["front"] or choice["plan"]
549
517
  if served is not None and not options.get("defer_services"):
@@ -609,7 +577,8 @@ def ram_budget(parts: Parts) -> dict[str, int]:
609
577
  f", short about {gib(ram_needed - available)}; primary window is unchanged"
610
578
  if fast is not None
611
579
  else ""
612
- )
580
+ ),
581
+ cause_code="MEMORY_INSUFFICIENT",
613
582
  )
614
583
  return ram_parts
615
584
 
@@ -15,7 +15,7 @@ from typing import Literal, TypedDict, cast
15
15
  from localmodels import approval, deploy, gateway, harness, hosts, preparation, reuse, vision
16
16
  from localmodels.budget import HARNESS_RAM as HARNESS_RAM
17
17
  from localmodels.budget import RAM_FLOOR as RAM_FLOOR
18
- from localmodels.budget import gib
18
+ from localmodels.budget import gib, host_ram, placements
19
19
  from localmodels.gateway_bifrost import FAST_PROVIDER
20
20
  from localmodels.plan_envelope import PlanError, resolved_name
21
21
  from localmodels.plan_envelope import verified_in_place as verified_in_place
@@ -49,6 +49,10 @@ def ram_floor(metal: bool) -> int:
49
49
  class StackError(RuntimeError):
50
50
  """The stack cannot be planned or applied as asked; the message says why."""
51
51
 
52
+ def __init__(self, message: str, *, cause_code: str | None = None) -> None:
53
+ super().__init__(message)
54
+ self.cause_code = cause_code
55
+
52
56
 
53
57
  class StackGuardError(StackError):
54
58
  """An approval guard with structured, separately sanitized public diagnostics."""
@@ -61,7 +65,7 @@ class StackGuardError(StackError):
61
65
  changed_fields: tuple[str, ...] = (),
62
66
  public_message: str = "",
63
67
  ) -> None:
64
- super().__init__(message)
68
+ super().__init__(message, cause_code=cause_code)
65
69
  self.cause_code = cause_code
66
70
  self.changed_fields = changed_fields
67
71
  # A literal, path-free sentence the machine result may carry; never the message itself.
@@ -409,8 +413,9 @@ class StackRecord(_RunFields):
409
413
 
410
414
 
411
415
  def default_gateway(platform: str = sys.platform) -> str:
412
- """Bifrost, except on Windows: no Windows Bifrost build is pinned, Magpie's is (decision 32)."""
413
- return "magpie" if platform == "win32" else harness.DEFAULT_GATEWAY
416
+ """This tool's Bifrost on every supported platform (Linux, macOS, Windows x64; WHI-973)."""
417
+ _ = platform
418
+ return harness.DEFAULT_GATEWAY
414
419
 
415
420
 
416
421
  def default_options() -> StackOptions:
@@ -618,7 +623,8 @@ def download_budget(
618
623
  if free is not None and disk_needed > free:
619
624
  raise StackError(
620
625
  f"not enough disk space: the stack needs about {gib(disk_needed)}, "
621
- f"{facts['disk']['path']} has only {gib(free)} free"
626
+ f"{facts['disk']['path']} has only {gib(free)} free",
627
+ cause_code="DISK_INSUFFICIENT",
622
628
  )
623
629
  return {
624
630
  "disk_free_bytes": free,
@@ -650,3 +656,50 @@ def engine_line(part: Plan) -> str:
650
656
  f" engine {release['build']} ({release['commit'][:8]}), {release['backend']}"
651
657
  + "".join(f", {n}" for n in needs if n)
652
658
  )
659
+
660
+
661
+ def no_fit_reason(
662
+ facts: HostFacts,
663
+ cards: list[int],
664
+ mac: bool,
665
+ *,
666
+ vram_fit: bool = False,
667
+ reclaimed_ram: int = 0,
668
+ ) -> tuple[str, str | None]:
669
+ """Explain why no verified auto LLM fit and classify the refusal for structured callers."""
670
+ gpus = {g["index"]: g for g in facts.get("gpus") or []}
671
+ if mac:
672
+ return "", "MEMORY_INSUFFICIENT"
673
+ if not gpus:
674
+ return "", None
675
+ if not cards:
676
+ eligible = [
677
+ p
678
+ for p in placements(facts)
679
+ if not p.pooled and not p.budget.uma and len(p.gpu_indices) == 1
680
+ ]
681
+ if not eligible:
682
+ return ": no supported single-card GPU placement", None
683
+ if not all(p.conflicts for p in eligible):
684
+ return (
685
+ ": no GPU meets automatic selection requirements; check GPU service discovery",
686
+ None,
687
+ )
688
+ free = ", ".join(
689
+ f"GPU {p.gpu_indices[0]} {gib(gpus[p.gpu_indices[0]]['free_bytes'])} free"
690
+ for p in eligible
691
+ )
692
+ return (
693
+ f": every placeable card has other GPU work ({free}), and --llm auto skips "
694
+ "such cards; plan again once they end, or, if sharing is fine and that card has "
695
+ "room, use --gpu N --share-gpu",
696
+ "GPU_CONFLICT",
697
+ )
698
+ if vram_fit:
699
+ avail = gib(host_ram(facts, reclaimed_bytes=reclaimed_ram)[1])
700
+ return f": not enough available RAM ({avail} available)", "MEMORY_INSUFFICIENT"
701
+ best = gpus[cards[0]]
702
+ return (
703
+ f": the roomiest GPU {cards[0]} has only {gib(best['free_bytes'])} free",
704
+ "MEMORY_INSUFFICIENT",
705
+ )
@@ -18,7 +18,7 @@ from localmodels import stack_decision as decide
18
18
  from localmodels import stack_gpu_memory as gpu_memory
19
19
  from localmodels import stack_hardware as hardware
20
20
  from localmodels import stack_llm_ram as llm_ram
21
- from localmodels.budget import gib, holders, host_ram, idle_cards, sharing_cards
21
+ from localmodels.budget import busy_cards, gib, holders, host_ram, idle_cards, sharing_cards
22
22
  from localmodels.context_policy import AgentPosture
23
23
  from localmodels.engines import engine_lock_path
24
24
  from localmodels.plan_envelope import PlanError
@@ -160,9 +160,9 @@ def poly_reserve_mib(recipe: suite.SuiteRecipe, gpu: GPU, beside_mib: int) -> in
160
160
 
161
161
 
162
162
  def auto_strata_wanted(facts: HostFacts, options: StackOptions) -> bool:
163
- """Whether ``--llm auto`` also weighs Strata recipes: on Linux and Windows (Strata has no
164
- macOS build; on Windows only recipes whose engine has a Windows build, see
165
- auto_strata_candidates), and not for ``--prefer concurrent``, because a Strata recipe whose
163
+ """Whether ``--llm auto`` also weighs Strata recipes: on Linux and Windows (a Mac runs a
164
+ strata-poly recipe that ``--llm`` names, and none is validated there; on Windows only
165
+ recipes whose engine has a Windows build, see auto_strata_candidates), and not for ``--prefer concurrent``, because a Strata recipe whose
166
166
  experts stay in RAM gains nothing from a second request (GY1), nor under ``--context``: a
167
167
  Strata recipe fixes its own window."""
168
168
  return (
@@ -230,6 +230,23 @@ def strata_recipe(facts: HostFacts, requested: str) -> tuple[suite.SuiteRecipe |
230
230
  ]
231
231
 
232
232
 
233
+ METAL_BESIDE_BYTES = 12 << 30
234
+
235
+
236
+ def unified_bytes(recipe: suite.SuiteRecipe) -> int:
237
+ """What a strata-poly LLM holds on a Mac, where every expert stays in unified memory: its
238
+ files and METAL_BESIDE_BYTES (PS219, M5 Ultra, prompts up to 58K tokens: the engine held 1.4
239
+ to 4.4 GiB beside them; --conversation-cache-mib auto parks up to 8 GiB more)."""
240
+ return sum(f["size_bytes"] for f in recipe["files"] if not f.get("vision")) + METAL_BESIDE_BYTES
241
+
242
+
243
+ def _on_unified_memory(llm: Plan, recipe: suite.SuiteRecipe) -> Plan:
244
+ """The plan on a Mac: priced whole and once (``launch.unified_bytes``), no cgroup ceiling."""
245
+ added = int(str(llm["launch"]["memory_estimate_bytes"])) - recipe["memory_estimate_bytes"]
246
+ llm["launch"]["unified_bytes"] = unified_bytes(recipe) + added
247
+ return suite.unbounded(llm)
248
+
249
+
233
250
  def _suite_gpu(
234
251
  facts: HostFacts,
235
252
  llm: suite.SuiteRecipe,
@@ -255,6 +272,17 @@ def _suite_gpu(
255
272
  )
256
273
  if found is not None:
257
274
  return found
275
+ mac = metal.device(facts) if llm["runtime"] == "strata-poly" else None # Strata is CUDA only
276
+ if mac is not None: # one Metal GPU on unified memory
277
+ if gpu not in (None, 0):
278
+ raise StackError(f"this computer has one Metal GPU (GPU 0), no GPU {gpu}")
279
+ busy = busy_cards(facts, [mac["uuid"]])
280
+ if busy and not share_gpu:
281
+ raise StackError("; ".join(busy) + "; if sharing is fine, plan again with --share-gpu")
282
+ if mac["free_bytes"] < need:
283
+ free = gib(mac["free_bytes"])
284
+ raise StackError(f"{llm['id']} needs {gib(need)} of unified memory, {free} is free")
285
+ return mac
258
286
  candidates = sharing_cards(facts, need) if share_gpu else idle_cards(facts, need)
259
287
  cards = [g for g in candidates if gpu is None or g["index"] == gpu]
260
288
  if not cards:
@@ -296,7 +324,8 @@ def strata_parts(
296
324
  except PlanError as exc:
297
325
  raise StackError(f"{exc}; cannot share a card with {llm_recipe['id']}") from None
298
326
  vram = pick.tier["vram_bytes"] if pick else 0
299
- need = int(llm_recipe.get("vram_bytes", 0))
327
+ unified = metal.supported(facts) and llm_recipe["runtime"] == "strata-poly"
328
+ need = unified_bytes(llm_recipe) if unified else int(llm_recipe.get("vram_bytes", 0))
300
329
  gpu = _suite_gpu(
301
330
  facts, llm_recipe, need, running_llm, options.get("gpu"), share_gpu=options["share_gpu"]
302
331
  )
@@ -336,7 +365,9 @@ def strata_parts(
336
365
  reasoning_budget=int(options.get("reasoning_budget") or 0),
337
366
  )
338
367
  llm = running_llm or suite.build_plan(hosts.LOCAL_ID, facts, llm_recipe, opts)
339
- if not running_llm and facts["platform"] == "win32":
368
+ if not running_llm and unified:
369
+ llm = _on_unified_memory(llm, llm_recipe)
370
+ elif not running_llm and facts["platform"] == "win32":
340
371
  llm = suite.unbounded(llm) # no cgroups: priced by the recipe's estimate
341
372
  if running_llm:
342
373
  warnings.append(
@@ -359,7 +390,12 @@ def strata_parts(
359
390
 
360
391
  ceiling = suite.size_bytes(options["suite_memory"])
361
392
  available = host_ram(facts, reclaimed_bytes=owned_ram())[1]
362
- used = bounded_ram(llm) + decide.host_ram(choice) + HARNESS_RAM
393
+ floor = ram_floor(unified)
394
+
395
+ def held(plan: Plan) -> int:
396
+ return int(str(plan["launch"]["unified_bytes"])) if unified else bounded_ram(plan)
397
+
398
+ used = held(llm) + decide.host_ram(choice) + HARNESS_RAM
363
399
  aux = fit_aux(
364
400
  aux_plans(facts, options, listening, previous, warnings, approved=approved),
365
401
  used,
@@ -367,21 +403,24 @@ def strata_parts(
367
403
  ceiling,
368
404
  available,
369
405
  warnings,
406
+ floor=floor,
370
407
  )
371
- room = min(ceiling, available - RAM_FLOOR) - used - sum(bounded_ram(p) for p in aux)
408
+ room = min(ceiling, available - floor) - used - sum(bounded_ram(p) for p in aux)
372
409
  llm = _decide_parking(
373
410
  llm, llm_recipe, facts, opts, options, running_llm is not None, room, warnings
374
411
  )
375
- whole = bounded_ram(llm) + decide.host_ram(choice) + sum(map(bounded_ram, aux)) + HARNESS_RAM
412
+ if unified and "unified_bytes" not in llm["launch"]: # parking planned the LLM again
413
+ llm = _on_unified_memory(llm, llm_recipe)
414
+ whole = held(llm) + decide.host_ram(choice) + sum(map(bounded_ram, aux)) + HARNESS_RAM
376
415
  if whole > ceiling:
377
416
  raise StackError(
378
417
  f"the whole-stack estimate {gib(whole)} exceeds --suite-memory {options['suite_memory']}"
379
418
  )
380
- if options["llm"] == "auto" and not running_llm and whole + RAM_FLOOR > available:
419
+ if options["llm"] == "auto" and not running_llm and whole + floor > available:
381
420
  # stack_compose.assemble would refuse this plan outright; refusing here lets auto move
382
421
  # on to a smaller recipe or to llama.cpp.
383
422
  raise StackError(
384
- f"its stack needs about {gib(whole + RAM_FLOOR)} of RAM, {gib(available)} is available"
423
+ f"its stack needs about {gib(whole + floor)} of RAM, {gib(available)} is available"
385
424
  )
386
425
  vram_needed = need + vram
387
426
  if vram_needed > gpu["total_bytes"]:
@@ -392,7 +431,7 @@ def strata_parts(
392
431
  return {
393
432
  "llm": llm,
394
433
  "llm_running": running_llm is not None,
395
- "llm_ram": bounded_ram(llm),
434
+ "llm_ram": held(llm),
396
435
  "decision": choice,
397
436
  "aux": aux,
398
437
  "ram_available": available,
@@ -1,7 +1,7 @@
1
- # PolyStrata 0.1.45-poly.9's Python server (serve/server.py, MIT) for strata-poly LLM recipes:
1
+ # PolyStrata 0.2.20-poly.1's Python server (terminal/serve/server.py, MIT) for strata-poly LLM recipes:
2
2
  # jinja2 3.1.6 (BSD-3-Clause) with markupsafe 3.0.3 (BSD-3-Clause) renders the chat template,
3
3
  # regex 2026.9.10 (Apache-2.0 and CNRI-Python) drives its tokenizer, psutil 7.2.2 (BSD-3-Clause)
4
- # reads memory for its status page. The versions are PolyStrata's own requirements.txt pins; its
4
+ # reads memory for its status page. The versions are PolyStrata's own terminal/requirements.txt pins, unchanged since 0.1.45-poly.9; its
5
5
  # build tools, numpy, pillow (images are off in these recipes) and download helpers are left out.
6
6
  # Installed by localmodels/frontend.py with --require-hashes --no-deps. Regenerate with
7
7
  # uv pip compile --universal --python-version 3.10 --generate-hashes --no-header --no-annotate
@@ -24,6 +24,7 @@ import argparse
24
24
  import json
25
25
  import os
26
26
  import runpy
27
+ import shutil
27
28
  import subprocess
28
29
  import sys
29
30
  from pathlib import Path
@@ -54,6 +55,23 @@ def prepare(engine_dir: Path, gguf: Path, deploy_dir: Path) -> None:
54
55
  )
55
56
  if not tokenizer_ready(deploy_dir):
56
57
  raise SystemExit(f"{tool} wrote no tokenizer into {deploy_dir}")
58
+ # A GGUF without a chat template of its own: the recipe ships the model's beside it.
59
+ own, written = (
60
+ gguf.parent / "chat_template.jinja",
61
+ deploy_dir / "tokenizer" / "chat_template.jinja",
62
+ )
63
+ if own.is_file() and not written.exists():
64
+ shutil.copyfile(own, written)
65
+
66
+
67
+ def seed_expert_profile(engine_dir: Path, config: Path) -> None:
68
+ """The engine keeps its expert counts in the deployment's ``expert-profile.txt``. For a model
69
+ PolyStrata ships counts for (the profile's ``shipped_expert_profile``), that file starts as
70
+ the shipped one, as upstream's setup has it."""
71
+ shipped = json.loads(config.read_text(encoding="utf-8")).get("shipped_expert_profile")
72
+ own = config.parent / "expert-profile.txt"
73
+ if shipped and not own.exists():
74
+ shutil.copyfile(source_root(engine_dir) / shipped, own)
57
75
 
58
76
 
59
77
  def _expanded(value: object, home: str) -> object:
@@ -115,6 +133,7 @@ def main(argv: list[str] | None = None) -> None:
115
133
  root = str(source_root(args.engine_dir).resolve())
116
134
  if root not in sys.path:
117
135
  sys.path.insert(0, root)
136
+ seed_expert_profile(args.engine_dir, args.config)
118
137
  sys.argv = server_argv(args.engine_dir, resolve(args.config), args.host, args.port)
119
138
  runpy.run_path(sys.argv[0], run_name="__main__")
120
139
 
@@ -13,6 +13,7 @@ ceiling stands for the whole suite (the 24 GB + 64 GB tier keeps it under 64 GB)
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
+ import copy
16
17
  import json
17
18
  import subprocess
18
19
  import sys
@@ -91,6 +92,12 @@ class ExpertCacheSizing(TypedDict):
91
92
  source: str # where the terms were measured
92
93
 
93
94
 
95
+ class CardArgs(TypedDict, total=False):
96
+ at_least_bytes: int
97
+ platforms: list[str] # only on these (facts["platform"]); every platform when absent
98
+ args: list[str]
99
+
100
+
94
101
  class SuiteRecipe(cat.ComponentRecipe, total=False):
95
102
  """A catalog component the suite launches from a template (see module docstring)."""
96
103
 
@@ -108,6 +115,9 @@ class SuiteRecipe(cat.ComponentRecipe, total=False):
108
115
  # strata-poly recipes: what the engine keeps free of the card (--vram-reserve-mib) for the
109
116
  # display and its own overshoot of that reserve.
110
117
  vram_reserve_mib: int
118
+ # strata-poly recipes: engine flags given only to a card with room to spare (``at_least_bytes``
119
+ # of the card less the reserve) or only on some platforms, appended to the profile's args.
120
+ card_args: list[CardArgs]
111
121
  limits: dict[str, str]
112
122
  env: dict[str, str]
113
123
  argv: list[str]
@@ -154,15 +164,26 @@ class SuiteOptions:
154
164
  slice_limits: dict[str, str] = field(default_factory=dict)
155
165
 
156
166
 
167
+ _RECIPES_CACHE: dict[Path, tuple[int, int, list[SuiteRecipe]]] = {}
168
+
169
+
170
+ def _cached_suite_recipes() -> list[SuiteRecipe]:
171
+ resolved = cat.CATALOG_PATH.resolve()
172
+ stat = resolved.stat()
173
+ cached = _RECIPES_CACHE.get(resolved)
174
+ if cached is not None and cached[0] == stat.st_mtime_ns and cached[1] == stat.st_size:
175
+ return cached[2]
176
+ raw = json.loads(resolved.read_text(encoding="utf-8"))
177
+ out = [r for r in decode(raw.get("components", []), list[SuiteRecipe]) if "argv" in r]
178
+ _RECIPES_CACHE[resolved] = (stat.st_mtime_ns, stat.st_size, out)
179
+ return out
180
+
181
+
157
182
  def recipes(task: str | None = None, runtime: str | None = None) -> list[SuiteRecipe]:
158
- raw = json.loads(cat.CATALOG_PATH.read_text(encoding="utf-8"))
159
- out = decode(raw.get("components", []), list[SuiteRecipe])
160
183
  return [
161
- r
162
- for r in out
163
- if (task is None or r["task"] == task)
164
- and (runtime is None or r["runtime"] == runtime)
165
- and "argv" in r
184
+ copy.deepcopy(r)
185
+ for r in _cached_suite_recipes()
186
+ if (task is None or r["task"] == task) and (runtime is None or r["runtime"] == runtime)
166
187
  ]
167
188
 
168
189
 
@@ -332,6 +353,21 @@ def build_plan(host_id: str, facts: HostFacts, r: SuiteRecipe, options: SuiteOpt
332
353
  profile_template["vision"] = vision.strata_section(reader, cores, exe="{vision_exe}")
333
354
  if r["runtime"] == "strata":
334
355
  profile_template["args"] = [*cast("list[str]", profile_template["args"]), "--vision"]
356
+ if options.gpu and r.get("card_args"):
357
+ # Under --gpu-memory the reserve also holds what the share leaves out of the real card
358
+ # (stack_gpu_memory.LEFT_OUT, stack_suite.poly_reserve_mib), so the room is counted on it.
359
+ left_out = int(cast("dict[str, int]", options.gpu).get("share_left_out_bytes", 0))
360
+ room = options.gpu["total_bytes"] + left_out - (options.vram_reserve_mib << 20)
361
+ profile_template["args"] = [
362
+ *cast("list[str]", profile_template["args"]),
363
+ *(
364
+ a
365
+ for group in r["card_args"]
366
+ if room >= group["at_least_bytes"]
367
+ and facts["platform"] in group.get("platforms", [facts["platform"]])
368
+ for a in group["args"]
369
+ ),
370
+ ]
335
371
  if options.reasoning_budget and r["runtime"] == "strata":
336
372
  # strata-<model>.json's default for requests that name none (Strata DETAILS, v0.2.4).
337
373
  profile_template["reasoning_budget_tokens"] = options.reasoning_budget
@@ -468,7 +504,8 @@ def _readiness(plan: Plan, r: SuiteRecipe) -> None:
468
504
 
469
505
 
470
506
  def _check_runtime(facts: HostFacts, recipe: SuiteRecipe) -> None:
471
- if facts["platform"] == "darwin" and recipe["runtime"] in STRATA_RUNTIMES:
507
+ # PolyStrata's strata-poly has a Metal build; Strata's own engine is CUDA only.
508
+ if facts["platform"] == "darwin" and recipe["runtime"] == "strata":
472
509
  raise PlanError("Strata recipes need CUDA and cannot run on Apple Silicon Metal")
473
510
 
474
511
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simplex-localmodels
3
- Version: 0.1.0.dev50
3
+ Version: 0.1.0.dev52
4
4
  Summary: Detect hardware, recommend and install a verified local model stack
5
5
  License-Expression: LicenseRef-Proprietary
6
6
  License-File: NOTICE