quantprobe 1.15.0__tar.gz → 1.17.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.15.0/quantprobe.egg-info → quantprobe-1.17.0}/PKG-INFO +2 -2
- {quantprobe-1.15.0 → quantprobe-1.17.0}/README.md +1 -1
- {quantprobe-1.15.0 → quantprobe-1.17.0}/pyproject.toml +1 -1
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/__init__.py +1 -1
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/optimize.py +5 -5
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/plan.py +42 -11
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/spec.py +153 -141
- {quantprobe-1.15.0 → quantprobe-1.17.0/quantprobe.egg-info}/PKG-INFO +2 -2
- {quantprobe-1.15.0 → quantprobe-1.17.0}/LICENSE +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/__main__.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/auto.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/cli.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/dashboard.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/detect.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/fetch.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/probe.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/recipes/mistral-7b.json +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/recipes/qwen2.5-7b.json +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/recipes/qwen3-30b.json +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/recipes/qwen3.5-35b.json +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/recipes.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/runtime.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe/target.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe.egg-info/SOURCES.txt +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe.egg-info/dependency_links.txt +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe.egg-info/entry_points.txt +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe.egg-info/requires.txt +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/quantprobe.egg-info/top_level.txt +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/setup.cfg +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/tests/test_engine.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/tests/test_evaluator.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.0}/tests/test_pipeline.py +0 -0
- {quantprobe-1.15.0 → quantprobe-1.17.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.17.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
|
|
@@ -118,7 +118,7 @@ Copyability is the whole mechanism: code answers repeat their input, prose inven
|
|
|
118
118
|
## When quantprobe won't help you
|
|
119
119
|
|
|
120
120
|
- **Your model already fits comfortably in VRAM at 4 bits or more.** Community quants are near-lossless there, and — measured — quantizing further buys almost no speed once a model is resident: the same 7B at Q2_K vs Q4_K_M is 36% smaller and **4% slower**. Quantize to make a model *fit*; once it fits, stop.
|
|
121
|
-
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it.
|
|
121
|
+
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it. We do not have a point prediction for it, and we would rather say so than quote a number wearing a band too wide to mean anything. What we can state is **one-sided and exception-free**: across 8 models and 13 benchmarks, real speed was **≥ 0.90× the printed number every single time**, and in 12 of the 13 it was strictly higher — typically 1.1×–1.8×. That is a falsifiable claim with the same logical form as our ±25% band, just asymmetric: one measurement below 0.90× kills it. We have refuted six candidate explanations for the gap, including our own favourites: it is not fixed overhead, not GPU clock state, not bytes-per-token, not monotone in bit-width, not a per-format constant, and not a bytes-weighted mixture of the actual tensor types. Within a single architecture it moves cleanly with the dominant tensor type; across architectures it does not transfer. We would rather publish that than move a constant on thin evidence. **This is the single most useful thing you can send us:** `quantprobe bench --contribute` on a GPU-resident model turns your machine into the datapoint that fixes it.
|
|
122
122
|
- **You need task-level eval scores** (MMLU, HellaSwag). quantprobe measures perplexity and KL divergence only.
|
|
123
123
|
- **Your architecture isn't in the fragility atlas** (four families so far). The probe still works on your model; the published priors just won't apply. *Open an issue with your result — those are the most valuable datapoints.*
|
|
124
124
|
- **You want multi-token prediction modeled in the planner.** It isn't. Measured, the effect runs from **+17% (dense, GPU-resident) to −24% (MoE, experts in RAM)** — there's no single multiplier to apply. [Full 2×2 →](preregistrations/2026-07-24-law6-speculation-economics.md)
|
|
@@ -100,7 +100,7 @@ Copyability is the whole mechanism: code answers repeat their input, prose inven
|
|
|
100
100
|
## When quantprobe won't help you
|
|
101
101
|
|
|
102
102
|
- **Your model already fits comfortably in VRAM at 4 bits or more.** Community quants are near-lossless there, and — measured — quantizing further buys almost no speed once a model is resident: the same 7B at Q2_K vs Q4_K_M is 36% smaller and **4% slower**. Quantize to make a model *fit*; once it fits, stop.
|
|
103
|
-
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it.
|
|
103
|
+
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it. We do not have a point prediction for it, and we would rather say so than quote a number wearing a band too wide to mean anything. What we can state is **one-sided and exception-free**: across 8 models and 13 benchmarks, real speed was **≥ 0.90× the printed number every single time**, and in 12 of the 13 it was strictly higher — typically 1.1×–1.8×. That is a falsifiable claim with the same logical form as our ±25% band, just asymmetric: one measurement below 0.90× kills it. We have refuted six candidate explanations for the gap, including our own favourites: it is not fixed overhead, not GPU clock state, not bytes-per-token, not monotone in bit-width, not a per-format constant, and not a bytes-weighted mixture of the actual tensor types. Within a single architecture it moves cleanly with the dominant tensor type; across architectures it does not transfer. We would rather publish that than move a constant on thin evidence. **This is the single most useful thing you can send us:** `quantprobe bench --contribute` on a GPU-resident model turns your machine into the datapoint that fixes it.
|
|
104
104
|
- **You need task-level eval scores** (MMLU, HellaSwag). quantprobe measures perplexity and KL divergence only.
|
|
105
105
|
- **Your architecture isn't in the fragility atlas** (four families so far). The probe still works on your model; the published priors just won't apply. *Open an issue with your result — those are the most valuable datapoints.*
|
|
106
106
|
- **You want multi-token prediction modeled in the planner.** It isn't. Measured, the effect runs from **+17% (dense, GPU-resident) to −24% (MoE, experts in RAM)** — there's no single multiplier to apply. [Full 2×2 →](preregistrations/2026-07-24-law6-speculation-economics.md)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "quantprobe"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.17.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.17.0"
|
|
@@ -136,11 +136,11 @@ def run(a):
|
|
|
136
136
|
# gives is the inconsistency class that cost us the plan-vs-bench correction.
|
|
137
137
|
roomier = next((r for r in ranked if r["bits"] >= 4.5 and "all in VRAM" in r["desc"]), None)
|
|
138
138
|
if "all in VRAM" in best["desc"]:
|
|
139
|
-
print(f"\n note:
|
|
140
|
-
print(f"
|
|
141
|
-
print(f"
|
|
142
|
-
print(f"
|
|
143
|
-
print(f"
|
|
139
|
+
print(f"\n note: we do not have a point prediction for all-in-VRAM - measured efficiency")
|
|
140
|
+
print(f" varies too much across models for the number above to carry a band. What we can")
|
|
141
|
+
print(f" state is one-sided and exception-free: in 13 of 13 benchmarks real speed was")
|
|
142
|
+
print(f" >= 0.90x this number, and in 12 of 13 it was HIGHER, typically 1.1x-1.8x. Read it")
|
|
143
|
+
print(f" as a floor, not a ceiling.")
|
|
144
144
|
if roomier and best["bits"] < 4.5:
|
|
145
145
|
print(f" It also already fits, and a lower quant buys almost nothing once it does: the same")
|
|
146
146
|
print(f" 7B at Q2_K vs Q4_K_M is 36% smaller and 4% SLOWER. The honest pick here is")
|
|
@@ -351,10 +351,13 @@ def fits_in_vram_advice(placement, bits):
|
|
|
351
351
|
This is the most common configuration for anyone with adequate VRAM, and it is where the law
|
|
352
352
|
is least trustworthy. Two separate facts, both measured, both worth telling the user:
|
|
353
353
|
|
|
354
|
-
1.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
354
|
+
1. There is NO point prediction for this regime - and pretending otherwise is worse than
|
|
355
|
+
saying so. Measured efficiency varies 0.32-0.56 across 8 models (six candidate
|
|
356
|
+
explanations refuted, prereg #15/#24); a number quoted with a band that wide is not a
|
|
357
|
+
prediction. What survives is a ONE-SIDED BOUND with the same logical form as the law's
|
|
358
|
+
own +/-25% claim, just asymmetric: real speed >= 0.90x the printed number, 13 of 13
|
|
359
|
+
benchmarks, no exceptions, falsified by any single measurement below it. In 12 of the 13
|
|
360
|
+
it was strictly above, typically 1.1x-1.8x.
|
|
358
361
|
|
|
359
362
|
2. Below 4.5 bits, quantizing further buys almost nothing. Same 7B, same card, only the
|
|
360
363
|
quantization changed (pre-registration #16, r=3):
|
|
@@ -371,11 +374,12 @@ def fits_in_vram_advice(placement, bits):
|
|
|
371
374
|
"""
|
|
372
375
|
if placement != "all in VRAM":
|
|
373
376
|
return None
|
|
374
|
-
note = ("
|
|
375
|
-
"
|
|
376
|
-
"
|
|
377
|
-
"
|
|
378
|
-
"
|
|
377
|
+
note = ("we do not have a point prediction for this placement - measured efficiency varies "
|
|
378
|
+
"too much across models for the number above to carry a band (0.32-0.56, six candidate "
|
|
379
|
+
"explanations refuted). What we can state is one-sided and has no exceptions: in 13 of "
|
|
380
|
+
"13 benchmarks real speed was >= 0.90x this number, and in 12 of 13 it was HIGHER, "
|
|
381
|
+
"typically 1.1x-1.8x. Read it as a floor, not a ceiling - a single measurement below "
|
|
382
|
+
"0.90x would falsify this and we ask for exactly that measurement below.")
|
|
379
383
|
if bits < 4.5:
|
|
380
384
|
note += (" It also already fits, and going lower-bit buys almost nothing: the same 7B at "
|
|
381
385
|
"Q2_K vs Q4_K_M is 36% smaller and 4% SLOWER (19.17 vs 20.03 tok/s). Quantize "
|
|
@@ -401,9 +405,20 @@ def speculation_advice(moe, placement):
|
|
|
401
405
|
|
|
402
406
|
Returns None when we have no measurement for the case rather than guessing.
|
|
403
407
|
"""
|
|
404
|
-
# Only the fully-offloaded case is measured (exps=CPU). A partial split puts some experts
|
|
405
|
-
# on the fast tier, which we have NOT measured - so it gets no claim either way.
|
|
406
408
|
experts_offloaded = "exps=CPU" in (placement or "")
|
|
409
|
+
if moe and "split experts" in (placement or ""):
|
|
410
|
+
# Measured on the flagship ITSELF, on this exact placement (pre-registration #28). The
|
|
411
|
+
# axis that matters is COPY vs NOVEL, not code vs prose: the prize attaches to output
|
|
412
|
+
# that reproduces context spans (edits, refactors, quoting) - most of what coding agents
|
|
413
|
+
# emit, and none of what fresh generation emits.
|
|
414
|
+
return ("if your output REUSES its context - edits, refactors, RAG quoting - add "
|
|
415
|
+
"`--spec-type ngram-simple` to llama-server: measured **2.41x decode** on THIS "
|
|
416
|
+
"model and placement (20.7 -> 50.0 tok/s, 89% draft acceptance), one flag, no "
|
|
417
|
+
"download, identical output. That is 22% ABOVE this box's raw-decode wall - the "
|
|
418
|
+
"one lever that can pass it. Novel generation gains nothing (0% acceptance), and "
|
|
419
|
+
"a separate 0.6B DRAFT MODEL is measured NET NEGATIVE here (0.72x): its own "
|
|
420
|
+
"forward passes cost more than verification saves. Note llama-cli ignores "
|
|
421
|
+
"--spec-type silently; the flag only works on llama-server.")
|
|
407
422
|
if moe and experts_offloaded:
|
|
408
423
|
return ("speculation will NOT pay here: measured +3% (ngram) and -24% (MTP) with experts "
|
|
409
424
|
"offloaded - a verify batch unions experts, and every extra one is a slow read.")
|
|
@@ -634,6 +649,17 @@ def run(args):
|
|
|
634
649
|
ub = ubatch_flags(best[0], ne * max(args.bits, 4.5) / 8 * 1.08 if moe else 0.0, vc)
|
|
635
650
|
run_flags = f"{best[3]} {ub}" if ub else best[3]
|
|
636
651
|
print(f"\n run it: llama-server -m model.gguf {run_flags}")
|
|
652
|
+
# I-quant files on a host tier: measured 2.7x slower than K-quants at the same size
|
|
653
|
+
# (pre-registration #31: IQ3_XS 10.6 GB/s vs Q2_K 28.4 / Q4_K_M 29.7 on pure-CPU decode).
|
|
654
|
+
# The warning fires only when weights actually land on the CPU - in VRAM the IQ formats
|
|
655
|
+
# are fine, so warning there would be crying wolf.
|
|
656
|
+
if getattr(args, "iq_share", 0.0) > 0.3 and any(
|
|
657
|
+
k in best[0] for k in ("->RAM", "CPU", "disk", "split experts")):
|
|
658
|
+
print(f"\n WARNING: this file is {args.iq_share*100:.0f}% I-quant (IQ*) tensors and this"
|
|
659
|
+
f" placement puts weights\n on the CPU tier, where IQ formats decode ~2.7x slower"
|
|
660
|
+
f" than K-quants of the same size\n (measured: 10.6 vs ~29 GB/s effective)."
|
|
661
|
+
f" Re-download the model as Q_K (e.g. Q3_K_M\n instead of IQ3_XS) before"
|
|
662
|
+
f" trusting the speed above.")
|
|
637
663
|
ph = phase_advice(best[0], cfgs)
|
|
638
664
|
if ph:
|
|
639
665
|
print(f"\n phase: {ph}")
|
|
@@ -650,6 +676,11 @@ def run(args):
|
|
|
650
676
|
print(" every cell in ONE session (pre-registration #25) showed the alternatives were "
|
|
651
677
|
"dominated,")
|
|
652
678
|
print(" so there is nothing to choose. One fewer knob, and the honest number.")
|
|
679
|
+
print()
|
|
680
|
+
print(" long prompts, same document: send cache_prompt=true to llama-server. Measured")
|
|
681
|
+
print(" here (pre-registration #29): the second question against a 2k-token document")
|
|
682
|
+
print(" pays 183 ms of prompt time instead of 5381 - 29x - because the document KV is")
|
|
683
|
+
print(" reused and only the new question is processed. Restarting the server is cold.")
|
|
653
684
|
if ub:
|
|
654
685
|
print(f"\n prompt speed: `{ub}` is worth **+73% prefill** on this placement (measured "
|
|
655
686
|
f"199.9 -> 345.9 tok/s, pre-registration #19). It costs nothing on generation "
|
|
@@ -1,141 +1,153 @@
|
|
|
1
|
-
"""quantprobe autospec - read the MODEL's law-parameters from the GGUF itself.
|
|
2
|
-
|
|
3
|
-
A GGUF already contains everything the decode law needs:
|
|
4
|
-
total params = sum of tensor element counts
|
|
5
|
-
routed/active = expert tensor split + expert_used/expert_count from metadata
|
|
6
|
-
effective bits = file bytes x 8 / total params (the real number, not the type name)
|
|
7
|
-
kv bytes/pos = exact, from layer count x KV heads x head dims (MLA-aware)
|
|
8
|
-
So `--gguf model.gguf` alone fully specifies the model; flags remain as overrides.
|
|
9
|
-
"""
|
|
10
|
-
from __future__ import annotations
|
|
11
|
-
import os
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _field(r, *names):
|
|
15
|
-
for f in r.fields.values():
|
|
16
|
-
for n in names:
|
|
17
|
-
if f.name.endswith(n):
|
|
18
|
-
try:
|
|
19
|
-
return int(f.parts[f.data[0]][0])
|
|
20
|
-
except Exception:
|
|
21
|
-
pass
|
|
22
|
-
return None
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def from_gguf(path):
|
|
26
|
-
from gguf import GGUFReader
|
|
27
|
-
r = GGUFReader(path)
|
|
28
|
-
n_layer = _field(r, ".block_count") or 32
|
|
29
|
-
total = 0
|
|
30
|
-
routed = 0
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
#
|
|
108
|
-
#
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
"""
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
r
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
1
|
+
"""quantprobe autospec - read the MODEL's law-parameters from the GGUF itself.
|
|
2
|
+
|
|
3
|
+
A GGUF already contains everything the decode law needs:
|
|
4
|
+
total params = sum of tensor element counts
|
|
5
|
+
routed/active = expert tensor split + expert_used/expert_count from metadata
|
|
6
|
+
effective bits = file bytes x 8 / total params (the real number, not the type name)
|
|
7
|
+
kv bytes/pos = exact, from layer count x KV heads x head dims (MLA-aware)
|
|
8
|
+
So `--gguf model.gguf` alone fully specifies the model; flags remain as overrides.
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
import os
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _field(r, *names):
|
|
15
|
+
for f in r.fields.values():
|
|
16
|
+
for n in names:
|
|
17
|
+
if f.name.endswith(n):
|
|
18
|
+
try:
|
|
19
|
+
return int(f.parts[f.data[0]][0])
|
|
20
|
+
except Exception:
|
|
21
|
+
pass
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def from_gguf(path):
|
|
26
|
+
from gguf import GGUFReader
|
|
27
|
+
r = GGUFReader(path)
|
|
28
|
+
n_layer = _field(r, ".block_count") or 32
|
|
29
|
+
total = 0
|
|
30
|
+
routed = 0
|
|
31
|
+
iq_bytes = all_bytes = 0
|
|
32
|
+
for t in r.tensors:
|
|
33
|
+
n = 1
|
|
34
|
+
for d in t.shape:
|
|
35
|
+
n *= int(d)
|
|
36
|
+
total += n
|
|
37
|
+
if "exps" in t.name or "_expert" in t.name:
|
|
38
|
+
routed += n
|
|
39
|
+
# bytes-weighted I-quant share. Measured (pre-registration #31): on the CPU tier the
|
|
40
|
+
# IQ formats deliver 10.6 GB/s against ~29 for K-quants at the same size - a 2.7x
|
|
41
|
+
# decode penalty for any host-resident placement. The K-format dequant is
|
|
42
|
+
# bandwidth-shaped on AVX2; the IQ codebook lookup is compute-shaped, and 4 cores
|
|
43
|
+
# cannot hide it.
|
|
44
|
+
nb = int(getattr(t, "n_bytes", 0) or 0)
|
|
45
|
+
all_bytes += nb
|
|
46
|
+
if t.tensor_type.name.startswith("IQ"):
|
|
47
|
+
iq_bytes += nb
|
|
48
|
+
ne_params = total - routed
|
|
49
|
+
|
|
50
|
+
n_exp = _field(r, ".expert_count")
|
|
51
|
+
n_used = _field(r, ".expert_used_count")
|
|
52
|
+
if routed and n_exp and n_used:
|
|
53
|
+
active = ne_params + routed * n_used / n_exp
|
|
54
|
+
moe = True
|
|
55
|
+
else:
|
|
56
|
+
active, moe = total, False
|
|
57
|
+
|
|
58
|
+
# exact KV bytes/pos (f16): MLA caches the latent; GQA caches heads x dims, K+V
|
|
59
|
+
kv_lora = _field(r, ".attention.kv_lora_rank")
|
|
60
|
+
if kv_lora:
|
|
61
|
+
rope = _field(r, ".rope.dimension_count") or 64
|
|
62
|
+
kvp = n_layer * (kv_lora + rope) * 2
|
|
63
|
+
else:
|
|
64
|
+
kv_heads = _field(r, ".attention.head_count_kv") or 8
|
|
65
|
+
k_dim = _field(r, ".attention.key_length")
|
|
66
|
+
v_dim = _field(r, ".attention.value_length")
|
|
67
|
+
if not k_dim:
|
|
68
|
+
emb = _field(r, ".embedding_length") or 4096
|
|
69
|
+
heads = _field(r, ".attention.head_count") or 32
|
|
70
|
+
k_dim = v_dim = emb // heads
|
|
71
|
+
kvp = n_layer * kv_heads * ((k_dim or 128) + (v_dim or k_dim or 128)) * 2
|
|
72
|
+
|
|
73
|
+
bits = os.path.getsize(path) * 8 / total
|
|
74
|
+
arch = None
|
|
75
|
+
for field in r.fields.values(): # recipe matching needs (arch, n_layer), not layers alone
|
|
76
|
+
if field.name == "general.architecture":
|
|
77
|
+
try:
|
|
78
|
+
arch = bytes(field.parts[field.data[0]]).decode("utf-8")
|
|
79
|
+
except Exception:
|
|
80
|
+
arch = None
|
|
81
|
+
break
|
|
82
|
+
return dict(t=total / 1e9, a=active / 1e9, ne=ne_params / 1e9, moe=moe,
|
|
83
|
+
bits=round(bits, 2), kvp=int(kvp), n_layer=n_layer, arch=arch,
|
|
84
|
+
iq_share=(iq_bytes / all_bytes) if all_bytes else 0.0)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def apply(a, quiet=False):
|
|
88
|
+
"""Fill law-parameters from a.gguf for anything the user didn't set. Explicit flags win."""
|
|
89
|
+
g = getattr(a, "gguf", None)
|
|
90
|
+
if not g or not os.path.isfile(g):
|
|
91
|
+
return False
|
|
92
|
+
try:
|
|
93
|
+
s = from_gguf(g)
|
|
94
|
+
except Exception as e:
|
|
95
|
+
if not quiet:
|
|
96
|
+
print(f"[quantprobe] autospec skipped ({e}); using flags/presets")
|
|
97
|
+
return False
|
|
98
|
+
used = []
|
|
99
|
+
if getattr(a, "total", None) is None and getattr(a, "model", None) is None:
|
|
100
|
+
a.total = s["t"]; a.active = a.active or s["a"]; a.always_active = a.always_active or s["ne"]
|
|
101
|
+
used.append(f"{s['t']:.1f}B total, {s['a']:.1f}B active")
|
|
102
|
+
if getattr(a, "bits", None) is None:
|
|
103
|
+
a.bits = s["bits"]; used.append(f"{s['bits']:g} effective bits")
|
|
104
|
+
if getattr(a, "kv_per_pos", None) is None:
|
|
105
|
+
a.kv_per_pos = s["kvp"] / 1024; used.append(f"KV {s['kvp']/1024:.0f} KB/pos")
|
|
106
|
+
if getattr(a, "n_layer", None) is None:
|
|
107
|
+
a.n_layer = s["n_layer"] # enables the MoE partial-offload -ot regex (needs real layer indices)
|
|
108
|
+
a.iq_share = s.get("iq_share", 0.0) # read-only: lets plan warn when IQ weights land on a CPU tier
|
|
109
|
+
if used and not quiet:
|
|
110
|
+
print(f"[quantprobe] read from GGUF: " + ", ".join(used))
|
|
111
|
+
return True
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# --- tensor-role registry -----------------------------------------------------------------
|
|
115
|
+
# WHAT TRANSFERS between models is structure, not fragility. Which tensor classes exist and
|
|
116
|
+
# which are always-active is a property of the ARCHITECTURE, so it is knowable for a model
|
|
117
|
+
# nobody has ever probed. Which LAYERS are fragile is not (Law 3; Mistral is early-fragile
|
|
118
|
+
# where its near-twin Qwen is late, a 25x error if you guess).
|
|
119
|
+
#
|
|
120
|
+
# This registry exists because we shipped that bug: hybrid SSM architectures name their
|
|
121
|
+
# recurrent-state tensors ssm_*, our protection pattern only matched attn_*, and every SSM
|
|
122
|
+
# tensor silently landed at the aggressive base level (fixed in v1.6.4, cost -24% ppl).
|
|
123
|
+
# Anything unrecognised is now REPORTED rather than silently compressed.
|
|
124
|
+
TENSOR_ROLES = [
|
|
125
|
+
("routed-expert", r"ffn_(gate|up|down)_exps", "compressible: ~8 of N experts fire per token"),
|
|
126
|
+
("shared-expert", r"ffn_.*_shexp", "ALWAYS ACTIVE on every token - protect"),
|
|
127
|
+
("attention", r"attn_", "ALWAYS ACTIVE - protect"),
|
|
128
|
+
("recurrent/SSM", r"ssm_", "ALWAYS ACTIVE - protect"),
|
|
129
|
+
("embedding", r"(token_embd|output\.)", "ALWAYS ACTIVE - protect"),
|
|
130
|
+
("mtp-head", r"nextn", "ALWAYS ACTIVE when MTP is on - protect"),
|
|
131
|
+
("router", r"ffn_gate_inp", "tiny, kept at full precision"),
|
|
132
|
+
("norm", r"(_norm|norm\.)", "tiny, kept at full precision"),
|
|
133
|
+
("dense-ffn", r"ffn_(gate|up|down)\.", "dense FFN - the depth-aware band applies here"),
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def tensor_roles(path):
|
|
138
|
+
"""Classify a GGUF's tensors by role. Returns (roles, unknown) with byte totals, so the
|
|
139
|
+
builder can warn about weight classes it has no protection rule for."""
|
|
140
|
+
import re
|
|
141
|
+
from gguf import GGUFReader
|
|
142
|
+
r = GGUFReader(path)
|
|
143
|
+
roles, unknown = {}, {}
|
|
144
|
+
for t in r.tensors:
|
|
145
|
+
nbytes = int(t.n_bytes) if hasattr(t, "n_bytes") else 0
|
|
146
|
+
for name, pat, _ in TENSOR_ROLES:
|
|
147
|
+
if re.search(pat, t.name):
|
|
148
|
+
roles[name] = roles.get(name, 0) + nbytes
|
|
149
|
+
break
|
|
150
|
+
else:
|
|
151
|
+
key = re.sub(r"blk\.\d+\.", "", t.name)
|
|
152
|
+
unknown[key] = unknown.get(key, 0) + nbytes
|
|
153
|
+
return roles, unknown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantprobe
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.17.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
|
|
@@ -118,7 +118,7 @@ Copyability is the whole mechanism: code answers repeat their input, prose inven
|
|
|
118
118
|
## When quantprobe won't help you
|
|
119
119
|
|
|
120
120
|
- **Your model already fits comfortably in VRAM at 4 bits or more.** Community quants are near-lossless there, and — measured — quantizing further buys almost no speed once a model is resident: the same 7B at Q2_K vs Q4_K_M is 36% smaller and **4% slower**. Quantize to make a model *fit*; once it fits, stop.
|
|
121
|
-
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it.
|
|
121
|
+
- **You want a tight number for a model that fits entirely in VRAM.** This is the placement the law knows least well, and the ±25% band above does **not** apply to it. We do not have a point prediction for it, and we would rather say so than quote a number wearing a band too wide to mean anything. What we can state is **one-sided and exception-free**: across 8 models and 13 benchmarks, real speed was **≥ 0.90× the printed number every single time**, and in 12 of the 13 it was strictly higher — typically 1.1×–1.8×. That is a falsifiable claim with the same logical form as our ±25% band, just asymmetric: one measurement below 0.90× kills it. We have refuted six candidate explanations for the gap, including our own favourites: it is not fixed overhead, not GPU clock state, not bytes-per-token, not monotone in bit-width, not a per-format constant, and not a bytes-weighted mixture of the actual tensor types. Within a single architecture it moves cleanly with the dominant tensor type; across architectures it does not transfer. We would rather publish that than move a constant on thin evidence. **This is the single most useful thing you can send us:** `quantprobe bench --contribute` on a GPU-resident model turns your machine into the datapoint that fixes it.
|
|
122
122
|
- **You need task-level eval scores** (MMLU, HellaSwag). quantprobe measures perplexity and KL divergence only.
|
|
123
123
|
- **Your architecture isn't in the fragility atlas** (four families so far). The probe still works on your model; the published priors just won't apply. *Open an issue with your result — those are the most valuable datapoints.*
|
|
124
124
|
- **You want multi-token prediction modeled in the planner.** It isn't. Measured, the effect runs from **+17% (dense, GPU-resident) to −24% (MoE, experts in RAM)** — there's no single multiplier to apply. [Full 2×2 →](preregistrations/2026-07-24-law6-speculation-economics.md)
|
|
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
|