quantprobe 1.18.0__tar.gz → 1.19.0__tar.gz
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.
- {quantprobe-1.18.0/quantprobe.egg-info → quantprobe-1.19.0}/PKG-INFO +1 -1
- {quantprobe-1.18.0 → quantprobe-1.19.0}/pyproject.toml +1 -1
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/__init__.py +1 -1
- quantprobe-1.19.0/quantprobe/calibrate.py +216 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/cli.py +171 -163
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/detect.py +183 -167
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/plan.py +81 -7
- {quantprobe-1.18.0 → quantprobe-1.19.0/quantprobe.egg-info}/PKG-INFO +1 -1
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe.egg-info/SOURCES.txt +1 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/LICENSE +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/README.md +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/__main__.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/auto.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/dashboard.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/fetch.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/optimize.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/probe.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/recipes/mistral-7b.json +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen2.5-7b.json +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen3-30b.json +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen3.5-35b.json +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/recipes.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/runtime.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/spec.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe/target.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe.egg-info/dependency_links.txt +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe.egg-info/entry_points.txt +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe.egg-info/requires.txt +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/quantprobe.egg-info/top_level.txt +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/setup.cfg +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/tests/test_engine.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/tests/test_evaluator.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/tests/test_pipeline.py +0 -0
- {quantprobe-1.18.0 → quantprobe-1.19.0}/tests/test_transforms.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantprobe
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.19.0
|
|
4
4
|
Summary: Probe-then-quantize for LLMs: measure a model's fragility curve, plan bit/tier placement by the tiered decode law, and emit ready-to-run llama.cpp recipes.
|
|
5
5
|
Author: Federico Sciuca
|
|
6
6
|
License: MIT
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "quantprobe"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.19.0"
|
|
8
8
|
description = "Probe-then-quantize for LLMs: measure a model's fragility curve, plan bit/tier placement by the tiered decode law, and emit ready-to-run llama.cpp recipes."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -8,4 +8,4 @@ Three commands, all grounded in measured laws (see LAWS.md in the repo):
|
|
|
8
8
|
Every constant in `plan` is fitted from measurements published in the repo, including two
|
|
9
9
|
pre-registered hardware predictions confirmed within 8%.
|
|
10
10
|
"""
|
|
11
|
-
__version__ = "1.
|
|
11
|
+
__version__ = "1.19.0"
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""quantprobe calibrate - measure THIS machine's constants instead of assuming ours.
|
|
2
|
+
|
|
3
|
+
Why this command exists: every constant this tool ships was measured on one reference box, and
|
|
4
|
+
pre-registration #59 proved that even on that box, fitted constants do not transfer across
|
|
5
|
+
models - let alone across machines. The law FORMS travel; the numbers do not. So on your
|
|
6
|
+
machine the honest move is to measure, not assume.
|
|
7
|
+
|
|
8
|
+
What it measures (each value tagged, nothing sent anywhere):
|
|
9
|
+
[measured] RAM stream bandwidth - a real sequential read, the pattern CPU decode is bound by.
|
|
10
|
+
Spec-sheet MT/s overstates what decode gets by 30-60%.
|
|
11
|
+
[measured] disk sequential read - only with --model FILE (reads the file's tail region).
|
|
12
|
+
[measured] GPU clock health - idle + max clocks now; sustained-under-load if an anchor
|
|
13
|
+
runs. Catches the STUCK BOOST STATE failure mode we
|
|
14
|
+
diagnosed on the reference box (SM locked ~18% low at cool
|
|
15
|
+
temps after hours of GPU churn; only a reboot clears it -
|
|
16
|
+
pre-registrations #60/#61).
|
|
17
|
+
[measured] pure-CPU anchor - only with --model: llama-bench -ngl 0 on your file, stored
|
|
18
|
+
as a reference point for plan's predicted-vs-measured line.
|
|
19
|
+
|
|
20
|
+
Results persist to ~/.quantprobe/calibration.json. `plan` (and everything built on it) uses the
|
|
21
|
+
measured RAM/disk numbers automatically whenever it would otherwise auto-detect, and labels them
|
|
22
|
+
[calibrated] instead of [table]/[default]. Delete the file to go back to detection.
|
|
23
|
+
"""
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
import json, os, platform, subprocess, threading, time
|
|
26
|
+
|
|
27
|
+
CAL_DIR = os.path.join(os.path.expanduser("~"), ".quantprobe")
|
|
28
|
+
CAL_PATH = os.path.join(CAL_DIR, "calibration.json")
|
|
29
|
+
STALE_DAYS = 60 # hardware does not drift, but drivers and RAM configs do
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _run(cmd, timeout=30):
|
|
33
|
+
try:
|
|
34
|
+
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout).stdout
|
|
35
|
+
except Exception:
|
|
36
|
+
return ""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def measure_ram_stream(gb=1.0, passes=3):
|
|
40
|
+
"""Sequential read bandwidth of main memory, GB/s. Best of `passes`.
|
|
41
|
+
|
|
42
|
+
numpy sum over a float32 array bigger than any cache: the same access pattern the CPU
|
|
43
|
+
expert path is bound by. Falls back to None (with the reason) if numpy is missing or
|
|
44
|
+
allocation fails - a partial calibration is still a calibration.
|
|
45
|
+
"""
|
|
46
|
+
try:
|
|
47
|
+
import numpy as np
|
|
48
|
+
except ImportError:
|
|
49
|
+
return None, "numpy not installed - RAM stream skipped (pip install numpy)"
|
|
50
|
+
n = int(gb * 1e9 / 4)
|
|
51
|
+
try:
|
|
52
|
+
a = np.ones(n, dtype=np.float32)
|
|
53
|
+
except MemoryError:
|
|
54
|
+
return None, f"could not allocate {gb:g} GB - RAM stream skipped"
|
|
55
|
+
# int64-view max, not float sum: float reductions in numpy can be COMPUTE-bound (measured
|
|
56
|
+
# 9.3 GB/s on the reference box where the memory delivers 26) and would silently calibrate
|
|
57
|
+
# numpy's ALU instead of the memory bus. Integer max is one SIMD pass, one read per byte -
|
|
58
|
+
# it reproduces the reference box's independently measured 26.1 GB/s stream.
|
|
59
|
+
v = a.view(np.int64)
|
|
60
|
+
best = 0.0
|
|
61
|
+
for _ in range(passes):
|
|
62
|
+
t0 = time.perf_counter()
|
|
63
|
+
v.max()
|
|
64
|
+
dt = time.perf_counter() - t0
|
|
65
|
+
best = max(best, (n * 4) / 1e9 / dt)
|
|
66
|
+
del a
|
|
67
|
+
return round(best, 2), None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def gpu_state():
|
|
71
|
+
"""Current + max clocks and temperature via nvidia-smi; None if no NVIDIA GPU."""
|
|
72
|
+
out = _run(["nvidia-smi", "--query-gpu=name,clocks.sm,clocks.max.sm,clocks.mem,temperature.gpu",
|
|
73
|
+
"--format=csv,noheader,nounits"])
|
|
74
|
+
line = out.strip().splitlines()[0] if out.strip() else ""
|
|
75
|
+
if "," not in line:
|
|
76
|
+
return None
|
|
77
|
+
try:
|
|
78
|
+
name, sm, sm_max, mem, temp = [v.strip() for v in line.rsplit(",", 4)]
|
|
79
|
+
return dict(name=name, sm=int(sm), sm_max=int(sm_max), mem=int(mem), temp=int(temp))
|
|
80
|
+
except ValueError:
|
|
81
|
+
return None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class ClockSampler:
|
|
85
|
+
"""Samples clocks.sm in a thread while a benchmark runs - the boost-state instrument."""
|
|
86
|
+
|
|
87
|
+
def __init__(self, every=3.0):
|
|
88
|
+
self.every, self.samples, self._stop = every, [], threading.Event()
|
|
89
|
+
self._t = threading.Thread(target=self._loop, daemon=True)
|
|
90
|
+
|
|
91
|
+
def _loop(self):
|
|
92
|
+
while not self._stop.is_set():
|
|
93
|
+
st = gpu_state()
|
|
94
|
+
if st:
|
|
95
|
+
self.samples.append((st["sm"], st["temp"]))
|
|
96
|
+
self._stop.wait(self.every)
|
|
97
|
+
|
|
98
|
+
def __enter__(self):
|
|
99
|
+
self._t.start()
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
def __exit__(self, *exc):
|
|
103
|
+
self._stop.set()
|
|
104
|
+
self._t.join(timeout=5)
|
|
105
|
+
|
|
106
|
+
def sustained(self):
|
|
107
|
+
"""Median SM MHz over loaded samples (>1000 MHz), or None."""
|
|
108
|
+
loaded = sorted(s for s, _ in self.samples if s > 1000)
|
|
109
|
+
return loaded[len(loaded) // 2] if loaded else None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def boost_verdict(sustained, sm_max, temp):
|
|
113
|
+
"""The #60/#61 diagnostic as a one-line verdict."""
|
|
114
|
+
if sustained is None or not sm_max:
|
|
115
|
+
return None
|
|
116
|
+
frac = sustained / sm_max
|
|
117
|
+
if frac >= 0.87:
|
|
118
|
+
return f"healthy: sustained {sustained} of {sm_max} MHz max [measured]"
|
|
119
|
+
hot = temp is not None and temp >= 80
|
|
120
|
+
if hot:
|
|
121
|
+
return (f"THROTTLED: sustained {sustained} of {sm_max} MHz at {temp} C - thermal; "
|
|
122
|
+
"check cooling")
|
|
123
|
+
return (f"STUCK BOOST STATE: sustained {sustained} of {sm_max} MHz at cool temps - the "
|
|
124
|
+
"failure mode measured in preregistrations #60/#61 (-25-30%% real speed). Consumer "
|
|
125
|
+
"cards cannot reset it live: REBOOT, then re-run calibrate")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def cpu_anchor(model_path, llama_dir=None):
|
|
129
|
+
"""Pure-CPU tg32 on the user's own file: a real measured reference point.
|
|
130
|
+
|
|
131
|
+
Placement chosen because it needs no VRAM-fit logic and no MoE byte accounting - it is the
|
|
132
|
+
one arm that runs identically on every machine that can load the file at all.
|
|
133
|
+
"""
|
|
134
|
+
from .runtime import find_llama
|
|
135
|
+
try:
|
|
136
|
+
binp = find_llama(llama_dir, "llama-bench")
|
|
137
|
+
except SystemExit:
|
|
138
|
+
return None, "llama-bench not found - anchor skipped (pass --llama-dir)"
|
|
139
|
+
with ClockSampler() as clk:
|
|
140
|
+
out = _run([binp, "-m", model_path, "-ngl", "0", "-n", "32", "-p", "0", "-r", "1"],
|
|
141
|
+
timeout=1800)
|
|
142
|
+
for line in out.splitlines():
|
|
143
|
+
if "tg32" in line and "|" in line:
|
|
144
|
+
try:
|
|
145
|
+
toks = float(line.split("|")[-2].strip().split()[0])
|
|
146
|
+
return dict(placement="pure CPU (-ngl 0)", metric="tg32", tok_s=toks,
|
|
147
|
+
model=os.path.basename(model_path),
|
|
148
|
+
model_gb=round(os.path.getsize(model_path) / 1e9, 3),
|
|
149
|
+
sustained_sm=clk.sustained()), None
|
|
150
|
+
except (ValueError, IndexError):
|
|
151
|
+
break
|
|
152
|
+
return None, "could not parse llama-bench output - anchor skipped"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def load():
|
|
156
|
+
"""Return (calibration dict, age_days) or (None, None). Used by plan."""
|
|
157
|
+
try:
|
|
158
|
+
with open(CAL_PATH, encoding="utf-8") as f:
|
|
159
|
+
cal = json.load(f)
|
|
160
|
+
age = (time.time() - cal.get("ts", 0)) / 86400
|
|
161
|
+
return cal, age
|
|
162
|
+
except (OSError, ValueError):
|
|
163
|
+
return None, None
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def run(a):
|
|
167
|
+
print("quantprobe calibrate - measuring THIS machine (nothing is sent anywhere)\n")
|
|
168
|
+
cal = dict(ts=time.time(), date=time.strftime("%Y-%m-%d"), host=platform.node(),
|
|
169
|
+
tool_version=__import__("quantprobe").__version__)
|
|
170
|
+
|
|
171
|
+
ram_bw, why = measure_ram_stream()
|
|
172
|
+
if ram_bw:
|
|
173
|
+
cal["ram_bw_measured"] = ram_bw
|
|
174
|
+
print(f" RAM stream: {ram_bw:.2f} GB/s [measured] - this replaces the spec-sheet "
|
|
175
|
+
"number, which overstates what decode gets")
|
|
176
|
+
else:
|
|
177
|
+
print(f" RAM stream: {why}")
|
|
178
|
+
|
|
179
|
+
st = gpu_state()
|
|
180
|
+
if st:
|
|
181
|
+
cal["gpu"] = st
|
|
182
|
+
print(f" GPU: {st['name']}, idle {st['sm']} MHz (max {st['sm_max']}), {st['temp']} C [os]")
|
|
183
|
+
else:
|
|
184
|
+
print(" GPU: none detected (nvidia-smi absent/empty)")
|
|
185
|
+
|
|
186
|
+
model = getattr(a, "model", None)
|
|
187
|
+
if model and os.path.isfile(model):
|
|
188
|
+
from .detect import measure_disk
|
|
189
|
+
cal["disk_bw_measured"] = round(measure_disk(model), 2)
|
|
190
|
+
print(f" disk: {cal['disk_bw_measured']:.2f} GB/s sequential on your file [measured]")
|
|
191
|
+
if not getattr(a, "skip_bench", False):
|
|
192
|
+
print(" anchor: running llama-bench -ngl 0 tg32 on your file (1-10 min on big models)...")
|
|
193
|
+
anchor, why = cpu_anchor(model, getattr(a, "llama_dir", None))
|
|
194
|
+
if anchor:
|
|
195
|
+
cal["anchors"] = [anchor]
|
|
196
|
+
print(f" anchor: {anchor['tok_s']:.2f} tok/s pure-CPU on "
|
|
197
|
+
f"{anchor['model']} ({anchor['model_gb']:g} GB) [measured]")
|
|
198
|
+
v = boost_verdict(anchor.get("sustained_sm"), st and st.get("sm_max"),
|
|
199
|
+
st and st.get("temp"))
|
|
200
|
+
if v:
|
|
201
|
+
cal["boost_verdict"] = v
|
|
202
|
+
print(f" GPU under load: {v}")
|
|
203
|
+
else:
|
|
204
|
+
print(f" anchor: {why}")
|
|
205
|
+
elif model:
|
|
206
|
+
print(f" --model: file not found: {model}")
|
|
207
|
+
else:
|
|
208
|
+
print(" (pass --model your.gguf to also measure disk + a real decode anchor)")
|
|
209
|
+
|
|
210
|
+
os.makedirs(CAL_DIR, exist_ok=True)
|
|
211
|
+
with open(CAL_PATH, "w", encoding="utf-8") as f:
|
|
212
|
+
json.dump(cal, f, indent=1)
|
|
213
|
+
print(f"\n saved: {CAL_PATH}")
|
|
214
|
+
print(" plan/optimize/auto now use the measured values automatically (tagged [calibrated]).")
|
|
215
|
+
print(" Delete the file to return to auto-detection. Re-run after RAM/driver changes.")
|
|
216
|
+
return cal
|
|
@@ -1,163 +1,171 @@
|
|
|
1
|
-
"""quantprobe CLI - probe / plan / fetch."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
|
-
from .plan import numlist, MODELS as _MODELS
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def main():
|
|
9
|
-
import sys
|
|
10
|
-
try:
|
|
11
|
-
sys.stdout.reconfigure(errors="replace")
|
|
12
|
-
except Exception:
|
|
13
|
-
pass
|
|
14
|
-
ap = argparse.ArgumentParser(
|
|
15
|
-
prog="quantprobe",
|
|
16
|
-
description="Probe-then-quantize for LLMs: fragility curves, placement plans, recipes. "
|
|
17
|
-
"Laws + evidence: github.com/FedericoTs/quantprobe")
|
|
18
|
-
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
19
|
-
|
|
20
|
-
p = sub.add_parser("probe", help="measure a GGUF's depth-fragility curve, emit the recipe (Law 3)")
|
|
21
|
-
p.add_argument("--gguf", required=True, help="f16/bf16 (or high-precision) source GGUF")
|
|
22
|
-
p.add_argument("--bands", type=int, default=4)
|
|
23
|
-
p.add_argument("--chunks", type=int, default=32)
|
|
24
|
-
p.add_argument("--eval", required=True, help="raw text eval file (e.g. wikitext-2 test)")
|
|
25
|
-
p.add_argument("--ngl", type=int, default=99, help="GPU layers for perplexity (0 for CPU)")
|
|
26
|
-
p.add_argument("--workdir", default=None)
|
|
27
|
-
p.add_argument("--llama-dir", default=None, help="dir containing llama-quantize/llama-perplexity")
|
|
28
|
-
p.add_argument("--apply", action="store_true", help="after probing, BUILD the recommended depth-aware GGUF")
|
|
29
|
-
p.add_argument("--out", default=None, help="output path for --apply (default: <model>-depthaware.gguf)")
|
|
30
|
-
p.add_argument("--imatrix", default=None, help="importance-matrix file for --apply, or 'auto' to generate one first (measured -8.5%% ppl at ~3 bits, free in size and speed)")
|
|
31
|
-
p.add_argument("--imatrix-chunks", type=int, default=100, help="calibration chunks when --imatrix auto (default 100)")
|
|
32
|
-
p.add_argument("--yes", "-y", action="store_true", help="skip the time-commitment confirmation for long runs")
|
|
33
|
-
p.add_argument("--dry-run", action="store_true")
|
|
34
|
-
|
|
35
|
-
q = sub.add_parser("plan", help="evaluate every bit/tier placement, predict tok/s (Law 4)")
|
|
36
|
-
q.add_argument("--model", default=None, help="preset: " + " ".join(sorted(_MODELS)))
|
|
37
|
-
q.add_argument("--machine", default=None, help="preset: 2016-xmp 2016 gaming ddr5 colibri")
|
|
38
|
-
q.add_argument("--bits", type=float, default=None, help="effective bits/weight (default: read from --gguf, else 2.5)")
|
|
39
|
-
q.add_argument("--total", type=float, help="total params (B)")
|
|
40
|
-
q.add_argument("--active", type=float, help="active params per token (B)")
|
|
41
|
-
q.add_argument("--always-active", type=float, help="always-active (attention/embed) params (B)")
|
|
42
|
-
q.add_argument("--vram", type=numlist, help="GB; comma-list for multi-GPU: 24,24"); q.add_argument("--vram-bw", type=numlist, help="GB/s; comma-list aggregates x0.85")
|
|
43
|
-
q.add_argument("--ram", type=float); q.add_argument("--ram-bw", type=float)
|
|
44
|
-
q.add_argument("--disk-bw", type=numlist, help="GB/s; comma-list (RAID) aggregates x0.75")
|
|
45
|
-
q.add_argument("--gguf", default=None, help="optional: read total/active/bits/KV exactly from this GGUF")
|
|
46
|
-
q.add_argument("--ctx", type=int, default=0, help="context depth: adds KV reads/token + KV memory to the prediction (Law 4 v2)")
|
|
47
|
-
q.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB (default: model preset, or 96)")
|
|
48
|
-
|
|
49
|
-
def hwargs(sp):
|
|
50
|
-
sp.add_argument("--model", default=None); sp.add_argument("--machine", default=None)
|
|
51
|
-
sp.add_argument("--bits", type=float, default=None, help="effective bits/weight (default: read from --gguf, else 2.5)")
|
|
52
|
-
sp.add_argument("--total", type=float); sp.add_argument("--active", type=float)
|
|
53
|
-
sp.add_argument("--always-active", type=float)
|
|
54
|
-
sp.add_argument("--vram", type=numlist); sp.add_argument("--vram-bw", type=numlist)
|
|
55
|
-
sp.add_argument("--ram", type=float); sp.add_argument("--ram-bw", type=float)
|
|
56
|
-
sp.add_argument("--disk-bw", type=numlist)
|
|
57
|
-
sp.add_argument("--ctx", type=int, default=0, help="context depth for the prediction (Law 4 v2)")
|
|
58
|
-
sp.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB")
|
|
59
|
-
sp.add_argument("--llama-dir", default=None); sp.add_argument("--dry", action="store_true")
|
|
60
|
-
|
|
61
|
-
r = sub.add_parser("run", help="plan the best placement, then launch llama.cpp chat with those flags")
|
|
62
|
-
r.add_argument("--gguf", required=True); hwargs(r)
|
|
63
|
-
r.add_argument("--serve", action="store_true", help="launch llama-server instead of interactive chat")
|
|
64
|
-
r.add_argument("--extra", default=None, help="extra flags passed through to llama.cpp")
|
|
65
|
-
|
|
66
|
-
b = sub.add_parser("bench", help="measure real tok/s with the planned flags; print predicted vs measured")
|
|
67
|
-
b.add_argument("--gguf", required=True); hwargs(b)
|
|
68
|
-
b.add_argument("--reps", type=int, default=3)
|
|
69
|
-
b.add_argument("--depth", type=int, default=None, help="bench at KV depth N (llama-bench -d): measures the Law 4 v2 context term on YOUR box")
|
|
70
|
-
b.add_argument("--contribute", action="store_true", help="print a pre-filled, opt-in GitHub issue with your predicted-vs-measured point (you review before submitting; nothing auto-sent)")
|
|
71
|
-
|
|
72
|
-
d = sub.add_parser("dashboard", help="launch llama-server with planned flags + a live predicted-vs-measured chat page")
|
|
73
|
-
d.add_argument("--gguf", required=True); hwargs(d)
|
|
74
|
-
d.add_argument("--port", type=int, default=8077); d.add_argument("--server-port", type=int, default=8090)
|
|
75
|
-
d.add_argument("--no-open", action="store_true")
|
|
76
|
-
|
|
77
|
-
g = sub.add_parser("target", help="INVERSE planning: give a tok/s target, get the smartest feasible model + the speed-intelligence ladder")
|
|
78
|
-
g.add_argument("--tps", type=float, required=True, help="minimum tok/s you need")
|
|
79
|
-
hwargs(g)
|
|
80
|
-
g.add_argument("--ladder", action="store_true", help="print the full speed-vs-intelligence ladder")
|
|
81
|
-
|
|
82
|
-
z = sub.add_parser("quantize", help="COMPRESS: build a depth-aware GGUF from a model (protect the fragile band, rest 2-bit)")
|
|
83
|
-
z.add_argument("--gguf", required=True, help="high-precision source GGUF (f16/bf16/Q8)")
|
|
84
|
-
z.add_argument("--out", default=None, help="output path (default: <model>-depthaware.gguf)")
|
|
85
|
-
z.add_argument("--protect-late", type=int, default=12, help="protect the last N layers at 4-bit (default 12)")
|
|
86
|
-
z.add_argument("--protect", default=None, help="protect an explicit band LO-HI (e.g. 36-47) instead of --protect-late")
|
|
87
|
-
z.add_argument("--imatrix", default=None, help="importance-matrix file (build one with `probe --imatrix auto`); improves quality at zero size cost")
|
|
88
|
-
z.add_argument("--recipe", default=None, help="use a MEASURED fragile band from the community atlas instead of the default guess (see: quantprobe recipes)")
|
|
89
|
-
z.add_argument("--llama-dir", default=None)
|
|
90
|
-
z.add_argument("--dry", action="store_true")
|
|
91
|
-
|
|
92
|
-
sub.add_parser("recipes", help="the community fragility atlas: bands already measured, so you can skip the probe")
|
|
93
|
-
|
|
94
|
-
o = sub.add_parser("optimize", help="cheapest path to a target speed: search bits x placement x KV x hardware over the law")
|
|
95
|
-
o.add_argument("--tps", type=float, default=None, help="target tok/s (omit for the speed frontier)")
|
|
96
|
-
o.add_argument("--max-quality", type=float, default=None, help="quality-cost ceiling (default 1.12)")
|
|
97
|
-
o.add_argument("--any-runtime", action="store_true", help="include placements needing expert-caching runtimes (ktransformers-class), not just stock llama.cpp")
|
|
98
|
-
o.add_argument("--allow-prune", action="store_true", help="include REAP-class pruned variants (domain-specialized: +39%% out-of-domain ppl measured)")
|
|
99
|
-
hwargs(o)
|
|
100
|
-
|
|
101
|
-
au = sub.add_parser("auto", help="ONE command: model in, running setup out - optimizer picks the bits, the closest quant is fetched, run command printed")
|
|
102
|
-
au.add_argument("target", nargs="?", default=None,
|
|
103
|
-
help="model preset (qwen3-30b, qwen3-coder, glm-air, laguna-s, gemma-12b, mistral-7b, qwen3-235b, glm-4.7, glm-744b, kimi-k2.6, gpt-oss-120b, llama-70b, deepseek-16b) or a HF GGUF repo id; omit it and quantprobe ASKS (interactive)")
|
|
104
|
-
au.add_argument("--dir", default="./models", help="download directory (default ./models)")
|
|
105
|
-
au.add_argument("--run", action="store_true", help="launch chat immediately after the download")
|
|
106
|
-
hwargs(au)
|
|
107
|
-
au.add_argument("--tps", type=float, default=None, help="target tok/s for the optimizer")
|
|
108
|
-
au.add_argument("--max-quality", type=float, default=None)
|
|
109
|
-
au.add_argument("--allow-prune", action="store_true"); au.add_argument("--any-runtime", action="store_true")
|
|
110
|
-
au.add_argument("--custom", action="store_true", help="THE PRODUCT: fetch a high-precision source, probe YOUR model (~30-60 min), build a depth-aware GGUF personalized to it (machine-gated: skipped with an explanation when this box doesn't need sub-3-bit surgery)")
|
|
111
|
-
au.add_argument("--yes", "-y", action="store_true", help="skip time-commitment confirmations")
|
|
112
|
-
au.add_argument("--no-imatrix", action="store_true", help="skip importance-matrix calibration in --custom (faster build, measurably worse quality)")
|
|
113
|
-
au.add_argument("--force-custom", action="store_true", help="build the depth-aware GGUF even when the optimizer says this machine doesn't need it")
|
|
114
|
-
au.add_argument("--serve", action="store_true", help="with --run: llama-server instead of chat")
|
|
115
|
-
au.add_argument("--extra", default=None)
|
|
116
|
-
|
|
117
|
-
hwp = sub.add_parser("hw", help="detect THIS machine's memory tiers (no flags needed); every value tagged with its source")
|
|
118
|
-
hwp.add_argument("--measure", default=None, metavar="FILE", help="also MEASURE sequential disk read on a real file (e.g. a GGUF)")
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
"""quantprobe CLI - probe / plan / fetch."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from .plan import numlist, MODELS as _MODELS
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
import sys
|
|
10
|
+
try:
|
|
11
|
+
sys.stdout.reconfigure(errors="replace")
|
|
12
|
+
except Exception:
|
|
13
|
+
pass
|
|
14
|
+
ap = argparse.ArgumentParser(
|
|
15
|
+
prog="quantprobe",
|
|
16
|
+
description="Probe-then-quantize for LLMs: fragility curves, placement plans, recipes. "
|
|
17
|
+
"Laws + evidence: github.com/FedericoTs/quantprobe")
|
|
18
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
19
|
+
|
|
20
|
+
p = sub.add_parser("probe", help="measure a GGUF's depth-fragility curve, emit the recipe (Law 3)")
|
|
21
|
+
p.add_argument("--gguf", required=True, help="f16/bf16 (or high-precision) source GGUF")
|
|
22
|
+
p.add_argument("--bands", type=int, default=4)
|
|
23
|
+
p.add_argument("--chunks", type=int, default=32)
|
|
24
|
+
p.add_argument("--eval", required=True, help="raw text eval file (e.g. wikitext-2 test)")
|
|
25
|
+
p.add_argument("--ngl", type=int, default=99, help="GPU layers for perplexity (0 for CPU)")
|
|
26
|
+
p.add_argument("--workdir", default=None)
|
|
27
|
+
p.add_argument("--llama-dir", default=None, help="dir containing llama-quantize/llama-perplexity")
|
|
28
|
+
p.add_argument("--apply", action="store_true", help="after probing, BUILD the recommended depth-aware GGUF")
|
|
29
|
+
p.add_argument("--out", default=None, help="output path for --apply (default: <model>-depthaware.gguf)")
|
|
30
|
+
p.add_argument("--imatrix", default=None, help="importance-matrix file for --apply, or 'auto' to generate one first (measured -8.5%% ppl at ~3 bits, free in size and speed)")
|
|
31
|
+
p.add_argument("--imatrix-chunks", type=int, default=100, help="calibration chunks when --imatrix auto (default 100)")
|
|
32
|
+
p.add_argument("--yes", "-y", action="store_true", help="skip the time-commitment confirmation for long runs")
|
|
33
|
+
p.add_argument("--dry-run", action="store_true")
|
|
34
|
+
|
|
35
|
+
q = sub.add_parser("plan", help="evaluate every bit/tier placement, predict tok/s (Law 4)")
|
|
36
|
+
q.add_argument("--model", default=None, help="preset: " + " ".join(sorted(_MODELS)))
|
|
37
|
+
q.add_argument("--machine", default=None, help="preset: 2016-xmp 2016 gaming ddr5 colibri")
|
|
38
|
+
q.add_argument("--bits", type=float, default=None, help="effective bits/weight (default: read from --gguf, else 2.5)")
|
|
39
|
+
q.add_argument("--total", type=float, help="total params (B)")
|
|
40
|
+
q.add_argument("--active", type=float, help="active params per token (B)")
|
|
41
|
+
q.add_argument("--always-active", type=float, help="always-active (attention/embed) params (B)")
|
|
42
|
+
q.add_argument("--vram", type=numlist, help="GB; comma-list for multi-GPU: 24,24"); q.add_argument("--vram-bw", type=numlist, help="GB/s; comma-list aggregates x0.85")
|
|
43
|
+
q.add_argument("--ram", type=float); q.add_argument("--ram-bw", type=float)
|
|
44
|
+
q.add_argument("--disk-bw", type=numlist, help="GB/s; comma-list (RAID) aggregates x0.75")
|
|
45
|
+
q.add_argument("--gguf", default=None, help="optional: read total/active/bits/KV exactly from this GGUF")
|
|
46
|
+
q.add_argument("--ctx", type=int, default=0, help="context depth: adds KV reads/token + KV memory to the prediction (Law 4 v2)")
|
|
47
|
+
q.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB (default: model preset, or 96)")
|
|
48
|
+
|
|
49
|
+
def hwargs(sp):
|
|
50
|
+
sp.add_argument("--model", default=None); sp.add_argument("--machine", default=None)
|
|
51
|
+
sp.add_argument("--bits", type=float, default=None, help="effective bits/weight (default: read from --gguf, else 2.5)")
|
|
52
|
+
sp.add_argument("--total", type=float); sp.add_argument("--active", type=float)
|
|
53
|
+
sp.add_argument("--always-active", type=float)
|
|
54
|
+
sp.add_argument("--vram", type=numlist); sp.add_argument("--vram-bw", type=numlist)
|
|
55
|
+
sp.add_argument("--ram", type=float); sp.add_argument("--ram-bw", type=float)
|
|
56
|
+
sp.add_argument("--disk-bw", type=numlist)
|
|
57
|
+
sp.add_argument("--ctx", type=int, default=0, help="context depth for the prediction (Law 4 v2)")
|
|
58
|
+
sp.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB")
|
|
59
|
+
sp.add_argument("--llama-dir", default=None); sp.add_argument("--dry", action="store_true")
|
|
60
|
+
|
|
61
|
+
r = sub.add_parser("run", help="plan the best placement, then launch llama.cpp chat with those flags")
|
|
62
|
+
r.add_argument("--gguf", required=True); hwargs(r)
|
|
63
|
+
r.add_argument("--serve", action="store_true", help="launch llama-server instead of interactive chat")
|
|
64
|
+
r.add_argument("--extra", default=None, help="extra flags passed through to llama.cpp")
|
|
65
|
+
|
|
66
|
+
b = sub.add_parser("bench", help="measure real tok/s with the planned flags; print predicted vs measured")
|
|
67
|
+
b.add_argument("--gguf", required=True); hwargs(b)
|
|
68
|
+
b.add_argument("--reps", type=int, default=3)
|
|
69
|
+
b.add_argument("--depth", type=int, default=None, help="bench at KV depth N (llama-bench -d): measures the Law 4 v2 context term on YOUR box")
|
|
70
|
+
b.add_argument("--contribute", action="store_true", help="print a pre-filled, opt-in GitHub issue with your predicted-vs-measured point (you review before submitting; nothing auto-sent)")
|
|
71
|
+
|
|
72
|
+
d = sub.add_parser("dashboard", help="launch llama-server with planned flags + a live predicted-vs-measured chat page")
|
|
73
|
+
d.add_argument("--gguf", required=True); hwargs(d)
|
|
74
|
+
d.add_argument("--port", type=int, default=8077); d.add_argument("--server-port", type=int, default=8090)
|
|
75
|
+
d.add_argument("--no-open", action="store_true")
|
|
76
|
+
|
|
77
|
+
g = sub.add_parser("target", help="INVERSE planning: give a tok/s target, get the smartest feasible model + the speed-intelligence ladder")
|
|
78
|
+
g.add_argument("--tps", type=float, required=True, help="minimum tok/s you need")
|
|
79
|
+
hwargs(g)
|
|
80
|
+
g.add_argument("--ladder", action="store_true", help="print the full speed-vs-intelligence ladder")
|
|
81
|
+
|
|
82
|
+
z = sub.add_parser("quantize", help="COMPRESS: build a depth-aware GGUF from a model (protect the fragile band, rest 2-bit)")
|
|
83
|
+
z.add_argument("--gguf", required=True, help="high-precision source GGUF (f16/bf16/Q8)")
|
|
84
|
+
z.add_argument("--out", default=None, help="output path (default: <model>-depthaware.gguf)")
|
|
85
|
+
z.add_argument("--protect-late", type=int, default=12, help="protect the last N layers at 4-bit (default 12)")
|
|
86
|
+
z.add_argument("--protect", default=None, help="protect an explicit band LO-HI (e.g. 36-47) instead of --protect-late")
|
|
87
|
+
z.add_argument("--imatrix", default=None, help="importance-matrix file (build one with `probe --imatrix auto`); improves quality at zero size cost")
|
|
88
|
+
z.add_argument("--recipe", default=None, help="use a MEASURED fragile band from the community atlas instead of the default guess (see: quantprobe recipes)")
|
|
89
|
+
z.add_argument("--llama-dir", default=None)
|
|
90
|
+
z.add_argument("--dry", action="store_true")
|
|
91
|
+
|
|
92
|
+
sub.add_parser("recipes", help="the community fragility atlas: bands already measured, so you can skip the probe")
|
|
93
|
+
|
|
94
|
+
o = sub.add_parser("optimize", help="cheapest path to a target speed: search bits x placement x KV x hardware over the law")
|
|
95
|
+
o.add_argument("--tps", type=float, default=None, help="target tok/s (omit for the speed frontier)")
|
|
96
|
+
o.add_argument("--max-quality", type=float, default=None, help="quality-cost ceiling (default 1.12)")
|
|
97
|
+
o.add_argument("--any-runtime", action="store_true", help="include placements needing expert-caching runtimes (ktransformers-class), not just stock llama.cpp")
|
|
98
|
+
o.add_argument("--allow-prune", action="store_true", help="include REAP-class pruned variants (domain-specialized: +39%% out-of-domain ppl measured)")
|
|
99
|
+
hwargs(o)
|
|
100
|
+
|
|
101
|
+
au = sub.add_parser("auto", help="ONE command: model in, running setup out - optimizer picks the bits, the closest quant is fetched, run command printed")
|
|
102
|
+
au.add_argument("target", nargs="?", default=None,
|
|
103
|
+
help="model preset (qwen3-30b, qwen3-coder, glm-air, laguna-s, gemma-12b, mistral-7b, qwen3-235b, glm-4.7, glm-744b, kimi-k2.6, gpt-oss-120b, llama-70b, deepseek-16b) or a HF GGUF repo id; omit it and quantprobe ASKS (interactive)")
|
|
104
|
+
au.add_argument("--dir", default="./models", help="download directory (default ./models)")
|
|
105
|
+
au.add_argument("--run", action="store_true", help="launch chat immediately after the download")
|
|
106
|
+
hwargs(au)
|
|
107
|
+
au.add_argument("--tps", type=float, default=None, help="target tok/s for the optimizer")
|
|
108
|
+
au.add_argument("--max-quality", type=float, default=None)
|
|
109
|
+
au.add_argument("--allow-prune", action="store_true"); au.add_argument("--any-runtime", action="store_true")
|
|
110
|
+
au.add_argument("--custom", action="store_true", help="THE PRODUCT: fetch a high-precision source, probe YOUR model (~30-60 min), build a depth-aware GGUF personalized to it (machine-gated: skipped with an explanation when this box doesn't need sub-3-bit surgery)")
|
|
111
|
+
au.add_argument("--yes", "-y", action="store_true", help="skip time-commitment confirmations")
|
|
112
|
+
au.add_argument("--no-imatrix", action="store_true", help="skip importance-matrix calibration in --custom (faster build, measurably worse quality)")
|
|
113
|
+
au.add_argument("--force-custom", action="store_true", help="build the depth-aware GGUF even when the optimizer says this machine doesn't need it")
|
|
114
|
+
au.add_argument("--serve", action="store_true", help="with --run: llama-server instead of chat")
|
|
115
|
+
au.add_argument("--extra", default=None)
|
|
116
|
+
|
|
117
|
+
hwp = sub.add_parser("hw", help="detect THIS machine's memory tiers (no flags needed); every value tagged with its source")
|
|
118
|
+
hwp.add_argument("--measure", default=None, metavar="FILE", help="also MEASURE sequential disk read on a real file (e.g. a GGUF)")
|
|
119
|
+
|
|
120
|
+
cal = sub.add_parser("calibrate", help="MEASURE this machine's constants (RAM stream, disk, GPU boost health, decode anchor) - plan uses them automatically")
|
|
121
|
+
cal.add_argument("--model", default=None, metavar="FILE", help="a GGUF on this machine: unlocks disk measurement + a real pure-CPU decode anchor")
|
|
122
|
+
cal.add_argument("--skip-bench", action="store_true", help="measure RAM/disk/GPU only; skip the llama-bench anchor")
|
|
123
|
+
cal.add_argument("--llama-dir", default=None, help="folder containing llama-bench, if not on PATH")
|
|
124
|
+
|
|
125
|
+
f = sub.add_parser("fetch", help="robust HF download (Range-resume, retry)")
|
|
126
|
+
f.add_argument("repo", help="HF repo, or a preset: qwen3-30b, glm-air, deepseek-16b, qwen3-0.6b"); f.add_argument("dest"); f.add_argument("files", nargs="*")
|
|
127
|
+
|
|
128
|
+
a = ap.parse_args()
|
|
129
|
+
if a.cmd == "probe":
|
|
130
|
+
from . import probe
|
|
131
|
+
probe.run(a)
|
|
132
|
+
elif a.cmd == "plan":
|
|
133
|
+
from . import plan
|
|
134
|
+
plan.run(a)
|
|
135
|
+
elif a.cmd == "run":
|
|
136
|
+
from . import runtime
|
|
137
|
+
runtime.run(a)
|
|
138
|
+
elif a.cmd == "bench":
|
|
139
|
+
from . import runtime
|
|
140
|
+
runtime.bench(a)
|
|
141
|
+
elif a.cmd == "dashboard":
|
|
142
|
+
from . import dashboard
|
|
143
|
+
dashboard.dashboard(a)
|
|
144
|
+
elif a.cmd == "target":
|
|
145
|
+
from . import target
|
|
146
|
+
target.run(a)
|
|
147
|
+
elif a.cmd == "auto":
|
|
148
|
+
from . import auto
|
|
149
|
+
auto.run(a)
|
|
150
|
+
elif a.cmd == "optimize":
|
|
151
|
+
from . import optimize
|
|
152
|
+
optimize.run(a)
|
|
153
|
+
elif a.cmd == "hw":
|
|
154
|
+
from . import detect
|
|
155
|
+
detect.run(a)
|
|
156
|
+
elif a.cmd == "calibrate":
|
|
157
|
+
from . import calibrate
|
|
158
|
+
calibrate.run(a)
|
|
159
|
+
elif a.cmd == "recipes":
|
|
160
|
+
from . import recipes
|
|
161
|
+
recipes.run(a)
|
|
162
|
+
elif a.cmd == "quantize":
|
|
163
|
+
from . import probe
|
|
164
|
+
probe.quantize(a)
|
|
165
|
+
else:
|
|
166
|
+
from . import fetch
|
|
167
|
+
fetch.run(a)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if __name__ == "__main__":
|
|
171
|
+
main()
|
|
@@ -1,167 +1,183 @@
|
|
|
1
|
-
"""quantprobe hw - read the local machine's memory tiers, no questions asked.
|
|
2
|
-
|
|
3
|
-
Every printed value is tagged with its source:
|
|
4
|
-
[os] read from the operating system / driver (capacity, stick speed, GPU name)
|
|
5
|
-
[table] looked up from the device name (bandwidth spec, eta class)
|
|
6
|
-
[default] a conservative fallback - override it with flags
|
|
7
|
-
Bandwidths are THEORETICAL peaks (the law's eta absorbs realism, same convention as the presets).
|
|
8
|
-
Nothing is sent anywhere; this only reads local OS interfaces.
|
|
9
|
-
"""
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
import os, platform, re, shutil, subprocess
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _run(cmd, timeout=10):
|
|
15
|
-
try:
|
|
16
|
-
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout).stdout
|
|
17
|
-
except Exception:
|
|
18
|
-
return ""
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
# name-fragment -> (VRAM bandwidth GB/s, geta, gl). 1060 measured on the reference box; rest spec-sheet [table].
|
|
22
|
-
GPU_TABLE = [
|
|
23
|
-
("5090", 1792, 0.62, 0.42), ("5080", 960, 0.62, 0.42), ("5070 ti", 896, 0.62, 0.42),
|
|
24
|
-
("5070", 672, 0.6, 0.4), ("5060 ti", 448, 0.58, 0.38), ("5060", 448, 0.58, 0.38),
|
|
25
|
-
("4090", 1008, 0.62, 0.42), ("4080", 717, 0.6, 0.4),
|
|
26
|
-
("4070", 504, 0.55, 0.35), ("4060", 272, 0.5, 0.3),
|
|
27
|
-
("3090", 936, 0.6, 0.4), ("3080", 760, 0.58, 0.38), ("3070", 448, 0.52, 0.32),
|
|
28
|
-
("3060 ti", 448, 0.5, 0.3), ("3060", 360, 0.5, 0.3), ("3050", 224, 0.45, 0.28),
|
|
29
|
-
("2080", 448, 0.45, 0.25), ("2070", 448, 0.45, 0.25), ("2060", 336, 0.42, 0.22),
|
|
30
|
-
("1080", 320, 0.38, 0.06), ("1070", 256, 0.36, 0.05), ("1060", 192, 0.35, 0.04),
|
|
31
|
-
("a100", 1935, 0.7, 0.55), ("h100", 3350, 0.75, 0.6), ("rtx 6000", 960, 0.62, 0.42),
|
|
32
|
-
]
|
|
33
|
-
MAC_BW = {"m1 ultra": 800, "m1 max": 400, "m1 pro": 200, "m1": 68,
|
|
34
|
-
"m2 ultra": 800, "m2 max": 400, "m2 pro": 200, "m2": 100,
|
|
35
|
-
"m3 ultra": 819, "m3 max": 400, "m3 pro": 150, "m3": 100,
|
|
36
|
-
"m4 max": 546, "m4 pro": 273, "m4": 120}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def gpus():
|
|
40
|
-
"""[(name, vram_gb)] via nvidia-smi; empty list if none/AMD (AMD: pass flags for now)."""
|
|
41
|
-
out = _run(["nvidia-smi", "--query-gpu=name,memory.total", "--format=csv,noheader,nounits"])
|
|
42
|
-
gs = []
|
|
43
|
-
for line in out.strip().splitlines():
|
|
44
|
-
if "," in line:
|
|
45
|
-
name, mem = line.rsplit(",", 1)
|
|
46
|
-
try:
|
|
47
|
-
gs.append((name.strip(), float(mem) / 1024))
|
|
48
|
-
except ValueError:
|
|
49
|
-
pass
|
|
50
|
-
return gs
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def gpu_lookup(name):
|
|
54
|
-
n = name.lower()
|
|
55
|
-
for frag, bw, geta, gl in GPU_TABLE:
|
|
56
|
-
if frag in n:
|
|
57
|
-
return bw, geta, gl, "[table]"
|
|
58
|
-
return 300, 0.45, 0.27, "[default: unknown GPU, pass --vram-bw]"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def ram_windows():
|
|
62
|
-
"""(total_gb[os], mts[os], channels[os]) via CIM (wmic fallback)."""
|
|
63
|
-
ps = _run(["powershell", "-NoProfile", "-c",
|
|
64
|
-
"$m=Get-CimInstance Win32_PhysicalMemory; "
|
|
65
|
-
"($m|Measure-Object Capacity -Sum).Sum; "
|
|
66
|
-
"($m|Select-Object -First 1).ConfiguredClockSpeed; ($m|Measure-Object).Count"])
|
|
67
|
-
vals = [v.strip() for v in ps.strip().splitlines() if v.strip()]
|
|
68
|
-
if len(vals) >= 3:
|
|
69
|
-
try:
|
|
70
|
-
return float(vals[0]) / 2**30, float(vals[1]), int(vals[2])
|
|
71
|
-
except ValueError:
|
|
72
|
-
pass
|
|
73
|
-
return None, None, None
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def detect():
|
|
77
|
-
"""Return the machine as quantprobe hardware kwargs + a provenance report."""
|
|
78
|
-
sysname = platform.system()
|
|
79
|
-
hw, notes = {}, []
|
|
80
|
-
|
|
81
|
-
if sysname == "Darwin":
|
|
82
|
-
mem = _run(["sysctl", "-n", "hw.memsize"]).strip()
|
|
83
|
-
chip = _run(["sysctl", "-n", "machdep.cpu.brand_string"]).lower()
|
|
84
|
-
total = float(mem) / 2**30 if mem else 16.0
|
|
85
|
-
bw = next((b for frag, b in sorted(MAC_BW.items(), key=lambda x: -len(x[0])) if frag in chip), 100)
|
|
86
|
-
hw = dict(vram=round(total * 0.8), vram_bw=bw, ram=8, ram_bw=bw, disk_bw=3.5,
|
|
87
|
-
geta=0.26, gl=0.24)
|
|
88
|
-
notes.append(f"Apple unified memory: {total:.0f} GB [os], {bw} GB/s [table, est eta 0.26 - unvalidated: bench me]")
|
|
89
|
-
return hw, notes
|
|
90
|
-
|
|
91
|
-
# RAM
|
|
92
|
-
total, mts, sticks = (ram_windows() if os.name == "nt" else (None, None, None))
|
|
93
|
-
if total is None and os.path.exists("/proc/meminfo"):
|
|
94
|
-
with open("/proc/meminfo") as f:
|
|
95
|
-
kb = int(re.search(r"MemTotal:\s*(\d+)", f.read()).group(1))
|
|
96
|
-
total, mts, sticks = kb / 2**20, None, None
|
|
97
|
-
if total is None:
|
|
98
|
-
total = 16.0; notes.append("RAM capacity: 16 GB [default - detection failed]")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
else:
|
|
121
|
-
|
|
122
|
-
notes.append("
|
|
123
|
-
|
|
124
|
-
#
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
1
|
+
"""quantprobe hw - read the local machine's memory tiers, no questions asked.
|
|
2
|
+
|
|
3
|
+
Every printed value is tagged with its source:
|
|
4
|
+
[os] read from the operating system / driver (capacity, stick speed, GPU name)
|
|
5
|
+
[table] looked up from the device name (bandwidth spec, eta class)
|
|
6
|
+
[default] a conservative fallback - override it with flags
|
|
7
|
+
Bandwidths are THEORETICAL peaks (the law's eta absorbs realism, same convention as the presets).
|
|
8
|
+
Nothing is sent anywhere; this only reads local OS interfaces.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
import os, platform, re, shutil, subprocess
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _run(cmd, timeout=10):
|
|
15
|
+
try:
|
|
16
|
+
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout).stdout
|
|
17
|
+
except Exception:
|
|
18
|
+
return ""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# name-fragment -> (VRAM bandwidth GB/s, geta, gl). 1060 measured on the reference box; rest spec-sheet [table].
|
|
22
|
+
GPU_TABLE = [
|
|
23
|
+
("5090", 1792, 0.62, 0.42), ("5080", 960, 0.62, 0.42), ("5070 ti", 896, 0.62, 0.42),
|
|
24
|
+
("5070", 672, 0.6, 0.4), ("5060 ti", 448, 0.58, 0.38), ("5060", 448, 0.58, 0.38),
|
|
25
|
+
("4090", 1008, 0.62, 0.42), ("4080", 717, 0.6, 0.4),
|
|
26
|
+
("4070", 504, 0.55, 0.35), ("4060", 272, 0.5, 0.3),
|
|
27
|
+
("3090", 936, 0.6, 0.4), ("3080", 760, 0.58, 0.38), ("3070", 448, 0.52, 0.32),
|
|
28
|
+
("3060 ti", 448, 0.5, 0.3), ("3060", 360, 0.5, 0.3), ("3050", 224, 0.45, 0.28),
|
|
29
|
+
("2080", 448, 0.45, 0.25), ("2070", 448, 0.45, 0.25), ("2060", 336, 0.42, 0.22),
|
|
30
|
+
("1080", 320, 0.38, 0.06), ("1070", 256, 0.36, 0.05), ("1060", 192, 0.35, 0.04),
|
|
31
|
+
("a100", 1935, 0.7, 0.55), ("h100", 3350, 0.75, 0.6), ("rtx 6000", 960, 0.62, 0.42),
|
|
32
|
+
]
|
|
33
|
+
MAC_BW = {"m1 ultra": 800, "m1 max": 400, "m1 pro": 200, "m1": 68,
|
|
34
|
+
"m2 ultra": 800, "m2 max": 400, "m2 pro": 200, "m2": 100,
|
|
35
|
+
"m3 ultra": 819, "m3 max": 400, "m3 pro": 150, "m3": 100,
|
|
36
|
+
"m4 max": 546, "m4 pro": 273, "m4": 120}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def gpus():
|
|
40
|
+
"""[(name, vram_gb)] via nvidia-smi; empty list if none/AMD (AMD: pass flags for now)."""
|
|
41
|
+
out = _run(["nvidia-smi", "--query-gpu=name,memory.total", "--format=csv,noheader,nounits"])
|
|
42
|
+
gs = []
|
|
43
|
+
for line in out.strip().splitlines():
|
|
44
|
+
if "," in line:
|
|
45
|
+
name, mem = line.rsplit(",", 1)
|
|
46
|
+
try:
|
|
47
|
+
gs.append((name.strip(), float(mem) / 1024))
|
|
48
|
+
except ValueError:
|
|
49
|
+
pass
|
|
50
|
+
return gs
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def gpu_lookup(name):
|
|
54
|
+
n = name.lower()
|
|
55
|
+
for frag, bw, geta, gl in GPU_TABLE:
|
|
56
|
+
if frag in n:
|
|
57
|
+
return bw, geta, gl, "[table]"
|
|
58
|
+
return 300, 0.45, 0.27, "[default: unknown GPU, pass --vram-bw]"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def ram_windows():
|
|
62
|
+
"""(total_gb[os], mts[os], channels[os]) via CIM (wmic fallback)."""
|
|
63
|
+
ps = _run(["powershell", "-NoProfile", "-c",
|
|
64
|
+
"$m=Get-CimInstance Win32_PhysicalMemory; "
|
|
65
|
+
"($m|Measure-Object Capacity -Sum).Sum; "
|
|
66
|
+
"($m|Select-Object -First 1).ConfiguredClockSpeed; ($m|Measure-Object).Count"])
|
|
67
|
+
vals = [v.strip() for v in ps.strip().splitlines() if v.strip()]
|
|
68
|
+
if len(vals) >= 3:
|
|
69
|
+
try:
|
|
70
|
+
return float(vals[0]) / 2**30, float(vals[1]), int(vals[2])
|
|
71
|
+
except ValueError:
|
|
72
|
+
pass
|
|
73
|
+
return None, None, None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def detect():
|
|
77
|
+
"""Return the machine as quantprobe hardware kwargs + a provenance report."""
|
|
78
|
+
sysname = platform.system()
|
|
79
|
+
hw, notes = {}, []
|
|
80
|
+
|
|
81
|
+
if sysname == "Darwin":
|
|
82
|
+
mem = _run(["sysctl", "-n", "hw.memsize"]).strip()
|
|
83
|
+
chip = _run(["sysctl", "-n", "machdep.cpu.brand_string"]).lower()
|
|
84
|
+
total = float(mem) / 2**30 if mem else 16.0
|
|
85
|
+
bw = next((b for frag, b in sorted(MAC_BW.items(), key=lambda x: -len(x[0])) if frag in chip), 100)
|
|
86
|
+
hw = dict(vram=round(total * 0.8), vram_bw=bw, ram=8, ram_bw=bw, disk_bw=3.5,
|
|
87
|
+
geta=0.26, gl=0.24)
|
|
88
|
+
notes.append(f"Apple unified memory: {total:.0f} GB [os], {bw} GB/s [table, est eta 0.26 - unvalidated: bench me]")
|
|
89
|
+
return hw, notes
|
|
90
|
+
|
|
91
|
+
# RAM
|
|
92
|
+
total, mts, sticks = (ram_windows() if os.name == "nt" else (None, None, None))
|
|
93
|
+
if total is None and os.path.exists("/proc/meminfo"):
|
|
94
|
+
with open("/proc/meminfo") as f:
|
|
95
|
+
kb = int(re.search(r"MemTotal:\s*(\d+)", f.read()).group(1))
|
|
96
|
+
total, mts, sticks = kb / 2**20, None, None
|
|
97
|
+
if total is None:
|
|
98
|
+
total = 16.0; notes.append("RAM capacity: 16 GB [default - detection failed]")
|
|
99
|
+
# CHANNEL COUNT IS NOT STICK COUNT. The first external replication (RTX 3090 + Ryzen 8600G,
|
|
100
|
+
# 4 DIMMs on dual-channel AM5) hit exactly this: min(sticks, 8) assumed 4-channel and quoted
|
|
101
|
+
# 173 GB/s where the platform delivers ~86 peak - a 2x input error that a correct Law 4
|
|
102
|
+
# turned into a 2x wrong prediction. Consumer desktop platforms (AM4/AM5, LGA17xx/18xx) are
|
|
103
|
+
# DUAL-channel regardless of stick count; only HEDT/server parts go wider, and those we can
|
|
104
|
+
# recognize by CPU name. When in doubt: 2, plus a note - `quantprobe calibrate` measures the
|
|
105
|
+
# real stream and overrides all of this.
|
|
106
|
+
cpu_name = platform.processor().lower() if platform.processor() else ""
|
|
107
|
+
WIDE = ("threadripper", "epyc", "xeon w-3", "xeon(r) w9", "xeon(r) w7", "xeon gold",
|
|
108
|
+
"xeon platinum", "xeon silver")
|
|
109
|
+
if any(w in cpu_name for w in WIDE):
|
|
110
|
+
channels = max(1, min(sticks or 4, 8))
|
|
111
|
+
chan_src = f"assumes {channels}-channel [HEDT/server CPU detected]"
|
|
112
|
+
else:
|
|
113
|
+
channels = min(sticks, 2) if sticks else 2
|
|
114
|
+
chan_src = (f"dual-channel [consumer platform; {sticks} sticks does NOT mean {sticks} "
|
|
115
|
+
f"channels]" if sticks and sticks > 2 else f"assumes {channels}-channel")
|
|
116
|
+
if mts:
|
|
117
|
+
ram_bw = round(channels * mts * 8 / 1000) # theoretical peak, preset convention
|
|
118
|
+
notes.append(f"RAM: {total:.0f} GB, {sticks} stick(s) @ {mts:.0f} MT/s [os] -> {ram_bw} GB/s peak "
|
|
119
|
+
f"({chan_src}); real stream is typically ~55% of this - run `quantprobe calibrate` to measure yours")
|
|
120
|
+
else:
|
|
121
|
+
ram_bw = 48
|
|
122
|
+
notes.append(f"RAM: {total:.0f} GB [os]; speed unknown -> 48 GB/s [default: DDR4-3000 dual, pass --ram-bw]")
|
|
123
|
+
|
|
124
|
+
# GPU(s)
|
|
125
|
+
gs = gpus()
|
|
126
|
+
if gs:
|
|
127
|
+
vram = sum(g[1] for g in gs)
|
|
128
|
+
per = [gpu_lookup(g[0]) for g in gs] # per-card lookup (mixed pairs differ)
|
|
129
|
+
bw_sum = sum(p[0] for p in per)
|
|
130
|
+
vram_bw = bw_sum * (1.0 if len(gs) == 1 else 0.85) # aggregate w/ tensor-parallel loss
|
|
131
|
+
geta, gl, src = per[0][1], per[0][2], per[0][3] # eta class from the primary card
|
|
132
|
+
names = " + ".join(g[0] for g in gs)
|
|
133
|
+
notes.append(f"GPU: {names}, {vram:.0f} GB total [os], {vram_bw:.0f} GB/s {src}"
|
|
134
|
+
+ (f" (x{len(gs)} per-card sum, 0.85 TP efficiency [est]; slower card gates its share)" if len(gs) > 1 else ""))
|
|
135
|
+
hw.update(vram=vram, vram_bw=round(vram_bw), geta=geta, gl=gl)
|
|
136
|
+
else:
|
|
137
|
+
hw.update(vram=0, vram_bw=0)
|
|
138
|
+
notes.append("GPU: none detected (nvidia-smi absent/empty; AMD/Intel: pass --vram/--vram-bw) [os]")
|
|
139
|
+
|
|
140
|
+
# disk: class default; a real measured number needs `quantprobe hw --measure` (reads a large file)
|
|
141
|
+
hw.update(ram=round(total), ram_bw=ram_bw, disk_bw=0.5)
|
|
142
|
+
notes.append("disk: 0.5 GB/s [default: SATA-class; NVMe ~3.5, Gen4 ~7 - pass --disk-bw or run hw --measure]")
|
|
143
|
+
return hw, notes
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def measure_disk(path, mb=512):
|
|
147
|
+
"""Sequential read of a real file region, uncached-ish: the streaming pattern that matters."""
|
|
148
|
+
import time
|
|
149
|
+
size = os.path.getsize(path)
|
|
150
|
+
span = min(mb * 1024 * 1024, size)
|
|
151
|
+
off = max(0, size - span - (os.urandom(1)[0] % 7) * 1024 * 1024) # tail region, jittered
|
|
152
|
+
t0 = time.perf_counter()
|
|
153
|
+
with open(path, "rb", buffering=0) as f:
|
|
154
|
+
f.seek(off)
|
|
155
|
+
left = span
|
|
156
|
+
while left > 0:
|
|
157
|
+
chunk = f.read(min(1 << 24, left))
|
|
158
|
+
if not chunk:
|
|
159
|
+
break
|
|
160
|
+
left -= len(chunk)
|
|
161
|
+
dt = time.perf_counter() - t0
|
|
162
|
+
return (span - left) / 1e9 / dt
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def run(a):
|
|
166
|
+
hw, notes = detect()
|
|
167
|
+
print("quantprobe hw - this machine, as the law sees it\n")
|
|
168
|
+
for n in notes:
|
|
169
|
+
print(" " + n)
|
|
170
|
+
if getattr(a, "measure", None):
|
|
171
|
+
p = a.measure
|
|
172
|
+
if os.path.isfile(p):
|
|
173
|
+
bw = measure_disk(p)
|
|
174
|
+
hw["disk_bw"] = round(bw, 2)
|
|
175
|
+
print(f" disk MEASURED on {os.path.basename(p)}: {bw:.2f} GB/s sequential [measured]")
|
|
176
|
+
else:
|
|
177
|
+
print(f" --measure: file not found: {p}")
|
|
178
|
+
flags = (f"--vram {hw['vram']:g} --vram-bw {hw['vram_bw']:g} --ram {hw['ram']:g} "
|
|
179
|
+
f"--ram-bw {hw['ram_bw']:g} --disk-bw {hw['disk_bw']:g}")
|
|
180
|
+
print(f"\n equivalent flags (for sharing / estimating this box elsewhere):\n {flags}")
|
|
181
|
+
print("\n every command now uses these automatically when you pass no hardware flags;")
|
|
182
|
+
print(" pass --machine or explicit flags to estimate a DIFFERENT machine instead.")
|
|
183
|
+
return hw
|
|
@@ -131,7 +131,7 @@ def ubatch_flags(placement, vram_resident_gb, vc):
|
|
|
131
131
|
return None # nothing host-resident: no transfer to amortise
|
|
132
132
|
if vc * 0.90 - vram_resident_gb < UBATCH_HEADROOM_GB:
|
|
133
133
|
return None # no room for the bigger compute buffer; the -39% case
|
|
134
|
-
ub = safe_ubatch(vc * 0.90 - vram_resident_gb)
|
|
134
|
+
ub = safe_ubatch(vc * 0.90 - vram_resident_gb, cap=SAFE_UBATCH_CAP)
|
|
135
135
|
return "-b %d -ub %d" % (ub, ub) if ub else None
|
|
136
136
|
|
|
137
137
|
|
|
@@ -167,6 +167,14 @@ def safe_ubatch(headroom_gb, cap=2048):
|
|
|
167
167
|
that grows, and the measured margin between the last good point (902 MiB) and the first bad one
|
|
168
168
|
(1203 MiB) is under 300 MiB on a 6 GB card. Sizing to the last byte would re-create the cliff
|
|
169
169
|
one step further out.
|
|
170
|
+
|
|
171
|
+
The cap: 2048 was the ceiling this 6 GB box could validate - past it the buffer math already
|
|
172
|
+
said no, so larger values were never reachable here. On big-VRAM cards that cap was doing the
|
|
173
|
+
limiting itself: the first external replication (RTX 3090 24GB, 117B MoE) reported prefill
|
|
174
|
+
jumping 90 -> 470 tok/s at -b 4096 -ub 4096 [external datapoint, analogalok's 4090 numbers via
|
|
175
|
+
u/MoneroApe - NOT validated on our hardware; the buffer-fit math still gates it, so a card
|
|
176
|
+
without the headroom never sees 4096]. MoE prefill benefits disproportionately: each layer's
|
|
177
|
+
expert dispatch is one big matmul, and the batch amortizes it.
|
|
170
178
|
"""
|
|
171
179
|
budget_mib = max(0.0, headroom_gb) * 1024 * 0.5
|
|
172
180
|
ub = 0
|
|
@@ -178,6 +186,9 @@ def safe_ubatch(headroom_gb, cap=2048):
|
|
|
178
186
|
return ub
|
|
179
187
|
|
|
180
188
|
|
|
189
|
+
SAFE_UBATCH_CAP = 4096 # raised from 2048 for big-VRAM cards; see safe_ubatch docstring
|
|
190
|
+
|
|
191
|
+
|
|
181
192
|
# The measured Pareto frontier for a MoE whose experts do not fit VRAM, on the reference box
|
|
182
193
|
# (Qwen3-30B-A3B Q2_K, pre-registration #21, one session, r=3, -ub 2048). There is no single best
|
|
183
194
|
# placement: three configurations are Pareto-optimal and the right one depends on how many prompt
|
|
@@ -545,6 +556,16 @@ def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=No
|
|
|
545
556
|
r_need = size - ne * ab / 8 * 1.08
|
|
546
557
|
if v_need <= vc * 0.95 and r_need <= ra:
|
|
547
558
|
warn = "RAM boundary - needs --no-mmap; can be unstable" if r_need > ra * 0.85 else None
|
|
559
|
+
# PINNED-MEMORY CAPACITY RISK (first external replication, u/MoneroApe, extends D-08):
|
|
560
|
+
# `-ot ...=CPU` host buffers are CUDA-pinned. Pinning is why the PCIe path is fast -
|
|
561
|
+
# and pinning a large share of system RAM fails outright under memory pressure. On his
|
|
562
|
+
# 64 GB box the advice tried to pin 36.5 GB. The fallback when this bites: drop -ot
|
|
563
|
+
# entirely and let llama.cpp auto-placement decide (slower, but it starts). APPENDED
|
|
564
|
+
# to any existing warning, never masked by it - his rig had both problems at once.
|
|
565
|
+
if r_need > ra * 0.45:
|
|
566
|
+
pin = (f"pins {r_need:.0f}GB of {ra:.0f}GB RAM (CUDA host memory) - fails under "
|
|
567
|
+
"memory pressure; if it does, drop -ot and let auto-placement decide")
|
|
568
|
+
warn = f"{warn}; {pin}" if warn else pin
|
|
548
569
|
out.append(("hybrid: attention->VRAM, experts->RAM",
|
|
549
570
|
1 / (act_ne / (geta * vb) + act_ex / (eta_r * rb) + kv_gb / (ETA_KV * vb)), warn,
|
|
550
571
|
'-ngl 99 -ot "exps=CPU" --no-mmap'))
|
|
@@ -554,9 +575,14 @@ def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=No
|
|
|
554
575
|
# past the ceiling) - so the free-VRAM headroom is deliberately conservative.
|
|
555
576
|
# Desktop reserve: a real machine is not an empty GPU. Measured on this box during the
|
|
556
577
|
# pre-registration #13 sweep: Explorer + compositor + browser held 0.8-1.5 GB throughout.
|
|
557
|
-
#
|
|
558
|
-
#
|
|
559
|
-
|
|
578
|
+
# The 0.90 multiplier that used to stack on top of the reserve was a DOUBLE discount:
|
|
579
|
+
# the #62 resident-expert sweep measured the config it forbade (16 of 48 resident) as
|
|
580
|
+
# strictly better than the one it emitted (11 resident) - +15.3% prompt processing AND
|
|
581
|
+
# +6.3% generation, fitting fine at ub 1024 - while the overshoot it feared is now a
|
|
582
|
+
# SOFT edge (-6.6% pp at 18 resident, not the historical -29% hard cliff, which was the
|
|
583
|
+
# ubatch compute-buffer cliff and is guarded by safe_ubatch since v1.15). One reserve,
|
|
584
|
+
# counted once.
|
|
585
|
+
v_free = vc - v_need - DESKTOP_VRAM_RESERVE
|
|
560
586
|
experts_gb = size - ne * ab / 8 * 1.08
|
|
561
587
|
if v_free > 0.3 and experts_gb > 0:
|
|
562
588
|
f = min(1.0, v_free / experts_gb)
|
|
@@ -569,7 +595,10 @@ def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=No
|
|
|
569
595
|
# printed flags cannot deliver is the v1.6.5 bug class; without a layer count
|
|
570
596
|
# the row is suppressed and the footer tells the user how to unlock it.
|
|
571
597
|
if fl:
|
|
572
|
-
|
|
598
|
+
pin_warn = ((f"pins {ram_left:.0f}GB of {ra:.0f}GB RAM (CUDA host memory) - "
|
|
599
|
+
"fails under memory pressure; if it does, drop -ot and let "
|
|
600
|
+
"auto-placement decide") if ram_left > ra * 0.45 else None)
|
|
601
|
+
out.append((f"split experts: {f:.0%}->VRAM, rest->RAM", 1 / t_split, pin_warn, fl))
|
|
573
602
|
if (not moe) and vc > 0 and size + kv_gb > vc * 0.90 and size + kv_gb <= ra + vc * 0.9:
|
|
574
603
|
g = min(0.95, vc * 0.9 / (size + kv_gb)) # KV splits with its layers
|
|
575
604
|
# -ngl takes a LAYER COUNT. This emitted `int(g * 99)`, treating 99 - the all-layers
|
|
@@ -668,6 +697,30 @@ def run(args):
|
|
|
668
697
|
print("[quantprobe] no hardware flags: auto-detected this machine "
|
|
669
698
|
f"(vram {hw['vc']:g}GB@{hw['vb']:g} | ram {hw['rc']:g}GB@{hw['rb']:g} | disk {hw['db']:g} GB/s). "
|
|
670
699
|
"Pass --machine/flags to estimate a different box.")
|
|
700
|
+
# calibration overrides detection: MEASURED beats spec-sheet, on this machine only.
|
|
701
|
+
# Constants scoped deliberately (prereg #59: fitted constants do not transfer; measured
|
|
702
|
+
# local ones are exactly what does). Delete ~/.quantprobe/calibration.json to disable.
|
|
703
|
+
from . import calibrate as calmod
|
|
704
|
+
cal, age = calmod.load()
|
|
705
|
+
if cal:
|
|
706
|
+
applied = []
|
|
707
|
+
if cal.get("ram_bw_measured"):
|
|
708
|
+
# calibrate measures the DELIVERED stream; the law's constants were fitted
|
|
709
|
+
# against theoretical-peak inputs on the reference box, whose measured stream
|
|
710
|
+
# was 26.1 of a 48 GB/s peak (0.544). Expressing the user's measurement in the
|
|
711
|
+
# same peak-units keeps every fitted eta valid: peak_equiv = measured / 0.544.
|
|
712
|
+
# Assumption stated: stream-realism fraction is machine-similar. Anchoring on a
|
|
713
|
+
# measurement with one stated assumption beats assuming the peak outright.
|
|
714
|
+
hw["rb"] = round(cal["ram_bw_measured"] / 0.544)
|
|
715
|
+
applied.append(f"ram {cal['ram_bw_measured']:g} GB/s measured")
|
|
716
|
+
if cal.get("disk_bw_measured"):
|
|
717
|
+
hw["db"] = cal["disk_bw_measured"]
|
|
718
|
+
applied.append(f"disk {cal['disk_bw_measured']:g} GB/s measured")
|
|
719
|
+
if applied:
|
|
720
|
+
stale = f"; {age:.0f} days old - re-run `quantprobe calibrate`" if age and age > calmod.STALE_DAYS else ""
|
|
721
|
+
print(f"[quantprobe] calibration applied [{'; '.join(applied)}] ({cal.get('date','?')}{stale})")
|
|
722
|
+
if cal.get("boost_verdict") and "healthy" not in cal["boost_verdict"]:
|
|
723
|
+
print(f"[quantprobe] GPU health at last calibration: {cal['boost_verdict']}")
|
|
671
724
|
vc = hw.get("vc", args.vram); vb = hw.get("vb", args.vram_bw)
|
|
672
725
|
rc = hw.get("rc", args.ram); rb = hw.get("rb", args.ram_bw)
|
|
673
726
|
db = hw.get("db", args.disk_bw); geta = hw.get("geta", 0.45); gl = hw.get("gl", None)
|
|
@@ -701,11 +754,30 @@ def run(args):
|
|
|
701
754
|
w = f" [{warn}]" if warn else ""
|
|
702
755
|
print(f" {star} {tps:6.1f} tok/s {name}{w}")
|
|
703
756
|
best = cfgs[0]
|
|
757
|
+
# Speculation reality, TOP-LINE (first external replication, u/MoneroApe: the buried version
|
|
758
|
+
# of this note cost him a debugging session - the drafter silently produced 0 drafts on a
|
|
759
|
+
# novel prompt, exactly as D-10 measured, and the warning was ten paragraphs down).
|
|
760
|
+
print("\n speculation: pays ONLY when output copies its context (edits, refactors, RAG"
|
|
761
|
+
" quoting)\n - on novel generation the ngram drafter produces 0 drafts and changes"
|
|
762
|
+
" nothing (D-10,\n independently replicated on an RTX 3090). Details below.")
|
|
704
763
|
# Prefill lever, appended only where the measurement says it pays (host-resident weights with
|
|
705
764
|
# VRAM headroom). Not part of the law: `evaluate` is untouched and no anchor can move.
|
|
706
765
|
ub = ubatch_flags(best[0], ne * max(args.bits, 4.5) / 8 * 1.08 if moe else 0.0, vc)
|
|
707
766
|
run_flags = f"{best[3]} {ub}" if ub else best[3]
|
|
767
|
+
# --threads: llama.cpp's auto-detection can pick PHYSICAL cores only (the first external
|
|
768
|
+
# replication got 6 of 12 on a Ryzen 8600G and reported "decode struggled at 2 t/s ... this
|
|
769
|
+
# flag alone helped it jump past 9"; our own C-07 measured a 40% swing from the CPU-thread
|
|
770
|
+
# runtime alone). Emit the logical count explicitly whenever the placement has CPU-resident
|
|
771
|
+
# work; harmless when it does not.
|
|
772
|
+
import os as _os2
|
|
773
|
+
nthreads = _os2.cpu_count() or 0
|
|
774
|
+
if nthreads and any(k in best[0] for k in ("->RAM", "CPU", "disk", "split experts")):
|
|
775
|
+
run_flags = f"{run_flags} --threads {nthreads}"
|
|
708
776
|
print(f"\n run it: llama-server -m model.gguf {run_flags}")
|
|
777
|
+
if "--threads" in run_flags:
|
|
778
|
+
print(f" (--threads {nthreads} = this machine's LOGICAL cores; llama.cpp's own"
|
|
779
|
+
" auto-detect may pick\n physical-only and cost 2x on CPU-bound decode -"
|
|
780
|
+
" verify with your fork if unsure)")
|
|
709
781
|
# I-quant files on a host tier: measured 2.7x slower than K-quants at the same size
|
|
710
782
|
# (pre-registration #31: IQ3_XS 10.6 GB/s vs Q2_K 28.4 / Q4_K_M 29.7 on pure-CPU decode).
|
|
711
783
|
# The warning fires only when weights actually land on the CPU - in VRAM the IQ formats
|
|
@@ -728,8 +800,10 @@ def run(args):
|
|
|
728
800
|
print(f" Choosing wrong costs up to {rag['speedup_vs_worst']:.2f}x on a long-prompt workload.")
|
|
729
801
|
else:
|
|
730
802
|
print(f"\n workload: one setup wins at every prompt:generation ratio - {rag['label']}")
|
|
731
|
-
print(f" ({rag['pp']:.0f}
|
|
732
|
-
"
|
|
803
|
+
print(f" ({rag['pp']:.0f} pp2048 / {rag['tg']:.1f} tg128 - REFERENCE-BOX numbers at "
|
|
804
|
+
"those exact batch sizes;")
|
|
805
|
+
print(" a 22-token prompt measures startup, not prefill). Earlier versions offered a "
|
|
806
|
+
"choice here; re-measuring")
|
|
733
807
|
print(" every cell in ONE session (pre-registration #25) showed the alternatives were "
|
|
734
808
|
"dominated,")
|
|
735
809
|
print(" so there is nothing to choose. One fewer knob, and the honest number.")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantprobe
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.19.0
|
|
4
4
|
Summary: Probe-then-quantize for LLMs: measure a model's fragility curve, plan bit/tier placement by the tiered decode law, and emit ready-to-run llama.cpp recipes.
|
|
5
5
|
Author: Federico Sciuca
|
|
6
6
|
License: MIT
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|