quantprobe 1.6.5__tar.gz → 1.8.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.
Files changed (28) hide show
  1. {quantprobe-1.6.5/quantprobe.egg-info → quantprobe-1.8.0}/PKG-INFO +4 -2
  2. {quantprobe-1.6.5 → quantprobe-1.8.0}/README.md +3 -1
  3. {quantprobe-1.6.5 → quantprobe-1.8.0}/pyproject.toml +1 -1
  4. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/__init__.py +1 -1
  5. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/auto.py +7 -4
  6. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/cli.py +4 -0
  7. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/optimize.py +2 -1
  8. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/plan.py +45 -4
  9. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/probe.py +47 -4
  10. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/runtime.py +1 -1
  11. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/spec.py +2 -0
  12. {quantprobe-1.6.5 → quantprobe-1.8.0/quantprobe.egg-info}/PKG-INFO +4 -2
  13. {quantprobe-1.6.5 → quantprobe-1.8.0}/LICENSE +0 -0
  14. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/__main__.py +0 -0
  15. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/dashboard.py +0 -0
  16. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/detect.py +0 -0
  17. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/fetch.py +0 -0
  18. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe/target.py +0 -0
  19. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe.egg-info/SOURCES.txt +0 -0
  20. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe.egg-info/dependency_links.txt +0 -0
  21. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe.egg-info/entry_points.txt +0 -0
  22. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe.egg-info/requires.txt +0 -0
  23. {quantprobe-1.6.5 → quantprobe-1.8.0}/quantprobe.egg-info/top_level.txt +0 -0
  24. {quantprobe-1.6.5 → quantprobe-1.8.0}/setup.cfg +0 -0
  25. {quantprobe-1.6.5 → quantprobe-1.8.0}/tests/test_engine.py +0 -0
  26. {quantprobe-1.6.5 → quantprobe-1.8.0}/tests/test_evaluator.py +0 -0
  27. {quantprobe-1.6.5 → quantprobe-1.8.0}/tests/test_pipeline.py +0 -0
  28. {quantprobe-1.6.5 → quantprobe-1.8.0}/tests/test_transforms.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantprobe
3
- Version: 1.6.5
3
+ Version: 1.8.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
@@ -69,6 +69,8 @@ Add to that: a **byte-identical control** (two GGUFs the same size, 2.25 ppl apa
69
69
 
70
70
  **Open pre-registrations** — predictions staked publicly *before* measurement: [colibri v1.1, five falsifiable predictions (2026-07-23)](preregistrations/2026-07-23-colibri-v1.1.md) — dual-SSD scaling, int3 speedup, lattice-vs-scalar, AVX-512 tier-scoping, MTP×MoE antagonism — plus open bands on the CPU-only context slope and expert-pruning decode ([all verdicts](preregistrations/)).
71
71
 
72
+ **Recipe head-to-head, published in full:** [#11](preregistrations/2026-07-25-apex-vs-probe-depthaware.md) tested my depth-aware build against mudler's APEX at matched bytes and **I lost** (+8.9%); [#12](preregistrations/2026-07-25-recipe-upgrade-shexp-imatrix.md) fixed what it exposed and won the rematch by 1.1% — with the calibration caveat stated *before* measuring, because the win is in-domain and does not generalize as published. Both are scored in the open, loss first.
73
+
72
74
  **Live research track — Law 5 (prefill):** protocol-first and scored same-day in [weights/LAW5_PROTOCOL.md](weights/LAW5_PROTOCOL.md) — 6 staked hits, 4 published misses, and one self-caught retraction corrected in public within the hour, including the measured recipe that cuts an agent's 8k-context turn cost from ~75 s to ~0.5 s. Next up, staked before launch: [Law 6 — speculation economics](preregistrations/2026-07-24-law6-speculation-economics.md), scoring in public the week of 2026-07-27.
73
75
 
74
76
 
@@ -142,7 +144,7 @@ The loop is self-validating: `plan` predicted 17.5 for a file we then measured a
142
144
 
143
145
  ## Credits
144
146
 
145
- [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day.
147
+ [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day. The v1.7 recipe upgrade came the same way: **u/MoneroApe** (Reddit) pointed me at [apex-quant](https://github.com/localai-org/apex-quant) and TurboQuant, and testing my recipe against **mudler's APEX** exposed two real gaps in mine — unprotected always-active tensors (their kurtosis argument, adopted here) and no importance-matrix calibration at all. Their work made this tool measurably better; the head-to-head and its scope limits are published in full.
146
148
 
147
149
  ## License
148
150
 
@@ -51,6 +51,8 @@ Add to that: a **byte-identical control** (two GGUFs the same size, 2.25 ppl apa
51
51
 
52
52
  **Open pre-registrations** — predictions staked publicly *before* measurement: [colibri v1.1, five falsifiable predictions (2026-07-23)](preregistrations/2026-07-23-colibri-v1.1.md) — dual-SSD scaling, int3 speedup, lattice-vs-scalar, AVX-512 tier-scoping, MTP×MoE antagonism — plus open bands on the CPU-only context slope and expert-pruning decode ([all verdicts](preregistrations/)).
53
53
 
54
+ **Recipe head-to-head, published in full:** [#11](preregistrations/2026-07-25-apex-vs-probe-depthaware.md) tested my depth-aware build against mudler's APEX at matched bytes and **I lost** (+8.9%); [#12](preregistrations/2026-07-25-recipe-upgrade-shexp-imatrix.md) fixed what it exposed and won the rematch by 1.1% — with the calibration caveat stated *before* measuring, because the win is in-domain and does not generalize as published. Both are scored in the open, loss first.
55
+
54
56
  **Live research track — Law 5 (prefill):** protocol-first and scored same-day in [weights/LAW5_PROTOCOL.md](weights/LAW5_PROTOCOL.md) — 6 staked hits, 4 published misses, and one self-caught retraction corrected in public within the hour, including the measured recipe that cuts an agent's 8k-context turn cost from ~75 s to ~0.5 s. Next up, staked before launch: [Law 6 — speculation economics](preregistrations/2026-07-24-law6-speculation-economics.md), scoring in public the week of 2026-07-27.
55
57
 
56
58
 
@@ -124,7 +126,7 @@ The loop is self-validating: `plan` predicted 17.5 for a file we then measured a
124
126
 
125
127
  ## Credits
126
128
 
127
- [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day.
129
+ [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day. The v1.7 recipe upgrade came the same way: **u/MoneroApe** (Reddit) pointed me at [apex-quant](https://github.com/localai-org/apex-quant) and TurboQuant, and testing my recipe against **mudler's APEX** exposed two real gaps in mine — unprotected always-active tensors (their kurtosis argument, adopted here) and no importance-matrix calibration at all. Their work made this tool measurably better; the head-to-head and its scope limits are published in full.
128
130
 
129
131
  ## License
130
132
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quantprobe"
7
- version = "1.6.5"
7
+ version = "1.8.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.6.5"
11
+ __version__ = "1.8.0"
@@ -164,7 +164,7 @@ def run(a):
164
164
  if bits < 1.0 or bits > 9:
165
165
  continue
166
166
  _, _, cfgs = planmod.evaluate(t, ac, ne, moe, bits, vc, vb, rc, rb, db, geta, 1.0, gl,
167
- ctx=ctx, kvp=kvp)
167
+ ctx=ctx, kvp=kvp, n_layer=getattr(a, "n_layer", None))
168
168
  cfgs = [c for c in cfgs if "expert cache" not in c[0]]
169
169
  if not cfgs:
170
170
  continue
@@ -199,8 +199,9 @@ def run(a):
199
199
  dest = getattr(a, "dir", None) or "./models"
200
200
  os.makedirs(dest, exist_ok=True)
201
201
  print("\n[quantprobe auto --custom] source: " + spath + f" ({ssize/1e9:.1f} GB, {sbits:.1f}-bit)")
202
- print(" pipeline: fetch source -> probe the fragile band (~30-60 min) -> build the")
203
- print(" depth-aware GGUF. Interrupt anytime; the fetch resumes.")
202
+ cal = "skipped (--no-imatrix)" if getattr(a, "no_imatrix", False) else "calibrate (importance matrix)"
203
+ print(f" pipeline: fetch source -> probe the fragile band (~30-60 min) -> {cal} -> build")
204
+ print(" the depth-aware GGUF. Interrupt anytime; the fetch resumes.")
204
205
  if getattr(a, "dry", False):
205
206
  print(" (--dry: nothing downloaded)")
206
207
  return spath
@@ -214,7 +215,9 @@ def run(a):
214
215
  out = os.path.join(dest, os.path.basename(spath).rsplit(".gguf", 1)[0] + "-depthaware.gguf")
215
216
  pa = argparse.Namespace(gguf=srcfull, bands=4, chunks=32, eval=evalf, ngl=99,
216
217
  workdir=dest, llama_dir=getattr(a, "llama_dir", None),
217
- apply=True, out=out, dry_run=False)
218
+ apply=True, out=out, dry_run=False,
219
+ imatrix=None if getattr(a, "no_imatrix", False) else "auto",
220
+ imatrix_chunks=100)
218
221
  probemod.run(pa)
219
222
  print("\n[quantprobe auto --custom] your personalized model:")
220
223
  print(" quantprobe run --gguf " + out)
@@ -27,6 +27,8 @@ def main():
27
27
  p.add_argument("--llama-dir", default=None, help="dir containing llama-quantize/llama-perplexity")
28
28
  p.add_argument("--apply", action="store_true", help="after probing, BUILD the recommended depth-aware GGUF")
29
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)")
30
32
  p.add_argument("--dry-run", action="store_true")
31
33
 
32
34
  q = sub.add_parser("plan", help="evaluate every bit/tier placement, predict tok/s (Law 4)")
@@ -81,6 +83,7 @@ def main():
81
83
  z.add_argument("--out", default=None, help="output path (default: <model>-depthaware.gguf)")
82
84
  z.add_argument("--protect-late", type=int, default=12, help="protect the last N layers at 4-bit (default 12)")
83
85
  z.add_argument("--protect", default=None, help="protect an explicit band LO-HI (e.g. 36-47) instead of --protect-late")
86
+ z.add_argument("--imatrix", default=None, help="importance-matrix file (build one with `probe --imatrix auto`); improves quality at zero size cost")
84
87
  z.add_argument("--llama-dir", default=None)
85
88
  z.add_argument("--dry", action="store_true")
86
89
 
@@ -101,6 +104,7 @@ def main():
101
104
  au.add_argument("--max-quality", type=float, default=None)
102
105
  au.add_argument("--allow-prune", action="store_true"); au.add_argument("--any-runtime", action="store_true")
103
106
  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)")
107
+ au.add_argument("--no-imatrix", action="store_true", help="skip importance-matrix calibration in --custom (faster build, measurably worse quality)")
104
108
  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")
105
109
  au.add_argument("--serve", action="store_true", help="with --run: llama-server instead of chat")
106
110
  au.add_argument("--extra", default=None)
@@ -85,7 +85,8 @@ def run(a):
85
85
  if q > maxq:
86
86
  continue
87
87
  _, _, cfgs = planmod.evaluate(t * pf, ac, ne, moe, bits, vc, vb, rc2, rb, db2,
88
- geta, 1.0, gl, ctx=ctx, kvp=kvp * kf)
88
+ geta, 1.0, gl, ctx=ctx, kvp=kvp * kf,
89
+ n_layer=getattr(a, "n_layer", None) or m.get("nl"))
89
90
  if not cfgs:
90
91
  continue
91
92
  if not getattr(a, "any_runtime", False):
@@ -12,8 +12,8 @@ from __future__ import annotations
12
12
  # [est] otherwise. MLA models (deepseek) cache the compressed latent -> ~10x smaller: placement's
13
13
  # context story differs per architecture, which is why this is per-model, not a constant.
14
14
  MODELS = {
15
- "qwen3-30b": dict(t=30.5, a=3.3, ne=1.2, moe=True, kvp=98304, hint="Qwen3-30B-A3B"), # 48L x 4KV x 128d (exact; calibration anchor)
16
- "deepseek-16b": dict(t=15.7, a=2.4, ne=1.3, moe=True, kvp=31104, hint="DeepSeek-V2-Lite"), # MLA: 27L x (512+64) latent (exact)
15
+ "qwen3-30b": dict(t=30.5, a=3.3, ne=1.2, moe=True, kvp=98304, nl=48, hint="Qwen3-30B-A3B"), # 48L x 4KV x 128d (exact; calibration anchor)
16
+ "deepseek-16b": dict(t=15.7, a=2.4, ne=1.3, moe=True, kvp=31104, nl=27, hint="DeepSeek-V2-Lite"), # MLA: 27L x (512+64) latent (exact)
17
17
  "gemma-12b": dict(t=11.9, a=11.9, ne=11.9, moe=False, kvp=65536, hint="Gemma 4 12B"), # [est] SWA: long-ctx slope from global layers only
18
18
  "mistral-7b": dict(t=7.2, a=7.2, ne=7.2, moe=False, kvp=131072, hint="Mistral 7B"), # 32L x 8KV x 128d (exact)
19
19
  "glm-air": dict(t=110, a=12, ne=2.7, moe=True, kvp=94208, hint="GLM-4.5-Air 106B"), # [est]
@@ -23,6 +23,10 @@ MODELS = {
23
23
  "gpt-oss-120b": dict(t=120.4, a=5.1, ne=1.8, moe=True, kvp=73728, hint="gpt-oss-120b"), # total+active official; kvp: 36L x 8KV x 64d [est]
24
24
  "llama-70b": dict(t=70.6, a=70.6, ne=70.6, moe=False, kvp=327680, hint="Llama-3.3-70B"), # dense; kvp: 80L x 8KV x 128d
25
25
  }
26
+ DESKTOP_VRAM_RESERVE = 1.0 # GB held by the OS/desktop on a real machine, not the model's to use.
27
+ # Measured 0.8-1.5 GB on this box (pre-registration #13 sweep).
28
+ # Applied ONLY to the new MoE split row: existing rows keep their
29
+ # published anchors untouched.
26
30
  DEFAULT_KVP = 98304 # custom models without --kv-per-pos: typical GQA mid-size (Qwen3-30B class)
27
31
  ETA_KV = 0.70 # KV-read efficiency. Single-point calibration: measured tg32 d0->d16384
28
32
  # 20.02 -> 16.12 on Qwen3-30B (+12.1 ms/token = 133 GB/s effective on the
@@ -77,7 +81,18 @@ QUAL = {True: {2.0: 1.10, 2.5: 1.07, 3.0: 1.05, 4.5: 1.02, 6.5: 1.01, 8.5: 1.00
77
81
  False: {2.0: 1.45, 2.5: 1.30, 3.0: 1.12, 4.5: 1.03, 6.5: 1.01, 8.5: 1.00}}
78
82
 
79
83
 
80
- def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=None, ctx=0, kvp=0.0):
84
+ def moe_split_flags(frac, n_layer):
85
+ """-ot regex placing the FIRST ceil(frac*L) layers' experts on GPU, the rest on CPU.
86
+ Measured 2026-07-26 (pre-registration #13): +34.7% decode and ~2-3x prefill on a 6 GB card.
87
+ Returns None when the layer count is unknown - we will not emit a regex we cannot ground."""
88
+ if not n_layer or frac <= 0:
89
+ return None
90
+ k = max(1, min(n_layer - 1, int(frac * n_layer)))
91
+ return '-ngl 99 -ot "blk\\.(%s)\\.ffn_.*_exps\\.=CPU"' % "|".join(str(i) for i in range(k, n_layer))
92
+
93
+
94
+ def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=None, ctx=0, kvp=0.0,
95
+ n_layer=None):
81
96
  ab = max(bits, 4.5) # attention protected at ~4-bit (Law 3 recipes)
82
97
  size = (ne * ab / 8 + (t - ne) * bits / 8) * 1.08 * act_scale
83
98
  act_ne = ne * ab / 8 * 1.15 * act_scale
@@ -102,6 +117,28 @@ def evaluate(t, a, ne, moe, bits, vc, vb, rc, rb, db, geta, act_scale=1.0, gl=No
102
117
  out.append(("hybrid: attention->VRAM, experts->RAM",
103
118
  1 / (act_ne / (geta * vb) + act_ex / (eta_r * rb) + kv_gb / (ETA_KV * vb)), warn,
104
119
  '-ngl 99 -ot "exps=CPU" --no-mmap'))
120
+ # MoE partial expert offload: attention+KV in VRAM, then as many EXPERT layers as still
121
+ # fit, remainder on CPU. Measured pre-registration #13 (2026-07-26): +34.7% decode,
122
+ # ~2-3x prefill vs all-experts-to-CPU, with a hard CLIFF on overcommit (-29% at one step
123
+ # past the ceiling) - so the free-VRAM headroom is deliberately conservative.
124
+ # Desktop reserve: a real machine is not an empty GPU. Measured on this box during the
125
+ # pre-registration #13 sweep: Explorer + compositor + browser held 0.8-1.5 GB throughout.
126
+ # Overshooting the cutoff costs -29% (measured cliff), undershooting costs a few percent,
127
+ # so the asymmetry is deliberately resolved toward caution.
128
+ v_free = vc * 0.90 - v_need - DESKTOP_VRAM_RESERVE
129
+ experts_gb = size - ne * ab / 8 * 1.08
130
+ if v_free > 0.3 and experts_gb > 0:
131
+ f = min(1.0, v_free / experts_gb)
132
+ ram_left = experts_gb * (1 - f)
133
+ if f > 0.05 and ram_left <= ra:
134
+ t_split = (act_ne / (geta * vb) + f * act_ex / (geta * vb)
135
+ + (1 - f) * act_ex / (eta_r * rb) + kv_gb / (ETA_KV * vb))
136
+ fl = moe_split_flags(f, n_layer)
137
+ # Only offer it if we can emit the EXACT command. Advertising a speed the
138
+ # printed flags cannot deliver is the v1.6.5 bug class; without a layer count
139
+ # the row is suppressed and the footer tells the user how to unlock it.
140
+ if fl:
141
+ out.append((f"split experts: {f:.0%}->VRAM, rest->RAM", 1 / t_split, None, fl))
105
142
  if (not moe) and vc > 0 and size + kv_gb > vc * 0.90 and size + kv_gb <= ra + vc * 0.9:
106
143
  g = min(0.95, vc * 0.9 / (size + kv_gb)) # KV splits with its layers
107
144
  kv_t = g * kv_gb / (ETA_KV * vb) + (1 - g) * kv_gb / (ETA_KV * rb)
@@ -201,7 +238,8 @@ def run(args):
201
238
  kvp = (args.kv_per_pos * 1024 if getattr(args, "kv_per_pos", None)
202
239
  else m.get("kvp", DEFAULT_KVP))
203
240
 
204
- size, act, cfgs = evaluate(t, a, ne, moe, args.bits, vc, vb, rc, rb, db, geta, gl=gl, ctx=ctx, kvp=kvp)
241
+ nlay = getattr(args, 'n_layer', None) or m.get('nl') # 'nl' = layer count VERIFIED from a real GGUF
242
+ size, act, cfgs = evaluate(t, a, ne, moe, args.bits, vc, vb, rc, rb, db, geta, gl=gl, ctx=ctx, kvp=kvp, n_layer=nlay)
205
243
  q = qual_of(moe, args.bits)
206
244
  print(f"\nquantprobe plan - {m.get('hint', 'custom model')} @ {args.bits:g}-bit "
207
245
  f"on {hw.get('hint', 'custom machine')}")
@@ -245,5 +283,8 @@ def run(args):
245
283
  print(f" tier-boundary advisor: this config is {gap:.1f} GB over the {tier_name} boundary - "
246
284
  f"shave it ({lever}) -> ~{promoted[0][1]:.1f} tok/s (x{promoted[0][1]/best[1]:.1f})")
247
285
  break # nearest boundary only
286
+ if moe and vc > 0 and getattr(args, "n_layer", None) is None:
287
+ print("\n note: MoE partial expert offload (measured +34.7% decode, ~2-3x prefill) needs this\n"
288
+ " model's layer count to emit exact -ot flags - re-run with --gguf <file> to unlock it.")
248
289
  print("\n (eta bands fitted from published measurements; estimates +/-25%. "
249
290
  "Hybrid needs --no-mmap.)")
@@ -114,8 +114,12 @@ def run(a):
114
114
  f' {os.path.basename(a.gguf)} out-depthaware.gguf Q2_K 8', flush=True)
115
115
  if getattr(a, "apply", False):
116
116
  out = a.out or os.path.splitext(a.gguf)[0] + "-depthaware.gguf"
117
+ imat = getattr(a, "imatrix", None)
118
+ if imat == "auto":
119
+ imat = make_imatrix(a.llama_dir, a.gguf, a.eval, chunks=getattr(a, "imatrix_chunks", 100),
120
+ ngl=a.ngl, dry=a.dry_run)
117
121
  print("\n[quantprobe] --apply: building the recommended GGUF now...", flush=True)
118
- build_depthaware(a.llama_dir, a.gguf, out, lo, hi, bands[-1][1] + 1, dry=a.dry_run)
122
+ build_depthaware(a.llama_dir, a.gguf, out, lo, hi, bands[-1][1] + 1, dry=a.dry_run, imatrix=imat)
119
123
  else:
120
124
  print("\n (re-run with --apply --out model-2bit.gguf to BUILD this GGUF automatically)", flush=True)
121
125
 
@@ -125,11 +129,19 @@ def _band_re(lo, hi):
125
129
 
126
130
 
127
131
  def build_depthaware(llama_dir, src, out, protect_lo, protect_hi, n_lay,
128
- base="Q2_K", protect="q4_k", dry=False):
129
- """Actually PRODUCE the compressed GGUF: base bits everywhere, fragile band + attention + embed protected."""
132
+ base="Q2_K", protect="q4_k", dry=False, imatrix=None):
133
+ """Actually PRODUCE the compressed GGUF: base bits everywhere, fragile band + attention +
134
+ embed + always-active tensors protected; optional importance-matrix calibration."""
130
135
  # --dry previews the exact command WITHOUT requiring llama.cpp installed
131
136
  q = exe("llama-quantize") if dry else os.path.join(find_llama(llama_dir), exe("llama-quantize"))
132
137
  cmd = [q, "--allow-requantize"]
138
+ if imatrix:
139
+ cmd += ["--imatrix", imatrix]
140
+ # ALWAYS-ACTIVE tensors first: llama.cpp resolves --tensor-type first-match-wins (verified
141
+ # 2026-07-25), so this must precede the band rules or it silently does nothing. The shared
142
+ # expert fires on EVERY token (routed experts fire ~8/256) and is heavy-tailed: measured
143
+ # -3.2% ppl when protected at q8_0, for ~0.65% more bytes (pre-registration #12).
144
+ cmd += ["--tensor-type", "ffn_.*_shexp.*=q8_0"]
133
145
  if protect_lo > 0:
134
146
  cmd += ["--tensor-type", f"{_band_re(0, protect_lo - 1)}=q2_k"]
135
147
  if protect_hi < n_lay - 1:
@@ -150,6 +162,32 @@ def build_depthaware(llama_dir, src, out, protect_lo, protect_hi, n_lay,
150
162
  return out
151
163
 
152
164
 
165
+ def make_imatrix(llama_dir, src, eval_file, out=None, chunks=100, ngl=99, dry=False):
166
+ """Generate an importance matrix: measured -8.5% ppl at ~3 bits, at zero size and speed
167
+ cost (pre-registration #12). The single largest quality lever in the recipe.
168
+
169
+ The calibration corpus should NOT be your evaluation text - calibrating on the same data
170
+ you score against inflates the result. Wikitext TRAIN is used against a wikitext TEST eval.
171
+ """
172
+ out = out or os.path.splitext(src)[0] + ".imatrix.gguf"
173
+ if os.path.isfile(out):
174
+ print(f"[quantprobe] reusing existing imatrix: {out}")
175
+ return out
176
+ im = exe("llama-imatrix") if dry else os.path.join(find_llama(llama_dir), exe("llama-imatrix"))
177
+ cmd = [im, "-m", src, "-f", eval_file, "-o", out, "--chunks", str(chunks), "-ngl", str(ngl), "-c", "512"]
178
+ print(f"[quantprobe] building importance matrix over {chunks} chunks "
179
+ f"(one pass; slow on big models, but worth ~8% quality for free)")
180
+ print(" $ " + " ".join(cmd))
181
+ if dry:
182
+ return out
183
+ rc = subprocess.call(cmd)
184
+ if rc != 0 or not os.path.isfile(out):
185
+ print(f"[quantprobe] imatrix generation failed (exit {rc}); continuing WITHOUT calibration.")
186
+ return None
187
+ print(f"[quantprobe] imatrix ready -> {out} ({os.path.getsize(out)/1e6:.0f} MB)")
188
+ return out
189
+
190
+
153
191
  def quantize(a):
154
192
  """Standalone compress: build a depth-aware GGUF from an explicit band (no probing)."""
155
193
  if not os.path.isfile(a.gguf):
@@ -160,4 +198,9 @@ def quantize(a):
160
198
  else:
161
199
  lo, hi = n_lay - a.protect_late, n_lay - 1
162
200
  out = a.out or os.path.splitext(a.gguf)[0] + "-depthaware.gguf"
163
- build_depthaware(a.llama_dir, a.gguf, out, lo, hi, n_lay, dry=getattr(a, "dry", False))
201
+ imat = getattr(a, "imatrix", None)
202
+ if imat and not os.path.isfile(imat) and not getattr(a, "dry", False):
203
+ raise SystemExit(f"--imatrix file not found: {imat}\n"
204
+ " generate one first, or drop the flag to build without calibration.")
205
+ build_depthaware(a.llama_dir, a.gguf, out, lo, hi, n_lay,
206
+ dry=getattr(a, "dry", False), imatrix=imat)
@@ -65,7 +65,7 @@ def best_flags(a):
65
65
  kvp = (a.kv_per_pos * 1024 if getattr(a, "kv_per_pos", None)
66
66
  else m.get("kvp", planmod.DEFAULT_KVP))
67
67
  _, _, cfgs = planmod.evaluate(t, ac, ne, moe, a.bits, vc, vb, rc, rb, db, geta, act_scale, gl,
68
- ctx=ctx, kvp=kvp)
68
+ ctx=ctx, kvp=kvp, n_layer=getattr(a, "n_layer", None))
69
69
  # run/bench/dashboard LAUNCH stock llama.cpp, so they may only pick placements stock
70
70
  # llama.cpp can actually execute. The three-tier expert-cache row's "flags" field is a
71
71
  # PROSE description ("+ runtime-managed expert cache"), not argv - exec'ing it hands
@@ -84,6 +84,8 @@ def apply(a, quiet=False):
84
84
  a.bits = s["bits"]; used.append(f"{s['bits']:g} effective bits")
85
85
  if getattr(a, "kv_per_pos", None) is None:
86
86
  a.kv_per_pos = s["kvp"] / 1024; used.append(f"KV {s['kvp']/1024:.0f} KB/pos")
87
+ if getattr(a, "n_layer", None) is None:
88
+ a.n_layer = s["n_layer"] # enables the MoE partial-offload -ot regex (needs real layer indices)
87
89
  if used and not quiet:
88
90
  print(f"[quantprobe] read from GGUF: " + ", ".join(used))
89
91
  return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantprobe
3
- Version: 1.6.5
3
+ Version: 1.8.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
@@ -69,6 +69,8 @@ Add to that: a **byte-identical control** (two GGUFs the same size, 2.25 ppl apa
69
69
 
70
70
  **Open pre-registrations** — predictions staked publicly *before* measurement: [colibri v1.1, five falsifiable predictions (2026-07-23)](preregistrations/2026-07-23-colibri-v1.1.md) — dual-SSD scaling, int3 speedup, lattice-vs-scalar, AVX-512 tier-scoping, MTP×MoE antagonism — plus open bands on the CPU-only context slope and expert-pruning decode ([all verdicts](preregistrations/)).
71
71
 
72
+ **Recipe head-to-head, published in full:** [#11](preregistrations/2026-07-25-apex-vs-probe-depthaware.md) tested my depth-aware build against mudler's APEX at matched bytes and **I lost** (+8.9%); [#12](preregistrations/2026-07-25-recipe-upgrade-shexp-imatrix.md) fixed what it exposed and won the rematch by 1.1% — with the calibration caveat stated *before* measuring, because the win is in-domain and does not generalize as published. Both are scored in the open, loss first.
73
+
72
74
  **Live research track — Law 5 (prefill):** protocol-first and scored same-day in [weights/LAW5_PROTOCOL.md](weights/LAW5_PROTOCOL.md) — 6 staked hits, 4 published misses, and one self-caught retraction corrected in public within the hour, including the measured recipe that cuts an agent's 8k-context turn cost from ~75 s to ~0.5 s. Next up, staked before launch: [Law 6 — speculation economics](preregistrations/2026-07-24-law6-speculation-economics.md), scoring in public the week of 2026-07-27.
73
75
 
74
76
 
@@ -142,7 +144,7 @@ The loop is self-validating: `plan` predicted 17.5 for a file we then measured a
142
144
 
143
145
  ## Credits
144
146
 
145
- [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day.
147
+ [colibri](https://github.com/JustVugg/colibri) (744B on 25 GB, pure C) inspired the tier-streaming exploration. The quantization stack builds on [llama.cpp](https://github.com/ggml-org/llama.cpp) and the QTIP/QuIP# incoherence codecs — whose central tool our first law bounds. Independent research by Federico Sciuca, AI-supported, on one desktop; every claim is measured, and every negative that redirected the work is documented. The Law 4 context term (v1.1) was prompted by **u/RogerAI--fyi** (Reddit), who correctly observed the original formulation omitted per-token KV reads — measured, confirmed, and shipped within a day. The v1.7 recipe upgrade came the same way: **u/MoneroApe** (Reddit) pointed me at [apex-quant](https://github.com/localai-org/apex-quant) and TurboQuant, and testing my recipe against **mudler's APEX** exposed two real gaps in mine — unprotected always-active tensors (their kurtosis argument, adopted here) and no importance-matrix calibration at all. Their work made this tool measurably better; the head-to-head and its scope limits are published in full.
146
148
 
147
149
  ## License
148
150
 
File without changes
File without changes