@simplexai/localmodels-linux-x64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.36
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.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +141 -99
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +4 -0
- package/modules/localmodels/app.py +7 -2
- package/modules/localmodels/approval.py +4 -4
- package/modules/localmodels/bifrost_checks.py +121 -3
- package/modules/localmodels/bifrost_provider.py +53 -0
- package/modules/localmodels/bifrost_unit.py +32 -1
- package/modules/localmodels/budget.py +7 -1
- package/modules/localmodels/catalog.json +286 -12
- package/modules/localmodels/catalog.py +30 -29
- package/modules/localmodels/catalog_add.py +1 -0
- package/modules/localmodels/cli_parser.py +10 -2
- package/modules/localmodels/component.py +7 -1
- package/modules/localmodels/decode_calibration.json +6 -0
- package/modules/localmodels/decode_calibration.py +104 -0
- package/modules/localmodels/deploy.py +44 -7
- package/modules/localmodels/deploy_steps.py +10 -1
- package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
- package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
- package/modules/localmodels/engines.json +57 -1
- package/modules/localmodels/engines.py +6 -2
- package/modules/localmodels/estimator.py +21 -7
- package/modules/localmodels/frontend.py +4 -4
- package/modules/localmodels/gateway.py +14 -4
- package/modules/localmodels/gateway_app_bifrost.py +4 -3
- package/modules/localmodels/gateway_bifrost.py +70 -57
- package/modules/localmodels/gateway_probe.py +3 -4
- package/modules/localmodels/gguf.py +7 -0
- package/modules/localmodels/harness.py +24 -25
- package/modules/localmodels/harness_gateway.py +19 -10
- package/modules/localmodels/harness_probe.py +33 -6
- package/modules/localmodels/hosts.py +73 -9
- package/modules/localmodels/install.py +36 -6
- package/modules/localmodels/library_cli.py +179 -0
- package/modules/localmodels/library_convert.py +132 -0
- package/modules/localmodels/library_gateway.py +471 -0
- package/modules/localmodels/library_jobs.py +314 -0
- package/modules/localmodels/library_model.py +246 -0
- package/modules/localmodels/library_pricing.py +347 -0
- package/modules/localmodels/library_serve.py +348 -0
- package/modules/localmodels/library_state.py +373 -0
- package/modules/localmodels/library_status.py +349 -0
- package/modules/localmodels/llm_rank.py +77 -8
- package/modules/localmodels/memcalc.py +7 -30
- package/modules/localmodels/metal.py +26 -0
- package/modules/localmodels/metal_probe.py +11 -7
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/preparation.py +49 -0
- package/modules/localmodels/probe.py +8 -8
- package/modules/localmodels/process_identity.py +536 -9
- package/modules/localmodels/quant_formats.py +123 -0
- package/modules/localmodels/recommend.py +32 -3
- package/modules/localmodels/recommend_cli.py +8 -4
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +104 -6
- package/modules/localmodels/remote_ops_download.py +17 -2
- package/modules/localmodels/remote_ops_prepare.py +425 -0
- package/modules/localmodels/remote_ops_remove.py +40 -7
- package/modules/localmodels/remote_ops_service.py +110 -8
- package/modules/localmodels/remote_ops_verify.py +15 -2
- package/modules/localmodels/runtime_auth.py +31 -1
- package/modules/localmodels/runtime_cli.py +3 -4
- package/modules/localmodels/runtime_io.py +50 -6
- package/modules/localmodels/service_autostart.py +45 -1
- package/modules/localmodels/service_control.py +13 -0
- package/modules/localmodels/service_deployment.py +12 -3
- package/modules/localmodels/service_jobs.py +33 -4
- package/modules/localmodels/service_probe.py +67 -13
- package/modules/localmodels/service_stop.py +152 -0
- package/modules/localmodels/service_worker.py +9 -1
- package/modules/localmodels/services_cli.py +50 -6
- package/modules/localmodels/setup_inspection.py +34 -25
- package/modules/localmodels/setup_text.py +118 -0
- package/modules/localmodels/sizecalc.py +625 -0
- package/modules/localmodels/sizecalc_cli.py +249 -0
- package/modules/localmodels/stack.py +69 -17
- package/modules/localmodels/stack_args.py +91 -19
- package/modules/localmodels/stack_auto.py +78 -0
- package/modules/localmodels/stack_binding.py +23 -35
- package/modules/localmodels/stack_card.py +195 -0
- package/modules/localmodels/stack_cleanup.py +379 -0
- package/modules/localmodels/stack_clients.py +4 -1
- package/modules/localmodels/stack_compose.py +173 -206
- package/modules/localmodels/stack_console.py +2 -0
- package/modules/localmodels/stack_decision.py +3 -2
- package/modules/localmodels/stack_down.py +189 -0
- package/modules/localmodels/stack_events.py +54 -0
- package/modules/localmodels/stack_hardware.py +30 -34
- package/modules/localmodels/stack_journal.py +29 -8
- package/modules/localmodels/stack_ledger.py +411 -0
- package/modules/localmodels/stack_lifecycle.py +162 -167
- package/modules/localmodels/stack_llm_ram.py +57 -5
- package/modules/localmodels/stack_memory.py +721 -0
- package/modules/localmodels/stack_picks.py +147 -0
- package/modules/localmodels/stack_plan.py +143 -25
- package/modules/localmodels/stack_ports.py +22 -0
- package/modules/localmodels/stack_preflight.py +699 -0
- package/modules/localmodels/stack_review.py +123 -5
- package/modules/localmodels/stack_rollback.py +2 -0
- package/modules/localmodels/stack_route.py +256 -0
- package/modules/localmodels/stack_run.py +11 -0
- package/modules/localmodels/stack_suite.py +107 -20
- package/modules/localmodels/stack_summary.py +65 -4
- package/modules/localmodels/stack_try.py +354 -0
- package/modules/localmodels/stack_try_client.py +194 -0
- package/modules/localmodels/stack_try_docs.py +139 -0
- package/modules/localmodels/stack_up.py +8 -1
- package/modules/localmodels/stack_update.py +29 -4
- package/modules/localmodels/stack_verify.py +3 -1
- package/modules/localmodels/stack_view.py +10 -11
- package/modules/localmodels/stack_view_apply.py +4 -2
- package/modules/localmodels/stack_view_events.py +2 -1
- package/modules/localmodels/stack_view_serve.py +3 -0
- package/modules/localmodels/stack_view_text.py +1 -1
- package/modules/localmodels/stack_view_words.py +4 -1
- package/modules/localmodels/stack_warm.py +574 -0
- package/modules/localmodels/stack_whatif.py +558 -0
- package/modules/localmodels/suite.py +48 -39
- package/modules/localmodels/tool_archive.py +40 -0
- package/modules/localmodels/tools.json +8 -0
- package/modules/localmodels/transport.py +1 -0
- package/modules/localmodels/vision.py +8 -1
- package/modules/localmodels/web/sizecalc/app.js +431 -0
- package/modules/localmodels/web/sizecalc/calc.js +269 -0
- package/modules/localmodels/web/sizecalc/page.html +362 -0
- package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/logo-claude.svg +3 -0
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/localmodels/web/view/logo-pi.svg +6 -0
- package/modules/localmodels/web/view/view.css +4 -0
- package/modules/localmodels/web/view/view.js +15 -6
- package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/METADATA +1 -1
- package/modules/simplex_localmodels-0.1.0.dev36.dist-info/RECORD +242 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
"""Read-only hardware upgrades using the planner's ``--llm auto`` selection.
|
|
2
|
+
|
|
3
|
+
The document holds a baseline and independent upgrades. stack_compose.choose_parts weighs resident
|
|
4
|
+
models and Linux Strata recipes, including their RAM and local pack requirements. Context comes
|
|
5
|
+
from the catalog launch calculation or the selected recipe. No plan or facts are saved.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import copy
|
|
12
|
+
import json
|
|
13
|
+
import sys
|
|
14
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Literal, TypeAlias, TypedDict
|
|
17
|
+
|
|
18
|
+
from localmodels import (
|
|
19
|
+
app,
|
|
20
|
+
catalog,
|
|
21
|
+
cli_help,
|
|
22
|
+
deploy,
|
|
23
|
+
metal,
|
|
24
|
+
probe,
|
|
25
|
+
service_probe,
|
|
26
|
+
stack_picks,
|
|
27
|
+
suite,
|
|
28
|
+
)
|
|
29
|
+
from localmodels import stack_hardware as hardware
|
|
30
|
+
from localmodels.context_policy import posture_for, window_k
|
|
31
|
+
from localmodels.contracts import decode
|
|
32
|
+
from localmodels.memcalc import parse_size
|
|
33
|
+
from localmodels.plan_envelope import PlanError
|
|
34
|
+
from localmodels.probe import GPU, HostFacts, Services
|
|
35
|
+
from localmodels.stack_compose import agent_posture, choose_parts, ram_budget
|
|
36
|
+
from localmodels.stack_memory import Machine
|
|
37
|
+
from localmodels.stack_plan import StackError, StackOptions, default_options
|
|
38
|
+
|
|
39
|
+
SCHEMA = "localmodels.stack-what-if/v1"
|
|
40
|
+
GIB = 1 << 30
|
|
41
|
+
RAM_STEPS_GIB = (16, 32, 64)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Choice(TypedDict):
|
|
45
|
+
id: str
|
|
46
|
+
quant: str
|
|
47
|
+
quality: int
|
|
48
|
+
role: str
|
|
49
|
+
card: int
|
|
50
|
+
shared: bool
|
|
51
|
+
engine: str
|
|
52
|
+
reason: str
|
|
53
|
+
decode_tok_s: float | None
|
|
54
|
+
decode_basis: str
|
|
55
|
+
context: int
|
|
56
|
+
slots: int
|
|
57
|
+
kv_types: list[str]
|
|
58
|
+
speed_kind: str # estimated | measured | unavailable
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
Choices: TypeAlias = dict[str, Choice | None]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Capacity(TypedDict):
|
|
65
|
+
platform: str
|
|
66
|
+
ram_total_bytes: int
|
|
67
|
+
ram_available_bytes: int
|
|
68
|
+
cards: list[GPU]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Snapshot(TypedDict):
|
|
72
|
+
capacity: Capacity
|
|
73
|
+
choices: Choices
|
|
74
|
+
notes: list[str]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class Upgrade(TypedDict):
|
|
78
|
+
kind: str # ram | vram | unified
|
|
79
|
+
label: str
|
|
80
|
+
card: int | None
|
|
81
|
+
from_bytes: int
|
|
82
|
+
to_bytes: int
|
|
83
|
+
changes: dict[str, list[str]]
|
|
84
|
+
result: Snapshot
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Report(TypedDict):
|
|
88
|
+
schema: str
|
|
89
|
+
baseline: Snapshot
|
|
90
|
+
upgrades: list[Upgrade]
|
|
91
|
+
notes: list[str]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def read_host() -> HostFacts:
|
|
95
|
+
"""Collect facts without app.probe's cache write or any plan/state persistence."""
|
|
96
|
+
ports = app.probe_ports()
|
|
97
|
+
with ThreadPoolExecutor(max_workers=2) as pool:
|
|
98
|
+
actual = pool.submit(probe.collect, ports=ports)
|
|
99
|
+
services = pool.submit(service_probe.collect, ports)
|
|
100
|
+
facts = actual.result()
|
|
101
|
+
facts["services"] = decode(services.result(), Services)
|
|
102
|
+
return facts
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _card(index: int, total: int, used: int = 0) -> GPU:
|
|
106
|
+
return {
|
|
107
|
+
"index": index,
|
|
108
|
+
"uuid": f"what-if-gpu-{index}",
|
|
109
|
+
"name": "Simulated NVIDIA card",
|
|
110
|
+
"vendor": "nvidia",
|
|
111
|
+
"pci_bus_id": "",
|
|
112
|
+
"pci_device_id": None,
|
|
113
|
+
"total_bytes": total,
|
|
114
|
+
"free_bytes": max(0, total - used),
|
|
115
|
+
"used_bytes": used,
|
|
116
|
+
"util_percent": None,
|
|
117
|
+
"driver_version": "",
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _simulated() -> HostFacts:
|
|
122
|
+
return {
|
|
123
|
+
"schema": probe.SCHEMA,
|
|
124
|
+
"collected_at": "",
|
|
125
|
+
"hostname": "simulated",
|
|
126
|
+
"user": "",
|
|
127
|
+
"platform": "linux",
|
|
128
|
+
"arch": "x64",
|
|
129
|
+
"os": {},
|
|
130
|
+
"python": "",
|
|
131
|
+
"cpu": {},
|
|
132
|
+
"ram": {"total_bytes": 0, "available_bytes": 0},
|
|
133
|
+
"gpu_vendor_class": "nvidia",
|
|
134
|
+
"nvidia": {"cuda_version": "13.0"},
|
|
135
|
+
"gpus": [],
|
|
136
|
+
"cuda_pool": None,
|
|
137
|
+
"llama_servers": [],
|
|
138
|
+
"engines": [],
|
|
139
|
+
"disk": {"path": "", "free_bytes": None, "total_bytes": None},
|
|
140
|
+
"service_manager": {"kind": "nohup", "linger": False},
|
|
141
|
+
"errors": [],
|
|
142
|
+
"services": {
|
|
143
|
+
"compute_processes": [],
|
|
144
|
+
"systemd_units": [],
|
|
145
|
+
"containers": [],
|
|
146
|
+
"ports": [],
|
|
147
|
+
"unknown": {},
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _unified(facts: HostFacts, total: int) -> HostFacts:
|
|
153
|
+
"""A hypothetical Mac at Apple's default working set and simulated OS reservation."""
|
|
154
|
+
seen = copy.deepcopy(facts)
|
|
155
|
+
seen.update({"platform": "darwin", "arch": "arm64", "gpu_vendor_class": "apple_silicon"})
|
|
156
|
+
seen["gpus"], seen["cuda_pool"], seen["nvidia"] = [], None, None
|
|
157
|
+
used = max(metal.in_use(total), facts["ram"]["total_bytes"] - facts["ram"]["available_bytes"])
|
|
158
|
+
seen["ram"] = {
|
|
159
|
+
"total_bytes": total,
|
|
160
|
+
"available_bytes": max(0, total - used),
|
|
161
|
+
"pressure_level": 1,
|
|
162
|
+
}
|
|
163
|
+
seen["cgroup_memory"] = None
|
|
164
|
+
seen["metal"] = {
|
|
165
|
+
"name": "Simulated Apple Silicon",
|
|
166
|
+
"unified_memory": True,
|
|
167
|
+
"recommended_max_working_set_bytes": metal.default_working_set(total),
|
|
168
|
+
}
|
|
169
|
+
return seen
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def starting_facts(machine: Machine, facts: HostFacts | None = None) -> HostFacts:
|
|
173
|
+
"""Override supplied readings, or create a complete simulation without touching hardware."""
|
|
174
|
+
if machine.unified is not None and (machine.vram is not None or machine.ram is not None):
|
|
175
|
+
raise StackError("--unified-memory cannot be combined with --vram or --ram")
|
|
176
|
+
sizes = (machine.vram, machine.ram, machine.unified)
|
|
177
|
+
if any(size is not None and size <= 0 for size in sizes):
|
|
178
|
+
raise StackError("memory sizes must be greater than zero")
|
|
179
|
+
if machine.unified is not None and machine.unified < 8 * GIB:
|
|
180
|
+
raise StackError("--unified-memory must be at least 8 GiB")
|
|
181
|
+
complete = machine.unified is not None or (machine.vram is not None and machine.ram is not None)
|
|
182
|
+
if facts is None:
|
|
183
|
+
facts = _simulated() if complete else read_host()
|
|
184
|
+
seen = copy.deepcopy(facts)
|
|
185
|
+
if machine.unified is not None:
|
|
186
|
+
return _unified(seen, machine.unified)
|
|
187
|
+
if metal.supported(seen) and (machine.vram is not None or machine.ram is not None):
|
|
188
|
+
raise StackError("Apple Silicon shares one memory pool; use --unified-memory")
|
|
189
|
+
if machine.vram is not None:
|
|
190
|
+
seen["gpus"] = [_card(0, machine.vram)]
|
|
191
|
+
seen["cuda_pool"] = None
|
|
192
|
+
seen["metal"] = None
|
|
193
|
+
seen["gpu_vendor_class"] = "nvidia"
|
|
194
|
+
seen["services"] = _simulated()["services"]
|
|
195
|
+
if machine.ram is not None:
|
|
196
|
+
used = seen["ram"]["total_bytes"] - seen["ram"]["available_bytes"]
|
|
197
|
+
seen["ram"] = {
|
|
198
|
+
"total_bytes": machine.ram,
|
|
199
|
+
"available_bytes": max(0, machine.ram - used),
|
|
200
|
+
}
|
|
201
|
+
seen["cgroup_memory"] = None
|
|
202
|
+
return seen
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def _choice(facts: HostFacts, options: StackOptions, role: str) -> tuple[Choice | None, list[str]]:
|
|
206
|
+
try:
|
|
207
|
+
parts, _ = choose_parts(
|
|
208
|
+
facts,
|
|
209
|
+
{**options, "offline": True},
|
|
210
|
+
resolver=deploy.catalog_pins,
|
|
211
|
+
listening=lambda _: False,
|
|
212
|
+
previous=lambda *_: None,
|
|
213
|
+
existing=lambda _: [],
|
|
214
|
+
owned_ram=lambda: 0,
|
|
215
|
+
)
|
|
216
|
+
ram_budget(parts)
|
|
217
|
+
except (StackError, PlanError) as exc:
|
|
218
|
+
return None, [str(exc)]
|
|
219
|
+
llm = parts["llm"]
|
|
220
|
+
llm_id, launch = llm["model"]["id"], llm["launch"]
|
|
221
|
+
gpus = decode(llm["placement"].get("gpus") or [], list[dict[str, object]])
|
|
222
|
+
index = decode(gpus[0]["index"], int) if gpus else 0
|
|
223
|
+
notes = [w for w in parts["warnings"] if w.startswith("LLM: auto passed over")]
|
|
224
|
+
if recipe := next((r for r in suite.recipes("llm") if r["id"] == llm_id), None):
|
|
225
|
+
return {
|
|
226
|
+
"id": recipe["id"],
|
|
227
|
+
"quant": recipe["version"],
|
|
228
|
+
"quality": recipe["quality"]["score"],
|
|
229
|
+
"role": role,
|
|
230
|
+
"card": index,
|
|
231
|
+
"shared": False,
|
|
232
|
+
"engine": recipe["runtime"],
|
|
233
|
+
"reason": parts["warnings"][0] + "; experts in RAM",
|
|
234
|
+
"decode_tok_s": None,
|
|
235
|
+
"decode_basis": "unavailable",
|
|
236
|
+
"speed_kind": "unavailable",
|
|
237
|
+
"context": int(str(launch["window"])),
|
|
238
|
+
"slots": int(str(launch.get("slots", 1))),
|
|
239
|
+
"kv_types": [],
|
|
240
|
+
}, notes
|
|
241
|
+
entry = next(e for e in catalog.load_catalog_file() if e.id == llm_id)
|
|
242
|
+
posture = agent_posture(options)
|
|
243
|
+
if metal.supported(facts):
|
|
244
|
+
posture = posture_for(posture, "metal")
|
|
245
|
+
budget, _ = hardware.llm_budget(facts, index, options, entry=entry, posture=posture)
|
|
246
|
+
speed = catalog.decode_estimate(entry, entry.variants[-1], budget)
|
|
247
|
+
return {
|
|
248
|
+
"id": entry.id,
|
|
249
|
+
"quant": entry.variants[-1].quant,
|
|
250
|
+
"quality": entry.quality,
|
|
251
|
+
"role": role,
|
|
252
|
+
"card": index,
|
|
253
|
+
"shared": False,
|
|
254
|
+
"engine": entry.runtime,
|
|
255
|
+
"reason": f"stack plan --llm auto --prefer {role}, resident agent capacity fit",
|
|
256
|
+
"decode_tok_s": round(speed.tok_s, 1),
|
|
257
|
+
"decode_basis": speed.basis,
|
|
258
|
+
"speed_kind": "measured" if speed.basis == "measured-decode" else "estimated",
|
|
259
|
+
"context": int(str(launch["window"])),
|
|
260
|
+
"slots": int(str(launch["slots"])),
|
|
261
|
+
"kv_types": decode(launch["kv_types"], list[str]),
|
|
262
|
+
}, notes
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def snapshot(
|
|
266
|
+
facts: HostFacts,
|
|
267
|
+
*,
|
|
268
|
+
reuse_from: tuple[str, ...] = (),
|
|
269
|
+
base_dir: str = deploy.DEFAULT_BASE_DIR,
|
|
270
|
+
) -> Snapshot:
|
|
271
|
+
options = default_options()
|
|
272
|
+
options["reuse_from"] = list(reuse_from)
|
|
273
|
+
options["base_dir"] = base_dir
|
|
274
|
+
seen = hardware.view(facts, options, None)
|
|
275
|
+
priced, _ = metal.pressured(metal.reclaimed(facts) if metal.supported(facts) else facts)
|
|
276
|
+
choices: Choices = {"smartest": None, "fastest": None}
|
|
277
|
+
notes = list(seen["notes"])
|
|
278
|
+
if facts["hostname"] == "simulated" and facts["platform"] == "linux":
|
|
279
|
+
notes.append(
|
|
280
|
+
"Fully simulated Linux hardware assumes x64 and a CUDA 13.0 compatible driver; "
|
|
281
|
+
"runtime and system libraries have not been probed."
|
|
282
|
+
)
|
|
283
|
+
for role in stack_picks.ROLES:
|
|
284
|
+
choices[role], warnings = _choice(priced, {**options, "prefer": role}, role)
|
|
285
|
+
notes.extend(w for w in warnings if w not in notes)
|
|
286
|
+
smart, fast = choices["smartest"], choices["fastest"]
|
|
287
|
+
if smart is not None and fast is not None:
|
|
288
|
+
if fast["id"] == smart["id"] or (
|
|
289
|
+
fast["decode_tok_s"] is not None
|
|
290
|
+
and smart["decode_tok_s"] is not None
|
|
291
|
+
and fast["decode_tok_s"] < smart["decode_tok_s"] * stack_picks.WORTH_FASTER
|
|
292
|
+
):
|
|
293
|
+
choices["fastest"] = None
|
|
294
|
+
return {
|
|
295
|
+
"capacity": {
|
|
296
|
+
"platform": facts["platform"],
|
|
297
|
+
"ram_total_bytes": seen["ram_total_bytes"],
|
|
298
|
+
"ram_available_bytes": seen["ram_available_bytes"],
|
|
299
|
+
"cards": [hardware.device(facts, c["index"]) for c in seen["cards"]],
|
|
300
|
+
},
|
|
301
|
+
"choices": choices,
|
|
302
|
+
"notes": notes,
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def report(
|
|
307
|
+
facts: HostFacts,
|
|
308
|
+
*,
|
|
309
|
+
reuse_from: tuple[str, ...] = (),
|
|
310
|
+
base_dir: str = deploy.DEFAULT_BASE_DIR,
|
|
311
|
+
) -> Report:
|
|
312
|
+
"""Compare every independent upgrade with the baseline, never with the preceding step."""
|
|
313
|
+
baseline = snapshot(facts, reuse_from=reuse_from, base_dir=base_dir)
|
|
314
|
+
upgrades: list[Upgrade] = []
|
|
315
|
+
|
|
316
|
+
def add(
|
|
317
|
+
kind: Literal["ram", "vram", "unified"],
|
|
318
|
+
label: str,
|
|
319
|
+
before: int,
|
|
320
|
+
after: int,
|
|
321
|
+
seen: HostFacts,
|
|
322
|
+
card: int | None = None,
|
|
323
|
+
) -> None:
|
|
324
|
+
result = snapshot(seen, reuse_from=reuse_from, base_dir=base_dir)
|
|
325
|
+
changes = {}
|
|
326
|
+
for role in stack_picks.ROLES:
|
|
327
|
+
old, new = baseline["choices"].get(role), result["choices"].get(role)
|
|
328
|
+
if new is None:
|
|
329
|
+
changes[role] = ["available"] if old is not None else []
|
|
330
|
+
else:
|
|
331
|
+
changes[role] = sorted(
|
|
332
|
+
k for k, value in new.items() if old is None or old.get(k) != value
|
|
333
|
+
)
|
|
334
|
+
if result["notes"] != baseline["notes"]:
|
|
335
|
+
changes["smartest"].append("requirements")
|
|
336
|
+
upgrades.append(
|
|
337
|
+
{
|
|
338
|
+
"kind": kind,
|
|
339
|
+
"label": label,
|
|
340
|
+
"card": card,
|
|
341
|
+
"from_bytes": before,
|
|
342
|
+
"to_bytes": after,
|
|
343
|
+
"changes": changes,
|
|
344
|
+
"result": result,
|
|
345
|
+
}
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
total = facts["ram"]["total_bytes"]
|
|
349
|
+
if metal.supported(facts):
|
|
350
|
+
next_tier = next((t for t in hardware.MAC_TIERS_GIB if t * GIB > total), None)
|
|
351
|
+
if next_tier is not None:
|
|
352
|
+
add(
|
|
353
|
+
"unified",
|
|
354
|
+
f"{next_tier} GiB Mac unified memory",
|
|
355
|
+
total,
|
|
356
|
+
next_tier * GIB,
|
|
357
|
+
_unified(facts, next_tier * GIB),
|
|
358
|
+
)
|
|
359
|
+
else:
|
|
360
|
+
for delta in RAM_STEPS_GIB:
|
|
361
|
+
seen = copy.deepcopy(facts)
|
|
362
|
+
seen["ram"]["total_bytes"] += delta * GIB
|
|
363
|
+
seen["ram"]["available_bytes"] += delta * GIB
|
|
364
|
+
# host_ram applies this limit too; adding physical RAM cannot lift a container cap.
|
|
365
|
+
add("ram", f"+{delta} GiB RAM", total, total + delta * GIB, seen)
|
|
366
|
+
for gpu in facts["gpus"]:
|
|
367
|
+
if gpu["vendor"] != "nvidia" or gpu.get("mig_mode") == "enabled":
|
|
368
|
+
continue
|
|
369
|
+
for size in hardware.TIERS_GIB:
|
|
370
|
+
if size * GIB <= gpu["total_bytes"] * 1.1:
|
|
371
|
+
continue
|
|
372
|
+
seen = copy.deepcopy(facts)
|
|
373
|
+
held = gpu["total_bytes"] - gpu["free_bytes"]
|
|
374
|
+
replacement = _card(gpu["index"], size * GIB, held)
|
|
375
|
+
replacement["uuid"] = gpu["uuid"]
|
|
376
|
+
seen["gpus"] = [
|
|
377
|
+
replacement if g["index"] == gpu["index"] else g for g in seen["gpus"]
|
|
378
|
+
]
|
|
379
|
+
seen["cuda_pool"] = None
|
|
380
|
+
add(
|
|
381
|
+
"vram",
|
|
382
|
+
f"{size} GiB card (GPU {gpu['index']})",
|
|
383
|
+
gpu["total_bytes"],
|
|
384
|
+
size * GIB,
|
|
385
|
+
seen,
|
|
386
|
+
gpu["index"],
|
|
387
|
+
)
|
|
388
|
+
return {
|
|
389
|
+
"schema": SCHEMA,
|
|
390
|
+
"baseline": baseline,
|
|
391
|
+
"upgrades": upgrades,
|
|
392
|
+
"notes": [
|
|
393
|
+
"Each upgrade is independent and compared with the starting hardware.",
|
|
394
|
+
"Choices use stack plan --llm auto, with decision none and the default stack options. "
|
|
395
|
+
"Strata-generated packs must already exist; --reuse-from reads an existing directory. "
|
|
396
|
+
"Ports and previously running deployments are not assumed.",
|
|
397
|
+
"Hypothetical devices use class bandwidth estimates, without speculative decoding. "
|
|
398
|
+
"Capacity alone does not establish installation acceptance or measured speed.",
|
|
399
|
+
"Strata/PolyStrata speed is unavailable: no same-device measurement or calibrated "
|
|
400
|
+
"estimate is recorded for these simulations.",
|
|
401
|
+
*(
|
|
402
|
+
[
|
|
403
|
+
"Mac unified-memory steps describe a replacement computer at normal memory "
|
|
404
|
+
"pressure, using Apple's default working set. Reserved RAM is at least "
|
|
405
|
+
"stack memory's OS reservation, or the starting host's observed RAM use "
|
|
406
|
+
"when larger."
|
|
407
|
+
]
|
|
408
|
+
if any(step["kind"] == "unified" for step in upgrades)
|
|
409
|
+
else []
|
|
410
|
+
),
|
|
411
|
+
],
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def _label(choice: Choice | None) -> str:
|
|
416
|
+
if choice is None:
|
|
417
|
+
return "no choice offered"
|
|
418
|
+
speed = (
|
|
419
|
+
f"{choice['decode_tok_s']:.0f} tok/s {choice['speed_kind']}"
|
|
420
|
+
if choice["decode_tok_s"] is not None
|
|
421
|
+
else "speed unavailable"
|
|
422
|
+
)
|
|
423
|
+
kv = f", KV {'/'.join(choice['kv_types'])}" if choice["kv_types"] else ""
|
|
424
|
+
return (
|
|
425
|
+
f"{choice['id']} {choice['quant']} ({choice['engine']}) · score {choice['quality']} · "
|
|
426
|
+
f"{speed}, context {window_k(choice['context'])} shared x {choice['slots']}{kv}"
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
def render(data: Report) -> str:
|
|
431
|
+
start = data["baseline"]
|
|
432
|
+
capacity = start["capacity"]
|
|
433
|
+
lines = [
|
|
434
|
+
f"Starting hardware: {capacity['ram_total_bytes'] / GIB:g} GiB RAM "
|
|
435
|
+
f"({capacity['ram_available_bytes'] / GIB:g} GiB available)"
|
|
436
|
+
]
|
|
437
|
+
for gpu in capacity["cards"]:
|
|
438
|
+
lines.append(
|
|
439
|
+
f" GPU {gpu['index']}: {gpu['name']}, {gpu['total_bytes'] / GIB:g} GiB "
|
|
440
|
+
f"({'Metal working set' if gpu['vendor'] == 'apple' else 'VRAM'})"
|
|
441
|
+
)
|
|
442
|
+
for role in stack_picks.ROLES:
|
|
443
|
+
lines.append(f" {role}: {_label(start['choices'].get(role))}")
|
|
444
|
+
if (choice := start["choices"].get(role)) is not None and choice["engine"] != "llama.cpp":
|
|
445
|
+
lines.append(f" {choice['reason']}")
|
|
446
|
+
reported_notes = set(start["notes"])
|
|
447
|
+
shown: list[tuple[Choices, str]] = []
|
|
448
|
+
for step in data["upgrades"]:
|
|
449
|
+
if not any(step["changes"].values()):
|
|
450
|
+
lines.append(f"{step['label']} -> no change to smartest or fastest")
|
|
451
|
+
continue
|
|
452
|
+
repeated = next(
|
|
453
|
+
(
|
|
454
|
+
label
|
|
455
|
+
for choices, label in shown
|
|
456
|
+
if choices == step["result"]["choices"]
|
|
457
|
+
and set(step["result"]["notes"]) <= reported_notes
|
|
458
|
+
),
|
|
459
|
+
None,
|
|
460
|
+
)
|
|
461
|
+
if repeated is not None:
|
|
462
|
+
lines.append(f"{step['label']} -> same smartest and fastest as {repeated}")
|
|
463
|
+
continue
|
|
464
|
+
shown.append((step["result"]["choices"], step["label"]))
|
|
465
|
+
lines.append(step["label"])
|
|
466
|
+
for role in stack_picks.ROLES:
|
|
467
|
+
before, after = start["choices"].get(role), step["result"]["choices"].get(role)
|
|
468
|
+
if before != after:
|
|
469
|
+
lines.append(f" {role}: {_label(before)} -> {_label(after)}")
|
|
470
|
+
if after is not None and after["engine"] != "llama.cpp":
|
|
471
|
+
lines.append(f" {after['reason']}")
|
|
472
|
+
elif step["changes"][role] and after is not None:
|
|
473
|
+
lines.append(f" {role}: unchanged ({after['id']})")
|
|
474
|
+
else:
|
|
475
|
+
lines.append(f" {role}: unchanged")
|
|
476
|
+
for note in step["result"]["notes"]:
|
|
477
|
+
if note not in reported_notes:
|
|
478
|
+
lines.append(f" Note: {note}")
|
|
479
|
+
reported_notes.add(note)
|
|
480
|
+
lines.extend(f"Note: {note}" for note in [*start["notes"], *data["notes"]])
|
|
481
|
+
return "\n".join(lines)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def add_parser(actions: argparse._SubParsersAction[argparse.ArgumentParser]) -> None:
|
|
485
|
+
parser = actions.add_parser(
|
|
486
|
+
"what-if", help="compare hardware upgrades and what they unlock (read-only)"
|
|
487
|
+
)
|
|
488
|
+
machine = parser.add_mutually_exclusive_group()
|
|
489
|
+
machine.add_argument("--vram", metavar="SIZE", help="simulate one NVIDIA card, e.g. 24GiB")
|
|
490
|
+
machine.add_argument(
|
|
491
|
+
"--unified-memory", metavar="SIZE", help="simulate an Apple Silicon Mac, e.g. 24GiB"
|
|
492
|
+
)
|
|
493
|
+
parser.add_argument("--ram", metavar="SIZE", help="simulate host RAM, e.g. 64GiB")
|
|
494
|
+
parser.add_argument(
|
|
495
|
+
"--facts", type=Path, metavar="FILE", help="read saved facts without probing"
|
|
496
|
+
)
|
|
497
|
+
parser.add_argument(
|
|
498
|
+
"--base-dir",
|
|
499
|
+
default=deploy.DEFAULT_BASE_DIR,
|
|
500
|
+
metavar="DIR",
|
|
501
|
+
help="engines, weights and deployments (default %(default)s)",
|
|
502
|
+
)
|
|
503
|
+
parser.add_argument(
|
|
504
|
+
"--reuse-from",
|
|
505
|
+
action="append",
|
|
506
|
+
default=[],
|
|
507
|
+
metavar="DIR",
|
|
508
|
+
help="existing Strata model directory (read-only; repeatable)",
|
|
509
|
+
)
|
|
510
|
+
parser.add_argument("--json", action="store_true", help=f"print {SCHEMA} JSON")
|
|
511
|
+
cli_help.document(
|
|
512
|
+
parser,
|
|
513
|
+
"Compare independent RAM +16/+32/+64 GiB and larger VRAM tiers, or the next Mac "
|
|
514
|
+
"unified-memory tier, using stack plan's auto LLM selection. "
|
|
515
|
+
"Fully specified simulations need no probe. No facts or plans are saved.",
|
|
516
|
+
examples=[
|
|
517
|
+
("%(prog)s", "compare upgrades from this computer's readings"),
|
|
518
|
+
("%(prog)s --vram 24GiB --ram 64GiB", "simulate a card and RAM without probing"),
|
|
519
|
+
("%(prog)s --unified-memory 24GiB --json", "simulate a Mac without probing"),
|
|
520
|
+
("%(prog)s --facts host.json", "compare from saved hardware facts"),
|
|
521
|
+
(
|
|
522
|
+
"%(prog)s --vram 24GiB --ram 32GiB --reuse-from DIR",
|
|
523
|
+
"include an existing Strata pack",
|
|
524
|
+
),
|
|
525
|
+
],
|
|
526
|
+
sections=[
|
|
527
|
+
("output", f"changes in both choices; --json: {SCHEMA}, sizes in bytes"),
|
|
528
|
+
("exit status", "0 printed, even when no model fits; 2 bad input or unreadable facts"),
|
|
529
|
+
],
|
|
530
|
+
)
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
def cli(args: argparse.Namespace) -> int:
|
|
534
|
+
try:
|
|
535
|
+
machine = Machine(
|
|
536
|
+
vram=parse_size(args.vram) if args.vram else None,
|
|
537
|
+
ram=parse_size(args.ram) if args.ram else None,
|
|
538
|
+
unified=parse_size(args.unified_memory) if args.unified_memory else None,
|
|
539
|
+
)
|
|
540
|
+
facts = (
|
|
541
|
+
decode(json.loads(args.facts.read_text(encoding="utf-8")), HostFacts)
|
|
542
|
+
if args.facts
|
|
543
|
+
else None
|
|
544
|
+
)
|
|
545
|
+
data = report(
|
|
546
|
+
starting_facts(machine, facts),
|
|
547
|
+
reuse_from=tuple(args.reuse_from),
|
|
548
|
+
base_dir=args.base_dir,
|
|
549
|
+
)
|
|
550
|
+
except (OSError, ValueError, StackError) as exc:
|
|
551
|
+
print(f"stack what-if: {exc}", file=sys.stderr)
|
|
552
|
+
return 2
|
|
553
|
+
if args.json:
|
|
554
|
+
json.dump(data, sys.stdout, indent=1)
|
|
555
|
+
sys.stdout.write("\n")
|
|
556
|
+
else:
|
|
557
|
+
print(render(data))
|
|
558
|
+
return 0
|