@simplexai/localmodels-linux-x64 0.1.0-dev.49 → 0.1.0-dev.51

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 (67) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +65 -59
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/catalog.json +2395 -9
  5. package/modules/localmodels/deploy.py +29 -134
  6. package/modules/localmodels/download-mirrors.json +47 -0
  7. package/modules/localmodels/engines-strata-poly-0.2.19-poly.1.json +79 -0
  8. package/modules/localmodels/engines-strata-poly-0.2.20-poly.1.json +132 -0
  9. package/modules/localmodels/gateway.py +23 -6
  10. package/modules/localmodels/gateway_bifrost.py +6 -2
  11. package/modules/localmodels/harness.py +8 -2
  12. package/modules/localmodels/harness_gateway.py +78 -17
  13. package/modules/localmodels/harness_probe.py +43 -23
  14. package/modules/localmodels/hosts.py +52 -5
  15. package/modules/localmodels/library_floor.py +76 -0
  16. package/modules/localmodels/library_gateway.py +17 -1
  17. package/modules/localmodels/library_jobs.py +38 -6
  18. package/modules/localmodels/library_model.py +5 -0
  19. package/modules/localmodels/library_poly.py +273 -0
  20. package/modules/localmodels/library_pricing.py +24 -35
  21. package/modules/localmodels/library_serve.py +7 -0
  22. package/modules/localmodels/library_state.py +16 -0
  23. package/modules/localmodels/library_status.py +114 -29
  24. package/modules/localmodels/llm_rank.py +14 -0
  25. package/modules/localmodels/magpie_windows.py +312 -0
  26. package/modules/localmodels/plan_envelope.py +234 -3
  27. package/modules/localmodels/probe.py +1 -1
  28. package/modules/localmodels/process_identity.py +19 -9
  29. package/modules/localmodels/process_identity_darwin.py +155 -0
  30. package/modules/localmodels/remote_ops.py +11 -0
  31. package/modules/localmodels/remote_ops_download.py +30 -5
  32. package/modules/localmodels/remote_ops_service.py +11 -13
  33. package/modules/localmodels/reuse.py +13 -6
  34. package/modules/localmodels/runtime_cli.py +8 -8
  35. package/modules/localmodels/runtime_install.py +25 -1
  36. package/modules/localmodels/runtime_io.py +32 -18
  37. package/modules/localmodels/setup_inspection.py +83 -79
  38. package/modules/localmodels/setup_inspection_harness.py +147 -0
  39. package/modules/localmodels/setup_text.py +12 -0
  40. package/modules/localmodels/setup_upgrade.py +11 -1
  41. package/modules/localmodels/stack.py +3 -1
  42. package/modules/localmodels/stack_auto.py +6 -2
  43. package/modules/localmodels/stack_cli.py +39 -0
  44. package/modules/localmodels/stack_clients.py +1 -1
  45. package/modules/localmodels/stack_compose.py +12 -43
  46. package/modules/localmodels/stack_down.py +25 -16
  47. package/modules/localmodels/stack_hardware.py +12 -1
  48. package/modules/localmodels/stack_picks.py +28 -13
  49. package/modules/localmodels/stack_plan.py +55 -3
  50. package/modules/localmodels/stack_remove.py +3 -1
  51. package/modules/localmodels/stack_suite.py +80 -20
  52. package/modules/localmodels/strata-poly-serve-0.2.19-poly.1.txt +428 -0
  53. package/modules/localmodels/{strata-poly-serve-0.1.45-poly.9.txt → strata-poly-serve-0.2.20-poly.1.txt} +2 -2
  54. package/modules/localmodels/strata_poly_server.py +33 -2
  55. package/modules/localmodels/suite.py +45 -4
  56. package/modules/localmodels/tool_archive.py +4 -0
  57. package/modules/localmodels/vision.py +4 -2
  58. package/modules/localmodels/win_probe.py +24 -7
  59. package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/METADATA +1 -1
  60. package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/RECORD +62 -56
  61. package/package.json +1 -1
  62. package/tool.json +1 -1
  63. package/modules/localmodels/engines-strata-poly-0.1.45-poly.9.json +0 -75
  64. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/WHEEL +0 -0
  65. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/entry_points.txt +0 -0
  66. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/NOTICE +0 -0
  67. /package/modules/{simplex_localmodels-0.1.0.dev49.dist-info → simplex_localmodels-0.1.0.dev51.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,273 @@
1
+ """PolyStrata (``strata-poly``) LLM recipes for the model library.
2
+
3
+ Validated ``strata-poly`` chat recipes that declare model-card metadata (``display_name``,
4
+ ``description``, ``family``, ``publisher``, ``parameters``) join ``localmodels library`` on
5
+ supported NVIDIA Linux and Windows hosts alongside ``llama.cpp`` models. Pricing runs
6
+ ``suite.build_plan`` so CUDA 13 driver checks, glibc checks, vision reader placement and host
7
+ RAM ceilings stay identical to ``stack plan``.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from localmodels import (
13
+ budget,
14
+ catalog_recipes,
15
+ deploy,
16
+ engines,
17
+ hosts,
18
+ plan_envelope,
19
+ stack_suite,
20
+ suite,
21
+ vision,
22
+ )
23
+ from localmodels import catalog as cat
24
+ from localmodels.context_policy import AgentPosture
25
+ from localmodels.estimator import PhysicsRefusal
26
+ from localmodels.library_model import Reason, split_id
27
+ from localmodels.probe import GPU, HostFacts
28
+ from localmodels.records import Plan
29
+
30
+
31
+ def strata_ids() -> set[str]:
32
+ """Every catalog component id of a Strata/PolyStrata runtime."""
33
+ return {
34
+ c["id"] for c in catalog_recipes.components() if c["runtime"] in ("strata", "strata-poly")
35
+ }
36
+
37
+
38
+ def engine_blocker(exc: plan_envelope.PlanError) -> Reason | None:
39
+ """Structured unavailability reason for CUDA driver or runtime library refusals."""
40
+ if isinstance(exc, engines.CudaDriverError):
41
+ reason: Reason = {"code": "DRIVER_UPDATE_REQUIRED"}
42
+ if exc.required_cuda:
43
+ reason["required_cuda"] = exc.required_cuda
44
+ if exc.detected_cuda:
45
+ reason["detected_cuda"] = exc.detected_cuda
46
+ if exc.driver_version:
47
+ reason["driver_version"] = exc.driver_version
48
+ return reason
49
+ if isinstance(exc, engines.EngineUnavailableError):
50
+ reason = {"code": "RUNTIME_DEPENDENCY_MISSING"}
51
+ if exc.missing_libraries:
52
+ reason["missing_libraries"] = list(exc.missing_libraries)
53
+ if exc.required_glibc:
54
+ reason["required_glibc"] = exc.required_glibc
55
+ if exc.detected_glibc:
56
+ reason["detected_glibc"] = exc.detected_glibc
57
+ return reason
58
+ return None
59
+
60
+
61
+ def is_library_recipe(recipe: suite.SuiteRecipe) -> bool:
62
+ """True when a ``strata-poly`` LLM component carries complete model-card metadata."""
63
+ return (
64
+ recipe["runtime"] == "strata-poly"
65
+ and recipe["task"] == "llm"
66
+ and bool(recipe.get("display_name"))
67
+ and bool(recipe.get("description"))
68
+ )
69
+
70
+
71
+ def _validated_for(recipe: suite.SuiteRecipe, platform: str) -> bool:
72
+ if recipe.get("status") != "validated" or not stack_suite.built_for(recipe, platform):
73
+ return False
74
+ scope = recipe.get("validated_on")
75
+ if not scope:
76
+ return True
77
+ # Decision 48: Linux CUDA evidence also validates native Windows x64 CUDA builds.
78
+ return platform in scope or (platform == "win32" and "linux" in scope)
79
+
80
+
81
+ def eligible(recipe: suite.SuiteRecipe, platform: str) -> bool:
82
+ """Whether ``recipe`` should be shown by ``library status`` on ``platform``."""
83
+ return is_library_recipe(recipe) and _validated_for(recipe, platform)
84
+
85
+
86
+ def in_library(recipe_id: str, facts: HostFacts) -> bool:
87
+ """Whether ``recipe_id`` is exposed as a downloadable model in the library on this host."""
88
+ return any(
89
+ r["id"] == recipe_id and eligible(r, facts["platform"]) for r in suite.recipes("llm")
90
+ )
91
+
92
+
93
+ def is_poly_plan(plan: Plan) -> bool:
94
+ """True when ``plan`` deploys a ``strata-poly`` server."""
95
+ if str(plan["engine"].get("build") or "").startswith("strata-poly"):
96
+ return True
97
+ return str(plan["launch"].get("frontend_requirements") or "").startswith("strata-poly")
98
+
99
+
100
+ def as_entry(recipe: suite.SuiteRecipe) -> tuple[cat.CatalogEntry, cat.QuantVariant]:
101
+ """Build a ``CatalogEntry`` + ``QuantVariant`` view of a ``strata-poly`` recipe so
102
+ ``library_status`` and ``library_gateway`` render its model card without special cases."""
103
+ alias = recipe.get("alias") or recipe["id"]
104
+ weight_files = tuple(
105
+ cat.AssetFile(
106
+ path=f"{alias}.gguf" if i == 0 else str(f.get("local_name") or f["path"]),
107
+ size_bytes=int(f["size_bytes"]),
108
+ local=str(f.get("local_name") or "") or None,
109
+ revision=str(f.get("revision") or recipe["revision"]),
110
+ sha256=str(f["sha256"]),
111
+ )
112
+ for i, f in enumerate(recipe["files"])
113
+ if not f.get("vision")
114
+ )
115
+ vision_files = [f for f in recipe["files"] if f.get("vision")]
116
+ mmproj = (
117
+ cat.AssetFile(
118
+ path=str(vision_files[0]["path"]),
119
+ size_bytes=int(vision_files[0]["size_bytes"]),
120
+ local=str(vision_files[0].get("local_name") or "") or None,
121
+ revision=str(vision_files[0].get("revision") or recipe["revision"]),
122
+ sha256=str(vision_files[0]["sha256"]),
123
+ )
124
+ if vision_files
125
+ else None
126
+ )
127
+ variant = cat.QuantVariant(
128
+ quant=recipe["version"],
129
+ files=weight_files,
130
+ validated=recipe.get("status") == "validated",
131
+ )
132
+ quality_doc = recipe.get("quality")
133
+ score = int(quality_doc["score"]) if isinstance(quality_doc, dict) else 0
134
+ entry = cat.CatalogEntry(
135
+ id=recipe["id"],
136
+ display_name=recipe.get("display_name") or alias,
137
+ description=recipe.get("description") or "",
138
+ repo=recipe["repo"],
139
+ variants=(variant,),
140
+ n_ctx_train=int(recipe.get("context") or 65536),
141
+ full_layers=0,
142
+ recurrent_layers=0,
143
+ per_layer_f16=0,
144
+ moe=bool(recipe.get("moe", True)),
145
+ mmproj=mmproj,
146
+ quality=score,
147
+ license=recipe.get("license") or "",
148
+ license_url=recipe.get("license_url") or "",
149
+ status=recipe.get("status") or "",
150
+ tasks=tuple(recipe.get("tasks") or ("llm",)),
151
+ evidence=tuple(recipe.get("evidence") or ()),
152
+ validated_on=tuple(recipe.get("validated_on") or ()),
153
+ reasoning_efforts=tuple(recipe.get("reasoning_efforts") or ()),
154
+ runtime="strata-poly",
155
+ engine=recipe.get("engine") or "",
156
+ family=recipe.get("family") or "",
157
+ publisher=recipe.get("publisher") or "",
158
+ parameters=recipe.get("parameters") or "",
159
+ active_parameters=recipe.get("active_parameters") or "",
160
+ )
161
+ return entry, variant
162
+
163
+
164
+ def shown_entries(facts: HostFacts) -> list[tuple[cat.CatalogEntry, cat.QuantVariant]]:
165
+ """Every ``strata-poly`` library model visible on this host."""
166
+ platform = facts["platform"]
167
+ return [as_entry(r) for r in suite.recipes("llm") if eligible(r, platform)]
168
+
169
+
170
+ def find_entry(model_id: str) -> tuple[cat.CatalogEntry, cat.QuantVariant] | None:
171
+ """Resolve ``id:QUANT`` (or bare ``id``) to a ``strata-poly`` library model, or None."""
172
+ catalog_id, quant = split_id(model_id)
173
+ for recipe in suite.recipes("llm"):
174
+ if recipe["id"] == catalog_id and is_library_recipe(recipe):
175
+ if not quant or quant == recipe["version"]:
176
+ return as_entry(recipe)
177
+ return None
178
+
179
+
180
+ def _gpu_for_pool(facts: HostFacts, pool: str) -> GPU:
181
+ if not pool.startswith("gpu:"):
182
+ raise plan_envelope.PlanError(f"PolyStrata recipes need a discrete NVIDIA GPU, not {pool}")
183
+ index = int(pool.split(":", 1)[1])
184
+ gpu = next(
185
+ (g for g in facts.get("gpus") or [] if g["index"] == index and g.get("vendor") == "nvidia"),
186
+ None,
187
+ )
188
+ if gpu is None:
189
+ raise plan_envelope.PlanError(f"this computer has no NVIDIA GPU for pool {pool}")
190
+ return gpu
191
+
192
+
193
+ def price(
194
+ facts: HostFacts,
195
+ recipe_id: str,
196
+ pool: str,
197
+ base_dir: str,
198
+ port: int,
199
+ posture: AgentPosture,
200
+ *,
201
+ require_live: bool = False,
202
+ ) -> Plan:
203
+ """Price one ``strata-poly`` library model on discrete pool ``pool``."""
204
+ if facts["platform"] not in ("linux", "win32"):
205
+ raise plan_envelope.PlanError(
206
+ "PolyStrata recipes run on Linux and Windows NVIDIA GPUs only"
207
+ )
208
+ gpu = _gpu_for_pool(facts, pool)
209
+ recipe = suite.recipe(recipe_id)
210
+ if not stack_suite.built_for(recipe, facts["platform"]):
211
+ raise plan_envelope.PlanError(f"{recipe_id} has no engine build for {facts['platform']}")
212
+ spec = recipe.get("vision") or {}
213
+ reader = vision.strata_mode(posture.vision, gpu["total_bytes"], bool(spec))
214
+ reserve = stack_suite.poly_reserve_mib(recipe, gpu, 0)
215
+ opts = suite.SuiteOptions(
216
+ base_dir=base_dir,
217
+ hf_endpoint=deploy.hf_endpoint(),
218
+ gpu=gpu,
219
+ port=port,
220
+ vram_reserve_mib=reserve,
221
+ vision_reader=reader,
222
+ )
223
+ plan = suite.build_plan(hosts.LOCAL_ID, facts, recipe, opts)
224
+ if facts["platform"] == "win32":
225
+ plan = suite.unbounded(plan)
226
+ need_vram = int(recipe.get("vram_bytes") or 0)
227
+ if need_vram > gpu["total_bytes"]:
228
+ msg = f"{recipe_id} needs {need_vram} bytes of VRAM, exceeding {gpu['total_bytes']} bytes"
229
+ raise deploy.AgentMemoryError(
230
+ msg, PhysicsRefusal(need_vram, gpu["total_bytes"], msg), "GPU memory"
231
+ )
232
+ min_free = int(recipe.get("min_vram_free_bytes") or need_vram)
233
+ if require_live and min_free > gpu["free_bytes"]:
234
+ msg = (
235
+ f"{recipe_id} needs at least {min_free} bytes of free VRAM now, "
236
+ f"only {gpu['free_bytes']} bytes free"
237
+ )
238
+ raise deploy.AgentMemoryError(
239
+ msg, PhysicsRefusal(min_free, gpu["free_bytes"], msg), "GPU memory"
240
+ )
241
+ if not require_live and min_free > gpu["free_bytes"]:
242
+ msg = (
243
+ f"{recipe_id} needs at least {min_free} bytes of loadable VRAM, "
244
+ f"only {gpu['free_bytes']} bytes available"
245
+ )
246
+ raise deploy.AgentMemoryError(
247
+ msg, PhysicsRefusal(min_free, gpu["free_bytes"], msg), "GPU memory"
248
+ )
249
+ min_total_ram = int(recipe.get("min_ram_total_bytes") or 0)
250
+ total_ram = facts["ram"]["total_bytes"]
251
+ if min_total_ram > total_ram:
252
+ msg = (
253
+ f"{recipe_id} recommends at least {min_total_ram} bytes of system memory, "
254
+ f"this host has {total_ram} bytes"
255
+ )
256
+ raise deploy.AgentMemoryError(
257
+ msg, PhysicsRefusal(min_total_ram, total_ram, msg), "system memory"
258
+ )
259
+ needed_ram = suite.bounded_ram(plan) + budget.HARNESS_RAM + budget.RAM_FLOOR
260
+ _, avail_ram = budget.host_ram(facts)
261
+ if needed_ram > avail_ram:
262
+ msg = (
263
+ f"{recipe_id} needs {needed_ram} bytes of system memory, "
264
+ f"exceeding {avail_ram} bytes available"
265
+ )
266
+ raise deploy.AgentMemoryError(
267
+ msg, PhysicsRefusal(needed_ram, avail_ram, msg), "system memory"
268
+ )
269
+ # PolyStrata's expert cache fills free VRAM up to the recipe's full-VRAM footprint.
270
+ full_vram = int(str(plan["launch"].get("vram_bytes") or 0))
271
+ if full_vram > gpu["free_bytes"]:
272
+ plan["launch"]["vram_bytes"] = gpu["free_bytes"]
273
+ return plan
@@ -23,17 +23,18 @@ from typing import Any, Literal
23
23
 
24
24
  from localmodels import (
25
25
  budget,
26
- catalog_recipes,
27
26
  context_policy,
28
27
  deploy,
29
28
  engines,
30
29
  hosts,
30
+ library_poly,
31
31
  library_vram,
32
32
  llm_rank,
33
33
  metal,
34
34
  plan_envelope,
35
35
  stack_hardware,
36
36
  stack_llm_ram,
37
+ suite,
37
38
  vision,
38
39
  )
39
40
  from localmodels import catalog as cat
@@ -86,8 +87,9 @@ def is_chat(entry: cat.CatalogEntry) -> bool:
86
87
 
87
88
 
88
89
  def shown(facts: HostFacts, catalog: Iterable[cat.CatalogEntry]) -> list[Model]:
89
- """Validated chat models, library candidates, Mac ladder, and Windows fallback rows."""
90
- return [
90
+ """Validated chat models, library candidates, Mac ladder, Windows fallback, and
91
+ supported PolyStrata LLM recipes."""
92
+ rows = [
91
93
  Model(e, v)
92
94
  for e in catalog
93
95
  if is_chat(e)
@@ -99,6 +101,8 @@ def shown(facts: HostFacts, catalog: Iterable[cat.CatalogEntry]) -> list[Model]:
99
101
  )
100
102
  for v in e.variants
101
103
  ]
104
+ rows += [Model(e, v) for e, v in library_poly.shown_entries(facts)]
105
+ return rows
102
106
 
103
107
 
104
108
  def find(model_id: str, catalog: Iterable[cat.CatalogEntry]) -> Model:
@@ -110,6 +114,8 @@ def find(model_id: str, catalog: Iterable[cat.CatalogEntry]) -> Model:
110
114
  if not quant or variant.quant == quant:
111
115
  if quant or variant is entry.variants[-1]:
112
116
  return Model(entry, variant)
117
+ if poly := library_poly.find_entry(model_id):
118
+ return Model(*poly)
113
119
  raise LibraryError("MODEL_UNKNOWN", f"the catalog has no chat model {model_id}")
114
120
 
115
121
 
@@ -320,7 +326,9 @@ class LiveMemoryUnavailable(plan_envelope.PlanError):
320
326
 
321
327
 
322
328
  def host_ram_bytes(plan: Plan, catalog: tuple[cat.CatalogEntry, ...]) -> int:
323
- """Host RAM held by one discrete-GPU llama.cpp model plus its prompt-cache floor."""
329
+ """Host RAM held by one discrete-GPU model (llama.cpp or PolyStrata)."""
330
+ if library_poly.is_poly_plan(plan):
331
+ return suite.bounded_ram(plan)
324
332
  min_cache_bytes = (
325
333
  (posture().prompt_cache_min_mib << 20) if posture().prompt_cache_mib > 0 else 0
326
334
  )
@@ -345,6 +353,10 @@ def price(
345
353
  placement = pools(facts).get(pool)
346
354
  if placement is None:
347
355
  raise plan_envelope.PlanError(f"this computer has no pool {pool}")
356
+ if model.entry.runtime == "strata-poly":
357
+ return library_poly.price(
358
+ facts, model.entry.id, pool, base_dir, port, posture(), require_live=require_live
359
+ )
348
360
  if require_live and pool == "unified" and metal.supported(facts):
349
361
  if problem := metal.problem(facts):
350
362
  raise LiveMemoryUnavailable(problem)
@@ -418,31 +430,11 @@ class Priced:
418
430
  reclaim_bytes: int = 0 # approximate VRAM to free when reclaimable_desktop_vram is True
419
431
 
420
432
 
421
- def _engine_blocker(exc: plan_envelope.PlanError) -> Reason | None:
422
- if isinstance(exc, engines.CudaDriverError):
423
- reason: Reason = {"code": "DRIVER_UPDATE_REQUIRED"}
424
- if exc.required_cuda:
425
- reason["required_cuda"] = exc.required_cuda
426
- if exc.detected_cuda:
427
- reason["detected_cuda"] = exc.detected_cuda
428
- if exc.driver_version:
429
- reason["driver_version"] = exc.driver_version
430
- return reason
431
- if isinstance(exc, engines.EngineUnavailableError):
432
- reason = {"code": "RUNTIME_DEPENDENCY_MISSING"}
433
- if exc.missing_libraries:
434
- reason["missing_libraries"] = list(exc.missing_libraries)
435
- if exc.required_glibc:
436
- reason["required_glibc"] = exc.required_glibc
437
- if exc.detected_glibc:
438
- reason["detected_glibc"] = exc.detected_glibc
439
- return reason
440
- return None
441
-
442
-
443
433
  def _min_pool_need(model: Model, pool: str, exc: deploy.AgentMemoryError, facts: HostFacts) -> int:
444
434
  """Exact pool-aligned free bytes required at the agent floor when ``available_bytes`` clamped
445
435
  to zero inside ``agent_budget`` or ``vision.priced``."""
436
+ if model.entry.runtime == "strata-poly":
437
+ return exc.needed_bytes
446
438
  if gpu_index(pool) is not None:
447
439
  return exc.needed_bytes + AGENT_VRAM_RESERVE_BYTES
448
440
  if pool == "unified" and metal.supported(facts):
@@ -542,7 +534,7 @@ def judge(
542
534
  shortfall = gap
543
535
  continue
544
536
  except (engines.CudaDriverError, engines.EngineUnavailableError) as exc:
545
- blocker = blocker or _engine_blocker(exc)
537
+ blocker = blocker or library_poly.engine_blocker(exc)
546
538
  continue
547
539
  except plan_envelope.PlanError:
548
540
  continue
@@ -654,12 +646,6 @@ def download_reason(facts: HostFacts, priced: Priced, disk_free: int) -> Reason
654
646
  return None
655
647
 
656
648
 
657
- def _strata_ids() -> set[str]:
658
- return {
659
- c["id"] for c in catalog_recipes.components() if c["runtime"] in ("strata", "strata-poly")
660
- }
661
-
662
-
663
649
  def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, str] | None:
664
650
  """Best live-fitting llama.cpp library model ranked by ``llm_rank.choose()``."""
665
651
  catalog = entries()
@@ -673,7 +659,8 @@ def _smartest_library_fallback(facts: HostFacts, base_dir: str) -> tuple[str, st
673
659
  fallback_ids: set[str] = set()
674
660
  for model in shown(facts, catalog):
675
661
  if (
676
- not llm_rank.automatic_here(model.entry, facts)
662
+ model.entry.runtime != "llama.cpp"
663
+ or not llm_rank.automatic_here(model.entry, facts)
677
664
  or model.variant is not model.entry.variants[-1]
678
665
  ):
679
666
  continue
@@ -718,7 +705,9 @@ def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple
718
705
  (p for p in view.get("picks") or [] if p["role"] == "smartest" and not p.get("shared")),
719
706
  None,
720
707
  )
721
- if pick is not None and pick["id"] not in _strata_ids():
708
+ if pick is not None and (
709
+ pick["id"] not in library_poly.strata_ids() or library_poly.in_library(pick["id"], seen)
710
+ ):
722
711
  return (pick["id"], pick["quant"])
723
712
  if pick is not None or _cuda_uma(seen) is not None:
724
713
  return _smartest_library_fallback(seen, base_dir)
@@ -21,6 +21,7 @@ from localmodels import (
21
21
  app,
22
22
  deploy,
23
23
  engines,
24
+ frontend,
24
25
  harness,
25
26
  hosts,
26
27
  library_gateway,
@@ -269,6 +270,12 @@ def _start(
269
270
  handle.update("load", done, len(steps), load_step=load_step)
270
271
  progress(model.id, "load", done, len(steps), load_step=load_step)
271
272
 
273
+ if reqs := plan["launch"].get("frontend_requirements"):
274
+ try:
275
+ frontend.install(str(plan["launch"]["frontend_base_dir"]), str(reqs))
276
+ except frontend.FrontendError as exc:
277
+ raise _fail(record, LibraryError("ENGINE_START_FAILED", str(exc))) from None
278
+
272
279
  finished = app.run_deploy(hosts.LOCAL_ID, plan, on_event=seen)
273
280
  if not finished["ok"]:
274
281
  error = LibraryError(_start_code(finished), str(finished.get("error") or "start failed"))
@@ -76,6 +76,7 @@ class _JobSince20261113(TypedDict, total=False):
76
76
  source: str # download source label: huggingface | modelscope | custom | cache
77
77
  connections: int # active parallel download connections
78
78
  load_step: str # load sub-step: prepare | start | load | warm
79
+ error: Problem # a download that stopped cleanly: status shows why; cancel discards it
79
80
 
80
81
 
81
82
  class Job(_JobSince20261113):
@@ -233,6 +234,21 @@ def clear_job(model: str) -> None:
233
234
  path.unlink(missing_ok=True)
234
235
 
235
236
 
237
+ def fail_job(job: Job, error: Problem) -> None:
238
+ """Under ``locked()``: end the job's live claim while keeping its record and error on disk so
239
+ ``status`` reports why it stopped, ``cancel`` discards its partials, and a new download
240
+ resumes them."""
241
+ job["error"] = error
242
+ job["updated_at"] = utc_now()
243
+ hosts.save_private(job_path(job["model"]), job)
244
+ for path in (
245
+ cancel_path(job["model"]),
246
+ pid_path(job["model"]),
247
+ Path(str(pid_path(job["model"])) + ".identity.json"),
248
+ ):
249
+ path.unlink(missing_ok=True)
250
+
251
+
236
252
  class JobHandle:
237
253
  """This process's job: progress written for ``status``, at most once a second."""
238
254
 
@@ -7,6 +7,7 @@ from __future__ import annotations
7
7
  import datetime as dt
8
8
  import re
9
9
  import urllib.request
10
+ from collections.abc import Mapping
10
11
  from dataclasses import dataclass, field
11
12
  from typing import cast
12
13
 
@@ -14,6 +15,7 @@ from localmodels import (
14
15
  __version__,
15
16
  debug_mode,
16
17
  hosts,
18
+ library_floor,
17
19
  library_gateway,
18
20
  library_pricing,
19
21
  library_state,
@@ -32,6 +34,7 @@ from localmodels.library_model import (
32
34
  DebugInfo,
33
35
  Download,
34
36
  DownloadSource,
37
+ Engine,
35
38
  Holder,
36
39
  Host,
37
40
  LibraryError,
@@ -149,7 +152,9 @@ def _state(lib: Library, model: str, record: Record | None) -> tuple[str, Proble
149
152
  job, alive = lib.jobs.get(model, (None, False))
150
153
  if job is not None and alive:
151
154
  return ("downloading" if job["kind"] == "download" else "loading"), None
152
- if job is not None: # its process ended without clearing it
155
+ if job is not None: # its process ended without clearing it, or it failed and kept its partials
156
+ if isinstance(err := job.get("error"), dict) and isinstance(err.get("code"), str):
157
+ return "failed", {"code": err["code"], "detail": str(err.get("detail") or "")}
153
158
  code = "DOWNLOAD_FAILED" if job["kind"] == "download" else "ENGINE_START_FAILED"
154
159
  return "failed", {"code": code, "detail": f"the {job['kind']} process ended early"}
155
160
  if record is None:
@@ -294,13 +299,70 @@ def _loading(job: Job) -> Load:
294
299
  return {"step": step, "done_steps": done_steps, "total_steps": total_steps}
295
300
 
296
301
 
302
+ def _apply_engine_meta(lib: Library, found: Row, model: Model, plan: Plan | None) -> None:
303
+ engine_doc = plan["engine"] if plan is not None else None
304
+ engine = _engine_kind(
305
+ model.entry.runtime, str(engine_doc.get("build") or "") if engine_doc else ""
306
+ )
307
+ found["engine"] = engine
308
+ found["engine_label"] = (
309
+ _format_engine_label(engine_doc)
310
+ if engine_doc is not None
311
+ else _fallback_engine_label(model)
312
+ )
313
+ raw_slots = plan["launch"].get("slots") if plan is not None else None
314
+ parsed_slots = int(str(raw_slots)) if raw_slots is not None else 0
315
+ found["concurrency"] = (
316
+ parsed_slots
317
+ if parsed_slots >= 1
318
+ else (1 if engine in ("polystrata", "strata") else library_pricing.posture().slots)
319
+ )
320
+ if plan is not None and engine in ("polystrata", "strata"):
321
+ host_ram = library_pricing.host_ram_bytes(plan, lib.catalog)
322
+ if host_ram > 0:
323
+ found["host_ram_bytes"] = host_ram
324
+
325
+
326
+ def _apply_record_meta(
327
+ found: Row,
328
+ model: Model,
329
+ record: Record | None,
330
+ state: str,
331
+ problem: Problem | None,
332
+ ) -> None:
333
+ if state != "absent":
334
+ if (selector := pi_model_of(model, record)) is not None:
335
+ found["pi_model"] = selector
336
+ if record is not None:
337
+ if state == "loaded" and (reg := record.get("registration")):
338
+ found["endpoint"] = {
339
+ "base_url": str(record["plan"]["endpoint"]["base_url"]),
340
+ "gateway_model": reg["model"],
341
+ }
342
+ if (speed := record.get("tokens_per_second")) is not None:
343
+ found["tokens_per_second"] = round(speed, 1)
344
+ if (prefill := record.get("prompt_tokens_per_second")) is not None:
345
+ found["prompt_tokens_per_second"] = round(prefill, 1)
346
+ if state == "idle" and (note := record.get("note")):
347
+ found["note"] = note
348
+ if state == "failed" and problem is not None:
349
+ found["error"] = problem
350
+
351
+
297
352
  def row(lib: Library, model: Model) -> Row:
298
353
  record = lib.records.get(model.id)
299
354
  priced = lib.judge(model)
300
355
  state, problem = _state(lib, model.id, record)
301
356
  plan = _plan_of(lib, model, record, priced)
302
357
  job, alive = lib.jobs.get(model.id, (None, False))
303
- memory = library_pricing.memory_bytes(plan) if plan is not None else 0
358
+ fallback_memory, fallback_window, fallback_vision, fallback_download = (
359
+ library_floor.floor_metadata(
360
+ lib.facts, model, priced.need_bytes, memory_kind=priced.memory_kind
361
+ )
362
+ if plan is None
363
+ else (0, 0, False, 0)
364
+ )
365
+ memory = library_pricing.memory_bytes(plan) if plan is not None else fallback_memory
304
366
  if record is None and job is not None and alive:
305
367
  memory = job["memory_bytes"] or memory
306
368
  if record is not None and record["state"] != "loaded" and record.get("memory_bytes"):
@@ -318,11 +380,13 @@ def row(lib: Library, model: Model) -> Row:
318
380
  "name": model.name,
319
381
  "description": model.entry.description,
320
382
  "quant": model.variant.quant,
321
- "context_tokens": int(str(launch.get("window") or 0)),
322
- "vision": vision.reads_pictures(launch),
383
+ "context_tokens": int(str(launch.get("window") or 0))
384
+ if plan is not None
385
+ else fallback_window,
386
+ "vision": vision.reads_pictures(launch) if plan is not None else fallback_vision,
323
387
  "download_bytes": sum(f["size_bytes"] for f in plan["files"])
324
388
  if plan is not None
325
- else sum(f.size_bytes for f in model.variant.files),
389
+ else fallback_download,
326
390
  "memory_bytes": memory,
327
391
  "fit": priced.fit, # type: ignore[typeddict-item]
328
392
  "recommended": False,
@@ -341,23 +405,8 @@ def row(lib: Library, model: Model) -> Row:
341
405
  elif state == "loading" and job is not None and alive:
342
406
  found["load"] = _loading(job)
343
407
  found.update(card(model, found["vision"]))
344
- if state != "absent":
345
- if (selector := pi_model_of(model, record)) is not None:
346
- found["pi_model"] = selector
347
- if record is not None:
348
- if state == "loaded" and (reg := record.get("registration")):
349
- found["endpoint"] = {
350
- "base_url": str(record["plan"]["endpoint"]["base_url"]),
351
- "gateway_model": reg["model"],
352
- }
353
- if (speed := record.get("tokens_per_second")) is not None:
354
- found["tokens_per_second"] = round(speed, 1)
355
- if (prefill := record.get("prompt_tokens_per_second")) is not None:
356
- found["prompt_tokens_per_second"] = round(prefill, 1)
357
- if state == "idle" and (note := record.get("note")):
358
- found["note"] = note
359
- if state == "failed" and problem is not None:
360
- found["error"] = problem
408
+ _apply_engine_meta(lib, found, model, plan)
409
+ _apply_record_meta(found, model, record, state, problem)
361
410
  return found
362
411
 
363
412
 
@@ -433,6 +482,41 @@ def _pressure_label(level: object) -> MemoryPressure | None:
433
482
  return "critical"
434
483
 
435
484
 
485
+ _BACKEND_LABELS = {"cuda": "CUDA", "metal": "Metal", "cpu": "CPU"}
486
+
487
+
488
+ def _engine_kind(runtime: str, build: str = "") -> Engine:
489
+ if runtime == "strata-poly" or build.startswith("strata-poly"):
490
+ return "polystrata"
491
+ if runtime == "strata" or build.startswith("strata"):
492
+ return "strata"
493
+ return "llama.cpp"
494
+
495
+
496
+ def _format_engine_label(engine: Mapping[str, object]) -> str:
497
+ build = str(engine.get("build") or "")
498
+ if build.startswith("strata-poly-"):
499
+ label = f"PolyStrata {build.removeprefix('strata-poly-')}".strip()
500
+ elif build.startswith("strata-"):
501
+ label = f"Strata {build.removeprefix('strata-')}".strip()
502
+ else:
503
+ label = f"llama.cpp {build}".strip()
504
+ if (kind := engine.get("backend")) in _BACKEND_LABELS:
505
+ label += f" · {_BACKEND_LABELS[str(kind)]}"
506
+ return label
507
+
508
+
509
+ def _fallback_engine_label(model: Model) -> str:
510
+ tag = model.entry.engine or ""
511
+ if model.entry.runtime == "strata-poly":
512
+ version = tag.removeprefix("strata-poly-")
513
+ return f"PolyStrata {version}".strip() if version else "PolyStrata"
514
+ if model.entry.runtime == "strata":
515
+ version = tag.removeprefix("strata-")
516
+ return f"Strata {version}".strip() if version else "Strata"
517
+ return f"llama.cpp {tag}".strip() if tag else "llama.cpp"
518
+
519
+
436
520
  def host(lib: Library) -> Host:
437
521
  facts = lib.facts
438
522
  shown = library_pricing.visible(facts) # the cards the pools may use
@@ -441,13 +525,14 @@ def host(lib: Library) -> Host:
441
525
  os_info.get("distro")
442
526
  or " ".join(str(os_info.get(k) or "") for k in ("system", "release")).strip()
443
527
  )
444
- engine = next((p.plan["engine"] for p in lib.priced.values() if p.plan is not None), None)
445
- backend = {"cuda": "CUDA", "metal": "Metal", "cpu": "CPU"}
446
- engine_label = "llama.cpp"
447
- if engine is not None:
448
- engine_label = f"llama.cpp {engine.get('build') or ''}".strip()
449
- if (kind := engine.get("backend")) in backend:
450
- engine_label += f" · {backend[str(kind)]}"
528
+ engines = [p.plan["engine"] for p in lib.priced.values() if p.plan is not None]
529
+ by_family: dict[Engine, str] = {}
530
+ for engine in engines:
531
+ family = _engine_kind("", str(engine.get("build") or ""))
532
+ by_family.setdefault(family, _format_engine_label(engine))
533
+ engine_order: tuple[Engine, ...] = ("llama.cpp", "polystrata", "strata")
534
+ ordered = [by_family[f] for f in engine_order if f in by_family]
535
+ engine_label = " + ".join(ordered) if ordered else "llama.cpp"
451
536
  found: Host = {
452
537
  "platform": platform_name(facts),
453
538
  "arch": ARCH.get(str(facts.get("arch")), str(facts.get("arch"))),