@simplexai/localmodels-darwin-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
@@ -7,10 +7,11 @@ library_pricing, and the commands in library_jobs and library_serve.
7
7
 
8
8
  from __future__ import annotations
9
9
 
10
+ import datetime as dt
10
11
  import json
11
12
  import sys
12
- from collections.abc import Mapping
13
- from typing import Literal, TypedDict
13
+ from collections.abc import Mapping, Sequence
14
+ from typing import Literal, TypedDict, cast
14
15
 
15
16
  STATUS_SCHEMA = "localmodels.library-status/v1"
16
17
  EVENT_SCHEMA = "localmodels.library-event/v1"
@@ -19,6 +20,42 @@ CUSTOM_PROBE_SCHEMA = "localmodels.library-custom-probe/v1"
19
20
 
20
21
  ModelState = Literal["absent", "downloading", "idle", "loading", "loaded", "failed"]
21
22
  Engine = Literal["llama.cpp", "polystrata", "strata", "mlx"]
23
+ EngineDisplayName = Literal["llama.cpp", "PolyStrata", "Strata", "MLX"]
24
+ ENGINE_DISPLAY_NAMES: dict[Engine, EngineDisplayName] = {
25
+ "llama.cpp": "llama.cpp",
26
+ "polystrata": "PolyStrata",
27
+ "strata": "Strata",
28
+ "mlx": "MLX",
29
+ }
30
+ QuantMethod = Literal["gsq_rco", "unsloth_dynamic", "qat", "mlx", "standard"]
31
+ QUANT_METHODS = ("gsq_rco", "unsloth_dynamic", "qat", "mlx", "standard")
32
+ QuantFidelity = Literal[
33
+ "near_lossless", "high_fidelity_compact", "balanced", "compact", "ultra_compact"
34
+ ]
35
+ OffloadMode = Literal["gpu_resident", "hybrid_gpu_ram", "unified", "cpu"]
36
+ OFFLOAD_MODES = ("gpu_resident", "hybrid_gpu_ram", "unified", "cpu")
37
+ RecommendationReason = Literal[
38
+ "polystrata_engine",
39
+ "high_fidelity_compact_quant",
40
+ "near_lossless_quant",
41
+ "hybrid_gpu_ram_offload",
42
+ "fits_low_vram",
43
+ "smaller_footprint",
44
+ "long_context",
45
+ "best_quality_for_hardware",
46
+ "prefix_cache",
47
+ ]
48
+ RECOMMENDATION_REASONS = (
49
+ "polystrata_engine",
50
+ "high_fidelity_compact_quant",
51
+ "near_lossless_quant",
52
+ "hybrid_gpu_ram_offload",
53
+ "fits_low_vram",
54
+ "smaller_footprint",
55
+ "long_context",
56
+ "best_quality_for_hardware",
57
+ "prefix_cache",
58
+ )
22
59
  Fit = Literal["gpu", "unified", "system", "none"]
23
60
  Phase = Literal["download", "verify", "load", "warm", "smoke_test"]
24
61
  MemoryPressure = Literal["normal", "warn", "critical"]
@@ -279,6 +316,24 @@ class Load(TypedDict):
279
316
  total_steps: int
280
317
 
281
318
 
319
+ LOAD_BREAKDOWN_KEYS = (
320
+ "prepare_ms",
321
+ "engine_load_ms",
322
+ "touch_verify_ms",
323
+ "warm_ms",
324
+ "register_ms",
325
+ )
326
+ MAX_SAFE_COUNTER = 9007199254740991
327
+
328
+
329
+ class LoadBreakdownMs(TypedDict, total=False):
330
+ prepare_ms: int
331
+ engine_load_ms: int
332
+ touch_verify_ms: int
333
+ warm_ms: int
334
+ register_ms: int
335
+
336
+
282
337
  class _Endpoint(TypedDict):
283
338
  base_url: str
284
339
  gateway_model: str
@@ -362,6 +417,15 @@ class VerificationMeta(_VerificationMetaRequired, total=False):
362
417
  failure: VerificationFailure
363
418
 
364
419
 
420
+ class BaselineComparison(TypedDict):
421
+ """Savings and context delta relative to a larger sibling quantization in the same group."""
422
+
423
+ reference_quant: str
424
+ download_saved_bytes: int
425
+ memory_saved_bytes: int
426
+ context_delta_tokens: int
427
+
428
+
365
429
  class _Row(TypedDict):
366
430
  id: str
367
431
  name: str
@@ -414,8 +478,27 @@ class Row(_Row, total=False):
414
478
  custom: CustomRowMeta # present on custom hub models only
415
479
  verification: VerificationMeta # present on custom hub models only
416
480
  storage: Storage # on-disk file locations; absent when state is absent or no destinations exist
481
+ loaded_at: str | None # RFC3339 UTC timestamp when current load became ready (loaded only)
482
+ uptime_s: int | None # elapsed seconds since loaded_at, computed dynamically (loaded only)
483
+ load_duration_ms: int | None # total end-to-end duration of the load in ms (loaded only)
484
+ load_breakdown_ms: LoadBreakdownMs | None # per-phase load timing breakdown in ms (loaded only)
485
+ cold_load: bool | None # True/False when reliably determinable, else null (loaded only)
417
486
  error: Problem # failed only
418
487
  note: Note # idle only, when autoload was skipped
488
+ # Structured presentation metadata (all optional, additive since 2026-12-03).
489
+ group_id: str
490
+ display_name: str
491
+ suitability_rank: int
492
+ best_for_host: bool
493
+ quant_method: QuantMethod
494
+ bits_per_weight: float
495
+ quant_fidelity: QuantFidelity
496
+ engine_display_name: EngineDisplayName
497
+ offload_mode: OffloadMode
498
+ recommendation_reasons: list[RecommendationReason]
499
+ baseline_comparison: BaselineComparison
500
+ quality_score: int | None
501
+ estimated_tokens_per_second: float | None
419
502
 
420
503
 
421
504
  class _DebugInfo(TypedDict):
@@ -626,12 +709,39 @@ def library_id(catalog_id: str, quant: str) -> str:
626
709
  return f"{catalog_id}:{quant}"
627
710
 
628
711
 
712
+ _ENGINE_NAME_SUFFIX = {
713
+ "polystrata": "PolyStrata",
714
+ "strata": "Strata",
715
+ "mlx": "MLX",
716
+ }
717
+
718
+
629
719
  def display_name(model: str, quant: str) -> str:
630
720
  """What a person reads: the model's name and its variant, so no two rows share one (two
631
721
  catalog ids can share a display name, and one id has a row per variant)."""
632
722
  return f"{model} ({quant})"
633
723
 
634
724
 
725
+ def disambiguate_row_names(rows: Sequence[Row]) -> None:
726
+ """Guard ``library-v2.schema.json`` row ``name`` uniqueness across engines: if two rows share
727
+ the same ``(display_name, quant)`` under different engines, append an engine suffix to every
728
+ non-``llama.cpp`` row in that collision group."""
729
+ groups: dict[str, list[Row]] = {}
730
+ for row in rows:
731
+ groups.setdefault(row["name"], []).append(row)
732
+ for group in groups.values():
733
+ if len(group) < 2:
734
+ continue
735
+ engines = {row.get("engine", "llama.cpp") for row in group}
736
+ if len(engines) < 2:
737
+ continue
738
+ for row in group:
739
+ engine = row.get("engine", "llama.cpp")
740
+ if engine != "llama.cpp":
741
+ suffix = _ENGINE_NAME_SUFFIX.get(engine, str(engine))
742
+ row["name"] = f"{row['name']} · {suffix}"
743
+
744
+
635
745
  def split_id(value: str) -> tuple[str, str]:
636
746
  """(catalog id, quant); a bare catalog id has an empty quant (its last variant)."""
637
747
  catalog_id, _, quant = value.partition(":")
@@ -700,6 +810,68 @@ def problem_from_error(error: LibraryError) -> Problem:
700
810
  return sanitize_problem(raw)
701
811
 
702
812
 
813
+ def sanitize_load_breakdown(raw: object) -> LoadBreakdownMs | None:
814
+ """Validate and copy a persisted ``LoadBreakdownMs`` dict for status and result rows."""
815
+ if not isinstance(raw, Mapping):
816
+ return None
817
+ out: dict[str, int] = {}
818
+ for key in LOAD_BREAKDOWN_KEYS:
819
+ val = raw.get(key)
820
+ if isinstance(val, int) and not isinstance(val, bool) and 0 <= val <= MAX_SAFE_COUNTER:
821
+ out[key] = val
822
+ return cast(LoadBreakdownMs, out) if out else None
823
+
824
+
825
+ def parse_rfc3339_utc(raw: object) -> dt.datetime | None:
826
+ """Parse an RFC3339 timestamp with timezone offset into UTC, or None when invalid."""
827
+ if not isinstance(raw, str) or not raw.strip():
828
+ return None
829
+ text = raw.strip()
830
+ if text.endswith(("Z", "z")):
831
+ text = text[:-1] + "+00:00"
832
+ try:
833
+ parsed = dt.datetime.fromisoformat(text)
834
+ except ValueError:
835
+ return None
836
+ return parsed.astimezone(dt.timezone.utc) if parsed.tzinfo is not None else None
837
+
838
+
839
+ def apply_load_lifecycle(found: Row, record: Mapping[str, object], *, now_utc: dt.datetime) -> None:
840
+ """Project persisted load timing & dynamic uptime onto a loaded ``Row``."""
841
+ raw_loaded_at = record.get("loaded_at")
842
+ parsed_loaded_at = parse_rfc3339_utc(raw_loaded_at)
843
+ raw_duration = record.get("load_duration_ms")
844
+ duration = (
845
+ raw_duration
846
+ if isinstance(raw_duration, int)
847
+ and not isinstance(raw_duration, bool)
848
+ and 0 <= raw_duration <= MAX_SAFE_COUNTER
849
+ else None
850
+ )
851
+ breakdown = sanitize_load_breakdown(record.get("load_breakdown_ms"))
852
+ raw_cold = record.get("cold_load")
853
+ cold: bool | None = raw_cold if isinstance(raw_cold, bool) else None
854
+ if not (
855
+ parsed_loaded_at is not None
856
+ or duration is not None
857
+ or breakdown is not None
858
+ or "cold_load" in record
859
+ or "loaded_at" in record
860
+ ):
861
+ return
862
+ if parsed_loaded_at is not None and isinstance(raw_loaded_at, str):
863
+ found["loaded_at"] = raw_loaded_at
864
+ found["uptime_s"] = min(
865
+ MAX_SAFE_COUNTER, max(0, int((now_utc - parsed_loaded_at).total_seconds()))
866
+ )
867
+ else:
868
+ found["loaded_at"] = None
869
+ found["uptime_s"] = None
870
+ found["load_duration_ms"] = duration
871
+ found["load_breakdown_ms"] = breakdown
872
+ found["cold_load"] = cold
873
+
874
+
703
875
  def sanitize_problem(raw: Mapping[str, object]) -> Problem:
704
876
  """Validate and copy a persisted ``Problem`` dict for ``library status``."""
705
877
  out: Problem = {
@@ -8,33 +8,68 @@ fallback below validated models whenever a validated model fits (Decision 69).
8
8
 
9
9
  from __future__ import annotations
10
10
 
11
+ from collections.abc import Iterable, Mapping
12
+
11
13
  from localmodels import catalog as cat
12
- from localmodels import llm_rank, metal
14
+ from localmodels import catalog_recipes, llm_rank, metal, suite
13
15
  from localmodels.estimator import HardwareBudget
14
16
  from localmodels.library_model import Row
15
17
  from localmodels.library_pricing import Model
16
18
  from localmodels.planning import budget, memory_pools
17
- from localmodels.probe import HostFacts
19
+ from localmodels.probe import GPU, HostFacts
18
20
 
19
21
  _ACTIONABLE_UNAVAILABLE = frozenset({"DRIVER_UPDATE_REQUIRED", "RUNTIME_DEPENDENCY_MISSING"})
20
22
  _LONG_CONTEXT_FLOOR = 131_072
21
23
 
22
24
 
23
- def _mac_suitability_key(
25
+ def ranked_quality(entry: cat.CatalogEntry) -> int:
26
+ """Installed SimplexAI quality score, or 0 for editorial-only / unscored entries."""
27
+ if entry.quality <= 0:
28
+ return 0
29
+ if entry.quality_sources and not any(
30
+ s["type"] == "intelligence_score" for s in entry.quality_sources
31
+ ):
32
+ return 0
33
+ return entry.quality
34
+
35
+
36
+ def _quality_bands(scores: Iterable[int]) -> dict[int, int]:
37
+ """Group descending scores into greedy bands of width ``llm_rank.COIN_FLIP``."""
38
+ unique = sorted(set(scores), reverse=True)
39
+ bands: dict[int, int] = {}
40
+ band_idx = -1
41
+ anchor: int | None = None
42
+ for score in unique:
43
+ if anchor is None or anchor - score > llm_rank.COIN_FLIP:
44
+ band_idx += 1
45
+ anchor = score
46
+ bands[score] = band_idx
47
+ return bands
48
+
49
+
50
+ def _fidelity_rank(model: Model) -> int:
51
+ return catalog_recipes.fidelity_rank(model.entry.quant_fidelity, model.variant.quant)
52
+
53
+
54
+ def _est_tok_s(
24
55
  model: Model,
25
- row_doc: Row,
26
56
  hw: HardwareBudget | None,
27
- smartest_rungs: tuple[str, ...],
28
- ) -> tuple[object, ...]:
29
- """Order Apple Silicon library rows by machine-tailored suitability.
57
+ best_gpu: GPU | None,
58
+ poly_recipes: Mapping[str, suite.SuiteRecipe],
59
+ ) -> float:
60
+ if model.entry.runtime == "strata-poly":
61
+ recipe = poly_recipes.get(model.entry.id)
62
+ if recipe is None:
63
+ return 0.0
64
+ est = suite.poly_decode_estimate(recipe, best_gpu)
65
+ return round(est.tok_s, 1) if est is not None else 0.0
66
+ return round(cat.decode_estimate(model.entry, model.variant, hw).tok_s, 1) if hw else 0.0
30
67
 
31
- Recommended comes first, then fitting/active models ranked from high-intelligence validated
32
- models (>= yield score) through the primary Mac ladder rung (Ornith 1.5 9B), secondary
33
- validated models, fallback ladder rungs (Spark 4B), and ladder-replaced legacy entries
34
- (Ling 3.0 tiny). Models that do not fit this Mac follow from smallest memory requirement up.
35
- """
36
- entry, variant = model.entry, model.variant
37
- is_recommended = 0 if row_doc["recommended"] else 1
68
+
69
+ def _mac_bucket_tier(
70
+ model: Model, row_doc: Row, smartest_rungs: tuple[str, ...]
71
+ ) -> tuple[int, int]:
72
+ entry = model.entry
38
73
  if row_doc["state"] != "absent" or (
39
74
  row_doc["fit"] != "none" and row_doc["availability"]["downloadable"]
40
75
  ):
@@ -43,37 +78,67 @@ def _mac_suitability_key(
43
78
  avail_bucket = 1
44
79
  else:
45
80
  avail_bucket = 2
46
- est_tok_s = round(cat.decode_estimate(entry, variant, hw).tok_s, 1) if hw else 0.0
47
81
  if entry.id in llm_rank.MAC_LADDER_REPLACES:
48
82
  tier = 4
83
+ elif entry.id in smartest_rungs:
84
+ tier = 1 if smartest_rungs.index(entry.id) == 0 else 3
85
+ elif entry.status == "validated" and ranked_quality(entry) >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
86
+ tier = 0
87
+ else:
88
+ tier = 2
89
+ return avail_bucket, tier
90
+
91
+
92
+ def _mac_suitability_key(
93
+ model: Model,
94
+ row_doc: Row,
95
+ hw: HardwareBudget | None,
96
+ smartest_rungs: tuple[str, ...],
97
+ bands: Mapping[tuple[int, int], Mapping[int, int]],
98
+ ) -> tuple[object, ...]:
99
+ """Order Apple Silicon library rows by machine-tailored suitability.
100
+
101
+ Recommended comes first, then fitting/active models ranked from high-intelligence validated
102
+ models (>= yield score, grouped into ``COIN_FLIP`` bands) through the primary Mac ladder
103
+ rung (Ornith 1.5 9B), secondary validated/candidate models, fallback ladder rungs (Spark 4B),
104
+ and ladder-replaced legacy entries (Ling 3.0 tiny). Within equal quality bands, compact
105
+ variants win ties over larger ones. Models that do not fit this Mac follow from smallest
106
+ memory requirement up.
107
+ """
108
+ entry, variant = model.entry, model.variant
109
+ is_recommended = 0 if row_doc["recommended"] else 1
110
+ avail_bucket, tier = _mac_bucket_tier(model, row_doc, smartest_rungs)
111
+ rq = ranked_quality(entry)
112
+ band = bands.get((avail_bucket, tier), {}).get(rq, 0)
113
+ fidelity = _fidelity_rank(model)
114
+ est_tok_s = round(cat.decode_estimate(entry, variant, hw).tok_s, 1) if hw else 0.0
115
+ if tier == 4:
49
116
  rank_tuple: tuple[float, ...] = (
50
- -entry.quality,
117
+ -rq,
51
118
  -est_tok_s,
52
119
  -row_doc["context_tokens"],
53
- -variant.size_bytes,
120
+ variant.size_bytes,
54
121
  )
55
- elif entry.id in smartest_rungs:
122
+ elif tier in (1, 3):
56
123
  rung_idx = smartest_rungs.index(entry.id)
57
- tier = 1 if rung_idx == 0 else 3
58
124
  rank_tuple = (
59
125
  float(rung_idx),
60
126
  -est_tok_s,
61
127
  -row_doc["context_tokens"],
62
- -variant.size_bytes,
128
+ variant.size_bytes,
63
129
  )
64
- elif entry.status == "validated" and entry.quality >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
65
- tier = 0
130
+ elif tier == 0:
66
131
  rank_tuple = (
67
- -entry.quality,
132
+ float(band),
68
133
  -est_tok_s,
69
134
  -row_doc["context_tokens"],
70
- -variant.size_bytes,
135
+ variant.size_bytes,
71
136
  )
72
137
  else:
73
- tier = 2
74
138
  rank_tuple = (
75
- -entry.quality,
76
- -variant.size_bytes,
139
+ float(band),
140
+ float(fidelity),
141
+ variant.size_bytes,
77
142
  -est_tok_s,
78
143
  -row_doc["context_tokens"],
79
144
  )
@@ -108,36 +173,18 @@ def _best_cuda_budget(facts: HostFacts) -> HardwareBudget | None:
108
173
  return budget.agent_budget(best, facts) or best.budget
109
174
 
110
175
 
111
- def _max_visible_nvidia_bytes(facts: HostFacts) -> int:
176
+ def _best_visible_nvidia_gpu(facts: HostFacts) -> GPU | None:
112
177
  shown_cards = memory_pools.visible(facts)
113
- return max(
114
- (
115
- g["total_bytes"]
116
- for g in facts.get("gpus") or []
117
- if g.get("vendor") == "nvidia" and (shown_cards is None or g["index"] in shown_cards)
118
- ),
119
- default=0,
120
- )
121
-
178
+ gpus = [
179
+ g
180
+ for g in facts.get("gpus") or []
181
+ if g.get("vendor") == "nvidia" and (shown_cards is None or g["index"] in shown_cards)
182
+ ]
183
+ return max(gpus, key=lambda g: g["total_bytes"]) if gpus else None
122
184
 
123
- def _desktop_suitability_key(
124
- facts: HostFacts,
125
- model: Model,
126
- row_doc: Row,
127
- hw: HardwareBudget | None,
128
- max_gpu_bytes: int,
129
- ) -> tuple[object, ...]:
130
- """Order Linux and Windows library rows by suitability for this machine.
131
185
 
132
- Recommended always comes first. Fitting/active rows follow in validated-intelligence,
133
- context-tier, MoE efficiency and quantization-precision order, followed by optional library
134
- candidates (such as Ornith 1.5 9B) and then the Windows small-card fallback (Spark-X2.6 4B)
135
- whenever stronger models fit. Unavailable rows surface actionable driver/runtime upgrades
136
- (preferring variants whose VRAM floor fits this GPU) before memory/hardware-blocked rows
137
- ordered from smallest shortfall up.
138
- """
139
- entry, variant = model.entry, model.variant
140
- is_recommended = 0 if row_doc["recommended"] else 1
186
+ def _desktop_bucket_tier(facts: HostFacts, model: Model, row_doc: Row) -> tuple[int, int]:
187
+ entry = model.entry
141
188
  reason = row_doc["availability"].get("reason")
142
189
  reason_code = reason["code"] if reason is not None else ""
143
190
  if row_doc["state"] != "absent" or (
@@ -151,36 +198,80 @@ def _desktop_suitability_key(
151
198
  else:
152
199
  avail_bucket = 3
153
200
 
154
- est_tok_s = round(cat.decode_estimate(entry, variant, hw).tok_s, 1) if hw else 0.0
155
201
  if llm_rank.windows_fallback(entry, facts):
156
202
  tier = 3
203
+ elif entry.status != "validated":
204
+ tier = 2
205
+ elif ranked_quality(entry) >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
206
+ tier = 0
207
+ else:
208
+ tier = 1
209
+ return avail_bucket, tier
210
+
211
+
212
+ def _desktop_suitability_key(
213
+ facts: HostFacts,
214
+ model: Model,
215
+ row_doc: Row,
216
+ hw: HardwareBudget | None,
217
+ best_gpu: GPU | None,
218
+ poly_recipes: Mapping[str, suite.SuiteRecipe],
219
+ bands: Mapping[tuple[int, int], Mapping[int, int]],
220
+ ) -> tuple[object, ...]:
221
+ """Order Linux and Windows library rows by suitability for this machine.
222
+
223
+ Recommended always comes first. Fitting/active rows follow in ``COIN_FLIP``-banded
224
+ intelligence, quantization-fidelity, ``prefer_over_llama``, context-tier, MoE efficiency and
225
+ compact-first footprint order, followed by optional library candidates (ranked by installed
226
+ quality score, fidelity and ``prefer_over_llama`` so high-scoring builds never drop below
227
+ score-0 or 2-bit models) and then the Windows small-card fallback (Spark-X2.6 4B) whenever
228
+ stronger models fit. Unavailable rows surface actionable driver/runtime upgrades (preferring
229
+ variants whose VRAM floor fits this GPU) before memory/hardware-blocked rows ordered from
230
+ smallest shortfall up.
231
+ """
232
+ entry, variant = model.entry, model.variant
233
+ is_recommended = 0 if row_doc["recommended"] else 1
234
+ reason = row_doc["availability"].get("reason")
235
+ avail_bucket, tier = _desktop_bucket_tier(facts, model, row_doc)
236
+ rq = ranked_quality(entry)
237
+ band = bands.get((avail_bucket, tier), {}).get(rq, 0)
238
+ fidelity = _fidelity_rank(model)
239
+ prefer_poly = 0.0 if entry.prefer_over_llama else 1.0
240
+ est_tok_s = _est_tok_s(model, hw, best_gpu, poly_recipes)
241
+ max_gpu_bytes = best_gpu["total_bytes"] if best_gpu is not None else 0
242
+
243
+ if tier == 3:
157
244
  rank_tuple: tuple[float, ...] = (
158
245
  -row_doc["context_tokens"],
159
- -variant.size_bytes,
246
+ variant.size_bytes,
160
247
  -est_tok_s,
161
248
  )
162
- elif entry.status != "validated":
163
- tier = 2
249
+ elif tier == 2:
164
250
  rank_tuple = (
251
+ float(band),
252
+ float(fidelity),
253
+ prefer_poly,
254
+ variant.size_bytes,
165
255
  -row_doc["context_tokens"],
166
- -variant.size_bytes,
167
256
  -est_tok_s,
168
257
  )
169
- elif entry.quality >= llm_rank.MAC_DEFAULT_YIELD_SCORE:
170
- tier = 0
258
+ elif tier == 0:
171
259
  rank_tuple = (
172
- -entry.quality,
260
+ float(band),
261
+ float(fidelity),
262
+ prefer_poly,
173
263
  0.0 if row_doc["context_tokens"] >= _LONG_CONTEXT_FLOOR else 1.0,
174
264
  0.0 if entry.moe else 1.0,
175
- -variant.size_bytes,
265
+ variant.size_bytes,
176
266
  -row_doc["context_tokens"],
177
267
  -est_tok_s,
178
268
  )
179
269
  else:
180
- tier = 1
181
270
  rank_tuple = (
182
- -entry.quality,
183
- -variant.size_bytes,
271
+ float(band),
272
+ float(fidelity),
273
+ prefer_poly,
274
+ variant.size_bytes,
184
275
  -row_doc["context_tokens"],
185
276
  -est_tok_s,
186
277
  )
@@ -225,11 +316,26 @@ def order_rows(facts: HostFacts, models: list[Model], rows: list[Row]) -> list[R
225
316
  hw = (budget.agent_budget(placement, facts) or placement.budget) if placement else None
226
317
  ladder = llm_rank.mac_ladder(facts)
227
318
  smartest_rungs = ladder.smartest if ladder is not None else ()
228
- pairs.sort(key=lambda pair: _mac_suitability_key(pair[0], pair[1], hw, smartest_rungs))
319
+ grouped: dict[tuple[int, int], list[int]] = {}
320
+ for model, row_doc in pairs:
321
+ key = _mac_bucket_tier(model, row_doc, smartest_rungs)
322
+ grouped.setdefault(key, []).append(ranked_quality(model.entry))
323
+ bands = {k: _quality_bands(v) for k, v in grouped.items()}
324
+ pairs.sort(
325
+ key=lambda pair: _mac_suitability_key(pair[0], pair[1], hw, smartest_rungs, bands)
326
+ )
229
327
  return [row_doc for _, row_doc in pairs]
230
328
  hw = _best_cuda_budget(facts)
231
- max_gpu_bytes = _max_visible_nvidia_bytes(facts)
329
+ best_gpu = _best_visible_nvidia_gpu(facts)
330
+ poly_recipes = {r["id"]: r for r in suite.recipes("llm") if r["runtime"] == "strata-poly"}
331
+ grouped_desktop: dict[tuple[int, int], list[int]] = {}
332
+ for model, row_doc in pairs:
333
+ key = _desktop_bucket_tier(facts, model, row_doc)
334
+ grouped_desktop.setdefault(key, []).append(ranked_quality(model.entry))
335
+ bands = {k: _quality_bands(v) for k, v in grouped_desktop.items()}
232
336
  pairs.sort(
233
- key=lambda pair: _desktop_suitability_key(facts, pair[0], pair[1], hw, max_gpu_bytes)
337
+ key=lambda pair: _desktop_suitability_key(
338
+ facts, pair[0], pair[1], hw, best_gpu, poly_recipes, bands
339
+ )
234
340
  )
235
341
  return [row_doc for _, row_doc in pairs]