Download scripts/tbench/score_tb.py from jaytonde05/kv-cache-quantization-commands: direct link, hf CLI and curl.
- Browser
- Download file 2.69 kB
-
https://huggingface.co/datasets/jaytonde05/kv-cache-quantization-commands/resolve/main/scripts/tbench/score_tb.py
- Command line
-
hf download hf://datasets/jaytonde05/kv-cache-quantization-commands/scripts/tbench/score_tb.py
-
curl -L -o score_tb.py https://huggingface.co/datasets/jaytonde05/kv-cache-quantization-commands/resolve/main/scripts/tbench/score_tb.py
2.69 kB
| """Score Terminal-Bench 2.1 runs (~/tbench/jobs/tb21-<CFG>) and compare configs with paired statistics. | |
| Usage: python score_tb.py [JOBS_DIR] # default ~/tbench/jobs | |
| A task passes when its verifier reward is 1.0 (the official metric). | |
| """ | |
| import json | |
| import random | |
| import sys | |
| from pathlib import Path | |
| J = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / "tbench" / "jobs" | |
| CFGS = ["BF16", "BF16-FI", "FP8", "FP4"] | |
| PAIRS = [("BF16-FI", "BF16", "kernel effect"), ("FP8", "BF16", "FP8 KV effect"), ("FP4", "BF16-FI", "NVFP4 KV effect")] | |
| def load(cfg): | |
| out = {} | |
| for f in (J / f"tb21-{cfg}").glob("*__*/result.json"): | |
| r = json.loads(f.read_text()) | |
| rew = ((r.get("verifier_result") or {}).get("rewards") or {}).get("reward") or 0 | |
| exc = (r.get("exception_info") or {}).get("exception_type") | |
| out[r["task_name"].split("/")[-1]] = {"pass": 1 if rew >= 1 else 0, "exc": exc} | |
| return out | |
| def paired_ci(d, iters=10000, seed=0): | |
| rng, n = random.Random(seed), len(d) | |
| m = sorted(sum(d[rng.randrange(n)] for _ in range(n)) / n for _ in range(iters)) | |
| return sum(d) / n, m[int(0.025 * iters)], m[int(0.975 * iters)] | |
| R = {c: load(c) for c in CFGS} | |
| print("Terminal-Bench 2.1 (89 tasks, terminus-2, reasoning_effort=xhigh, k=1, agent timeout x4)") | |
| print(f"{'run':<10}{'done':>8}{'passed':>8}{'failed':>8}{'pass %':>9}{'timeouts':>10}{'other errs':>12}") | |
| for c in CFGS: | |
| v = R[c].values() | |
| n, p = len(v), sum(x["pass"] for x in v) | |
| to = sum(x["exc"] == "AgentTimeoutError" for x in v) | |
| oe = sum(bool(x["exc"]) and x["exc"] != "AgentTimeoutError" for x in v) | |
| print(f"{c:<10}{n:>5}/89{p:>8}{n - p:>8}{100 * p / max(n, 1):>9.1f}{to:>10}{oe:>12}") | |
| print("\nPaired differences (treatment - baseline, points), 95% bootstrap CI, flips pass->fail / fail->pass") | |
| for t, b, label in PAIRS: | |
| ids = sorted(set(R[t]) & set(R[b])) | |
| if not ids: | |
| continue | |
| m, lo, hi = paired_ci([R[t][i]["pass"] - R[b][i]["pass"] for i in ids]) | |
| pf = sum(R[b][i]["pass"] > R[t][i]["pass"] for i in ids) | |
| fp = sum(R[b][i]["pass"] < R[t][i]["pass"] for i in ids) | |
| print(f"{label:<17}{t:>9} vs {b:<9} {100 * m:+6.2f} [{100 * lo:+6.2f}, {100 * hi:+6.2f}] flips {pf}/{fp} n={len(ids)}") | |
| print("\nPer task (1 = pass, 0 = fail, T = agent timeout, E = other error, - = missing)") | |
| tasks = sorted(set().union(*R.values())) | |
| print(f"{'task':<40}" + "".join(f"{c:>9}" for c in CFGS)) | |
| for t in tasks: | |
| cells = [] | |
| for c in CFGS: | |
| x = R[c].get(t) | |
| s = "-" if x is None else str(x["pass"]) + ({"AgentTimeoutError": "T", None: ""}.get(x["exc"], "E")) | |
| cells.append(f"{s:>9}") | |
| print(f"{t:<40}" + "".join(cells)) | |