quantprobe 1.17.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.17.0/quantprobe.egg-info → quantprobe-1.19.0}/PKG-INFO +1 -1
- {quantprobe-1.17.0 → quantprobe-1.19.0}/pyproject.toml +1 -1
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/__init__.py +1 -1
- quantprobe-1.19.0/quantprobe/calibrate.py +216 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/cli.py +171 -163
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/detect.py +183 -167
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/plan.py +155 -14
- {quantprobe-1.17.0 → quantprobe-1.19.0/quantprobe.egg-info}/PKG-INFO +1 -1
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe.egg-info/SOURCES.txt +1 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/LICENSE +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/README.md +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/__main__.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/auto.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/dashboard.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/fetch.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/optimize.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/probe.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/recipes/mistral-7b.json +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen2.5-7b.json +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen3-30b.json +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/recipes/qwen3.5-35b.json +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/recipes.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/runtime.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/spec.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe/target.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe.egg-info/dependency_links.txt +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe.egg-info/entry_points.txt +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe.egg-info/requires.txt +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/quantprobe.egg-info/top_level.txt +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/setup.cfg +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/tests/test_engine.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/tests/test_evaluator.py +0 -0
- {quantprobe-1.17.0 → quantprobe-1.19.0}/tests/test_pipeline.py +0 -0
- {quantprobe-1.17.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()
|