@simplexai/localmodels-linux-x64 0.1.0-dev.35 → 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 (126) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +124 -102
  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 +15 -2
  8. package/modules/localmodels/catalog.json +235 -2
  9. package/modules/localmodels/catalog.py +51 -320
  10. package/modules/localmodels/catalog_add.py +2 -8
  11. package/modules/localmodels/catalog_recipes.py +321 -0
  12. package/modules/localmodels/cli_parser.py +4 -1
  13. package/modules/localmodels/console.py +5 -4
  14. package/modules/localmodels/contracts.py +13 -3
  15. package/modules/localmodels/debug_cli.py +158 -0
  16. package/modules/localmodels/debug_mode.py +727 -0
  17. package/modules/localmodels/debug_stub_server.py +192 -0
  18. package/modules/localmodels/decode_calibration.json +1 -1
  19. package/modules/localmodels/decode_calibration.py +34 -17
  20. package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
  21. package/modules/localmodels/gateway.py +21 -155
  22. package/modules/localmodels/gateway_accept.py +201 -0
  23. package/modules/localmodels/gateway_bifrost.py +19 -184
  24. package/modules/localmodels/gateway_cli.py +11 -4
  25. package/modules/localmodels/gateway_foundations.py +2 -4
  26. package/modules/localmodels/gateway_probe.py +0 -1
  27. package/modules/localmodels/gateway_server.py +2 -3
  28. package/modules/localmodels/gpu_specs.py +12 -0
  29. package/modules/localmodels/guard.py +2 -7
  30. package/modules/localmodels/harness.py +16 -129
  31. package/modules/localmodels/harness_cleanup.py +135 -0
  32. package/modules/localmodels/harness_gateway.py +16 -14
  33. package/modules/localmodels/harness_probe.py +12 -4
  34. package/modules/localmodels/hosts.py +25 -2
  35. package/modules/localmodels/http_local.py +59 -0
  36. package/modules/localmodels/install.py +23 -8
  37. package/modules/localmodels/library_gateway.py +9 -9
  38. package/modules/localmodels/library_jobs.py +76 -27
  39. package/modules/localmodels/library_serve.py +12 -1
  40. package/modules/localmodels/library_state.py +6 -1
  41. package/modules/localmodels/llm_rank.py +155 -7
  42. package/modules/localmodels/metal_probe.py +11 -7
  43. package/modules/localmodels/probe.py +108 -174
  44. package/modules/localmodels/process_identity.py +109 -154
  45. package/modules/localmodels/process_windows.py +86 -0
  46. package/modules/localmodels/recommend.py +32 -3
  47. package/modules/localmodels/recommend_cli.py +14 -6
  48. package/modules/localmodels/remote_ops.py +65 -0
  49. package/modules/localmodels/remote_ops_download.py +2 -2
  50. package/modules/localmodels/remote_ops_prepare.py +19 -0
  51. package/modules/localmodels/remote_ops_service.py +14 -2
  52. package/modules/localmodels/runtime_args.py +10 -3
  53. package/modules/localmodels/runtime_auth.py +5 -9
  54. package/modules/localmodels/runtime_cli.py +128 -129
  55. package/modules/localmodels/runtime_discovery.py +84 -0
  56. package/modules/localmodels/runtime_install.py +101 -0
  57. package/modules/localmodels/runtime_releases.py +302 -0
  58. package/modules/localmodels/service_stop.py +8 -108
  59. package/modules/localmodels/service_upgrade.py +394 -63
  60. package/modules/localmodels/services_cli.py +24 -14
  61. package/modules/localmodels/setup_inspection.py +97 -9
  62. package/modules/localmodels/setup_text.py +7 -0
  63. package/modules/localmodels/sizecalc.py +0 -1
  64. package/modules/localmodels/stack.py +14 -221
  65. package/modules/localmodels/stack_arena.py +732 -0
  66. package/modules/localmodels/stack_args.py +15 -9
  67. package/modules/localmodels/stack_auto.py +384 -3
  68. package/modules/localmodels/stack_aux_gpu.py +4 -3
  69. package/modules/localmodels/stack_capacity.py +138 -0
  70. package/modules/localmodels/stack_cleanup.py +9 -4
  71. package/modules/localmodels/stack_cli.py +286 -0
  72. package/modules/localmodels/stack_compose.py +76 -32
  73. package/modules/localmodels/stack_console.py +9 -6
  74. package/modules/localmodels/stack_hardware.py +96 -270
  75. package/modules/localmodels/stack_hardware_text.py +263 -0
  76. package/modules/localmodels/stack_journal.py +3 -9
  77. package/modules/localmodels/stack_ledger.py +48 -18
  78. package/modules/localmodels/stack_lifecycle.py +33 -312
  79. package/modules/localmodels/stack_mcp.py +729 -0
  80. package/modules/localmodels/stack_memory.py +0 -2
  81. package/modules/localmodels/stack_picks.py +73 -18
  82. package/modules/localmodels/stack_plan.py +23 -5
  83. package/modules/localmodels/stack_preflight.py +11 -19
  84. package/modules/localmodels/stack_remove.py +373 -0
  85. package/modules/localmodels/stack_route.py +101 -17
  86. package/modules/localmodels/stack_suite.py +16 -10
  87. package/modules/localmodels/stack_summary.py +14 -0
  88. package/modules/localmodels/stack_try.py +238 -24
  89. package/modules/localmodels/stack_try_client.py +53 -15
  90. package/modules/localmodels/stack_try_docs.py +2 -2
  91. package/modules/localmodels/stack_view.py +24 -171
  92. package/modules/localmodels/stack_view_access.py +114 -1
  93. package/modules/localmodels/stack_view_agent.py +3 -13
  94. package/modules/localmodels/stack_view_hub.py +9 -10
  95. package/modules/localmodels/stack_view_llm.py +1 -1
  96. package/modules/localmodels/stack_view_sandbox.py +2 -2
  97. package/modules/localmodels/stack_view_schema.py +183 -0
  98. package/modules/localmodels/stack_view_serve.py +7 -1
  99. package/modules/localmodels/stack_view_service.py +1 -2
  100. package/modules/localmodels/stack_view_text.py +13 -9
  101. package/modules/localmodels/stack_warm.py +3 -0
  102. package/modules/localmodels/stack_warm_store.py +517 -0
  103. package/modules/localmodels/tui.py +28 -4
  104. package/modules/localmodels/tui_dialogs.py +136 -0
  105. package/modules/localmodels/tui_modals.py +279 -0
  106. package/modules/localmodels/tui_screen.py +113 -154
  107. package/modules/localmodels/tui_views.py +134 -203
  108. package/modules/localmodels/web/index.html +510 -101
  109. package/modules/localmodels/web/sizecalc/app.js +363 -10
  110. package/modules/localmodels/web/sizecalc/page.html +27 -3
  111. package/modules/localmodels/web/view/fleet.html +11 -2
  112. package/modules/localmodels/web/view/fleet.js +191 -17
  113. package/modules/localmodels/web/view/i18n.js +3 -2
  114. package/modules/localmodels/web/view/index.html +1 -1
  115. package/modules/localmodels/web/view/nav.js +22 -3
  116. package/modules/localmodels/web/view/view.css +63 -18
  117. package/modules/localmodels/web/view/view.js +169 -32
  118. package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/METADATA +1 -1
  119. package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/RECORD +120 -98
  120. package/package.json +1 -1
  121. package/tool.json +1 -1
  122. package/modules/localmodels/engines-strata-0.1.49.1.json +0 -31
  123. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/WHEEL +0 -0
  124. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/entry_points.txt +0 -0
  125. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/NOTICE +0 -0
  126. /package/modules/{simplex_localmodels-0.1.0.dev35.dist-info → simplex_localmodels-0.1.0.dev37.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -1,9 +1,4 @@
1
- """Read-only hardware readings, card budgets and validated llama.cpp candidates.
2
-
3
- ``stack plan`` uses the same card budgets, plus whole-stack RAM and disk checks for Strata.
4
- A Mac shares unified memory; ``--unified-memory`` prices it as a smaller Mac.
5
- Only probe readings are measurements. ``snapshot`` preserves them without binding approval.
6
- """
1
+ """Read-only hardware readings, shared card budgets and llama.cpp capacity references."""
7
2
 
8
3
  from __future__ import annotations
9
4
 
@@ -13,19 +8,47 @@ from collections.abc import Callable
13
8
  from typing import Any, cast
14
9
 
15
10
  from localmodels import catalog as cat
16
- from localmodels import component, console, context_policy, gpu_specs, llm_rank, metal, suite
11
+ from localmodels import (
12
+ catalog_recipes,
13
+ component,
14
+ context_policy,
15
+ gpu_specs,
16
+ llm_rank,
17
+ metal,
18
+ stack_capacity,
19
+ stack_warm_store,
20
+ suite,
21
+ )
17
22
  from localmodels.budget import gib, holders, host_ram, placements, sharing_cards, unknown_services
18
23
  from localmodels.context_policy import AGENT, AgentPosture, cache_floor_bytes, posture_for
19
24
  from localmodels.estimator import (
20
- AGENT_DISPLAY_RESERVE_BYTES,
21
25
  AGENT_VRAM_RESERVE_BYTES,
22
- AGENT_VRAM_SAFETY_BYTES,
23
26
  METAL_VRAM_RESERVE_BYTES,
24
27
  HardwareBudget,
25
28
  )
26
29
  from localmodels.probe import GPU, HostFacts
27
30
  from localmodels.records import Plan
28
- from localmodels.stack_picks import lines as pick_lines
31
+ from localmodels.stack_hardware_text import (
32
+ agent_label as agent_label,
33
+ )
34
+ from localmodels.stack_hardware_text import (
35
+ lines as lines,
36
+ )
37
+ from localmodels.stack_hardware_text import (
38
+ on_metal as on_metal,
39
+ )
40
+ from localmodels.stack_hardware_text import (
41
+ plan_card as plan_card,
42
+ )
43
+ from localmodels.stack_hardware_text import (
44
+ plan_lines as plan_lines,
45
+ )
46
+ from localmodels.stack_hardware_text import (
47
+ reboot_line as reboot_line,
48
+ )
49
+ from localmodels.stack_hardware_text import (
50
+ slow_warning as slow_warning,
51
+ )
29
52
  from localmodels.stack_picks import picks
30
53
  from localmodels.stack_plan import (
31
54
  Card,
@@ -34,6 +57,7 @@ from localmodels.stack_plan import (
34
57
  LlmFit,
35
58
  StackError,
36
59
  StackOptions,
60
+ default_options,
37
61
  platform_error,
38
62
  )
39
63
 
@@ -41,8 +65,6 @@ GIB = 1 << 30
41
65
  TIERS_GIB = (8, 12, 16, 24, 32, 48, 96) # research/2026-10-24-vram-tier-stacks
42
66
  _NOMINAL_SLACK = 1.1 # a 24 GB card reports 22.5–24 GiB; an 80 GB one is not a 96 GB card
43
67
  _FIRST_TIER_RAM = 60 * GIB # 64 GB of RAM reads about 62 GiB
44
- _MAC = "--unified-memory SIZE prices it as a smaller Mac" # the next step's option hint
45
- _CARDS = "with several cards, --gpu N picks the card for the LLM and the decision model"
46
68
  # ``--unified-memory`` when the option is not given: a front-end that runs this tool (the Simplex
47
69
  # installer) passes its environment through, so the same ceiling reaches every plan it makes.
48
70
  UNIFIED_MEMORY_ENV = "LOCALMODELS_UNIFIED_MEMORY"
@@ -62,8 +84,7 @@ def add_arguments(parser: argparse._ActionsContainer) -> None:
62
84
 
63
85
 
64
86
  def with_platform_options(options: StackOptions, args: argparse.Namespace) -> StackOptions:
65
- """``options`` with ``--profile`` and ``--unified-memory`` when given, so plans made without
66
- them keep their ids; a front-end without the options (the TUI) passes them through."""
87
+ """Add explicit platform options; fronts without them preserve the existing plan options."""
67
88
  if profile := getattr(args, "profile", None):
68
89
  options["profile"] = profile
69
90
  if getattr(args, "unified_memory", None):
@@ -89,8 +110,7 @@ def assumed(facts: HostFacts, unified_memory: str | None) -> HostFacts:
89
110
 
90
111
 
91
112
  def decision_reserve(card_budget_bytes: int, options: StackOptions) -> int:
92
- """The smallest decision tier this card's auto budget would keep: what auto LLM selection
93
- holds back before testing a candidate. 0 when the decision is disabled or nothing fits."""
113
+ """Smallest decision reserve kept before auto selection; 0 if disabled or none fits."""
94
114
  if str(options["decision"]) == "none" or card_budget_bytes <= 0:
95
115
  return 0
96
116
  recipes = cat.decision_components()
@@ -106,12 +126,7 @@ def decision_reserve(card_budget_bytes: int, options: StackOptions) -> int:
106
126
 
107
127
 
108
128
  def cards(facts: HostFacts, gpu: int | None = None, *, share_gpu: bool = False) -> list[int]:
109
- """Indices of the single-card placements an auto LLM may take, most free memory first.
110
- Cards running foreign services are not candidates: choosing one would read as consent to
111
- share. ``gpu`` (``--gpu``) narrows them to that card, conflicts included: the plan then
112
- asks for ``--share-gpu`` like any named placement. A Mac has one card, its Metal GPU,
113
- which another inference server on it does not take away: there is no other card to prefer,
114
- and the plan asks for ``--share-gpu`` instead."""
129
+ """Single-card choices by free memory; foreign GPU work needs explicit sharing."""
115
130
  if share_gpu and unknown_services(facts):
116
131
  raise StackError(
117
132
  "GPU service owners unknown; explicit sharing cannot skip the unknown-service check"
@@ -129,6 +144,8 @@ def cards(facts: HostFacts, gpu: int | None = None, *, share_gpu: bool = False)
129
144
  raise StackError(
130
145
  f"no placeable GPU {gpu} here (usable cards: {found}; MIG-mode cards excluded)"
131
146
  )
147
+ if share_gpu and gpu not in {g["index"] for g in sharing_cards(facts, 0)}:
148
+ raise StackError("GPU process owners unknown; cannot share this GPU")
132
149
  return [gpu]
133
150
  allowed = {g["index"] for g in sharing_cards(facts, 0)} if share_gpu else set()
134
151
  free = [
@@ -142,8 +159,7 @@ def cards(facts: HostFacts, gpu: int | None = None, *, share_gpu: bool = False)
142
159
  def check_shared_start(
143
160
  part: Plan, facts: HostFacts, *, options: StackOptions | None = None, shared: bool = True
144
161
  ) -> None:
145
- """Recheck a placement's free VRAM right before its backend starts. Sharing needs every
146
- discovery section read; an unshared ``stack up`` only who uses the GPUs."""
162
+ """Recheck free VRAM and ownership before starting; sharing needs all discovery sections."""
147
163
  from localmodels import budget, hosts, stack_lifecycle
148
164
 
149
165
  services = facts.get("services")
@@ -169,6 +185,8 @@ def check_shared_start(
169
185
  raise StackError("the GPU-sharing model has no VRAM budget or no approved GPU placement")
170
186
  for target in assigned:
171
187
  card = next((g for g in facts.get("gpus") or [] if g["uuid"] == target["uuid"]), None)
188
+ if shared and card and card["index"] not in {g["index"] for g in sharing_cards(facts, 0)}:
189
+ raise StackError("GPU process owners unknown; cannot start a shared model")
172
190
  reserve = (
173
191
  decision_reserve(component.auto_budget(card["total_bytes"]), options)
174
192
  if card and options
@@ -207,26 +225,8 @@ def device(facts: HostFacts, index: int) -> GPU:
207
225
  return next(g for g in facts.get("gpus") or [] if g["index"] == index)
208
226
 
209
227
 
210
- def on_metal(part: Plan | None) -> bool:
211
- """The part runs on a Mac's Metal GPU."""
212
- return part is not None and metal.on_device(part["placement"])
213
-
214
-
215
- def plan_card(part: Plan | None, facts: HostFacts) -> int | None:
216
- """Resolve the running service's CUDA UUID to its current host index (0 on a Mac)."""
217
- if part is None:
218
- return None
219
- if on_metal(part):
220
- return 0
221
- devices = part["service"].get("env", {}).get("CUDA_VISIBLE_DEVICES")
222
- if not isinstance(devices, str) or not devices or "," in devices:
223
- return None
224
- return next((g["index"] for g in facts.get("gpus") or [] if g["uuid"] == devices), None)
225
-
226
-
227
228
  def held_elsewhere(name: str, part: Plan, gpu: int | None, facts: HostFacts) -> None:
228
- """Refuse reusing a running deployment that sits on another card than ``--gpu`` names:
229
- keeping it would silently drop the operator's choice."""
229
+ """Refuse reusing a running deployment on another card than ``--gpu`` names."""
230
230
  card = plan_card(part, facts)
231
231
  placed = part["placement"].get("gpus")
232
232
  had_gpu_binding = bool(placed) or bool(
@@ -276,11 +276,7 @@ def llm_budget(
276
276
  entry: cat.CatalogEntry | None = None,
277
277
  posture: AgentPosture = AGENT,
278
278
  ) -> tuple[HardwareBudget, int]:
279
- """(what an agent-posture LLM may use on card ``index`` now, the decision reserve held
280
- back): free memory less the agent safety and display reserves and the smallest decision tier the card's
281
- auto budget keeps. It carries the card's spec bandwidth for the speed estimate. On a Mac
282
- the free memory also holds the entry's host embeddings and prompt-cache floor.
283
- Without an entry this reports a generic hardware budget."""
279
+ """Live LLM budget and decision reserve, including safety, display and Metal host costs."""
284
280
  gpu = device(facts, index)
285
281
  on_mac = gpu["uuid"] == metal.METAL_UUID
286
282
  reserve = decision_reserve(component.auto_budget(gpu["total_bytes"]), options)
@@ -295,7 +291,7 @@ def llm_budget(
295
291
  usable = free - (METAL_VRAM_RESERVE_BYTES if on_mac else AGENT_VRAM_RESERVE_BYTES) - reserve
296
292
  budget = HardwareBudget(
297
293
  usable_vram_bytes=max(0, usable),
298
- total_device_bytes=0,
294
+ total_device_bytes=gpu["total_bytes"],
299
295
  ram_available_bytes=0,
300
296
  uma=on_mac,
301
297
  gpu_name=gpu["name"],
@@ -309,9 +305,16 @@ def llm_fits(
309
305
  facts: HostFacts, index: int, options: StackOptions, posture: AgentPosture
310
306
  ) -> list[LlmFit]:
311
307
  """Automatic candidates priced with their own embeddings and cache."""
308
+ from localmodels import stack_auto
309
+
312
310
  if device(facts, index)["uuid"] == metal.METAL_UUID:
313
311
  posture = posture_for(posture, "metal")
314
- found = []
312
+ merged: StackOptions = {**default_options(), **options}
313
+ capped = stack_auto.maybe_capped(facts, merged)
314
+ if capped is None:
315
+ return []
316
+ facts = capped
317
+ found: list[tuple[tuple[int, float], LlmFit]] = []
315
318
  for entry in (
316
319
  e
317
320
  for e in cat.load_catalog_file()
@@ -319,16 +322,33 @@ def llm_fits(
319
322
  ):
320
323
  variant = entry.variants[-1]
321
324
  budget, _ = llm_budget(facts, index, options, entry=entry, posture=posture)
322
- if llm_rank.agent_ready(entry, variant, budget, posture):
325
+ fits = (
326
+ llm_rank.automatic_fit(entry, facts, budget, posture, options)
327
+ if budget.uma
328
+ else stack_auto.llama_ram_fits(facts, merged, entry, index, posture, budget=budget)
329
+ )
330
+ if fits:
323
331
  speed = cat.decode_estimate(entry, variant, budget)
324
332
  fit: LlmFit = {
325
333
  "id": entry.id,
326
334
  "quant": variant.quant,
327
- "quality": entry.quality,
335
+ "quality": 0 if llm_rank.windows_fallback(entry, facts) else entry.quality,
328
336
  "decode_tok_s": round(speed.tok_s, 1),
329
337
  "decode_basis": speed.basis,
330
338
  }
331
- found.append((llm_rank.rank_key(entry, variant, budget), fit))
339
+ stack_warm_store.apply_fit_measurement(facts, index, fit)
340
+ if llm_rank.windows_fallback(entry, facts):
341
+ fit["candidate_fallback"] = True
342
+ tok_s = float(fit["decode_tok_s"]) if fit["decode_tok_s"] is not None else -1.0
343
+ found.append(((entry.quality, tok_s), fit))
344
+
345
+ llama_score = max(
346
+ (f["quality"] for _, f in found if not f.get("candidate_fallback")), default=-1
347
+ )
348
+ for fit in stack_auto.card_fits(facts, index, options, llama_score):
349
+ stack_warm_store.apply_fit_measurement(facts, index, fit)
350
+ found.append(((fit["quality"], -1.0), fit))
351
+ found = [row for row in found if not row[1].get("candidate_fallback")] or found
332
352
  default_id = llm_rank.listed_default(facts, [(f["id"], f["quality"]) for _, f in found])
333
353
  return [
334
354
  fit
@@ -413,7 +433,7 @@ def _card(
413
433
  budget, reserve = llm_budget(facts, g["index"], options)
414
434
  gen, width = g.get("pcie_gen"), g.get("pcie_width")
415
435
  on_mac = g["uuid"] == metal.METAL_UUID
416
- return {
436
+ shown: Card = {
417
437
  "index": g["index"],
418
438
  "uuid": g["uuid"],
419
439
  "name": g["name"],
@@ -437,11 +457,30 @@ def _card(
437
457
  if posture is not None and not mig
438
458
  else [],
439
459
  }
460
+ if posture is not None and not mig and not on_mac:
461
+ shown["capacity"] = stack_capacity.rows(facts, g["index"], options, posture)
462
+ return shown
463
+
464
+
465
+ def _set_linux_note(facts: HostFacts, notes: list[str], cards: list[Card]) -> None:
466
+ strata_ids = {
467
+ c["id"] for c in catalog_recipes.components() if c["runtime"] in ("strata", "strata-poly")
468
+ }
469
+ if facts["platform"] == "linux" and any(
470
+ f["decode_tok_s"] is None or f["id"] in strata_ids for c in cards for f in c["llm"]
471
+ ):
472
+ notes[0] = (
473
+ "per-card LLM lists include validated Strata/PolyStrata recipes whose "
474
+ "whole-stack RAM and disk fit"
475
+ )
440
476
 
441
477
 
442
478
  def view(facts: HostFacts, options: StackOptions, posture: AgentPosture | None) -> Hardware:
443
479
  """The hardware as ``stack`` prices it; ``posture`` None leaves the LLM lists empty."""
480
+ from localmodels import stack_auto
481
+
444
482
  facts, pressure_notes = metal.pressured(facts)
483
+ facts = stack_auto.maybe_capped(facts, {**default_options(), **options}) or facts
445
484
  total, available = host_ram(facts)
446
485
  os_info = facts.get("os") or {}
447
486
  driver = (facts.get("nvidia") or {}).get("driver_version")
@@ -469,6 +508,8 @@ def view(facts: HostFacts, options: StackOptions, posture: AgentPosture | None)
469
508
  if options.get("profile") != "macos-mlx-preview" and (error := metal.problem(facts)):
470
509
  notes.append(error)
471
510
  notes += pressure_notes
511
+ if facts["platform"] == "win32" and facts.get("gpus"):
512
+ notes.append(stack_capacity.WDDM_NOTE)
472
513
  mac = metal.device(facts)
473
514
  if mac is not None:
474
515
  notes.append(
@@ -524,6 +565,7 @@ def view(facts: HostFacts, options: StackOptions, posture: AgentPosture | None)
524
565
  if manager := facts.get("service_manager"):
525
566
  seen["service_manager"] = manager
526
567
  if posture is not None:
568
+ _set_linux_note(facts, notes, seen["cards"])
527
569
  seen["picks"] = picks(seen["cards"], llm_rank.mac_default(facts))
528
570
  return seen
529
571
 
@@ -531,219 +573,3 @@ def view(facts: HostFacts, options: StackOptions, posture: AgentPosture | None)
531
573
  def snapshot(facts: HostFacts, options: StackOptions) -> Hardware:
532
574
  """The copy a stack plan keeps: the readings it was priced against, without LLM lists."""
533
575
  return view(facts, options, None)
534
-
535
-
536
- def _card_head(c: Card) -> str:
537
- arch = c["architecture"] or ""
538
- if c["compute_capability"]:
539
- arch = f"{arch} (compute capability {c['compute_capability']})".lstrip()
540
- traits = [
541
- t
542
- for t in (
543
- arch,
544
- f"PCIe {c['pcie']}" if c["pcie"] else "",
545
- {True: "display attached", False: "no display", None: ""}[c["display_active"]],
546
- "MIG on" if c["mig"] else "",
547
- )
548
- if t
549
- ]
550
- return f"GPU {c['index']} {c['name']}" + "".join(f" · {t}" for t in traits)
551
-
552
-
553
- def lines(hw: Hardware, command: str) -> list[str]:
554
- """What ``stack hardware`` prints."""
555
- out = [
556
- f"Hardware of {hw['hostname']} (collected {console.local_time(hw['collected_at'])} local time; "
557
- f"{hw['system'] or 'system unknown'})"
558
- ]
559
- if not hw["cards"]:
560
- out.append(
561
- " GPU Apple Silicon Metal working set unknown"
562
- if hw.get("platform") == "darwin" and hw.get("arch") == "arm64"
563
- else " GPU no NVIDIA GPU found"
564
- )
565
- for c in hw["cards"]:
566
- reserved = f", driver reserved {gib(c['reserved_bytes'])}" if c["reserved_bytes"] else ""
567
- on_mac = c.get("uuid") == metal.METAL_UUID
568
- out += [
569
- f" {_card_head(c)}",
570
- f" Metal working-set limit {gib(c['total_bytes'])}; the memory available "
571
- f"now can give the GPU {gib(c['free_bytes'])}"
572
- if on_mac
573
- else f" VRAM {gib(c['total_bytes'])}: used {gib(c['used_bytes'])}, "
574
- f"free {gib(c['free_bytes'])}{reserved}",
575
- ]
576
- if c["mig"]:
577
- out.append(
578
- " in MIG mode CUDA sees only the instances; this tool places nothing "
579
- "on this card"
580
- )
581
- continue
582
- out.append(
583
- f" LLM may use {gib(c['llm_bytes'])} (free less a "
584
- f"{AGENT_VRAM_SAFETY_BYTES >> 20} MiB safety margin and a "
585
- f"{AGENT_DISPLAY_RESERVE_BYTES >> 20} MiB display reserve"
586
- + (", kept even with no display attached" if c["display_active"] is False else "")
587
- + (
588
- f", less the smallest decision reserve {gib(c['decision_reserve_bytes'])}"
589
- if c["decision_reserve_bytes"]
590
- else ""
591
- )
592
- + ")"
593
- )
594
- out.append(
595
- f" spec memory bandwidth {c['bandwidth_gb_s']:g} GB/s "
596
- "(vendor spec, not measured)"
597
- if c["bandwidth_gb_s"]
598
- else " memory bandwidth: speed is estimated from "
599
- f"{cat.DECODE_BASES['uma-class']} (not measured)"
600
- if on_mac
601
- else " memory bandwidth: the model is not in the spec table; speed is "
602
- f"estimated from {cat.DECODE_BASES['discrete-class']}"
603
- )
604
- if c["display_active"]:
605
- out.append(
606
- " a display is attached: the desktop takes VRAM that changes at any "
607
- "time; the plan prices what is free now"
608
- )
609
- if c["held_by"]:
610
- out.append(" held by: " + "; ".join(c["held_by"]))
611
- fits = [
612
- f"{f['id']} {f['quant']} (agent quality {f['quality']}, estimated decode "
613
- f"{f['decode_tok_s']:g} tok/s)"
614
- for f in c["llm"][:3]
615
- ]
616
- shown = f"top 3 of {len(c['llm'])}" if len(c["llm"]) > 3 else f"{len(fits)} in all"
617
- out.append(
618
- f" llama.cpp LLMs that fit (agent posture, validated, {shown}): "
619
- + ", ".join(fits)
620
- if fits
621
- else " LLMs that fit: no validated LLM fits this card in the agent posture"
622
- )
623
- if fits and not c["auto"]:
624
- out.append(
625
- " another inference service runs on the Metal GPU; once sharing with "
626
- "it is confirmed, add --share-gpu to stack plan"
627
- if on_mac
628
- else " other programs' services run on this card, so --llm auto skips "
629
- f"it; when sharing is confirmed, use --gpu {c['index']} --share-gpu"
630
- )
631
- slow = [f for f in c["llm"][:1] if f["decode_tok_s"] < cat.PLEASANT_FLOOR_TOK_S]
632
- if slow:
633
- out.append(
634
- " note: the first choice's estimated decode is below the "
635
- f"pleasant floor of {cat.PLEASANT_FLOOR_TOK_S:g} tok/s"
636
- )
637
- out.append(
638
- f" RAM {gib(hw['ram_total_bytes'])}, available {gib(hw['ram_available_bytes'])}"
639
- )
640
- free = hw["disk_free_bytes"]
641
- out.append(
642
- f" disk {hw['disk_path']}: {gib(free) if free is not None else 'unknown'} free"
643
- )
644
- out.append(f" tier {hw['tier']}")
645
- refused = platform_error(hw.get("platform", "linux"), arch=hw.get("arch"))
646
- out += pick_lines(hw.get("picks") or [], None if refused else command)
647
- out += [f" note {n}" for n in hw["notes"]]
648
- mac = any(c.get("uuid") == metal.METAL_UUID for c in hw["cards"])
649
- out.append(
650
- "Planning is not possible now: fix the probe or resource problem first, then check the "
651
- "hardware again."
652
- if hw.get("planning_problem")
653
- else "This platform can check its hardware; run the full suite on a supported Linux host "
654
- "or an Apple Silicon Mac."
655
- if platform_error(hw.get("platform", "linux"), arch=hw.get("arch"))
656
- else f"Next: {command} install (plan, confirm once, install and verify), or {command} "
657
- f"stack plan to only see and save the plan ({_MAC if mac else _CARDS})"
658
- )
659
- return out
660
-
661
-
662
- def plan_lines(hw: Hardware, llm: Plan, *, decision: bool = True) -> list[str]:
663
- """The hardware lines a stack plan summary opens with; the LLM's card is marked, and named
664
- as the decision model's too when the plan has one (it only ever shares the LLM's card)."""
665
- devices = llm["service"].get("env", {}).get("CUDA_VISIBLE_DEVICES")
666
- llm_uuid = devices if isinstance(devices, str) and devices and "," not in devices else None
667
- if on_metal(llm):
668
- llm_uuid = metal.METAL_UUID
669
- out = []
670
- for c in hw["cards"]:
671
- bandwidth = f", spec bandwidth {c['bandwidth_gb_s']:g} GB/s" if c["bandwidth_gb_s"] else ""
672
- here = llm_uuid is not None and c.get("uuid") == llm_uuid
673
- mark = (" (LLM and decision)" if decision else " (LLM)") if here else ""
674
- if c.get("uuid") == metal.METAL_UUID:
675
- out.append(
676
- f" hardware GPU 0 {c['name']}{mark}: Metal working-set limit "
677
- f"{gib(c['total_bytes'])}, {gib(c['free_bytes'])} for the GPU when planned "
678
- "(unified memory)"
679
- )
680
- continue
681
- out.append(
682
- f" hardware GPU {c['index']} {c['name']}{mark}: VRAM {gib(c['total_bytes'])}, "
683
- f"free when planned {gib(c['free_bytes'])}{bandwidth}"
684
- )
685
- out.append(
686
- f" hardware RAM {gib(hw['ram_total_bytes'])}, available when planned "
687
- f"{gib(hw['ram_available_bytes'])}; {hw['tier']}"
688
- )
689
- return out
690
-
691
-
692
- def reboot_line(hw: Hardware | None, llm: Plan, command: str) -> str:
693
- """What a reboot does to the planned services, and the one command that changes it."""
694
- kind = llm["service"]["kind"]
695
- if kind == "systemd-user":
696
- manager = hw.get("service_manager") if hw else None
697
- if manager and manager["linger"]:
698
- return (
699
- " reboot the services start at boot (systemd --user, linger on); nothing to "
700
- f"run; {command} stack up checks them and starts any that are missing"
701
- )
702
- return " reboot the services start when you log in (systemd --user)" + (
703
- "; linger is off, so they do not start at boot until someone logs in. To start "
704
- "them at boot, run once: loginctl enable-linger"
705
- if manager
706
- else ""
707
- )
708
- if kind == "launchd-user":
709
- return (
710
- " reboot the launchd jobs belong to the current login session; after a reboot "
711
- f"run {command} stack up to start them"
712
- )
713
- return (
714
- " reboot the services run under nohup and do not come back after a reboot; run "
715
- f"{command} stack up to start them, without reinstalling"
716
- )
717
-
718
-
719
- def slow_warning(facts: HostFacts, llm: Plan) -> list[str]:
720
- """A note when the stack's LLM, priced at its card's spec bandwidth, decodes below the
721
- pleasant floor; silent where the card model has no published figure."""
722
- model, index = llm["model"], plan_card(llm, facts)
723
- gpu = next((g for g in facts.get("gpus") or [] if g["index"] == index), None)
724
- entry = next((e for e in cat.load_catalog_file() if e.id == model.get("id")), None)
725
- variant = (
726
- next((v for v in entry.variants if v.quant == model.get("quant")), None) if entry else None
727
- )
728
- bandwidth = gpu_specs.bandwidth_gb_s(gpu["name"]) if gpu else None
729
- if entry is None or variant is None or gpu is None or bandwidth is None:
730
- return []
731
- budget = HardwareBudget(0, 0, 0, gpu_bandwidth_gb_s=bandwidth)
732
- tok_s = cat.decode_estimate(entry, variant, budget).tok_s
733
- if tok_s >= cat.PLEASANT_FLOOR_TOK_S:
734
- return []
735
- return [
736
- f"LLM: at the {gpu['name']} spec memory bandwidth of {bandwidth:g} GB/s, single-stream "
737
- f"decode is about {tok_s:.0f} tok/s (estimate), below the pleasant floor of "
738
- f"{cat.PLEASANT_FLOOR_TOK_S:g} tok/s; --llm can pick a smaller model"
739
- ]
740
-
741
-
742
- def agent_label(llm: Plan) -> str:
743
- """The concurrency and KV types an agent-posture LLM launches with; empty otherwise."""
744
- launch = llm["launch"]
745
- if launch.get("posture") != "agent":
746
- return ""
747
- kv = launch.get("kv_types")
748
- pair = [str(t) for t in kv] if isinstance(kv, list) else ["q8_0", "q8_0"]
749
- return f"{launch.get('slots')} parallel sessions sharing the KV ({'/'.join(pair)}), "