quantprobe 1.9.2__tar.gz → 1.10.1__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.9.2/quantprobe.egg-info → quantprobe-1.10.1}/PKG-INFO +1 -1
- {quantprobe-1.9.2 → quantprobe-1.10.1}/pyproject.toml +4 -1
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/__init__.py +1 -1
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/cli.py +6 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/probe.py +48 -0
- quantprobe-1.10.1/quantprobe/recipes/mistral-7b.json +50 -0
- quantprobe-1.10.1/quantprobe/recipes/qwen2.5-7b.json +50 -0
- quantprobe-1.10.1/quantprobe/recipes/qwen3-30b.json +50 -0
- quantprobe-1.10.1/quantprobe/recipes/qwen3.5-35b.json +50 -0
- quantprobe-1.10.1/quantprobe/recipes.py +75 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/spec.py +50 -1
- {quantprobe-1.9.2 → quantprobe-1.10.1/quantprobe.egg-info}/PKG-INFO +1 -1
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe.egg-info/SOURCES.txt +5 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/LICENSE +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/README.md +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/__main__.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/auto.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/dashboard.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/detect.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/fetch.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/optimize.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/plan.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/runtime.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe/target.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe.egg-info/dependency_links.txt +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe.egg-info/entry_points.txt +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe.egg-info/requires.txt +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/quantprobe.egg-info/top_level.txt +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/setup.cfg +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/tests/test_engine.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/tests/test_evaluator.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/tests/test_pipeline.py +0 -0
- {quantprobe-1.9.2 → quantprobe-1.10.1}/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.10.1
|
|
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.10.1"
|
|
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" }
|
|
@@ -26,3 +26,6 @@ quantprobe = "quantprobe.cli:main"
|
|
|
26
26
|
|
|
27
27
|
[tool.setuptools]
|
|
28
28
|
packages = ["quantprobe"]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-data]
|
|
31
|
+
quantprobe = ["recipes/*.json"]
|
|
@@ -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.10.1"
|
|
@@ -85,9 +85,12 @@ def main():
|
|
|
85
85
|
z.add_argument("--protect-late", type=int, default=12, help="protect the last N layers at 4-bit (default 12)")
|
|
86
86
|
z.add_argument("--protect", default=None, help="protect an explicit band LO-HI (e.g. 36-47) instead of --protect-late")
|
|
87
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)")
|
|
88
89
|
z.add_argument("--llama-dir", default=None)
|
|
89
90
|
z.add_argument("--dry", action="store_true")
|
|
90
91
|
|
|
92
|
+
sub.add_parser("recipes", help="the community fragility atlas: bands already measured, so you can skip the probe")
|
|
93
|
+
|
|
91
94
|
o = sub.add_parser("optimize", help="cheapest path to a target speed: search bits x placement x KV x hardware over the law")
|
|
92
95
|
o.add_argument("--tps", type=float, default=None, help="target tok/s (omit for the speed frontier)")
|
|
93
96
|
o.add_argument("--max-quality", type=float, default=None, help="quality-cost ceiling (default 1.12)")
|
|
@@ -145,6 +148,9 @@ def main():
|
|
|
145
148
|
elif a.cmd == "hw":
|
|
146
149
|
from . import detect
|
|
147
150
|
detect.run(a)
|
|
151
|
+
elif a.cmd == "recipes":
|
|
152
|
+
from . import recipes
|
|
153
|
+
recipes.run(a)
|
|
148
154
|
elif a.cmd == "quantize":
|
|
149
155
|
from . import probe
|
|
150
156
|
probe.quantize(a)
|
|
@@ -217,6 +217,24 @@ def build_depthaware(llama_dir, src, out, protect_lo, protect_hi, n_lay,
|
|
|
217
217
|
# 2026-07-25), so this must precede the band rules or it silently does nothing. The shared
|
|
218
218
|
# expert fires on EVERY token (routed experts fire ~8/256) and is heavy-tailed: measured
|
|
219
219
|
# -3.2% ppl when protected at q8_0, for ~0.65% more bytes (pre-registration #12).
|
|
220
|
+
# Pre-flight: does this model contain weight classes we have no protection rule for?
|
|
221
|
+
# We shipped exactly that bug once (SSM tensors, v1.6.4). Reporting beats silently
|
|
222
|
+
# compressing something always-active.
|
|
223
|
+
if not dry and os.path.isfile(src):
|
|
224
|
+
try:
|
|
225
|
+
from .spec import tensor_roles
|
|
226
|
+
roles, unknown = tensor_roles(src)
|
|
227
|
+
big = {k: v for k, v in unknown.items() if v > 5e7} # ignore trivia
|
|
228
|
+
if big:
|
|
229
|
+
tot = sum(big.values()) / 1e9
|
|
230
|
+
print(f"[quantprobe] NOTE: {tot:.2f} GB of tensors have no known role and will "
|
|
231
|
+
f"take the base quantization level:")
|
|
232
|
+
for k, v in sorted(big.items(), key=lambda x: -x[1])[:5]:
|
|
233
|
+
print(f" {k} ({v/1e9:.2f} GB)")
|
|
234
|
+
print(" If any of those are always-active, they should be protected - please "
|
|
235
|
+
"open an issue with the model name so the registry can be extended.")
|
|
236
|
+
except Exception:
|
|
237
|
+
pass
|
|
220
238
|
cmd += ["--tensor-type", "ffn_.*_shexp.*=q8_0"]
|
|
221
239
|
if protect_lo > 0:
|
|
222
240
|
cmd += ["--tensor-type", f"{_band_re(0, protect_lo - 1)}=q2_k"]
|
|
@@ -273,10 +291,40 @@ def quantize(a):
|
|
|
273
291
|
if not os.path.isfile(a.gguf):
|
|
274
292
|
raise SystemExit(f"GGUF not found: {a.gguf} (point --gguf at a real high-precision GGUF: f16/bf16/Q8)")
|
|
275
293
|
n_lay = n_layers(a.gguf)
|
|
294
|
+
rec_key = getattr(a, "recipe", None)
|
|
276
295
|
if a.protect:
|
|
277
296
|
lo, hi = (int(x) for x in a.protect.split("-"))
|
|
297
|
+
elif rec_key:
|
|
298
|
+
from . import recipes as recmod
|
|
299
|
+
r = recmod.find(key=rec_key)
|
|
300
|
+
if not r:
|
|
301
|
+
raise SystemExit(f"no recipe '{rec_key}'. See what has been measured: quantprobe recipes")
|
|
302
|
+
if r["model"]["n_layer"] != n_lay:
|
|
303
|
+
raise SystemExit(
|
|
304
|
+
f"recipe '{rec_key}' is for a {r['model']['n_layer']}-layer model; this file has "
|
|
305
|
+
f"{n_lay}.\n A fragile band is only meaningful for the model it was measured on.")
|
|
306
|
+
lo, hi = r["probe"]["fragile_band"]
|
|
307
|
+
print(f"[quantprobe] using measured recipe '{rec_key}': protect layers {lo}-{hi} "
|
|
308
|
+
f"({r['probe']['shape']}-fragile, {r['probe']['fragility_ratio']}x median)")
|
|
309
|
+
print(f" measured {r['provenance']['measured']} on {r['provenance']['hardware']}; "
|
|
310
|
+
f"evidence: {r['provenance']['raw_log']}")
|
|
278
311
|
else:
|
|
279
312
|
lo, hi = n_lay - a.protect_late, n_lay - 1
|
|
313
|
+
# If someone has already measured THIS model, say so - the default is a guess, and a
|
|
314
|
+
# measured band is strictly better information (Law 3: fragility is not predictable).
|
|
315
|
+
try:
|
|
316
|
+
from . import recipes as recmod
|
|
317
|
+
from .spec import from_gguf
|
|
318
|
+
arch = from_gguf(a.gguf).get("arch")
|
|
319
|
+
r = recmod.find(arch=arch, n_layer=n_lay)
|
|
320
|
+
if r:
|
|
321
|
+
rlo, rhi = r["probe"]["fragile_band"]
|
|
322
|
+
if (rlo, rhi) != (lo, hi):
|
|
323
|
+
print(f"[quantprobe] a MEASURED recipe exists for this model class "
|
|
324
|
+
f"({r['model']['name']}): fragile band {rlo}-{rhi}, not the default "
|
|
325
|
+
f"{lo}-{hi}.\n Use it: --recipe {r['model']['key']}")
|
|
326
|
+
except Exception:
|
|
327
|
+
pass
|
|
280
328
|
out = a.out or os.path.splitext(a.gguf)[0] + "-depthaware.gguf"
|
|
281
329
|
imat = getattr(a, "imatrix", None)
|
|
282
330
|
if imat and not os.path.isfile(imat) and not getattr(a, "dry", False):
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"model": {
|
|
4
|
+
"key": "mistral-7b",
|
|
5
|
+
"name": "Mistral-7B-Instruct-v0.3",
|
|
6
|
+
"arch": "llama",
|
|
7
|
+
"n_layer": 32,
|
|
8
|
+
"moe": false
|
|
9
|
+
},
|
|
10
|
+
"probe": {
|
|
11
|
+
"reference_ppl": 5.2055,
|
|
12
|
+
"band_deltas": [
|
|
13
|
+
{
|
|
14
|
+
"lo": 0,
|
|
15
|
+
"hi": 7,
|
|
16
|
+
"delta_ppl": 6.525
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"lo": 8,
|
|
20
|
+
"hi": 15,
|
|
21
|
+
"delta_ppl": 0.148
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"lo": 16,
|
|
25
|
+
"hi": 23,
|
|
26
|
+
"delta_ppl": 0.2248
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"lo": 24,
|
|
30
|
+
"hi": 31,
|
|
31
|
+
"delta_ppl": 0.2587
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"fragile_band": [
|
|
35
|
+
0,
|
|
36
|
+
7
|
|
37
|
+
],
|
|
38
|
+
"fragility_ratio": 26.99,
|
|
39
|
+
"shape": "early"
|
|
40
|
+
},
|
|
41
|
+
"provenance": {
|
|
42
|
+
"measured": "2026-06",
|
|
43
|
+
"eval": "WikiText-2 test (held out)",
|
|
44
|
+
"hardware": "GTX 1060 6GB / 16GB DDR4-3000 / i5-7600K",
|
|
45
|
+
"base_quant": "Q6_K",
|
|
46
|
+
"raw_log": "weights/data/mistral_atlas.log",
|
|
47
|
+
"method": "band probe: one band's FFNs -> q2_k at a time, rest at base; delta vs reference",
|
|
48
|
+
"contributor": "FedericoTs"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"model": {
|
|
4
|
+
"key": "qwen2.5-7b",
|
|
5
|
+
"name": "Qwen2.5-7B-Instruct",
|
|
6
|
+
"arch": "qwen2",
|
|
7
|
+
"n_layer": 28,
|
|
8
|
+
"moe": false
|
|
9
|
+
},
|
|
10
|
+
"probe": {
|
|
11
|
+
"reference_ppl": 6.1496,
|
|
12
|
+
"band_deltas": [
|
|
13
|
+
{
|
|
14
|
+
"lo": 0,
|
|
15
|
+
"hi": 6,
|
|
16
|
+
"delta_ppl": 0.8829
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"lo": 7,
|
|
20
|
+
"hi": 13,
|
|
21
|
+
"delta_ppl": 0.5406
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"lo": 14,
|
|
25
|
+
"hi": 20,
|
|
26
|
+
"delta_ppl": 0.5814
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"lo": 21,
|
|
30
|
+
"hi": 27,
|
|
31
|
+
"delta_ppl": 1.8545
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"fragile_band": [
|
|
35
|
+
21,
|
|
36
|
+
27
|
|
37
|
+
],
|
|
38
|
+
"fragility_ratio": 2.53,
|
|
39
|
+
"shape": "late"
|
|
40
|
+
},
|
|
41
|
+
"provenance": {
|
|
42
|
+
"measured": "2026-06",
|
|
43
|
+
"eval": "WikiText-2 test (held out)",
|
|
44
|
+
"hardware": "GTX 1060 6GB / 16GB DDR4-3000 / i5-7600K",
|
|
45
|
+
"base_quant": "Q6_K",
|
|
46
|
+
"raw_log": "weights/data/qwen_mech_probe.log",
|
|
47
|
+
"method": "band probe: one band's FFNs -> q2_k at a time, rest at base; delta vs reference",
|
|
48
|
+
"contributor": "FedericoTs"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"model": {
|
|
4
|
+
"key": "qwen3-30b",
|
|
5
|
+
"name": "Qwen3-30B-A3B",
|
|
6
|
+
"arch": "qwen3moe",
|
|
7
|
+
"n_layer": 48,
|
|
8
|
+
"moe": true
|
|
9
|
+
},
|
|
10
|
+
"probe": {
|
|
11
|
+
"reference_ppl": 10.3912,
|
|
12
|
+
"band_deltas": [
|
|
13
|
+
{
|
|
14
|
+
"lo": 0,
|
|
15
|
+
"hi": 11,
|
|
16
|
+
"delta_ppl": 0.5907
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"lo": 12,
|
|
20
|
+
"hi": 23,
|
|
21
|
+
"delta_ppl": 0.0165
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"lo": 24,
|
|
25
|
+
"hi": 35,
|
|
26
|
+
"delta_ppl": 0.1352
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"lo": 36,
|
|
30
|
+
"hi": 47,
|
|
31
|
+
"delta_ppl": 1.3374
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"fragile_band": [
|
|
35
|
+
36,
|
|
36
|
+
47
|
|
37
|
+
],
|
|
38
|
+
"fragility_ratio": 3.68,
|
|
39
|
+
"shape": "late"
|
|
40
|
+
},
|
|
41
|
+
"provenance": {
|
|
42
|
+
"measured": "2026-06",
|
|
43
|
+
"eval": "WikiText-2 test (held out)",
|
|
44
|
+
"hardware": "GTX 1060 6GB / 16GB DDR4-3000 / i5-7600K",
|
|
45
|
+
"base_quant": "Q4_K_M",
|
|
46
|
+
"raw_log": "weights/data/q30_bands.log",
|
|
47
|
+
"method": "band probe: one band's FFNs -> q2_k at a time, rest at base; delta vs reference",
|
|
48
|
+
"contributor": "FedericoTs"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": 1,
|
|
3
|
+
"model": {
|
|
4
|
+
"key": "qwen3.5-35b",
|
|
5
|
+
"name": "Qwen3.5-35B-A3B",
|
|
6
|
+
"arch": "qwen35moe",
|
|
7
|
+
"n_layer": 40,
|
|
8
|
+
"moe": true
|
|
9
|
+
},
|
|
10
|
+
"probe": {
|
|
11
|
+
"reference_ppl": 5.4298,
|
|
12
|
+
"band_deltas": [
|
|
13
|
+
{
|
|
14
|
+
"lo": 0,
|
|
15
|
+
"hi": 9,
|
|
16
|
+
"delta_ppl": 0.0909
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"lo": 10,
|
|
20
|
+
"hi": 19,
|
|
21
|
+
"delta_ppl": 0.1531
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"lo": 20,
|
|
25
|
+
"hi": 29,
|
|
26
|
+
"delta_ppl": 0.1579
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"lo": 30,
|
|
30
|
+
"hi": 39,
|
|
31
|
+
"delta_ppl": 0.4492
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"fragile_band": [
|
|
35
|
+
30,
|
|
36
|
+
39
|
|
37
|
+
],
|
|
38
|
+
"fragility_ratio": 2.89,
|
|
39
|
+
"shape": "late"
|
|
40
|
+
},
|
|
41
|
+
"provenance": {
|
|
42
|
+
"measured": "2026-07-25",
|
|
43
|
+
"eval": "WikiText-2 test (held out)",
|
|
44
|
+
"hardware": "GTX 1060 6GB / 16GB DDR4-3000 / i5-7600K",
|
|
45
|
+
"base_quant": "Q6_K",
|
|
46
|
+
"raw_log": "weights/data/apex_ab_stageA2.log",
|
|
47
|
+
"method": "band probe: one band's FFNs -> q2_k at a time, rest at base; delta vs reference",
|
|
48
|
+
"contributor": "FedericoTs"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""quantprobe recipes — the community fragility atlas.
|
|
2
|
+
|
|
3
|
+
Law 3 says where a model breaks under low-bit quantization is model-specific and must be
|
|
4
|
+
MEASURED. Measuring it is the expensive part of the pipeline (hours on a large model).
|
|
5
|
+
|
|
6
|
+
But the result is a property of the MODEL, not of your machine: Qwen3-30B's fragile band is
|
|
7
|
+
layers 36-47 whether you measured it on a GTX 1060 or an H100. So it needs measuring once,
|
|
8
|
+
globally, ever — and everyone after that skips straight to the build.
|
|
9
|
+
|
|
10
|
+
A recipe is a few numbers plus its evidence. Every entry carries the raw log it came from, the
|
|
11
|
+
eval corpus, and the hardware, because a recipe you cannot check is a recipe you should not use.
|
|
12
|
+
"""
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
import json, os, glob
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _dir():
|
|
18
|
+
"""Recipes ship with the package; a repo checkout falls back to the source tree."""
|
|
19
|
+
here = os.path.join(os.path.dirname(os.path.abspath(__file__)), "recipes")
|
|
20
|
+
if os.path.isdir(here):
|
|
21
|
+
return here
|
|
22
|
+
up = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "recipes")
|
|
23
|
+
return up if os.path.isdir(up) else here
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def load_all():
|
|
27
|
+
out = []
|
|
28
|
+
for f in sorted(glob.glob(os.path.join(_dir(), "*.json"))):
|
|
29
|
+
try:
|
|
30
|
+
out.append(json.load(open(f, encoding="utf-8")))
|
|
31
|
+
except Exception:
|
|
32
|
+
continue # a malformed contribution must not break the tool
|
|
33
|
+
return out
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def find(key=None, arch=None, n_layer=None):
|
|
37
|
+
"""Explicit key wins. Otherwise match on (arch, n_layer) — the two things that make a
|
|
38
|
+
recipe applicable. Layer count alone is not enough: different architectures share it."""
|
|
39
|
+
all_r = load_all()
|
|
40
|
+
if key:
|
|
41
|
+
for r in all_r:
|
|
42
|
+
if r["model"]["key"] == key:
|
|
43
|
+
return r
|
|
44
|
+
return None
|
|
45
|
+
if arch and n_layer:
|
|
46
|
+
for r in all_r:
|
|
47
|
+
if r["model"]["arch"] == arch and r["model"]["n_layer"] == n_layer:
|
|
48
|
+
return r
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def describe(r):
|
|
53
|
+
p, m, pr = r["probe"], r["model"], r["provenance"]
|
|
54
|
+
lo, hi = p["fragile_band"]
|
|
55
|
+
return (f"{m['name']} ({m['n_layer']} layers, {'MoE' if m['moe'] else 'dense'}) — "
|
|
56
|
+
f"fragile band layers {lo}-{hi} ({p['shape']}-fragile, {p['fragility_ratio']}x "
|
|
57
|
+
f"the median band)\n"
|
|
58
|
+
f" measured {pr['measured']} on {pr['hardware']}, eval {pr['eval']}\n"
|
|
59
|
+
f" evidence: {pr['raw_log']}")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def run(a):
|
|
63
|
+
"""`quantprobe recipes` — what has already been measured, so you don't have to."""
|
|
64
|
+
all_r = load_all()
|
|
65
|
+
if not all_r:
|
|
66
|
+
print("no recipes found (expected in quantprobe/recipes/*.json)")
|
|
67
|
+
return
|
|
68
|
+
print(f"\nquantprobe recipes — {len(all_r)} measured fragility bands\n")
|
|
69
|
+
print(" A recipe is someone's probe result. The fragile band is a property of the MODEL,")
|
|
70
|
+
print(" not your hardware, so it transfers: skip the probe, build in minutes.\n")
|
|
71
|
+
for r in all_r:
|
|
72
|
+
print(" " + describe(r).replace("\n", "\n "))
|
|
73
|
+
print(f" use it: quantprobe quantize --gguf <your-file> --recipe {r['model']['key']}\n")
|
|
74
|
+
print(" Measured one yourself? Open a PR with the JSON and your raw probe log —")
|
|
75
|
+
print(" every entry here carries its evidence, and contributions are held to the same bar.")
|
|
@@ -61,8 +61,16 @@ def from_gguf(path):
|
|
|
61
61
|
kvp = n_layer * kv_heads * ((k_dim or 128) + (v_dim or k_dim or 128)) * 2
|
|
62
62
|
|
|
63
63
|
bits = os.path.getsize(path) * 8 / total
|
|
64
|
+
arch = None
|
|
65
|
+
for field in r.fields.values(): # recipe matching needs (arch, n_layer), not layers alone
|
|
66
|
+
if field.name == "general.architecture":
|
|
67
|
+
try:
|
|
68
|
+
arch = bytes(field.parts[field.data[0]]).decode("utf-8")
|
|
69
|
+
except Exception:
|
|
70
|
+
arch = None
|
|
71
|
+
break
|
|
64
72
|
return dict(t=total / 1e9, a=active / 1e9, ne=ne_params / 1e9, moe=moe,
|
|
65
|
-
bits=round(bits, 2), kvp=int(kvp), n_layer=n_layer)
|
|
73
|
+
bits=round(bits, 2), kvp=int(kvp), n_layer=n_layer, arch=arch)
|
|
66
74
|
|
|
67
75
|
|
|
68
76
|
def apply(a, quiet=False):
|
|
@@ -89,3 +97,44 @@ def apply(a, quiet=False):
|
|
|
89
97
|
if used and not quiet:
|
|
90
98
|
print(f"[quantprobe] read from GGUF: " + ", ".join(used))
|
|
91
99
|
return True
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# --- tensor-role registry -----------------------------------------------------------------
|
|
103
|
+
# WHAT TRANSFERS between models is structure, not fragility. Which tensor classes exist and
|
|
104
|
+
# which are always-active is a property of the ARCHITECTURE, so it is knowable for a model
|
|
105
|
+
# nobody has ever probed. Which LAYERS are fragile is not (Law 3; Mistral is early-fragile
|
|
106
|
+
# where its near-twin Qwen is late, a 25x error if you guess).
|
|
107
|
+
#
|
|
108
|
+
# This registry exists because we shipped that bug: hybrid SSM architectures name their
|
|
109
|
+
# recurrent-state tensors ssm_*, our protection pattern only matched attn_*, and every SSM
|
|
110
|
+
# tensor silently landed at the aggressive base level (fixed in v1.6.4, cost -24% ppl).
|
|
111
|
+
# Anything unrecognised is now REPORTED rather than silently compressed.
|
|
112
|
+
TENSOR_ROLES = [
|
|
113
|
+
("routed-expert", r"ffn_(gate|up|down)_exps", "compressible: ~8 of N experts fire per token"),
|
|
114
|
+
("shared-expert", r"ffn_.*_shexp", "ALWAYS ACTIVE on every token - protect"),
|
|
115
|
+
("attention", r"attn_", "ALWAYS ACTIVE - protect"),
|
|
116
|
+
("recurrent/SSM", r"ssm_", "ALWAYS ACTIVE - protect"),
|
|
117
|
+
("embedding", r"(token_embd|output\.)", "ALWAYS ACTIVE - protect"),
|
|
118
|
+
("router", r"ffn_gate_inp", "tiny, kept at full precision"),
|
|
119
|
+
("norm", r"(_norm|norm\.)", "tiny, kept at full precision"),
|
|
120
|
+
("dense-ffn", r"ffn_(gate|up|down)\.", "dense FFN - the depth-aware band applies here"),
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def tensor_roles(path):
|
|
125
|
+
"""Classify a GGUF's tensors by role. Returns (roles, unknown) with byte totals, so the
|
|
126
|
+
builder can warn about weight classes it has no protection rule for."""
|
|
127
|
+
import re
|
|
128
|
+
from gguf import GGUFReader
|
|
129
|
+
r = GGUFReader(path)
|
|
130
|
+
roles, unknown = {}, {}
|
|
131
|
+
for t in r.tensors:
|
|
132
|
+
nbytes = int(t.n_bytes) if hasattr(t, "n_bytes") else 0
|
|
133
|
+
for name, pat, _ in TENSOR_ROLES:
|
|
134
|
+
if re.search(pat, t.name):
|
|
135
|
+
roles[name] = roles.get(name, 0) + nbytes
|
|
136
|
+
break
|
|
137
|
+
else:
|
|
138
|
+
key = re.sub(r"blk\.\d+\.", "", t.name)
|
|
139
|
+
unknown[key] = unknown.get(key, 0) + nbytes
|
|
140
|
+
return roles, unknown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantprobe
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.1
|
|
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
|
|
@@ -11,6 +11,7 @@ quantprobe/fetch.py
|
|
|
11
11
|
quantprobe/optimize.py
|
|
12
12
|
quantprobe/plan.py
|
|
13
13
|
quantprobe/probe.py
|
|
14
|
+
quantprobe/recipes.py
|
|
14
15
|
quantprobe/runtime.py
|
|
15
16
|
quantprobe/spec.py
|
|
16
17
|
quantprobe/target.py
|
|
@@ -20,6 +21,10 @@ quantprobe.egg-info/dependency_links.txt
|
|
|
20
21
|
quantprobe.egg-info/entry_points.txt
|
|
21
22
|
quantprobe.egg-info/requires.txt
|
|
22
23
|
quantprobe.egg-info/top_level.txt
|
|
24
|
+
quantprobe/recipes/mistral-7b.json
|
|
25
|
+
quantprobe/recipes/qwen2.5-7b.json
|
|
26
|
+
quantprobe/recipes/qwen3-30b.json
|
|
27
|
+
quantprobe/recipes/qwen3.5-35b.json
|
|
23
28
|
tests/test_engine.py
|
|
24
29
|
tests/test_evaluator.py
|
|
25
30
|
tests/test_pipeline.py
|
|
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
|