@simplexai/localmodels-linux-arm64 0.1.0-dev.104 → 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 (81) hide show
  1. package/README.md +1 -1
  2. package/bootstrap.identity +1 -1
  3. package/bootstrap.sha256 +80 -78
  4. package/modules/localmodels/__init__.py +1 -1
  5. package/modules/localmodels/__main__.py +204 -86
  6. package/modules/localmodels/apple_sensors.py +23 -0
  7. package/modules/localmodels/approval.py +25 -2
  8. package/modules/localmodels/catalog.json +454 -31
  9. package/modules/localmodels/catalog.py +11 -0
  10. package/modules/localmodels/catalog_recipes.py +61 -3
  11. package/modules/localmodels/cli_help.py +10 -0
  12. package/modules/localmodels/cli_parser.py +313 -230
  13. package/modules/localmodels/component.py +20 -2
  14. package/modules/localmodels/custom_probe.py +4 -2
  15. package/modules/localmodels/deploy.py +11 -1
  16. package/modules/localmodels/engine_adapters/suite_plan.py +21 -21
  17. package/modules/localmodels/host_sensors.py +25 -2
  18. package/modules/localmodels/hosts.py +26 -5
  19. package/modules/localmodels/library_cli.py +34 -16
  20. package/modules/localmodels/library_custom.py +9 -1
  21. package/modules/localmodels/library_direct.py +41 -1
  22. package/modules/localmodels/library_jobs.py +23 -4
  23. package/modules/localmodels/library_model.py +146 -1
  24. package/modules/localmodels/library_order.py +175 -69
  25. package/modules/localmodels/library_poly.py +42 -11
  26. package/modules/localmodels/library_presentation.py +485 -0
  27. package/modules/localmodels/library_pricing.py +3 -1
  28. package/modules/localmodels/library_serve.py +208 -3
  29. package/modules/localmodels/library_state.py +47 -10
  30. package/modules/localmodels/library_status.py +29 -16
  31. package/modules/localmodels/llm_rank.py +9 -3
  32. package/modules/localmodels/plan_envelope.py +11 -2
  33. package/modules/localmodels/probe.py +34 -7
  34. package/modules/localmodels/quant_formats.py +9 -2
  35. package/modules/localmodels/records.py +19 -2
  36. package/modules/localmodels/remote_ops_verify.py +91 -24
  37. package/modules/localmodels/runtime_index.py +303 -0
  38. package/modules/localmodels/setup_inspection.py +22 -3
  39. package/modules/localmodels/speech_cli.py +20 -14
  40. package/modules/localmodels/speech_serve.py +9 -2
  41. package/modules/localmodels/speech_server.py +3 -0
  42. package/modules/localmodels/stack_args.py +270 -139
  43. package/modules/localmodels/stack_auto.py +90 -5
  44. package/modules/localmodels/stack_cli.py +117 -116
  45. package/modules/localmodels/stack_compose.py +5 -1
  46. package/modules/localmodels/stack_debug.py +14 -4
  47. package/modules/localmodels/stack_down.py +2 -0
  48. package/modules/localmodels/stack_hardware.py +14 -12
  49. package/modules/localmodels/stack_mlx.py +8 -1
  50. package/modules/localmodels/stack_picks.py +19 -20
  51. package/modules/localmodels/stack_plan.py +3 -2
  52. package/modules/localmodels/stack_review.py +28 -7
  53. package/modules/localmodels/stack_suite.py +11 -9
  54. package/modules/localmodels/stack_up.py +2 -0
  55. package/modules/localmodels/stack_view.py +180 -35
  56. package/modules/localmodels/stack_view_demo.py +2 -0
  57. package/modules/localmodels/stack_view_gpu.py +36 -2
  58. package/modules/localmodels/stack_view_schema.py +26 -3
  59. package/modules/localmodels/stack_view_slots.py +3 -1
  60. package/modules/localmodels/stack_view_telemetry.py +90 -4
  61. package/modules/localmodels/stack_view_tick.py +246 -40
  62. package/modules/localmodels/stack_view_words.py +7 -0
  63. package/modules/localmodels/stack_whatif_html.py +9 -12
  64. package/modules/localmodels/suite.py +129 -2
  65. package/modules/localmodels/telemetry_math.py +458 -18
  66. package/modules/localmodels/transport.py +8 -1
  67. package/modules/localmodels/tts_cli.py +24 -20
  68. package/modules/localmodels/tts_serve.py +9 -2
  69. package/modules/localmodels/tts_sidecar.py +3 -0
  70. package/modules/localmodels/web/whatif/app.js +1 -1
  71. package/modules/localmodels/web/whatif/sim.js +8 -14
  72. package/modules/localmodels/win_probe.py +89 -16
  73. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/METADATA +1 -1
  74. package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/RECORD +76 -74
  75. package/package.json +1 -1
  76. package/tool.json +1 -1
  77. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/WHEEL +0 -0
  78. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/entry_points.txt +0 -0
  79. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/LICENSE +0 -0
  80. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/NOTICE +0 -0
  81. /package/modules/{simplex_localmodels-0.1.0.dev104.dist-info → simplex_localmodels-0.1.0.dev105.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -0,0 +1,485 @@
1
+ """Structured presentation metadata for ``library-status/v1`` rows and ``v1 PlanSummary``.
2
+
3
+ Keeps Linger free of regexes, hardcoded model-rank tables and bit-width heuristics: every
4
+ grouping slug, display title, quantization method/fidelity/BPW, engine display label, offload
5
+ mode, baseline savings comparison and recommendation reason comes directly from catalog and
6
+ planner truth.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import re
12
+ from collections.abc import Mapping, Sequence
13
+ from typing import cast
14
+
15
+ from localmodels import catalog as cat
16
+ from localmodels import (
17
+ catalog_recipes,
18
+ library_order,
19
+ metal,
20
+ quant_formats,
21
+ suite,
22
+ )
23
+ from localmodels.estimator import HardwareBudget
24
+ from localmodels.library_model import (
25
+ ENGINE_DISPLAY_NAMES,
26
+ BaselineComparison,
27
+ Engine,
28
+ EngineDisplayName,
29
+ OffloadMode,
30
+ QuantFidelity,
31
+ QuantMethod,
32
+ RecommendationReason,
33
+ Row,
34
+ )
35
+ from localmodels.library_pricing import Model
36
+ from localmodels.planning import budget, memory_pools
37
+ from localmodels.probe import GPU, HostFacts
38
+ from localmodels.records import Plan
39
+
40
+ _SLUG_BAD_RE = re.compile(r"[^a-z0-9._-]+")
41
+ _LONG_CONTEXT_FLOOR = 131_072
42
+ _LOW_VRAM_CEILING_BYTES = 16 << 30
43
+ # Quant patterns treated as higher-precision reference baselines within a model group.
44
+ _Q4_REFERENCE_PRIORITY: tuple[str, ...] = (
45
+ "UD-Q4_K_XL",
46
+ "Q4_K_XL",
47
+ "UD-Q4_K_M",
48
+ "Q4_K_M",
49
+ "UD-IQ4_XS",
50
+ "IQ4_XS",
51
+ "Q4_0",
52
+ "QAD-Q4_0",
53
+ "Q5_K_M",
54
+ "Q8_0",
55
+ )
56
+
57
+
58
+ def _slug(text: str) -> str:
59
+ cleaned = _SLUG_BAD_RE.sub("-", text.strip().lower()).strip("-._")
60
+ return cleaned or "model"
61
+
62
+
63
+ def clean_display_name(entry: cat.CatalogEntry, quant: str) -> str:
64
+ """Clean base model title without trailing ``(<quant>)``."""
65
+ raw = (entry.display_name or entry.id).strip()
66
+ suffix = f" ({quant})"
67
+ if quant and raw.endswith(suffix) and len(raw) > len(suffix):
68
+ raw = raw[: -len(suffix)].strip()
69
+ return (raw or entry.id)[:120]
70
+
71
+
72
+ def group_id(entry: cat.CatalogEntry, quant: str) -> str:
73
+ """Stable group identifier derived from catalog ``base_model`` (e.g. ``inkling-2-mini``).
74
+
75
+ Distinct branded fine-tunes that list an upstream ``base_model`` (such as
76
+ ``underdog-saluki-27b`` or ``ternary-bonsai-2.5-27b``) keep their own group slug rather
77
+ than collapsing into the upstream base family.
78
+ """
79
+ title_slug = _slug(clean_display_name(entry, quant))
80
+ if entry.base_model:
81
+ tail = entry.base_model.rsplit("/", 1)[-1]
82
+ base_slug = _slug(tail)
83
+ entry_lower = entry.id.lower()
84
+ short_stem = base_slug.split("-", 1)[1] if "-" in base_slug else ""
85
+ if (
86
+ title_slug == base_slug
87
+ or entry_lower.startswith(base_slug)
88
+ or (len(short_stem) >= 6 and entry_lower.startswith(short_stem))
89
+ ):
90
+ return base_slug[:120]
91
+ return (title_slug or _slug(entry.id))[:120]
92
+
93
+
94
+ def quant_method(quant: str) -> QuantMethod:
95
+ """Structured quantization method tag from the variant's canonical quant label."""
96
+ upper = quant.strip().upper()
97
+ if upper.startswith("GSQ-RCO-"):
98
+ return "gsq_rco"
99
+ if upper.startswith("UD-"):
100
+ return "unsloth_dynamic"
101
+ if upper.startswith(("QAD-", "QAT-")):
102
+ return "qat"
103
+ if upper.startswith("MLX-"):
104
+ return "mlx"
105
+ return "standard"
106
+
107
+
108
+ def bits_per_weight(entry: cat.CatalogEntry, quant: str) -> float | None:
109
+ """Catalog-declared or format-table average bits per weight; None when unknown."""
110
+ if entry.bits_per_weight is not None and entry.bits_per_weight > 0:
111
+ return round(float(entry.bits_per_weight), 2)
112
+ fmt = quant_formats.lookup(quant)
113
+ if fmt is not None and fmt.bits > 0:
114
+ return round(float(fmt.bits), 2)
115
+ return None
116
+
117
+
118
+ def quant_fidelity(entry: cat.CatalogEntry, quant: str) -> QuantFidelity:
119
+ """Structured quantization fidelity tier for ``entry``/``quant``."""
120
+ return cast(QuantFidelity, catalog_recipes.infer_quant_fidelity(entry.quant_fidelity, quant))
121
+
122
+
123
+ def engine_display_name(engine: Engine) -> EngineDisplayName:
124
+ return ENGINE_DISPLAY_NAMES[engine]
125
+
126
+
127
+ def _best_gpu(facts: HostFacts, pool: str) -> GPU | None:
128
+ shown = memory_pools.visible(facts)
129
+ gpus = [
130
+ g
131
+ for g in facts.get("gpus") or []
132
+ if g.get("vendor") == "nvidia" and (shown is None or g["index"] in shown)
133
+ ]
134
+ if not gpus:
135
+ return None
136
+ if pool.startswith("gpu:"):
137
+ try:
138
+ idx = int(pool.split(":", 1)[1])
139
+ except ValueError:
140
+ idx = -1
141
+ for gpu in gpus:
142
+ if gpu["index"] == idx:
143
+ return gpu
144
+ return max(gpus, key=lambda g: g["total_bytes"])
145
+
146
+
147
+ def _host_budget(facts: HostFacts) -> HardwareBudget | None:
148
+ if metal.supported(facts):
149
+ placement = next(
150
+ (p for p in budget.placements(facts, planning=True) if p.backend == "metal"),
151
+ None,
152
+ )
153
+ return (budget.agent_budget(placement, facts) or placement.budget) if placement else None
154
+ shown = memory_pools.visible(facts)
155
+ cuda_placements = [
156
+ p
157
+ for p in budget.placements(facts, planning=True)
158
+ if not p.pooled
159
+ and p.backend == "cuda"
160
+ and (not p.gpu_indices or shown is None or all(idx in shown for idx in p.gpu_indices))
161
+ ]
162
+ if not cuda_placements:
163
+ return None
164
+ best = max(cuda_placements, key=lambda p: p.budget.total_device_bytes)
165
+ return budget.agent_budget(best, facts) or best.budget
166
+
167
+
168
+ def offload_mode(
169
+ facts: HostFacts,
170
+ row: Row,
171
+ model: Model,
172
+ plan: Plan | None,
173
+ poly_recipes: Mapping[str, suite.SuiteRecipe],
174
+ ) -> OffloadMode:
175
+ """How weights execute on this host: unified, CPU, full GPU-resident, or hybrid GPU+RAM."""
176
+ pool = row["pool"]
177
+ if (
178
+ pool == "unified"
179
+ or metal.supported(facts)
180
+ or memory_pools.cuda_uma_bytes(facts) is not None
181
+ ):
182
+ return "unified"
183
+ if pool == "system" or (plan is not None and plan["placement"].get("id") == "cpu"):
184
+ return "cpu"
185
+ engine = row.get("engine") or "llama.cpp"
186
+ if engine == "strata":
187
+ return "hybrid_gpu_ram"
188
+ if engine == "polystrata":
189
+ recipe = poly_recipes.get(model.entry.id)
190
+ gpu = _best_gpu(facts, pool)
191
+ if recipe is not None and suite.poly_gpu_resident(recipe, gpu):
192
+ return "gpu_resident"
193
+ return "hybrid_gpu_ram"
194
+ if plan is not None and bool(plan["launch"].get("spilled")):
195
+ return "hybrid_gpu_ram"
196
+ return "gpu_resident"
197
+
198
+
199
+ def estimated_tokens_per_second(
200
+ facts: HostFacts,
201
+ row: Row,
202
+ model: Model,
203
+ hw: HardwareBudget | None,
204
+ poly_recipes: Mapping[str, suite.SuiteRecipe],
205
+ ) -> float | None:
206
+ """Estimated single-stream decode speed on this host; None when offloaded or unknown."""
207
+ engine = row.get("engine") or "llama.cpp"
208
+ if engine == "strata":
209
+ return None
210
+ if engine == "polystrata":
211
+ recipe = poly_recipes.get(model.entry.id)
212
+ if recipe is None:
213
+ return None
214
+ est = suite.poly_decode_estimate(recipe, _best_gpu(facts, row["pool"]))
215
+ return round(est.tok_s, 1) if est is not None and est.tok_s > 0 else None
216
+ if hw is None:
217
+ return None
218
+ est = cat.decode_estimate(model.entry, model.variant, hw)
219
+ return round(est.tok_s, 1) if est.tok_s > 0 else None
220
+
221
+
222
+ def _has_low_vram_card(facts: HostFacts) -> bool:
223
+ if metal.supported(facts) or memory_pools.cuda_uma_bytes(facts) is not None:
224
+ return False
225
+ gpu = _best_gpu(facts, "")
226
+ return gpu is not None and gpu["total_bytes"] <= _LOW_VRAM_CEILING_BYTES
227
+
228
+
229
+ def _reasons(
230
+ *,
231
+ best_for_host: bool,
232
+ engine: Engine,
233
+ fidelity: QuantFidelity,
234
+ mode: OffloadMode,
235
+ fits_low_vram: bool,
236
+ smaller_footprint: bool,
237
+ context_tokens: int,
238
+ prefix_cache: bool,
239
+ ) -> list[RecommendationReason]:
240
+ found: list[RecommendationReason] = []
241
+ if best_for_host:
242
+ found.append("best_quality_for_hardware")
243
+ if engine == "polystrata":
244
+ found.append("polystrata_engine")
245
+ if fidelity == "high_fidelity_compact":
246
+ found.append("high_fidelity_compact_quant")
247
+ elif fidelity == "near_lossless":
248
+ found.append("near_lossless_quant")
249
+ if mode == "hybrid_gpu_ram":
250
+ found.append("hybrid_gpu_ram_offload")
251
+ if fits_low_vram:
252
+ found.append("fits_low_vram")
253
+ if smaller_footprint:
254
+ found.append("smaller_footprint")
255
+ if context_tokens >= _LONG_CONTEXT_FLOOR:
256
+ found.append("long_context")
257
+ if prefix_cache:
258
+ found.append("prefix_cache")
259
+ return found
260
+
261
+
262
+ def _poly_recipe_map() -> dict[str, suite.SuiteRecipe]:
263
+ return {r["id"]: r for r in suite.recipes("llm") if r["runtime"] == "strata-poly"}
264
+
265
+
266
+ def apply_row_meta(
267
+ facts: HostFacts,
268
+ row: Row,
269
+ model: Model,
270
+ plan: Plan | None,
271
+ *,
272
+ hw: HardwareBudget | None = None,
273
+ poly_recipes: Mapping[str, suite.SuiteRecipe] | None = None,
274
+ ) -> None:
275
+ """Attach intrinsic presentation metadata to one ``library-status/v1`` row."""
276
+ recipes = _poly_recipe_map() if poly_recipes is None else poly_recipes
277
+ host_hw = _host_budget(facts) if hw is None else hw
278
+ engine: Engine = row.get("engine") or "llama.cpp"
279
+ fidelity = quant_fidelity(model.entry, model.variant.quant)
280
+ mode = offload_mode(facts, row, model, plan, recipes)
281
+ rq = library_order.ranked_quality(model.entry)
282
+
283
+ row["group_id"] = group_id(model.entry, model.variant.quant)
284
+ row["display_name"] = clean_display_name(model.entry, model.variant.quant)
285
+ row["quant_method"] = quant_method(model.variant.quant)
286
+ if (bpw := bits_per_weight(model.entry, model.variant.quant)) is not None:
287
+ row["bits_per_weight"] = bpw
288
+ row["quant_fidelity"] = fidelity
289
+ row["engine_display_name"] = engine_display_name(engine)
290
+ row["offload_mode"] = mode
291
+ row["quality_score"] = rq if rq > 0 else None
292
+ row["estimated_tokens_per_second"] = estimated_tokens_per_second(
293
+ facts, row, model, host_hw, recipes
294
+ )
295
+ prefix_cache = engine == "polystrata" or (
296
+ plan is not None and int(str(plan["launch"].get("conversation_cache_mib") or 0)) > 0
297
+ )
298
+ reasons = _reasons(
299
+ best_for_host=False,
300
+ engine=engine,
301
+ fidelity=fidelity,
302
+ mode=mode,
303
+ fits_low_vram=_has_low_vram_card(facts) and row["fit"] != "none",
304
+ smaller_footprint=False,
305
+ context_tokens=row["context_tokens"],
306
+ prefix_cache=prefix_cache,
307
+ )
308
+ if reasons:
309
+ row["recommendation_reasons"] = reasons
310
+
311
+
312
+ def _reference_row(rows: Sequence[Row], target: Row) -> Row | None:
313
+ """Pick the larger Q4-class sibling in the same ``group_id`` for ``baseline_comparison``."""
314
+ target_dl = target["download_bytes"]
315
+ target_engine = target.get("engine")
316
+ candidates: list[tuple[int, int, int, Row]] = []
317
+ for sibling in rows:
318
+ if sibling["id"] == target["id"] or sibling["quant"] == target["quant"]:
319
+ continue
320
+ if sibling["download_bytes"] <= target_dl:
321
+ continue
322
+ upper = sibling["quant"].strip().upper()
323
+ if upper not in _Q4_REFERENCE_PRIORITY:
324
+ continue
325
+ same_engine = 0 if sibling.get("engine") == target_engine else 1
326
+ priority = _Q4_REFERENCE_PRIORITY.index(upper)
327
+ candidates.append((same_engine, priority, -sibling["download_bytes"], sibling))
328
+ if not candidates:
329
+ return None
330
+ candidates.sort(key=lambda item: (item[0], item[1], item[2]))
331
+ return candidates[0][3]
332
+
333
+
334
+ def enrich_status_rows(
335
+ facts: HostFacts,
336
+ ordered_rows: list[Row],
337
+ best_id: str | None,
338
+ ) -> None:
339
+ """Populate cross-row host-relative metadata after ``library_order.order_rows``."""
340
+ low_vram_host = _has_low_vram_card(facts)
341
+ by_group: dict[str, list[Row]] = {}
342
+ for row in ordered_rows:
343
+ gid = row.get("group_id") or _slug(row["id"])
344
+ by_group.setdefault(gid, []).append(row)
345
+
346
+ group_counters: dict[str, int] = {}
347
+ for row in ordered_rows:
348
+ gid = row.get("group_id") or _slug(row["id"])
349
+ rank = group_counters.get(gid, 0) + 1
350
+ group_counters[gid] = rank
351
+ row["suitability_rank"] = rank
352
+ is_best = best_id is not None and row["id"] == best_id
353
+ row["best_for_host"] = is_best
354
+
355
+ ref = _reference_row(by_group[gid], row)
356
+ has_smaller = False
357
+ if ref is not None:
358
+ saved_dl = ref["download_bytes"] - row["download_bytes"]
359
+ if saved_dl > 0:
360
+ comparison: BaselineComparison = {
361
+ "reference_quant": ref["quant"],
362
+ "download_saved_bytes": saved_dl,
363
+ "memory_saved_bytes": max(0, ref["memory_bytes"] - row["memory_bytes"]),
364
+ "context_delta_tokens": row["context_tokens"] - ref["context_tokens"],
365
+ }
366
+ row["baseline_comparison"] = comparison
367
+ has_smaller = True
368
+
369
+ engine: Engine = row.get("engine") or "llama.cpp"
370
+ fidelity: QuantFidelity = row.get("quant_fidelity") or "balanced"
371
+ mode: OffloadMode = row.get("offload_mode") or "gpu_resident"
372
+ existing = set(row.get("recommendation_reasons") or ())
373
+ reasons = _reasons(
374
+ best_for_host=is_best,
375
+ engine=engine,
376
+ fidelity=fidelity,
377
+ mode=mode,
378
+ fits_low_vram=low_vram_host and row["fit"] != "none",
379
+ smaller_footprint=has_smaller,
380
+ context_tokens=row["context_tokens"],
381
+ prefix_cache="prefix_cache" in existing or engine == "polystrata",
382
+ )
383
+ if reasons:
384
+ row["recommendation_reasons"] = reasons
385
+ else:
386
+ row.pop("recommendation_reasons", None)
387
+
388
+
389
+ def plan_presentation(
390
+ plan: Plan,
391
+ *,
392
+ context_window: int,
393
+ gpus: Sequence[Mapping[str, object]],
394
+ unified: bool,
395
+ ) -> dict[str, object]:
396
+ """Additive presentation fields for v1 ``PlanSummary`` (``stack_review.summarize``)."""
397
+ model = plan["model"]
398
+ model_id = str(model.get("id") or "")
399
+ quant = str(model.get("quant") or "")
400
+ engine_doc: Mapping[str, object] = plan.get("engine") or {}
401
+ build = str(engine_doc.get("build") or "")
402
+ backend = str(engine_doc.get("backend") or "")
403
+ if build.startswith("strata-poly") or str(
404
+ plan["launch"].get("frontend_requirements") or ""
405
+ ).startswith("strata-poly"):
406
+ engine: Engine = "polystrata"
407
+ elif build.startswith("strata"):
408
+ engine = "strata"
409
+ elif backend == "mlx" or build.startswith("mlx"):
410
+ engine = "mlx"
411
+ else:
412
+ engine = "llama.cpp"
413
+
414
+ explicit_fidelity = ""
415
+ recipe: suite.SuiteRecipe | None = None
416
+ if engine in ("polystrata", "strata"):
417
+ recipe = next((r for r in suite.recipes("llm") if r["id"] == model_id), None)
418
+ if recipe is not None:
419
+ explicit_fidelity = str(recipe.get("quant_fidelity") or "")
420
+ else:
421
+ entry = cat.find_entry(model_id)
422
+ if entry is not None:
423
+ explicit_fidelity = entry.quant_fidelity
424
+
425
+ fidelity = cast(QuantFidelity, catalog_recipes.infer_quant_fidelity(explicit_fidelity, quant))
426
+ mode: OffloadMode
427
+ if unified:
428
+ mode = "unified"
429
+ elif plan["placement"].get("id") == "cpu":
430
+ mode = "cpu"
431
+ elif engine == "strata":
432
+ mode = "hybrid_gpu_ram"
433
+ elif engine == "polystrata":
434
+ first_total = gpus[0].get("totalBytes") if gpus else None
435
+ if isinstance(first_total, int) and first_total > 0 and recipe is not None:
436
+ synth_gpu = cast(
437
+ GPU,
438
+ {
439
+ "index": 0,
440
+ "uuid": "",
441
+ "name": "",
442
+ "total_bytes": first_total,
443
+ "free_bytes": first_total,
444
+ "used_bytes": 0,
445
+ "vendor": "nvidia",
446
+ },
447
+ )
448
+ mode = (
449
+ "gpu_resident" if suite.poly_gpu_resident(recipe, synth_gpu) else "hybrid_gpu_ram"
450
+ )
451
+ else:
452
+ mode = "hybrid_gpu_ram"
453
+ elif bool(plan["launch"].get("spilled")):
454
+ mode = "hybrid_gpu_ram"
455
+ else:
456
+ mode = "gpu_resident"
457
+
458
+ low_vram = not unified and any(
459
+ isinstance(tb := g.get("totalBytes"), int)
460
+ and not isinstance(tb, bool)
461
+ and 0 < tb <= _LOW_VRAM_CEILING_BYTES
462
+ for g in gpus
463
+ )
464
+ prefix_cache = (
465
+ engine == "polystrata" or int(str(plan["launch"].get("conversation_cache_mib") or 0)) > 0
466
+ )
467
+ reasons = _reasons(
468
+ best_for_host=False,
469
+ engine=engine,
470
+ fidelity=fidelity,
471
+ mode=mode,
472
+ fits_low_vram=low_vram,
473
+ smaller_footprint=False,
474
+ context_tokens=context_window,
475
+ prefix_cache=prefix_cache,
476
+ )
477
+ out: dict[str, object] = {
478
+ "engine": engine,
479
+ "quant_fidelity": fidelity,
480
+ }
481
+ if quant:
482
+ out["quant"] = quant
483
+ if reasons:
484
+ out["recommendation_reasons"] = reasons
485
+ return out
@@ -544,7 +544,9 @@ def smartest(facts: HostFacts, base_dir: str = deploy.DEFAULT_BASE_DIR) -> tuple
544
544
  if (shown_cards := memory_pools.visible(facts)) is not None:
545
545
  seen["gpus"] = [g for g in seen.get("gpus") or [] if g["index"] in shown_cards]
546
546
  try:
547
- view = stack_hardware.view(seen, default_options(), posture())
547
+ opts = default_options()
548
+ opts["base_dir"] = base_dir
549
+ view = stack_hardware.view(seen, opts, posture())
548
550
  except (KeyError, ValueError, TypeError, OSError):
549
551
  return None
550
552
  pick = next(