@simplexai/localmodels-linux-arm64 0.1.0-dev.60 → 0.1.0-dev.61

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 (74) hide show
  1. package/bootstrap.identity +1 -1
  2. package/bootstrap.sha256 +73 -60
  3. package/modules/localmodels/__init__.py +1 -1
  4. package/modules/localmodels/__main__.py +5 -3
  5. package/modules/localmodels/auth_proxy.py +185 -19
  6. package/modules/localmodels/catalog.json +363 -0
  7. package/modules/localmodels/catalog.py +1 -1
  8. package/modules/localmodels/catalog_add.py +5 -5
  9. package/modules/localmodels/catalog_license.py +2 -0
  10. package/modules/localmodels/catalog_recipes.py +2 -0
  11. package/modules/localmodels/cli_parser.py +6 -2
  12. package/modules/localmodels/context_policy.py +40 -4
  13. package/modules/localmodels/debug_mode.py +13 -0
  14. package/modules/localmodels/debug_stub_server.py +156 -1
  15. package/modules/localmodels/deploy.py +11 -2
  16. package/modules/localmodels/download-mirrors.json +12 -0
  17. package/modules/localmodels/engines-b12757-mix-ef2df21.json +26 -0
  18. package/modules/localmodels/engines-whisper-b5454.json +120 -1
  19. package/modules/localmodels/gateway_app_bifrost.py +14 -14
  20. package/modules/localmodels/gateway_bifrost.py +4 -1
  21. package/modules/localmodels/gateway_cli.py +14 -80
  22. package/modules/localmodels/gateway_server.py +88 -16
  23. package/modules/localmodels/gpu_specs.py +35 -1
  24. package/modules/localmodels/harness.py +1 -2
  25. package/modules/localmodels/hf_repo.py +12 -4
  26. package/modules/localmodels/install.py +4 -4
  27. package/modules/localmodels/library_serve.py +69 -13
  28. package/modules/localmodels/npm_transport.py +4 -58
  29. package/modules/localmodels/recommend_cli.py +2 -1
  30. package/modules/localmodels/remote_ops.py +120 -713
  31. package/modules/localmodels/remote_ops_common.py +729 -0
  32. package/modules/localmodels/remote_ops_download.py +397 -381
  33. package/modules/localmodels/remote_ops_mirrors.py +26 -65
  34. package/modules/localmodels/remote_ops_prepare.py +43 -35
  35. package/modules/localmodels/remote_ops_ranges.py +98 -62
  36. package/modules/localmodels/remote_ops_remove.py +30 -22
  37. package/modules/localmodels/remote_ops_service.py +102 -95
  38. package/modules/localmodels/remote_ops_verify.py +94 -63
  39. package/modules/localmodels/runtime_cli.py +15 -5
  40. package/modules/localmodels/runtime_io.py +54 -1
  41. package/modules/localmodels/speech-sv.txt +93 -0
  42. package/modules/localmodels/speech_admission.py +437 -0
  43. package/modules/localmodels/speech_catalog.py +170 -0
  44. package/modules/localmodels/speech_cli.py +273 -0
  45. package/modules/localmodels/speech_jobs.py +772 -0
  46. package/modules/localmodels/speech_model.py +404 -0
  47. package/modules/localmodels/speech_serve.py +287 -0
  48. package/modules/localmodels/speech_server.py +837 -0
  49. package/modules/localmodels/speech_state.py +697 -0
  50. package/modules/localmodels/speech_worker_sensevoice.py +255 -0
  51. package/modules/localmodels/speech_workers.py +783 -0
  52. package/modules/localmodels/stack.py +0 -33
  53. package/modules/localmodels/stack_auto.py +5 -3
  54. package/modules/localmodels/stack_aux_gpu.py +45 -4
  55. package/modules/localmodels/stack_capacity.py +77 -8
  56. package/modules/localmodels/stack_cli.py +16 -1
  57. package/modules/localmodels/stack_compose.py +1 -1
  58. package/modules/localmodels/stack_down.py +24 -1
  59. package/modules/localmodels/stack_hardware.py +57 -88
  60. package/modules/localmodels/stack_hardware_text.py +4 -59
  61. package/modules/localmodels/stack_memory.py +13 -3
  62. package/modules/localmodels/stack_suite.py +9 -10
  63. package/modules/localmodels/stack_summary.py +4 -4
  64. package/modules/localmodels/stack_view_llm.py +1 -1
  65. package/modules/localmodels/transport.py +3 -2
  66. package/modules/localmodels/tui_views.py +2 -2
  67. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/METADATA +1 -1
  68. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/RECORD +70 -57
  69. package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/NOTICE +9 -0
  70. package/package.json +1 -1
  71. package/tool.json +1 -1
  72. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/WHEEL +0 -0
  73. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/entry_points.txt +0 -0
  74. /package/modules/{simplex_localmodels-0.1.0.dev60.dist-info → simplex_localmodels-0.1.0.dev61.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import argparse
6
5
  import copy
7
6
  import json
8
7
  import os
@@ -37,10 +36,6 @@ from localmodels.contracts import decode
37
36
  from localmodels.plan_envelope import PlanError
38
37
  from localmodels.probe import HostFacts
39
38
  from localmodels.records import Plan, ProgressEvent
40
- from localmodels.stack_args import add_parser as add_parser
41
- from localmodels.stack_args import add_plan_arguments as add_plan_arguments
42
- from localmodels.stack_args import conversation_cache as _conversation_cache
43
- from localmodels.stack_args import options_from_args as options_from_args
44
39
  from localmodels.stack_compose import agent_posture, compose, running_record
45
40
  from localmodels.stack_plan import (
46
41
  HARNESS_RAM,
@@ -57,7 +52,6 @@ from localmodels.stack_plan import (
57
52
  )
58
53
  from localmodels.stack_progress import forward
59
54
  from localmodels.stack_run import report as report
60
- from localmodels.stack_summary import summary as summary
61
55
 
62
56
  __all__ = [ # this module's API, with the stack_plan names callers reach through it
63
57
  "HARNESS_RAM",
@@ -67,18 +61,14 @@ __all__ = [ # this module's API, with the stack_plan names callers reach throug
67
61
  "StackOptions",
68
62
  "StackPlan",
69
63
  "StackRecord",
70
- "add_parser",
71
64
  "apply",
72
- "_conversation_cache",
73
65
  "build",
74
- "cli",
75
66
  "compose",
76
67
  "default_options",
77
68
  "digest",
78
69
  "execute",
79
70
  "load",
80
71
  "save",
81
- "summary",
82
72
  ]
83
73
 
84
74
 
@@ -548,26 +538,3 @@ def _run_components(
548
538
  stack_run.update(session, list(parts.values()), None)
549
539
  stack_run.finish(session, "completed")
550
540
  return persist(None)
551
-
552
-
553
- # ---------------------------------------------------------------------------- command line
554
-
555
-
556
- def _day2(args: argparse.Namespace) -> int:
557
- from localmodels import stack_cli
558
-
559
- return stack_cli.day2(args)
560
-
561
-
562
- def cli(args: argparse.Namespace) -> int:
563
- from localmodels import stack_cli
564
-
565
- return stack_cli.run_cli(
566
- args,
567
- build=build,
568
- save=save,
569
- load=load,
570
- apply=apply,
571
- report=report,
572
- day2_fn=_day2,
573
- )
@@ -21,6 +21,7 @@ from localmodels import (
21
21
  metal,
22
22
  preparation,
23
23
  reuse,
24
+ stack_capacity,
24
25
  stack_llm_ram,
25
26
  stack_ports,
26
27
  stack_suite,
@@ -30,7 +31,6 @@ from localmodels import (
30
31
  from localmodels import stack_aux_gpu as aux_gpu
31
32
  from localmodels import stack_decision as decide
32
33
  from localmodels import stack_gpu_memory as gpu_memory
33
- from localmodels import stack_hardware as hardware
34
34
  from localmodels.budget import HARNESS_RAM, RAM_FLOOR, gpu_conflicts, host_ram
35
35
  from localmodels.context_policy import AgentPosture
36
36
  from localmodels.estimator import HardwareBudget
@@ -320,7 +320,9 @@ def llama_ram_fits(
320
320
  if capped is not facts:
321
321
  facts = capped
322
322
  if budget is not None:
323
- budget = hardware.llm_budget(facts, index, merged, entry=entry, posture=posture)[0]
323
+ budget = stack_capacity.llm_budget(facts, index, merged, entry=entry, posture=posture)[
324
+ 0
325
+ ]
324
326
  listening, previous, existing, qa_cpu_decision = reads
325
327
  port = _probe_port(facts, merged, entry.id, listening, previous)
326
328
  merged["llm_port"] = port
@@ -424,7 +426,7 @@ def auto_llama_fits(
424
426
  continue
425
427
  variant = entry.variants[-1]
426
428
  for index in cards:
427
- card = hardware.llm_budget(facts, index, options, entry=entry, posture=posture)[0]
429
+ card = stack_capacity.llm_budget(facts, index, options, entry=entry, posture=posture)[0]
428
430
  fits = (
429
431
  llm_rank.automatic_fit(entry, facts, card, posture, options)
430
432
  if card.uma
@@ -16,9 +16,9 @@ from localmodels import component, hosts, metal, suite
16
16
  from localmodels import stack_decision as decide
17
17
  from localmodels.budget import gib
18
18
  from localmodels.plan_envelope import PlanError
19
- from localmodels.probe import HostFacts
19
+ from localmodels.probe import GPU, HostFacts
20
20
  from localmodels.records import Plan
21
- from localmodels.stack_plan import DecisionChoice
21
+ from localmodels.stack_plan import HARNESS_RAM, DecisionChoice, ram_floor
22
22
 
23
23
  # endpoint contract -> catalog task of the auxiliaries that have a GPU variant
24
24
  GPU_TASKS = {"embedding": "embedding", "rerank": "reranker"}
@@ -53,6 +53,45 @@ def _degrades(llm: Plan, again: Plan) -> bool:
53
53
  )
54
54
 
55
55
 
56
+ def _metal_keep_aux(
57
+ facts: HostFacts,
58
+ card: GPU,
59
+ llm: Plan,
60
+ choice: DecisionChoice,
61
+ aux: list[Plan],
62
+ price_llm: decide.PriceLLM,
63
+ ) -> Plan:
64
+ """Step optional Metal ubatch/MTP back to 512/0 when unified-memory auxiliaries need the RAM."""
65
+ launch = llm["launch"]
66
+ if not aux or (
67
+ int(str(launch.get("ubatch") or 512)) <= 512
68
+ and int(str(launch.get("mtp_draft_depth") or 0)) <= 0
69
+ ):
70
+ return llm
71
+ needed = (
72
+ int(str(launch.get("unified_bytes") or 0))
73
+ + decide.host_ram(choice)
74
+ + HARNESS_RAM
75
+ + sum(suite.bounded_ram(p) for p in aux)
76
+ + ram_floor(True)
77
+ )
78
+ if needed <= facts["ram"]["available_bytes"]:
79
+ return llm
80
+ held = metal.holds(facts, decide.host_ram(choice))
81
+ try:
82
+ plain = price_llm(held, str(llm["placement"]["id"]), mtp=False)
83
+ except PlanError:
84
+ return llm
85
+ before, after = llm["launch"], plain["launch"]
86
+ same_posture = (
87
+ int(str(after["window"])) >= int(str(before["window"]))
88
+ and int(str(after.get("slots") or 1)) >= int(str(before.get("slots") or 1))
89
+ and str(after.get("kv_types")) == str(before.get("kv_types"))
90
+ and str(after.get("vision") or "off") == str(before.get("vision") or "off")
91
+ )
92
+ return plain if same_posture else llm
93
+
94
+
56
95
  def place(
57
96
  facts: HostFacts,
58
97
  llm: Plan,
@@ -68,8 +107,10 @@ def place(
68
107
  or a variant that would cost the LLM any window, slot or KV precision it held beside the
69
108
  decision model keeps the CPU plan."""
70
109
  card = decide.llm_card(llm, facts)
71
- if card is None or card["uuid"] == metal.METAL_UUID or llm["launch"].get("posture") != "agent":
72
- return aux, llm # a Mac's Metal GPU shares the RAM the CPU auxiliaries already take
110
+ if card is None or llm["launch"].get("posture") != "agent":
111
+ return aux, llm
112
+ if card["uuid"] == metal.METAL_UUID:
113
+ return aux, _metal_keep_aux(facts, card, llm, choice, aux, price_llm)
73
114
  held = _decision_vram(choice)
74
115
  out: list[Plan] = []
75
116
  for part in aux:
@@ -10,11 +10,17 @@ from __future__ import annotations
10
10
  from dataclasses import replace
11
11
 
12
12
  from localmodels import catalog as cat
13
- from localmodels import llm_rank
13
+ from localmodels import component, context_policy, gpu_specs, llm_rank, metal
14
14
  from localmodels.budget import gib
15
- from localmodels.context_policy import AgentPosture
16
- from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES, PhysicsRefusal
17
- from localmodels.probe import HostFacts
15
+ from localmodels.context_policy import AGENT, AgentPosture, cache_floor_bytes, posture_for
16
+ from localmodels.estimator import (
17
+ AGENT_VRAM_RESERVE_BYTES,
18
+ METAL_VRAM_RESERVE_BYTES,
19
+ HardwareBudget,
20
+ PhysicsRefusal,
21
+ )
22
+ from localmodels.plan_envelope import PlanError
23
+ from localmodels.probe import GPU, HostFacts
18
24
  from localmodels.stack_plan import CapacityFit, Hardware, StackOptions
19
25
 
20
26
  WDDM_NOTE = (
@@ -24,12 +30,71 @@ WDDM_NOTE = (
24
30
  )
25
31
 
26
32
 
33
+ def decision_reserve(card_budget_bytes: int, options: StackOptions) -> int:
34
+ """Smallest decision reserve kept before auto selection; 0 if disabled or none fits."""
35
+ if str(options["decision"]) == "none" or card_budget_bytes <= 0:
36
+ return 0
37
+ recipes = cat.decision_components()
38
+ requested = str(options["decision"])
39
+ pool = recipes if requested == "auto" else [r for r in recipes if r["id"] == requested]
40
+ fitting = [
41
+ t["vram_bytes"] + component.VRAM_MARGIN
42
+ for r in pool
43
+ for t in r["tiers"]
44
+ if t["vram_bytes"] + component.VRAM_MARGIN <= card_budget_bytes
45
+ ]
46
+ return min(fitting) if fitting else 0
47
+
48
+
49
+ def device(facts: HostFacts, index: int) -> GPU:
50
+ """Card ``index`` of ``cards``: an NVIDIA card, or a Mac's Metal GPU."""
51
+ found = metal.device(facts)
52
+ if found is not None and index == 0:
53
+ return found
54
+ return next(g for g in facts.get("gpus") or [] if g["index"] == index)
55
+
56
+
57
+ def llm_budget(
58
+ facts: HostFacts,
59
+ index: int,
60
+ options: StackOptions,
61
+ *,
62
+ entry: cat.CatalogEntry | None = None,
63
+ posture: AgentPosture = AGENT,
64
+ ) -> tuple[HardwareBudget, int]:
65
+ """Live LLM budget and decision reserve, including safety, display and Metal host costs."""
66
+ gpu = device(facts, index)
67
+ on_mac = gpu["uuid"] == metal.METAL_UUID
68
+ reserve = decision_reserve(component.auto_budget(gpu["total_bytes"]), options)
69
+ free = gpu["free_bytes"]
70
+ if on_mac:
71
+ profile = entry.profile(entry.variants[-1]) if entry is not None else None
72
+ mac_posture = posture_for(posture, "metal")
73
+ host_bytes = context_policy.metal_host_bytes(profile, mac_posture) if profile else 0
74
+ room = facts["ram"]["available_bytes"] - metal.HOST_KEEP_BYTES - host_bytes
75
+ floor = cache_floor_bytes(mac_posture, profile)
76
+ free = min(gpu["total_bytes"], room - floor)
77
+ usable = free - (METAL_VRAM_RESERVE_BYTES if on_mac else AGENT_VRAM_RESERVE_BYTES) - reserve
78
+ budget = HardwareBudget(
79
+ usable_vram_bytes=max(0, usable),
80
+ total_device_bytes=gpu["total_bytes"],
81
+ ram_available_bytes=0,
82
+ uma=on_mac,
83
+ gpu_name=gpu["name"],
84
+ platform=facts.get("platform", ""),
85
+ gpu_bandwidth_gb_s=gpu_specs.bandwidth_gb_s(
86
+ gpu["name"], total_bytes=facts["ram"]["total_bytes"] if on_mac else None
87
+ ),
88
+ )
89
+ return budget, reserve
90
+
91
+
27
92
  def rows(
28
93
  facts: HostFacts, index: int, options: StackOptions, posture: AgentPosture
29
94
  ) -> list[CapacityFit]:
30
- from localmodels import stack_hardware as hardware
95
+ from localmodels import deploy
31
96
 
32
- gpu = hardware.device(facts, index)
97
+ gpu = device(facts, index)
33
98
  if gpu["vendor"] != "nvidia" or gpu.get("mig_mode") == "enabled":
34
99
  return []
35
100
  total: HostFacts = {
@@ -43,16 +108,20 @@ def rows(
43
108
  for entry in cat.load_catalog_file():
44
109
  if entry.runtime != "llama.cpp" or entry.status not in ("candidate", "validated"):
45
110
  continue
111
+ try:
112
+ deploy.engine_plan(facts, deploy.PlanOptions(model_id=entry.id), entry, "cuda", [], [])
113
+ except PlanError:
114
+ continue
46
115
  variant = entry.variants[-1]
47
116
  choices = []
48
117
  # Keep the requested posture when possible; a one-slot trial is always explicit.
49
118
  for slots in dict.fromkeys((posture.slots, 1)):
50
119
  bounded = replace(posture, target=posture.floor, preferred=posture.floor, slots=slots)
51
- full, reserve = hardware.llm_budget(total, index, options, entry=entry, posture=bounded)
120
+ full, reserve = llm_budget(total, index, options, entry=entry, posture=bounded)
52
121
  decision = entry.launch_plan(variant, full, agent=bounded).decision
53
122
  if isinstance(decision, PhysicsRefusal):
54
123
  continue
55
- current, _ = hardware.llm_budget(facts, index, options, entry=entry, posture=bounded)
124
+ current, _ = llm_budget(facts, index, options, entry=entry, posture=bounded)
56
125
  current_decision = entry.launch_plan(variant, current, agent=bounded).decision
57
126
  fits_now = not isinstance(current_decision, PhysicsRefusal)
58
127
  if not isinstance(current_decision, PhysicsRefusal):
@@ -18,11 +18,13 @@ from localmodels import (
18
18
  deploy,
19
19
  harness,
20
20
  hosts,
21
+ stack,
21
22
  stack_arena,
22
23
  stack_card,
23
24
  stack_client_settings,
24
25
  stack_down,
25
26
  stack_events,
27
+ stack_hardware_text,
26
28
  stack_ledger,
27
29
  stack_mcp,
28
30
  stack_memory,
@@ -75,7 +77,7 @@ def _hardware(facts: HostFacts | None, as_json: bool, unified_memory: str | None
75
77
  json.dump(seen, sys.stdout, ensure_ascii=False, indent=1)
76
78
  sys.stdout.write("\n")
77
79
  else:
78
- print("\n".join(hardware.lines(seen, command())))
80
+ print("\n".join(stack_hardware_text.lines(seen, command())))
79
81
  return 0
80
82
 
81
83
 
@@ -326,3 +328,16 @@ def run_cli(
326
328
  print(json.dumps(_plan_error_payload(exc), separators=(",", ":")))
327
329
  print(f"stack: {exc}", file=sys.stderr)
328
330
  return 2
331
+
332
+
333
+ def cli(args: argparse.Namespace) -> int:
334
+ """Entry point for ``localmodels stack`` subcommands."""
335
+ return run_cli(
336
+ args,
337
+ build=stack.build,
338
+ save=stack.save,
339
+ load=stack.load,
340
+ apply=stack.apply,
341
+ report=stack.report,
342
+ day2_fn=day2,
343
+ )
@@ -494,7 +494,7 @@ def _llama_parts(
494
494
  base_dir=options["base_dir"],
495
495
  hf_download_endpoint=options["hf_endpoint"],
496
496
  hf_api_endpoint=options["hf_endpoint"],
497
- agent=posture if mtp else replace(posture, mtp_draft_depth=0),
497
+ agent=posture if mtp else replace(posture, mtp_draft_depth=0, ubatch_pinned=True),
498
498
  quant=str(options.get("quant") or ""),
499
499
  ),
500
500
  entries=entries,
@@ -14,7 +14,16 @@ import sys
14
14
  from collections.abc import Callable
15
15
  from typing import Literal, TypedDict
16
16
 
17
- from localmodels import console, deploy, gateway, gateway_bifrost, harness, harness_gateway, hosts
17
+ from localmodels import (
18
+ console,
19
+ deploy,
20
+ gateway,
21
+ gateway_bifrost,
22
+ harness,
23
+ harness_gateway,
24
+ hosts,
25
+ speech_state,
26
+ )
18
27
  from localmodels import stack_lifecycle as lifecycle
19
28
  from localmodels.contracts import decode
20
29
  from localmodels.stack_plan import StackError, StackPlan, platform_error
@@ -162,6 +171,20 @@ def _down(out: Out) -> DownReport:
162
171
  f"{'✗' if failed else '…'} {plan['name']} {'failed to stop' if failed else 'stopped'}"
163
172
  )
164
173
  parts.append(row)
174
+ speech_action, speech_detail = speech_state.stop_sidecar_if_recorded()
175
+ if speech_action == "stopped" or speech_action == "failed":
176
+ parts.append(
177
+ {
178
+ "name": "speech-sidecar",
179
+ "task": "stt",
180
+ "action": speech_action,
181
+ "detail": speech_detail,
182
+ }
183
+ )
184
+ out(
185
+ f"{'✗' if speech_action == 'failed' else '…'} speech-sidecar "
186
+ f"{'failed to stop' if speech_action == 'failed' else 'stopped'}"
187
+ )
165
188
  return {
166
189
  "schema": SCHEMA,
167
190
  "ok": not gate.startswith("failed") and all(p["action"] != "failed" for p in parts),
@@ -11,10 +11,10 @@ from localmodels import catalog as cat
11
11
  from localmodels import (
12
12
  catalog_recipes,
13
13
  component,
14
- context_policy,
15
14
  gpu_specs,
16
15
  llm_rank,
17
16
  metal,
17
+ stack_auto,
18
18
  stack_capacity,
19
19
  stack_warm_store,
20
20
  suite,
@@ -26,35 +26,13 @@ from localmodels.budget import (
26
26
  placements,
27
27
  sharing_cards,
28
28
  )
29
- from localmodels.context_policy import AGENT, AgentPosture, cache_floor_bytes, posture_for
30
- from localmodels.estimator import (
31
- AGENT_VRAM_RESERVE_BYTES,
32
- METAL_VRAM_RESERVE_BYTES,
33
- HardwareBudget,
34
- )
29
+ from localmodels.context_policy import AgentPosture, posture_for
30
+ from localmodels.estimator import AGENT_VRAM_RESERVE_BYTES
35
31
  from localmodels.probe import GPU, HostFacts
36
32
  from localmodels.records import Plan
37
- from localmodels.stack_hardware_text import (
38
- agent_label as agent_label,
39
- )
40
- from localmodels.stack_hardware_text import (
41
- lines as lines,
42
- )
43
- from localmodels.stack_hardware_text import (
44
- on_metal as on_metal,
45
- )
46
- from localmodels.stack_hardware_text import (
47
- plan_card as plan_card,
48
- )
49
- from localmodels.stack_hardware_text import (
50
- plan_lines as plan_lines,
51
- )
52
- from localmodels.stack_hardware_text import (
53
- reboot_line as reboot_line,
54
- )
55
- from localmodels.stack_hardware_text import (
56
- slow_advisory as slow_advisory,
57
- )
33
+ from localmodels.stack_capacity import decision_reserve as decision_reserve
34
+ from localmodels.stack_capacity import device as device
35
+ from localmodels.stack_capacity import llm_budget as llm_budget
58
36
  from localmodels.stack_picks import picks
59
37
  from localmodels.stack_plan import (
60
38
  Card,
@@ -115,20 +93,58 @@ def assumed(facts: HostFacts, unified_memory: str | None) -> HostFacts:
115
93
  raise StackError(str(exc) or f"cannot parse --unified-memory {unified_memory}") from None
116
94
 
117
95
 
118
- def decision_reserve(card_budget_bytes: int, options: StackOptions) -> int:
119
- """Smallest decision reserve kept before auto selection; 0 if disabled or none fits."""
120
- if str(options["decision"]) == "none" or card_budget_bytes <= 0:
96
+ def on_metal(part: Plan | None) -> bool:
97
+ """The part runs on a Mac's Metal GPU."""
98
+ return part is not None and metal.on_device(part["placement"])
99
+
100
+
101
+ def plan_card(part: Plan | None, facts: HostFacts) -> int | None:
102
+ """Resolve the running service's CUDA UUID to its current host index (0 on a Mac)."""
103
+ if part is None:
104
+ return None
105
+ if on_metal(part):
121
106
  return 0
122
- recipes = cat.decision_components()
123
- requested = str(options["decision"])
124
- pool = recipes if requested == "auto" else [r for r in recipes if r["id"] == requested]
125
- fitting = [
126
- t["vram_bytes"] + component.VRAM_MARGIN
127
- for r in pool
128
- for t in r["tiers"]
129
- if t["vram_bytes"] + component.VRAM_MARGIN <= card_budget_bytes
130
- ]
131
- return min(fitting) if fitting else 0
107
+ devices = part["service"].get("env", {}).get("CUDA_VISIBLE_DEVICES")
108
+ if not isinstance(devices, str) or not devices or "," in devices:
109
+ return None
110
+ return next((g["index"] for g in facts.get("gpus") or [] if g["uuid"] == devices), None)
111
+
112
+
113
+ def slow_advisory(facts: HostFacts, llm: Plan) -> str | None:
114
+ model = llm["model"]
115
+ model_id, quant = model.get("id"), model.get("quant")
116
+ if not isinstance(model_id, str) or not isinstance(quant, str):
117
+ return None
118
+ identified, index = stack_warm_store.resolve_part_gpu(llm, facts)
119
+ if not identified or index is None:
120
+ return None
121
+ seen = stack_warm_store.lookup(facts, index, model_id, quant)
122
+ if seen is not None:
123
+ note = cat.decode_advisory(seen, measured=True)
124
+ else:
125
+ entry = cat.find_entry(model_id)
126
+ placement = next(
127
+ (
128
+ target
129
+ for target in placements(facts, planning=False)
130
+ if not target.pooled
131
+ and (target.backend == "metal" or target.gpu_indices == (index,))
132
+ ),
133
+ None,
134
+ )
135
+ if (
136
+ placement is None
137
+ or entry is None
138
+ or entry.runtime != "llama.cpp"
139
+ or llm["launch"].get("spilled")
140
+ ):
141
+ return None
142
+ variant = next((v for v in entry.variants if v.quant == quant), None)
143
+ if variant is None:
144
+ return None
145
+ speed = cat.decode_estimate(entry, variant, placement.budget, backend=placement.backend)
146
+ note = cat.decode_advisory(speed.tok_s, measured=speed.basis == "measured-decode")
147
+ return f"LLM: {note}; --llm can pick a smaller model" if note else None
132
148
 
133
149
 
134
150
  def cards(facts: HostFacts, gpu: int | None = None, *, share_gpu: bool = False) -> list[int]:
@@ -223,14 +239,6 @@ def shared_start_guard(
223
239
  return check
224
240
 
225
241
 
226
- def device(facts: HostFacts, index: int) -> GPU:
227
- """Card ``index`` of ``cards``: an NVIDIA card, or a Mac's Metal GPU."""
228
- found = metal.device(facts)
229
- if found is not None and index == 0:
230
- return found
231
- return next(g for g in facts.get("gpus") or [] if g["index"] == index)
232
-
233
-
234
242
  def held_elsewhere(name: str, part: Plan, gpu: int | None, facts: HostFacts) -> None:
235
243
  """Refuse reusing a running deployment on another card than ``--gpu`` names."""
236
244
  card = plan_card(part, facts)
@@ -274,47 +282,10 @@ def decision_elsewhere(choice: DecisionChoice, gpu: int | None, facts: HostFacts
274
282
  return []
275
283
 
276
284
 
277
- def llm_budget(
278
- facts: HostFacts,
279
- index: int,
280
- options: StackOptions,
281
- *,
282
- entry: cat.CatalogEntry | None = None,
283
- posture: AgentPosture = AGENT,
284
- ) -> tuple[HardwareBudget, int]:
285
- """Live LLM budget and decision reserve, including safety, display and Metal host costs."""
286
- gpu = device(facts, index)
287
- on_mac = gpu["uuid"] == metal.METAL_UUID
288
- reserve = decision_reserve(component.auto_budget(gpu["total_bytes"]), options)
289
- free = gpu["free_bytes"]
290
- if on_mac:
291
- profile = entry.profile(entry.variants[-1]) if entry is not None else None
292
- mac_posture = posture_for(posture, "metal")
293
- host_bytes = context_policy.metal_host_bytes(profile, mac_posture) if profile else 0
294
- room = facts["ram"]["available_bytes"] - metal.HOST_KEEP_BYTES - host_bytes
295
- floor = cache_floor_bytes(mac_posture, profile)
296
- free = min(gpu["total_bytes"], room - floor)
297
- usable = free - (METAL_VRAM_RESERVE_BYTES if on_mac else AGENT_VRAM_RESERVE_BYTES) - reserve
298
- budget = HardwareBudget(
299
- usable_vram_bytes=max(0, usable),
300
- total_device_bytes=gpu["total_bytes"],
301
- ram_available_bytes=0,
302
- uma=on_mac,
303
- gpu_name=gpu["name"],
304
- platform=facts.get("platform", ""),
305
- gpu_bandwidth_gb_s=gpu_specs.bandwidth_gb_s(
306
- gpu["name"], total_bytes=facts["ram"]["total_bytes"] if on_mac else None
307
- ),
308
- )
309
- return budget, reserve
310
-
311
-
312
285
  def llm_fits(
313
286
  facts: HostFacts, index: int, options: StackOptions, posture: AgentPosture
314
287
  ) -> list[LlmFit]:
315
288
  """Automatic candidates priced with their own embeddings and cache."""
316
- from localmodels import stack_auto
317
-
318
289
  if device(facts, index)["uuid"] == metal.METAL_UUID:
319
290
  posture = posture_for(posture, "metal")
320
291
  merged: StackOptions = {**default_options(), **options}
@@ -511,8 +482,6 @@ def _set_linux_note(facts: HostFacts, notes: list[str], cards: list[Card]) -> No
511
482
 
512
483
  def view(facts: HostFacts, options: StackOptions, posture: AgentPosture | None) -> Hardware:
513
484
  """The hardware as ``stack`` prices it; ``posture`` None leaves the LLM lists empty."""
514
- from localmodels import stack_auto
515
-
516
485
  facts, pressure_notes = metal.pressured(facts)
517
486
  facts = stack_auto.maybe_capped(facts, {**default_options(), **options}) or facts
518
487
  total, available = host_ram(facts)
@@ -3,13 +3,12 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from localmodels import catalog as cat
6
- from localmodels import catalog_recipes, console, metal, stack_capacity, stack_warm_store
7
- from localmodels.budget import gib, placements
6
+ from localmodels import catalog_recipes, console, metal, stack_capacity, stack_hardware
7
+ from localmodels.budget import gib
8
8
  from localmodels.estimator import (
9
9
  AGENT_DISPLAY_RESERVE_BYTES,
10
10
  AGENT_VRAM_SAFETY_BYTES,
11
11
  )
12
- from localmodels.probe import HostFacts
13
12
  from localmodels.records import Plan
14
13
  from localmodels.stack_picks import label as fit_label
15
14
  from localmodels.stack_picks import lines as pick_lines
@@ -19,23 +18,6 @@ _MAC = "--unified-memory SIZE prices it as a smaller Mac" # the next step's opt
19
18
  _CARDS = "with several cards, --gpu N picks the card for the LLM and the decision model"
20
19
 
21
20
 
22
- def on_metal(part: Plan | None) -> bool:
23
- """The part runs on a Mac's Metal GPU."""
24
- return part is not None and metal.on_device(part["placement"])
25
-
26
-
27
- def plan_card(part: Plan | None, facts: HostFacts) -> int | None:
28
- """Resolve the running service's CUDA UUID to its current host index (0 on a Mac)."""
29
- if part is None:
30
- return None
31
- if on_metal(part):
32
- return 0
33
- devices = part["service"].get("env", {}).get("CUDA_VISIBLE_DEVICES")
34
- if not isinstance(devices, str) or not devices or "," in devices:
35
- return None
36
- return next((g["index"] for g in facts.get("gpus") or [] if g["uuid"] == devices), None)
37
-
38
-
39
21
  def card_head(c: Card) -> str:
40
22
  arch = c["architecture"] or ""
41
23
  if c["compute_capability"]:
@@ -169,7 +151,7 @@ def plan_lines(hw: Hardware, llm: Plan, *, decision: bool = True) -> list[str]:
169
151
  as the decision model's too when the plan has one (it only ever shares the LLM's card)."""
170
152
  devices = llm["service"].get("env", {}).get("CUDA_VISIBLE_DEVICES")
171
153
  llm_uuid = devices if isinstance(devices, str) and devices and "," not in devices else None
172
- if on_metal(llm):
154
+ if stack_hardware.on_metal(llm):
173
155
  llm_uuid = metal.METAL_UUID
174
156
  out = []
175
157
  for c in hw["cards"]:
@@ -180,7 +162,7 @@ def plan_lines(hw: Hardware, llm: Plan, *, decision: bool = True) -> list[str]:
180
162
  out.append(
181
163
  f" hardware GPU 0 {c['name']}{mark}: Metal working-set limit "
182
164
  f"{gib(c['total_bytes'])}, {gib(c['free_bytes'])} for the GPU when planned "
183
- "(unified memory)"
165
+ f"(unified memory){bandwidth}"
184
166
  )
185
167
  continue
186
168
  out.append(
@@ -221,43 +203,6 @@ def reboot_line(hw: Hardware | None, llm: Plan, command: str) -> str:
221
203
  )
222
204
 
223
205
 
224
- def slow_advisory(facts: HostFacts, llm: Plan) -> str | None:
225
- model = llm["model"]
226
- model_id, quant = model.get("id"), model.get("quant")
227
- if not isinstance(model_id, str) or not isinstance(quant, str):
228
- return None
229
- identified, index = stack_warm_store.resolve_part_gpu(llm, facts)
230
- if not identified or index is None:
231
- return None
232
- seen = stack_warm_store.lookup(facts, index, model_id, quant)
233
- if seen is not None:
234
- note = cat.decode_advisory(seen, measured=True)
235
- else:
236
- entry = cat.find_entry(model_id)
237
- placement = next(
238
- (
239
- target
240
- for target in placements(facts, planning=False)
241
- if not target.pooled
242
- and (target.backend == "metal" or target.gpu_indices == (index,))
243
- ),
244
- None,
245
- )
246
- if (
247
- placement is None
248
- or entry is None
249
- or entry.runtime != "llama.cpp"
250
- or llm["launch"].get("spilled")
251
- ):
252
- return None
253
- variant = next((v for v in entry.variants if v.quant == quant), None)
254
- if variant is None:
255
- return None
256
- speed = cat.decode_estimate(entry, variant, placement.budget, backend=placement.backend)
257
- note = cat.decode_advisory(speed.tok_s, measured=speed.basis == "measured-decode")
258
- return f"LLM: {note}; --llm can pick a smaller model" if note else None
259
-
260
-
261
206
  def agent_label(llm: Plan) -> str:
262
207
  """The concurrency and KV types an agent-posture LLM launches with; empty otherwise."""
263
208
  launch = llm["launch"]