quantprobe 1.19.0__tar.gz → 1.20.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 (34) hide show
  1. {quantprobe-1.19.0/quantprobe.egg-info → quantprobe-1.20.0}/PKG-INFO +1 -1
  2. {quantprobe-1.19.0 → quantprobe-1.20.0}/pyproject.toml +1 -1
  3. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/__init__.py +1 -1
  4. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/calibrate.py +55 -16
  5. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/cli.py +4 -0
  6. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/plan.py +62 -24
  7. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/runtime.py +6 -0
  8. {quantprobe-1.19.0 → quantprobe-1.20.0/quantprobe.egg-info}/PKG-INFO +1 -1
  9. {quantprobe-1.19.0 → quantprobe-1.20.0}/LICENSE +0 -0
  10. {quantprobe-1.19.0 → quantprobe-1.20.0}/README.md +0 -0
  11. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/__main__.py +0 -0
  12. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/auto.py +0 -0
  13. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/dashboard.py +0 -0
  14. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/detect.py +0 -0
  15. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/fetch.py +0 -0
  16. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/optimize.py +0 -0
  17. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/probe.py +0 -0
  18. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/recipes/mistral-7b.json +0 -0
  19. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/recipes/qwen2.5-7b.json +0 -0
  20. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/recipes/qwen3-30b.json +0 -0
  21. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/recipes/qwen3.5-35b.json +0 -0
  22. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/recipes.py +0 -0
  23. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/spec.py +0 -0
  24. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe/target.py +0 -0
  25. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe.egg-info/SOURCES.txt +0 -0
  26. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe.egg-info/dependency_links.txt +0 -0
  27. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe.egg-info/entry_points.txt +0 -0
  28. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe.egg-info/requires.txt +0 -0
  29. {quantprobe-1.19.0 → quantprobe-1.20.0}/quantprobe.egg-info/top_level.txt +0 -0
  30. {quantprobe-1.19.0 → quantprobe-1.20.0}/setup.cfg +0 -0
  31. {quantprobe-1.19.0 → quantprobe-1.20.0}/tests/test_engine.py +0 -0
  32. {quantprobe-1.19.0 → quantprobe-1.20.0}/tests/test_evaluator.py +0 -0
  33. {quantprobe-1.19.0 → quantprobe-1.20.0}/tests/test_pipeline.py +0 -0
  34. {quantprobe-1.19.0 → quantprobe-1.20.0}/tests/test_transforms.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantprobe
3
- Version: 1.19.0
3
+ Version: 1.20.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.19.0"
7
+ version = "1.20.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.19.0"
11
+ __version__ = "1.20.0"
@@ -84,7 +84,7 @@ def gpu_state():
84
84
  class ClockSampler:
85
85
  """Samples clocks.sm in a thread while a benchmark runs - the boost-state instrument."""
86
86
 
87
- def __init__(self, every=3.0):
87
+ def __init__(self, every=1.0):
88
88
  self.every, self.samples, self._stop = every, [], threading.Event()
89
89
  self._t = threading.Thread(target=self._loop, daemon=True)
90
90
 
@@ -104,9 +104,15 @@ class ClockSampler:
104
104
  self._t.join(timeout=5)
105
105
 
106
106
  def sustained(self):
107
- """Median SM MHz over loaded samples (>1000 MHz), or None."""
107
+ """Median SM MHz over loaded samples (>1000 MHz); None below 3 samples.
108
+
109
+ The minimum matters: a short benchmark gives the sampler only the model-LOAD phase,
110
+ where clocks sit mid-ramp - measured on the reference box as a false STUCK-BOOST verdict
111
+ (1506 read during load; the very next real benchmarks sustained 1873-1898). One or two
112
+ samples are a coin flip, not a diagnosis.
113
+ """
108
114
  loaded = sorted(s for s, _ in self.samples if s > 1000)
109
- return loaded[len(loaded) // 2] if loaded else None
115
+ return loaded[len(loaded) // 2] if len(loaded) >= 3 else None
110
116
 
111
117
 
112
118
  def boost_verdict(sustained, sm_max, temp):
@@ -125,25 +131,23 @@ def boost_verdict(sustained, sm_max, temp):
125
131
  "cards cannot reset it live: REBOOT, then re-run calibrate")
126
132
 
127
133
 
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
+ def _bench_anchor(model_path, ngl, metric_tokens, llama_dir=None):
135
+ """One llama-bench arm on the user's own file, clocks sampled. Returns (dict, err)."""
134
136
  from .runtime import find_llama
135
137
  try:
136
138
  binp = find_llama(llama_dir, "llama-bench")
137
139
  except SystemExit:
138
140
  return None, "llama-bench not found - anchor skipped (pass --llama-dir)"
141
+ tag = f"tg{metric_tokens}"
139
142
  with ClockSampler() as clk:
140
- out = _run([binp, "-m", model_path, "-ngl", "0", "-n", "32", "-p", "0", "-r", "1"],
141
- timeout=1800)
143
+ out = _run([binp, "-m", model_path, "-ngl", str(ngl), "-n", str(metric_tokens),
144
+ "-p", "0", "-r", "1"], timeout=1800)
142
145
  for line in out.splitlines():
143
- if "tg32" in line and "|" in line:
146
+ if tag in line and "|" in line:
144
147
  try:
145
148
  toks = float(line.split("|")[-2].strip().split()[0])
146
- return dict(placement="pure CPU (-ngl 0)", metric="tg32", tok_s=toks,
149
+ return dict(placement=("pure CPU (-ngl 0)" if ngl == 0 else "all-in-VRAM (-ngl 99)"),
150
+ metric=tag, tok_s=toks,
147
151
  model=os.path.basename(model_path),
148
152
  model_gb=round(os.path.getsize(model_path) / 1e9, 3),
149
153
  sustained_sm=clk.sustained()), None
@@ -152,6 +156,26 @@ def cpu_anchor(model_path, llama_dir=None):
152
156
  return None, "could not parse llama-bench output - anchor skipped"
153
157
 
154
158
 
159
+ def cpu_anchor(model_path, llama_dir=None):
160
+ """Pure-CPU tg32 on the user's own file: a real measured reference point.
161
+
162
+ Placement chosen because it needs no VRAM-fit logic and no MoE byte accounting - it is the
163
+ one arm that runs identically on every machine that can load the file at all.
164
+ """
165
+ return _bench_anchor(model_path, 0, 32, llama_dir)
166
+
167
+
168
+ def gpu_anchor(model_path, vram_gb, llama_dir=None):
169
+ """All-in-VRAM tg128 on the user's own file - the GPU-tier anchor. Only offered when the file
170
+ clearly fits (80% of detected VRAM), because an OOM teaches nothing and wastes minutes.
171
+ tg128 rather than tg64: the run must outlast the model-load phase by enough for the clock
172
+ sampler to collect real loaded samples (see ClockSampler.sustained)."""
173
+ gb = os.path.getsize(model_path) / 1e9
174
+ if not vram_gb or gb > 0.8 * vram_gb:
175
+ return None, f"model {gb:.1f} GB does not clearly fit {vram_gb or 0:.0f} GB VRAM - GPU anchor skipped"
176
+ return _bench_anchor(model_path, 99, 128, llama_dir)
177
+
178
+
155
179
  def load():
156
180
  """Return (calibration dict, age_days) or (None, None). Used by plan."""
157
181
  try:
@@ -189,19 +213,34 @@ def run(a):
189
213
  cal["disk_bw_measured"] = round(measure_disk(model), 2)
190
214
  print(f" disk: {cal['disk_bw_measured']:.2f} GB/s sequential on your file [measured]")
191
215
  if not getattr(a, "skip_bench", False):
216
+ cal["anchors"] = []
192
217
  print(" anchor: running llama-bench -ngl 0 tg32 on your file (1-10 min on big models)...")
193
218
  anchor, why = cpu_anchor(model, getattr(a, "llama_dir", None))
194
219
  if anchor:
195
- cal["anchors"] = [anchor]
220
+ cal["anchors"].append(anchor)
196
221
  print(f" anchor: {anchor['tok_s']:.2f} tok/s pure-CPU on "
197
222
  f"{anchor['model']} ({anchor['model_gb']:g} GB) [measured]")
198
- v = boost_verdict(anchor.get("sustained_sm"), st and st.get("sm_max"),
223
+ else:
224
+ print(f" anchor: {why}")
225
+ vram_gb = None
226
+ if st:
227
+ out = _run(["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"])
228
+ try:
229
+ vram_gb = float(out.strip().splitlines()[0]) / 1024
230
+ except (ValueError, IndexError):
231
+ pass
232
+ ganchor, gwhy = gpu_anchor(model, vram_gb, getattr(a, "llama_dir", None))
233
+ if ganchor:
234
+ cal["anchors"].append(ganchor)
235
+ print(f" anchor: {ganchor['tok_s']:.2f} tok/s all-in-VRAM on "
236
+ f"{ganchor['model']} [measured]")
237
+ v = boost_verdict(ganchor.get("sustained_sm"), st and st.get("sm_max"),
199
238
  st and st.get("temp"))
200
239
  if v:
201
240
  cal["boost_verdict"] = v
202
241
  print(f" GPU under load: {v}")
203
242
  else:
204
- print(f" anchor: {why}")
243
+ print(f" anchor: {gwhy}")
205
244
  elif model:
206
245
  print(f" --model: file not found: {model}")
207
246
  else:
@@ -45,6 +45,8 @@ def main():
45
45
  q.add_argument("--gguf", default=None, help="optional: read total/active/bits/KV exactly from this GGUF")
46
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
47
  q.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB (default: model preset, or 96)")
48
+ q.add_argument("--no-anchors", action="store_true",
49
+ help="ignore calibrate's anchor runs; use the plain law constants")
48
50
 
49
51
  def hwargs(sp):
50
52
  sp.add_argument("--model", default=None); sp.add_argument("--machine", default=None)
@@ -57,6 +59,8 @@ def main():
57
59
  sp.add_argument("--ctx", type=int, default=0, help="context depth for the prediction (Law 4 v2)")
58
60
  sp.add_argument("--kv-per-pos", type=float, default=None, help="KV bytes per position in KB")
59
61
  sp.add_argument("--llama-dir", default=None); sp.add_argument("--dry", action="store_true")
62
+ sp.add_argument("--no-anchors", action="store_true",
63
+ help="ignore calibrate's anchor runs; use the plain law constants")
60
64
 
61
65
  r = sub.add_parser("run", help="plan the best placement, then launch llama.cpp chat with those flags")
62
66
  r.add_argument("--gguf", required=True); hwargs(r)
@@ -676,6 +676,67 @@ def check_presets(args):
676
676
  " or pass flags: --vram/--vram-bw/--ram/--ram-bw/--disk-bw (no flags = auto-detect this box)" % (mac, ", ".join(sorted(MACHINES))))
677
677
 
678
678
 
679
+ def apply_calibration_overrides(hw, args):
680
+ """MEASURED beats spec-sheet, on this machine only - the ONE place calibration and anchors
681
+ touch the constants, shared by plan AND runtime.best_flags so the two commands can never
682
+ disagree about the same input again (the v1.10.5 bug class; layer 3 enforces it, and caught
683
+ this function's absence the same day the anchors shipped).
684
+
685
+ Calibration (rb/db): calibrate measures the DELIVERED stream; the law's constants were fitted
686
+ against theoretical-peak inputs on the reference box, whose measured stream was 26.1 of a
687
+ 48 GB/s peak (0.544). Expressing the user's measurement in the same peak-units keeps every
688
+ fitted eta valid. Assumption stated: stream-realism fraction is machine-similar.
689
+
690
+ Anchors (prereg #64, gate: LOO median error 19.0% -> 5.8%): each anchor becomes a TIER-LOCAL
691
+ ratio between what the anchor arm measured and what the law predicts for that same arm - the
692
+ ratio then scales that tier's bandwidth for every OTHER prediction. The target's own
693
+ measurement is never consulted (that would be a lookup, the #59 failure class). Ratios are
694
+ clamped 0.70-1.40; anchor models are dense, so dense etas price their arms; the clamp absorbs
695
+ anchor-format bias (L-16). `--no-anchors` disables.
696
+ """
697
+ from . import calibrate as calmod
698
+ cal, age = calmod.load()
699
+ if not cal:
700
+ return hw
701
+ applied = []
702
+ if cal.get("ram_bw_measured"):
703
+ hw["rb"] = round(cal["ram_bw_measured"] / 0.544)
704
+ applied.append(f"ram {cal['ram_bw_measured']:g} GB/s measured")
705
+ if cal.get("disk_bw_measured"):
706
+ hw["db"] = cal["disk_bw_measured"]
707
+ applied.append(f"disk {cal['disk_bw_measured']:g} GB/s measured")
708
+ if applied:
709
+ stale = f"; {age:.0f} days old - re-run `quantprobe calibrate`" if age and age > calmod.STALE_DAYS else ""
710
+ print(f"[quantprobe] calibration applied [{'; '.join(applied)}] ({cal.get('date','?')}{stale})")
711
+ if cal.get("boost_verdict") and "healthy" not in cal["boost_verdict"]:
712
+ print(f"[quantprobe] GPU health at last calibration: {cal['boost_verdict']}")
713
+ if not getattr(args, "no_anchors", False):
714
+ ratios = {}
715
+ for an in (cal.get("anchors") or []):
716
+ try:
717
+ gb_a, ts = float(an["model_gb"]), float(an["tok_s"])
718
+ if gb_a <= 0 or ts <= 0:
719
+ continue
720
+ if "pure CPU" in an.get("placement", ""):
721
+ pred = 0.62 * hw["rb"] / gb_a # dense CPU eta
722
+ ratios["cpu"] = max(0.70, min(1.40, ts / pred))
723
+ elif "all-in-VRAM" in an.get("placement", "") and hw.get("vb"):
724
+ pred = hw.get("geta", 0.45) * hw["vb"] / gb_a
725
+ ratios["gpu"] = max(0.70, min(1.40, ts / pred))
726
+ except (KeyError, TypeError, ValueError, ZeroDivisionError):
727
+ continue
728
+ if ratios:
729
+ if "cpu" in ratios:
730
+ hw["rb"] = hw["rb"] * ratios["cpu"]
731
+ if "gpu" in ratios:
732
+ hw["vb"] = hw["vb"] * ratios["gpu"]
733
+ print("[quantprobe] anchored: "
734
+ + ", ".join(f"{k.upper()} x{v:.2f}" for k, v in sorted(ratios.items()))
735
+ + " from your calibrate anchor runs [tier ratios, clamped 0.70-1.40;"
736
+ " --no-anchors disables]")
737
+ return hw
738
+
739
+
679
740
  def run(args):
680
741
  from . import spec as specmod
681
742
  specmod.apply(args)
@@ -697,30 +758,7 @@ def run(args):
697
758
  print("[quantprobe] no hardware flags: auto-detected this machine "
698
759
  f"(vram {hw['vc']:g}GB@{hw['vb']:g} | ram {hw['rc']:g}GB@{hw['rb']:g} | disk {hw['db']:g} GB/s). "
699
760
  "Pass --machine/flags to estimate a different box.")
700
- # calibration overrides detection: MEASURED beats spec-sheet, on this machine only.
701
- # Constants scoped deliberately (prereg #59: fitted constants do not transfer; measured
702
- # local ones are exactly what does). Delete ~/.quantprobe/calibration.json to disable.
703
- from . import calibrate as calmod
704
- cal, age = calmod.load()
705
- if cal:
706
- applied = []
707
- if cal.get("ram_bw_measured"):
708
- # calibrate measures the DELIVERED stream; the law's constants were fitted
709
- # against theoretical-peak inputs on the reference box, whose measured stream
710
- # was 26.1 of a 48 GB/s peak (0.544). Expressing the user's measurement in the
711
- # same peak-units keeps every fitted eta valid: peak_equiv = measured / 0.544.
712
- # Assumption stated: stream-realism fraction is machine-similar. Anchoring on a
713
- # measurement with one stated assumption beats assuming the peak outright.
714
- hw["rb"] = round(cal["ram_bw_measured"] / 0.544)
715
- applied.append(f"ram {cal['ram_bw_measured']:g} GB/s measured")
716
- if cal.get("disk_bw_measured"):
717
- hw["db"] = cal["disk_bw_measured"]
718
- applied.append(f"disk {cal['disk_bw_measured']:g} GB/s measured")
719
- if applied:
720
- stale = f"; {age:.0f} days old - re-run `quantprobe calibrate`" if age and age > calmod.STALE_DAYS else ""
721
- print(f"[quantprobe] calibration applied [{'; '.join(applied)}] ({cal.get('date','?')}{stale})")
722
- if cal.get("boost_verdict") and "healthy" not in cal["boost_verdict"]:
723
- print(f"[quantprobe] GPU health at last calibration: {cal['boost_verdict']}")
761
+ apply_calibration_overrides(hw, args)
724
762
  vc = hw.get("vc", args.vram); vb = hw.get("vb", args.vram_bw)
725
763
  rc = hw.get("rc", args.ram); rb = hw.get("rb", args.ram_bw)
726
764
  db = hw.get("db", args.disk_bw); geta = hw.get("geta", 0.45); gl = hw.get("gl", None)
@@ -45,6 +45,9 @@ def best_flags(a):
45
45
  db=auto["disk_bw"], geta=auto.get("geta", 0.45), gl=auto.get("gl"))
46
46
  print("[quantprobe] hardware auto-detected (run `quantprobe hw` for details; "
47
47
  "pass --machine/flags to estimate a different box)")
48
+ # the SAME calibration+anchor path plan uses - one function, so the commands can
49
+ # never disagree about the same input (v1.10.5 bug class; layer 3 enforces this)
50
+ planmod.apply_calibration_overrides(hw, a)
48
51
  vc = planmod.agg_cap(a.vram) if a.vram is not None else hw.get("vc", 0)
49
52
  vb = planmod.agg_bw(a.vram_bw, 0.85) if a.vram_bw is not None else hw.get("vb", 0)
50
53
  rc = a.ram if a.ram is not None else hw.get("rc", 16)
@@ -188,6 +191,9 @@ def tier_view(a, best):
188
191
  db=auto["disk_bw"], geta=auto.get("geta", 0.45), gl=auto.get("gl"))
189
192
  print("[quantprobe] hardware auto-detected (run `quantprobe hw` for details; "
190
193
  "pass --machine/flags to estimate a different box)")
194
+ # the SAME calibration+anchor path plan uses - one function, so the commands can
195
+ # never disagree about the same input (v1.10.5 bug class; layer 3 enforces this)
196
+ planmod.apply_calibration_overrides(hw, a)
191
197
  vc = planmod.agg_cap(a.vram) if a.vram is not None else hw.get("vc", 0)
192
198
  rc = a.ram if a.ram is not None else hw.get("rc", 16)
193
199
  size = os.path.getsize(a.gguf) / 1e9 if a.gguf and os.path.isfile(a.gguf) else 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantprobe
3
- Version: 1.19.0
3
+ Version: 1.20.0
4
4
  Summary: Probe-then-quantize for LLMs: measure a model's fragility curve, plan bit/tier placement by the tiered decode law, and emit ready-to-run llama.cpp recipes.
5
5
  Author: Federico Sciuca
6
6
  License: MIT
File without changes
File without changes
File without changes