@simplexai/localmodels-linux-x64 0.1.0-dev.36 → 0.1.0-dev.37

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 (121) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +119 -98
  3. package/kit.py +1 -0
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +9 -3
  6. package/modules/localmodels/bifrost_config.py +188 -0
  7. package/modules/localmodels/budget.py +13 -2
  8. package/modules/localmodels/catalog.py +51 -320
  9. package/modules/localmodels/catalog_add.py +2 -8
  10. package/modules/localmodels/catalog_recipes.py +321 -0
  11. package/modules/localmodels/cli_parser.py +4 -1
  12. package/modules/localmodels/console.py +5 -4
  13. package/modules/localmodels/contracts.py +13 -3
  14. package/modules/localmodels/debug_cli.py +158 -0
  15. package/modules/localmodels/debug_mode.py +727 -0
  16. package/modules/localmodels/debug_stub_server.py +192 -0
  17. package/modules/localmodels/decode_calibration.json +1 -1
  18. package/modules/localmodels/decode_calibration.py +34 -17
  19. package/modules/localmodels/gateway.py +21 -155
  20. package/modules/localmodels/gateway_accept.py +201 -0
  21. package/modules/localmodels/gateway_bifrost.py +19 -184
  22. package/modules/localmodels/gateway_cli.py +11 -4
  23. package/modules/localmodels/gateway_foundations.py +2 -4
  24. package/modules/localmodels/gateway_probe.py +0 -1
  25. package/modules/localmodels/gateway_server.py +2 -3
  26. package/modules/localmodels/gpu_specs.py +12 -0
  27. package/modules/localmodels/guard.py +2 -7
  28. package/modules/localmodels/harness.py +16 -129
  29. package/modules/localmodels/harness_cleanup.py +135 -0
  30. package/modules/localmodels/harness_gateway.py +16 -14
  31. package/modules/localmodels/harness_probe.py +12 -4
  32. package/modules/localmodels/hosts.py +25 -2
  33. package/modules/localmodels/http_local.py +59 -0
  34. package/modules/localmodels/install.py +23 -8
  35. package/modules/localmodels/library_gateway.py +9 -9
  36. package/modules/localmodels/library_jobs.py +76 -27
  37. package/modules/localmodels/library_serve.py +12 -1
  38. package/modules/localmodels/library_state.py +6 -1
  39. package/modules/localmodels/llm_rank.py +102 -9
  40. package/modules/localmodels/probe.py +108 -174
  41. package/modules/localmodels/process_identity.py +109 -154
  42. package/modules/localmodels/process_windows.py +86 -0
  43. package/modules/localmodels/recommend.py +1 -1
  44. package/modules/localmodels/recommend_cli.py +14 -6
  45. package/modules/localmodels/remote_ops.py +65 -0
  46. package/modules/localmodels/remote_ops_service.py +14 -2
  47. package/modules/localmodels/runtime_args.py +10 -3
  48. package/modules/localmodels/runtime_auth.py +5 -9
  49. package/modules/localmodels/runtime_cli.py +128 -129
  50. package/modules/localmodels/runtime_discovery.py +84 -0
  51. package/modules/localmodels/runtime_install.py +101 -0
  52. package/modules/localmodels/runtime_releases.py +302 -0
  53. package/modules/localmodels/service_stop.py +8 -108
  54. package/modules/localmodels/service_upgrade.py +394 -63
  55. package/modules/localmodels/services_cli.py +24 -14
  56. package/modules/localmodels/setup_inspection.py +97 -9
  57. package/modules/localmodels/setup_text.py +7 -0
  58. package/modules/localmodels/sizecalc.py +0 -1
  59. package/modules/localmodels/stack.py +14 -221
  60. package/modules/localmodels/stack_arena.py +732 -0
  61. package/modules/localmodels/stack_args.py +15 -9
  62. package/modules/localmodels/stack_auto.py +384 -3
  63. package/modules/localmodels/stack_aux_gpu.py +4 -3
  64. package/modules/localmodels/stack_capacity.py +138 -0
  65. package/modules/localmodels/stack_cleanup.py +9 -4
  66. package/modules/localmodels/stack_cli.py +286 -0
  67. package/modules/localmodels/stack_compose.py +58 -25
  68. package/modules/localmodels/stack_console.py +9 -6
  69. package/modules/localmodels/stack_hardware.py +92 -263
  70. package/modules/localmodels/stack_hardware_text.py +263 -0
  71. package/modules/localmodels/stack_journal.py +3 -9
  72. package/modules/localmodels/stack_ledger.py +48 -18
  73. package/modules/localmodels/stack_lifecycle.py +33 -312
  74. package/modules/localmodels/stack_mcp.py +729 -0
  75. package/modules/localmodels/stack_memory.py +0 -2
  76. package/modules/localmodels/stack_picks.py +59 -12
  77. package/modules/localmodels/stack_plan.py +19 -1
  78. package/modules/localmodels/stack_preflight.py +11 -19
  79. package/modules/localmodels/stack_remove.py +373 -0
  80. package/modules/localmodels/stack_route.py +101 -17
  81. package/modules/localmodels/stack_suite.py +11 -7
  82. package/modules/localmodels/stack_summary.py +14 -0
  83. package/modules/localmodels/stack_try.py +238 -24
  84. package/modules/localmodels/stack_try_client.py +53 -15
  85. package/modules/localmodels/stack_try_docs.py +2 -2
  86. package/modules/localmodels/stack_view.py +24 -171
  87. package/modules/localmodels/stack_view_access.py +114 -1
  88. package/modules/localmodels/stack_view_agent.py +3 -13
  89. package/modules/localmodels/stack_view_hub.py +9 -10
  90. package/modules/localmodels/stack_view_llm.py +1 -1
  91. package/modules/localmodels/stack_view_sandbox.py +2 -2
  92. package/modules/localmodels/stack_view_schema.py +183 -0
  93. package/modules/localmodels/stack_view_serve.py +7 -1
  94. package/modules/localmodels/stack_view_service.py +1 -2
  95. package/modules/localmodels/stack_view_text.py +13 -9
  96. package/modules/localmodels/stack_warm.py +3 -0
  97. package/modules/localmodels/stack_warm_store.py +517 -0
  98. package/modules/localmodels/tui.py +28 -4
  99. package/modules/localmodels/tui_dialogs.py +136 -0
  100. package/modules/localmodels/tui_modals.py +279 -0
  101. package/modules/localmodels/tui_screen.py +113 -154
  102. package/modules/localmodels/tui_views.py +134 -203
  103. package/modules/localmodels/web/index.html +510 -101
  104. package/modules/localmodels/web/sizecalc/app.js +363 -10
  105. package/modules/localmodels/web/sizecalc/page.html +27 -3
  106. package/modules/localmodels/web/view/fleet.html +11 -2
  107. package/modules/localmodels/web/view/fleet.js +191 -17
  108. package/modules/localmodels/web/view/i18n.js +3 -2
  109. package/modules/localmodels/web/view/index.html +1 -1
  110. package/modules/localmodels/web/view/nav.js +22 -3
  111. package/modules/localmodels/web/view/view.css +63 -18
  112. package/modules/localmodels/web/view/view.js +169 -32
  113. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
  114. package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +115 -94
  115. package/package.json +1 -1
  116. package/tool.json +1 -1
  117. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  118. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
  119. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
  120. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
  121. /package/modules/{simplex_localmodels-0.1.0.dev36.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,188 @@
1
+ """Configuration rendering and private config/datasheet storage for the Bifrost gateway."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import contextlib
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ from typing import Any
10
+
11
+ from localmodels import bifrost_datasheet, bifrost_provider
12
+ from localmodels.gateway_requests import AuxEndpoint
13
+ from localmodels.harness import GatewayPlan, HarnessError
14
+
15
+ ADMIN_USER = "localmodels"
16
+ LOG_BATCH_INTERVAL = "250ms" # logs_store.writer.batch_interval; Bifrost's default is 5s
17
+ STORE = ("config.db", "config.db-wal", "config.db-shm") # derived from config.json and datasheets
18
+ COMPLEX_RULE = "localmodels-agent-complex"
19
+ AGENT_RULE = "localmodels-agent"
20
+ FAST_PROVIDER = "localmodels-llm-fast"
21
+ DECISION_TIMEOUT = "10s"
22
+ AUX_PROVIDERS = {
23
+ "embedding": "localmodels-embedding",
24
+ "rerank": "localmodels-rerank",
25
+ "stt": "localmodels-stt",
26
+ }
27
+ # The analyzer requires keyword lists even when the decision model classifies; they only decide
28
+ # when it does not answer, so a few plain words suffice.
29
+ _KEYWORDS = {
30
+ "simple_keywords": ["hello", "thanks", "what is"],
31
+ "medium_keywords": ["explain", "summarize", "write"],
32
+ "complex_keywords": ["refactor", "debug", "design", "architecture"],
33
+ }
34
+ _AGENT_MATCH = "model == 'localmodels-agent'"
35
+
36
+
37
+ def render(
38
+ gw: GatewayPlan,
39
+ llm_key: str,
40
+ decision_key: str | None,
41
+ aux: list[AuxEndpoint],
42
+ app: Path,
43
+ password: str,
44
+ keep: dict[str, Any] | None = None,
45
+ *,
46
+ fast_key: str | None = None,
47
+ ) -> dict[str, Any]:
48
+ """The config.json for one approved plan, before ``bifrost_search.inject``. ``keep`` carries
49
+ providers of an earlier config this call does not manage (a re-sync keeps the STT provider)."""
50
+ llm = gw["llm"]
51
+ providers: dict[str, Any] = dict(keep or {})
52
+ providers[gw["llm_provider"]] = bifrost_provider.render(
53
+ "llm", llm["url"], llm["model"], llm_key, gw["llm_provider"]
54
+ )
55
+ decision = gw["decision"] if decision_key is not None else None
56
+ if decision is not None and decision_key is not None:
57
+ providers[gw["decision_provider"]] = bifrost_provider.render(
58
+ "decision", decision["url"], decision["model"], decision_key, gw["decision_provider"]
59
+ )
60
+ for ep in aux:
61
+ pid = AUX_PROVIDERS.get(str(ep.get("contract")))
62
+ if pid:
63
+ providers[pid] = bifrost_provider.render(
64
+ str(ep["contract"]), str(ep["url"]), str(ep["model"]), str(ep["key"]), pid
65
+ )
66
+ target = {"provider": gw["llm_provider"], "model": llm["model"], "weight": 1}
67
+ default_target = target
68
+ if fast := gw.get("llm_fast"):
69
+ if decision is None or not fast_key:
70
+ raise HarnessError("two-LLM routing requires both LLM keys and a ready decision model")
71
+ providers[FAST_PROVIDER] = bifrost_provider.render(
72
+ "llm", fast["url"], fast["model"], fast_key, FAST_PROVIDER
73
+ )
74
+ default_target = {"provider": FAST_PROVIDER, "model": fast["model"], "weight": 1}
75
+ rules: list[dict[str, Any]] = []
76
+ governance: dict[str, Any] = {
77
+ "auth_config": {
78
+ "is_enabled": True,
79
+ "admin_username": ADMIN_USER,
80
+ "admin_password": password,
81
+ "disable_auth_on_inference": True,
82
+ },
83
+ }
84
+ if decision is not None:
85
+ rules.append(
86
+ {
87
+ "id": COMPLEX_RULE,
88
+ "name": COMPLEX_RULE,
89
+ "description": "hard turns, as the decision model classifies them",
90
+ "cel_expression": f"{_AGENT_MATCH} && complexity_tier == 'COMPLEX'",
91
+ "targets": [target],
92
+ "priority": 0,
93
+ }
94
+ )
95
+ governance["complexity_analyzer_config"] = {
96
+ "keywords": _KEYWORDS,
97
+ "classifier": "decision",
98
+ "decision": {
99
+ "provider": gw["decision_provider"],
100
+ "model": decision["model"],
101
+ "timeout": DECISION_TIMEOUT,
102
+ "previous_message_count": 1,
103
+ },
104
+ }
105
+ rules.append(
106
+ {
107
+ "id": AGENT_RULE,
108
+ "name": AGENT_RULE,
109
+ "description": "local agent turns sent to the local LLM",
110
+ "cel_expression": _AGENT_MATCH,
111
+ "targets": [default_target],
112
+ "priority": 1,
113
+ }
114
+ )
115
+ governance["routing_rules"] = rules
116
+ config = render_config(providers, governance, app)
117
+ config["framework"] = bifrost_datasheet.framework(app)
118
+ return config
119
+
120
+
121
+ def render_config(
122
+ providers: dict[str, Any], governance: dict[str, Any], app: Path
123
+ ) -> dict[str, Any]:
124
+ """Shared private storage, management authentication and content logging policy."""
125
+ return {
126
+ "$schema": "https://www.getbifrost.ai/schema",
127
+ "source_of_truth": "config.json",
128
+ "client": {
129
+ "enable_logging": True,
130
+ "disable_content_logging": True,
131
+ "allow_per_request_content_storage_override": False,
132
+ "allow_per_request_raw_override": False,
133
+ "dump_errors_in_console_logs": False,
134
+ "enforce_auth_on_inference": False,
135
+ "max_request_body_size_mb": 32,
136
+ },
137
+ "config_store": {
138
+ "enabled": True,
139
+ "type": "sqlite",
140
+ "config": {"path": str(app / "config.db")},
141
+ },
142
+ "logs_store": {
143
+ "enabled": True,
144
+ "type": "sqlite",
145
+ "config": {"path": str(app / "logs.db")},
146
+ # Bifrost writes its request log in batches, 5 s apart by default; `stack view`
147
+ # reads that log to show calls, so a short interval keeps it close to real time.
148
+ # Measured on the pinned v2.3.0: a call is in the log 5.0 s after it ends by
149
+ # default, 0.2-0.25 s with this (2026-11-03, WHI-511).
150
+ "writer": {"batch_interval": LOG_BATCH_INTERVAL},
151
+ },
152
+ "providers": providers,
153
+ "governance": governance,
154
+ }
155
+
156
+
157
+ def read_config(app: Path) -> dict[str, Any]:
158
+ try:
159
+ value = json.loads((app / "config.json").read_text(encoding="utf-8"))
160
+ except (OSError, ValueError):
161
+ return {}
162
+ return value if isinstance(value, dict) else {}
163
+
164
+
165
+ def write_config(app: Path, config: dict[str, Any], sheets: dict[str, Any] | None = None) -> bool:
166
+ """Write config.json (0600), and the datasheets it names when given, where any differs; the
167
+ derived config store goes with them, so providers or windows a new config leaves out cannot
168
+ linger in it, and Bifrost loads the datasheets into the empty store before it answers."""
169
+ files = (sheets or {}) | {"config.json": config}
170
+ changed = False
171
+ for name, value in files.items():
172
+ text = json.dumps(value, ensure_ascii=False, indent=1) + "\n"
173
+ path = app / name
174
+ with contextlib.suppress(OSError):
175
+ if path.read_text(encoding="utf-8") == text:
176
+ continue
177
+ app.mkdir(parents=True, exist_ok=True)
178
+ app.chmod(0o700)
179
+ tmp = path.with_name(f"{name}.tmp")
180
+ fd = os.open(tmp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
181
+ with os.fdopen(fd, "w", encoding="utf-8") as f:
182
+ f.write(text)
183
+ os.replace(tmp, path)
184
+ changed = True
185
+ if changed:
186
+ for name in STORE:
187
+ (app / name).unlink(missing_ok=True)
188
+ return changed
@@ -149,7 +149,8 @@ def gpu_conflicts(facts: HostFacts) -> dict[str, list[str]]:
149
149
  found: dict[str, list[str]] = {}
150
150
  for proc in services.get("compute_processes") or []:
151
151
  if proc["owned"] is not True:
152
- found.setdefault(proc["gpu_uuid"], []).append(f"process {proc['pid']} {proc['name']}")
152
+ label = "GPU context" if facts.get("platform") == "win32" else "process"
153
+ found.setdefault(proc["gpu_uuid"], []).append(f"{label} {proc['pid']} {proc['name']}")
153
154
  for box in services.get("containers") or []:
154
155
  if not _SERVING_IMAGE_RE.search(f"{box['image']} {box['name']}"):
155
156
  continue
@@ -175,7 +176,12 @@ def holders(facts: HostFacts) -> dict[str, list[str]]:
175
176
  reasons = [f"in use: {gib(taken)}"] if held(g) and not idle_desktop else []
176
177
  if conflicts.get(g["uuid"]):
177
178
  reasons.append(
178
- "runs services this tool does not own: " + ", ".join(conflicts[g["uuid"]])
179
+ (
180
+ "GPU contexts this tool does not own: "
181
+ if facts["platform"] == "win32"
182
+ else "runs services this tool does not own: "
183
+ )
184
+ + ", ".join(conflicts[g["uuid"]])
179
185
  )
180
186
  if reasons:
181
187
  found[g["uuid"]] = reasons
@@ -238,6 +244,11 @@ def sharing_cards(facts: HostFacts, need_bytes: int) -> list[GPU]:
238
244
  if g["vendor"] == "nvidia"
239
245
  and g.get("mig_mode") != "enabled"
240
246
  and g["free_bytes"] >= need_bytes
247
+ and all(
248
+ p["owned"] is not None
249
+ for p in services["compute_processes"] or []
250
+ if p["gpu_uuid"] == g["uuid"]
251
+ )
241
252
  ],
242
253
  key=lambda g: (-g["free_bytes"], -link_rate(g), g["index"]),
243
254
  )
@@ -13,14 +13,42 @@ multi-GPU host is priced per card and as a pooled split.
13
13
 
14
14
  from __future__ import annotations
15
15
 
16
- import base64
17
16
  import json
18
- import re
17
+ from collections.abc import Sequence
19
18
  from dataclasses import dataclass, field
20
19
  from pathlib import Path, PurePosixPath
21
- from typing import TypedDict, cast
22
20
 
23
21
  from localmodels import decode_calibration, vision
22
+ from localmodels.catalog_recipes import CATALOG_PATH as CATALOG_PATH
23
+ from localmodels.catalog_recipes import EFFORT_LEVELS as EFFORT_LEVELS
24
+ from localmodels.catalog_recipes import FIXTURE_DIR as FIXTURE_DIR
25
+ from localmodels.catalog_recipes import PLATFORMS as PLATFORMS
26
+ from localmodels.catalog_recipes import QUALITY_SOURCE_TYPES as QUALITY_SOURCE_TYPES
27
+ from localmodels.catalog_recipes import STATUSES as STATUSES
28
+ from localmodels.catalog_recipes import TASKS as TASKS
29
+ from localmodels.catalog_recipes import AssetData as AssetData
30
+ from localmodels.catalog_recipes import CatalogData as CatalogData
31
+ from localmodels.catalog_recipes import ComponentFile as ComponentFile
32
+ from localmodels.catalog_recipes import ComponentRecipe as ComponentRecipe
33
+ from localmodels.catalog_recipes import DecisionFrontend as DecisionFrontend
34
+ from localmodels.catalog_recipes import DecisionRecipe as DecisionRecipe
35
+ from localmodels.catalog_recipes import DecisionTier as DecisionTier
36
+ from localmodels.catalog_recipes import LlamaComponentRecipe as LlamaComponentRecipe
37
+ from localmodels.catalog_recipes import ModelData as ModelData
38
+ from localmodels.catalog_recipes import OptionalAssetData as OptionalAssetData
39
+ from localmodels.catalog_recipes import OptionalCatalogData as OptionalCatalogData
40
+ from localmodels.catalog_recipes import OptionalModelData as OptionalModelData
41
+ from localmodels.catalog_recipes import OptionalVariantData as OptionalVariantData
42
+ from localmodels.catalog_recipes import ProvenanceData as ProvenanceData
43
+ from localmodels.catalog_recipes import QualityData as QualityData
44
+ from localmodels.catalog_recipes import QualitySource as QualitySource
45
+ from localmodels.catalog_recipes import VariantData as VariantData
46
+ from localmodels.catalog_recipes import component_recipe as component_recipe
47
+ from localmodels.catalog_recipes import components as components
48
+ from localmodels.catalog_recipes import decision_components as decision_components
49
+ from localmodels.catalog_recipes import llama_components as llama_components
50
+ from localmodels.catalog_recipes import problems as problems
51
+ from localmodels.catalog_recipes import shipped_fixture as shipped_fixture
24
52
  from localmodels.context_policy import (
25
53
  FLOOR,
26
54
  RUNTIME_OVERHEAD_BYTES,
@@ -41,14 +69,6 @@ from localmodels.estimator import (
41
69
  )
42
70
  from localmodels.gguf import model_id_from_stem
43
71
 
44
- CATALOG_PATH = Path(__file__).with_name("catalog.json")
45
-
46
-
47
- class QualitySource(TypedDict):
48
- type: str # one of QUALITY_SOURCE_TYPES
49
- ref: str # a run id, report path or citation; "editorial" names whose judgement it was
50
- date: str
51
-
52
72
 
53
73
  @dataclass(frozen=True)
54
74
  class AssetFile:
@@ -299,7 +319,9 @@ def decode_estimate(
299
319
  if backend == "auto" and budget.uma and budget.platform == "darwin":
300
320
  effective_backend = "metal"
301
321
  factor = (
302
- decode_calibration.efficiency(decode_calibration.category(entry, effective_backend))
322
+ decode_calibration.efficiency(
323
+ decode_calibration.category(entry, effective_backend, budget.gpu_name)
324
+ )
303
325
  if calibrated and not spilled
304
326
  else 1.0
305
327
  )
@@ -329,302 +351,9 @@ def validated_here(entry: CatalogEntry, platform: str) -> bool:
329
351
  return not scope or key in scope or (key == "win32" and "linux" in scope)
330
352
 
331
353
 
332
- # ── catalog data ──
354
+ # ── catalog loading ──
333
355
 
334
- _SCHEMA_VERSION = 3
335
356
  _READABLE_SCHEMAS = (2, 3) # schema 2: bare quality integers and no provenance fields
336
- STATUSES = ("candidate", "validated", "deprecated")
337
- PLATFORMS = ("linux", "darwin", "win32") # validated_on: Linux, Apple Silicon Macs, Windows
338
- EFFORT_LEVELS = ("low", "medium", "high") # reasoning_effort values a gateway may send, in order
339
- TASKS = tuple("llm vision decision embedding reranker stt tts search privacy-span".split())
340
- # intelligence_score: the installed SimplexAI score (decisions 26, 33); make check keeps it equal
341
- QUALITY_SOURCE_TYPES = ("editorial", "own_eval", "external_index", "kld", "intelligence_score")
342
-
343
-
344
- class AssetData(TypedDict):
345
- path: str
346
- size_bytes: int
347
-
348
-
349
- class OptionalAssetData(AssetData, total=False):
350
- local: str
351
- repo: str
352
- revision: str
353
- sha256: str # with a 40-hex commit revision
354
-
355
-
356
- class VariantData(TypedDict):
357
- quant: str
358
- files: list[OptionalAssetData]
359
-
360
-
361
- class OptionalVariantData(VariantData, total=False):
362
- validated: bool
363
- lazy_bytes: int
364
- embd_table_bytes: int
365
- mtp_layer_bytes: int
366
-
367
-
368
- class ModelData(TypedDict):
369
- id: str
370
- display_name: str
371
- description: str
372
- repo: str
373
- variants: list[OptionalVariantData]
374
- n_ctx_train: int
375
- full_layers: int
376
- recurrent_layers: int
377
- per_layer_f16: int
378
-
379
-
380
- class QualityData(TypedDict):
381
- score: int
382
- sources: list[QualitySource]
383
-
384
-
385
- class ProvenanceData(TypedDict, total=False):
386
- """Where an installable entry comes from and what governs its use. ``license`` is the license
387
- a user must honour; a quantization of third-party weights inherits ``base_license`` from
388
- ``base_model`` and names the quantizer's own ``artifact_license`` beside it."""
389
-
390
- license: str
391
- license_url: str
392
- status: str # one of STATUSES
393
- tasks: list[str] # TASKS; a component's own task is one of them
394
- evidence: list[str] # catalog/<run id> or a report path; empty for an untested candidate
395
- validated_on: list[str] # since 2026-10-29: the platforms its evidence covers, if not all
396
- reasoning_efforts: list[str] # since 2026-10-30: the levels its template accepts, if not all
397
- artifact_license: str
398
- artifact_license_url: str
399
- base_model: str
400
- base_license: str
401
- base_license_url: str
402
-
403
-
404
- PROVENANCE_FIELDS = tuple(ProvenanceData.__annotations__)
405
-
406
-
407
- class OptionalModelData(ModelData, ProvenanceData, total=False):
408
- runtime: str
409
- swa_layers: int
410
- swa_window: int
411
- moe: bool
412
- mtp: bool
413
- mtp_draft_depth: int
414
- agent_mtp: bool
415
- n_vocab: int
416
- sampling: dict[str, str]
417
- min_engine: str
418
- chat_template: str
419
- quality: int | QualityData
420
- decode_fraction: float
421
- architecture: str
422
- ssm_d_inner: int
423
- ssm_d_state: int
424
- ssm_d_conv: int
425
- ssm_n_group: int
426
- ssm_dt_rank: int
427
- n_embd: int
428
- tied_embeddings: bool
429
- kv_k_only: bool
430
- mmproj: OptionalAssetData | None
431
- draft: OptionalAssetData | None
432
- mtp_head: OptionalAssetData | None
433
-
434
-
435
- class _ComponentFileOptional(TypedDict, total=False):
436
- url: str # llama components: absolute URL off the Hub (self-quantized GGUF); suites: a template
437
-
438
-
439
- class ComponentFile(_ComponentFileOptional):
440
- path: str
441
- size_bytes: int
442
- sha256: str
443
-
444
-
445
- class ComponentRecipe(ProvenanceData):
446
- id: str
447
- task: str
448
- runtime: str
449
- version: str
450
- repo: str
451
- revision: str
452
- memory_estimate_bytes: int
453
- files: list[ComponentFile]
454
-
455
-
456
- class CatalogData(TypedDict):
457
- schema_version: int
458
- models: list[OptionalModelData]
459
-
460
-
461
- class OptionalCatalogData(CatalogData, total=False):
462
- components: list[ComponentRecipe]
463
-
464
-
465
- class LlamaComponentRecipe(ComponentRecipe):
466
- """A task component served by a pinned llama-server build (runtime llama.cpp-cpu, or
467
- llama.cpp for a decision model, which only runs on a GPU)."""
468
-
469
- engine: str # engine lock tag; engines-<tag>.json beside the catalog
470
- alias: str
471
- context: int # the default prompt cap; a decision prompt is one ubatch, so -c = -b = -ub
472
- contract: str # the readiness request remote_ops sends, e.g. "systemone"
473
- note: str
474
-
475
-
476
- class DecisionTier(TypedDict):
477
- """One prompt cap of a decision model, measured on lab-12021 (RTX 4090 D, llama.cpp b11583)."""
478
-
479
- context: int
480
- vram_bytes: int # peak of the llama-server process with a prompt of about 80% of the cap
481
- index: (
482
- float # Decision Index 0.3 public-index estimate, 14,000-row sample; refusals count wrong
483
- )
484
-
485
-
486
- class DecisionFrontend(TypedDict):
487
- """startlux-decide in front of llama-server: the model folder's tokenizer and decision_config
488
- plus the hash-locked package environment named by ``requirements`` beside the catalog."""
489
-
490
- kind: str
491
- repo: str
492
- revision: str
493
- files: list[ComponentFile]
494
- requirements: str
495
- memory_estimate_bytes: int
496
-
497
-
498
- class _DecisionOptional(TypedDict, total=False):
499
- frontend: DecisionFrontend # absent: llama-server answers /v1/systemone itself
500
-
501
-
502
- class DecisionRecipe(LlamaComponentRecipe, _DecisionOptional):
503
- """A Jev-like decision model. It only ever runs on a GPU: on a CPU it is 40-70 times slower
504
- than on a GPU, which forfeits its System One role (AGENTS.md)."""
505
-
506
- family: str
507
- commercial_use: bool # False: the weights' license restricts commercial use
508
- tiers: list[DecisionTier]
509
- board: dict[str, float] # leaderboard public and full score, snapshot named in evidence
510
- latency_ms: dict[str, float] # single-stream p50 on lab-12021: 1 and 16 questions
511
- pros: list[str]
512
- cons: list[str]
513
-
514
-
515
- def components() -> list[ComponentRecipe]:
516
- """Every task recipe in catalog order. Task recipes share the catalog, but never enter the
517
- GGUF recommender."""
518
- raw = json.loads(CATALOG_PATH.read_text(encoding="utf-8"))
519
- return decode(raw.get("components", []), list[ComponentRecipe])
520
-
521
-
522
- def component_recipe(model_id: str) -> ComponentRecipe:
523
- return next(recipe for recipe in components() if recipe["id"] == model_id)
524
-
525
-
526
- def llama_components(task: str) -> list[LlamaComponentRecipe]:
527
- """llama-server task components in catalog order (the first is the default)."""
528
- return [
529
- decode(recipe, LlamaComponentRecipe)
530
- for recipe in components()
531
- if recipe["task"] == task and recipe["runtime"] in ("llama.cpp-cpu", "llama.cpp")
532
- ]
533
-
534
-
535
- def decision_components() -> list[DecisionRecipe]:
536
- """Jev-like decision models in catalog order."""
537
- return [decode(recipe, DecisionRecipe) for recipe in llama_components("decision")]
538
-
539
-
540
- _REQUIRED_PROVENANCE = ("license", "license_url", "status", "tasks", "evidence")
541
- _STRATA_PROVENANCE = (
542
- "artifact_license",
543
- "artifact_license_url",
544
- "base_model",
545
- "base_license",
546
- "base_license_url",
547
- )
548
-
549
-
550
- def _entry_problems(
551
- item: OptionalModelData | ComponentRecipe, task: str, runtime: str
552
- ) -> list[str]:
553
- fields = cast(dict[str, object], item)
554
- required = _REQUIRED_PROVENANCE + (_STRATA_PROVENANCE if runtime == "strata" else ())
555
- found = [
556
- f"{key} is missing"
557
- for key in required
558
- if key not in fields or (key != "evidence" and not fields[key])
559
- ]
560
- found += [
561
- f"{key} is not an https URL"
562
- for key in ("license_url", "artifact_license_url", "base_license_url")
563
- if fields.get(key) and not str(fields[key]).startswith("https://")
564
- ]
565
- if item.get("status") and item.get("status") not in STATUSES:
566
- found.append(f"status is not one of {', '.join(STATUSES)}")
567
- if item.get("status") == "validated" and not item.get("evidence"):
568
- found.append("validated status needs at least one evidence reference")
569
- scope = item.get("validated_on")
570
- if scope is not None and (not scope or any(p not in PLATFORMS for p in scope)):
571
- found.append(f"validated_on must name some of {', '.join(PLATFORMS)}")
572
- if scope and item.get("status") != "validated":
573
- found.append("validated_on needs status validated")
574
- efforts = item.get("reasoning_efforts")
575
- if efforts is not None and (
576
- not efforts or list(efforts) != [e for e in EFFORT_LEVELS if e in efforts]
577
- ):
578
- found.append(f"reasoning_efforts must list some of {', '.join(EFFORT_LEVELS)} in order")
579
- tasks = item.get("tasks") or []
580
- if any(t not in TASKS for t in tasks):
581
- found.append("tasks has an unknown task")
582
- if tasks and task not in tasks:
583
- found.append(f"tasks does not include its task {task}")
584
- if item.get("base_license") and item.get("license") != item.get("base_license"):
585
- found.append("license must be the inherited base_license")
586
- return found
587
-
588
-
589
- def _pin_problems(model: OptionalModelData) -> list[str]:
590
- """A file pinned by content must name that content and the commit that holds it."""
591
- assets = [f for v in model["variants"] for f in v["files"]]
592
- assets += [a for a in (model.get("mmproj"), model.get("draft"), model.get("mtp_head")) if a]
593
- found = []
594
- for asset in assets:
595
- if "sha256" not in asset:
596
- continue
597
- if not re.fullmatch(r"[0-9a-f]{64}", asset["sha256"]):
598
- found.append(f"{asset['path']} sha256 is not 64 hex digits")
599
- if not re.fullmatch(r"[0-9a-f]{40}", asset.get("revision", "")):
600
- found.append(f"{asset['path']} sha256 needs a 40-hex commit revision")
601
- return found
602
-
603
-
604
- def problems(value: object) -> list[str]:
605
- """Why this catalog is not complete as schema 3, one line per entry and field (never values):
606
- every model and component names its license with an https link, status, tasks and evidence;
607
- a model cites the source of its quality score; a Strata recipe of third-party weights names
608
- its artifact license and the base license it inherits."""
609
- doc = decode(value, OptionalCatalogData)
610
- if doc.get("schema_version") != _SCHEMA_VERSION:
611
- return [f"schema_version is not {_SCHEMA_VERSION}"]
612
- found = []
613
- for m in doc["models"]:
614
- issues = _entry_problems(m, "llm", "llama.cpp")
615
- if m.get("runtime", "llama.cpp") not in ("llama.cpp", "mlx-lm"):
616
- issues.append("runtime is unknown")
617
- quality = m.get("quality")
618
- if not isinstance(quality, dict) or not quality["sources"]:
619
- issues.append("quality has no sources")
620
- elif any(s["type"] not in QUALITY_SOURCE_TYPES for s in quality["sources"]):
621
- issues.append("quality.sources[].type is unknown")
622
- issues += _pin_problems(m)
623
- found += [f"models.{m['id']}: {issue}" for issue in issues]
624
- for c in doc.get("components", []):
625
- issues = _entry_problems(c, c["task"], c["runtime"])
626
- found += [f"components.{c['id']}: {issue}" for issue in issues]
627
- return found
628
357
 
629
358
 
630
359
  def _asset_from(d: OptionalAssetData | None) -> AssetFile | None:
@@ -719,8 +448,23 @@ def load_catalog(value: object) -> tuple[CatalogEntry, ...]:
719
448
  return tuple(entries)
720
449
 
721
450
 
451
+ _CATALOG_CACHE: dict[Path, tuple[int, int, tuple[CatalogEntry, ...]]] = {}
452
+
453
+
722
454
  def load_catalog_file(path: Path = CATALOG_PATH) -> tuple[CatalogEntry, ...]:
723
- return load_catalog(json.loads(path.read_text(encoding="utf-8-sig")))
455
+ resolved = path.resolve()
456
+ stat = resolved.stat()
457
+ cached = _CATALOG_CACHE.get(resolved)
458
+ if cached is not None and cached[0] == stat.st_mtime_ns and cached[1] == stat.st_size:
459
+ return cached[2]
460
+ entries = load_catalog(json.loads(resolved.read_text(encoding="utf-8-sig")))
461
+ _CATALOG_CACHE[resolved] = (stat.st_mtime_ns, stat.st_size, entries)
462
+ return entries
463
+
464
+
465
+ def find_entry(model_id: str, entries: Sequence[CatalogEntry] | None = None) -> CatalogEntry | None:
466
+ pool = load_catalog_file() if entries is None else entries
467
+ return next((entry for entry in pool if entry.id == model_id), None)
724
468
 
725
469
 
726
470
  def build_number(tag: str | None) -> int | None:
@@ -735,16 +479,3 @@ def engine_too_old(entry: CatalogEntry, engine_tag: str | None) -> bool:
735
479
  engine is not gated here: the deploy plan pins one that satisfies ``min_engine``."""
736
480
  have, need = build_number(engine_tag), build_number(entry.min_engine)
737
481
  return have is not None and need is not None and have < need
738
-
739
-
740
- FIXTURE_DIR = Path(__file__).with_name("fixtures")
741
-
742
-
743
- def shipped_fixture(fixture: dict[str, object]) -> dict[str, object]:
744
- """An acceptance input this package ships travels with the verify step as a data: URL, so the
745
- target needs no network for it; the target still checks its size and SHA256."""
746
- path = FIXTURE_DIR / str(fixture.get("name"))
747
- if not path.is_file():
748
- return fixture
749
- data = base64.b64encode(path.read_bytes()).decode()
750
- return {**fixture, "url": "data:application/octet-stream;base64," + data}
@@ -12,14 +12,13 @@ the Hub, exactly like a hand-entered unpinned file."""
12
12
  from __future__ import annotations
13
13
 
14
14
  import argparse
15
- import hashlib
16
15
  import json
17
16
  import re
18
17
  from datetime import date
19
18
  from pathlib import Path
20
19
  from typing import Any
21
20
 
22
- from localmodels import catalog, cli_help
21
+ from localmodels import catalog, cli_help, http_local
23
22
  from localmodels.catalog import STATUSES, TASKS
24
23
  from localmodels.estimator import LayerKind, profile_from_gguf
25
24
  from localmodels.gguf import GGUFHeader, read_gguf_header, split_parts
@@ -42,12 +41,7 @@ def quant_from_stem(stem: str) -> str | None:
42
41
  return tail if _QUANT_RE.fullmatch(tail) else None
43
42
 
44
43
 
45
- def _sha256(path: Path) -> str:
46
- digest = hashlib.sha256()
47
- with path.open("rb") as f:
48
- for chunk in iter(lambda: f.read(1 << 20), b""):
49
- digest.update(chunk)
50
- return digest.hexdigest()
44
+ _sha256 = http_local.sha256_file
51
45
 
52
46
 
53
47
  def entry_files(path: Path, revision: str | None) -> list[dict[str, Any]]: