Download examples/pilot.py from Zihan-Zoe/same-skill-different-harness: direct link, hf CLI and curl.
- Browser
- Download file 4.57 kB
-
https://huggingface.co/datasets/Zihan-Zoe/same-skill-different-harness/resolve/main/examples/pilot.py
- Command line
-
hf download hf://datasets/Zihan-Zoe/same-skill-different-harness/examples/pilot.py
-
curl -L -o pilot.py https://huggingface.co/datasets/Zihan-Zoe/same-skill-different-harness/resolve/main/examples/pilot.py
4.57 kB
| """Study 2: benchmark-level explore-then-commit from a small labeled pilot (see PREREGISTRATION.md).""" | |
| import csv | |
| import gzip | |
| import json | |
| from collections import defaultdict | |
| from pathlib import Path | |
| import numpy as np | |
| HERE = Path(__file__).resolve().parent | |
| BENCH = ["LiveMath", "SimpleQA", "SQuAD", "Hotpot Context", "Hotpot FullWiki"] | |
| MODELS = ["Qwen3.5-9B", "Sonnet 4.6", "Sonnet 5", "GPT-5.6-sol"] | |
| TARGETS = MODELS[1:] | |
| SKILLS = ["NoSkill", "Direct", "SkillOpt", "Trace2Skill"] | |
| USD = {"Qwen3.5-9B": 0.0, "Sonnet 4.6": 4.286e-6, "Sonnet 5": 3.052e-6, "GPT-5.6-sol": 4.276e-6} | |
| KS, DELTAS, ORDERS = [10, 20, 50], [0.0, 5.0], 200 | |
| def score(r): | |
| b = r["benchmark"] | |
| return float(r["hard"] if b == "LiveMath" else r["simpleqa_regrade"] if b == "SimpleQA" else r["em"]) | |
| def load(): | |
| acc = defaultdict(lambda: [0.0, 0.0, 0]) | |
| for r in csv.DictReader(gzip.open(HERE / "records_h123.csv.gz", "rt")): | |
| if r["benchmark"] not in BENCH: | |
| continue | |
| a = acc[(r["model"], r["harness"], r["benchmark"], r["skill"], r["task_id"])] | |
| a[0] += score(r) | |
| a[1] += float(r["tokens"]) | |
| a[2] += 1 | |
| cfg = defaultdict(dict) # (model, harness, bench, skill) -> task -> (score 0-100, tokens, usd) | |
| for (m, h, b, s, t), (sc, tk, n) in acc.items(): | |
| cfg[(m, h, b, s)][t] = (100 * sc / n, tk / n, USD[m] * tk / n) | |
| return cfg | |
| def units(cfg): | |
| for m in MODELS: | |
| for s in SKILLS: | |
| for b in BENCH: | |
| yield "A: H1 vs H2", (m, s), cfg[(m, "H1", b, s)], cfg[(m, "H2", b, s)] | |
| yield "B: H2 vs H3", (m, s), cfg[(m, "H2", b, s)], cfg[(m, "H3", b, s)] | |
| for T in TARGETS: | |
| for s in SKILLS: | |
| for b in BENCH: | |
| yield f"C: Qwen vs {T}", (T, s), cfg[("Qwen3.5-9B", "H2", b, s)], cfg[(T, "H2", b, s)] | |
| def evaluate(default, alt, rng): | |
| tasks = sorted(set(default) & set(alt)) | |
| D = np.array([default[t] for t in tasks]) # columns: score, tokens, usd | |
| A = np.array([alt[t] for t in tasks]) | |
| n = len(tasks) | |
| full_d, full_a = D.mean(0), A.mean(0) | |
| oracle_alt = full_a[0] > full_d[0] | |
| gap = abs(full_a[0] - full_d[0]) | |
| out = {"default": full_d, "alt": full_a, "oracle": full_a if oracle_alt else full_d, | |
| "oracle_picks_alt": np.array([float(oracle_alt)])} | |
| orders = [rng.permutation(n) for _ in range(ORDERS)] | |
| for k in KS: | |
| for dl in DELTAS: | |
| res, wrong = [], 0 | |
| for o in orders: | |
| p, rest = o[:k], o[k:] | |
| go = A[p, 0].mean() - D[p, 0].mean() >= dl | |
| C = A if go else D | |
| sc = C[:, 0].mean() | |
| cost = (D[p, 1:].sum(0) + A[p, 1:].sum(0) + C[rest, 1:].sum(0)) / n | |
| res.append([sc, *cost]) | |
| wrong += (go != oracle_alt) and gap >= 2 | |
| out[f"pilot k={k} d={dl:g}"] = np.mean(res, 0) | |
| out[f"wrong k={k} d={dl:g}"] = wrong / ORDERS | |
| return out | |
| def main(): | |
| cfg = load() | |
| rng = np.random.default_rng(42) | |
| agg = defaultdict(lambda: defaultdict(list)) | |
| for dec, grp, d, a in units(cfg): | |
| for pol, v in evaluate(d, a, rng).items(): | |
| agg[dec][pol].append(v) | |
| summary = {} | |
| for dec, pols in agg.items(): | |
| rows = {} | |
| orc = np.mean(pols["oracle"], 0) | |
| for pol, vals in pols.items(): | |
| if pol.startswith("wrong"): | |
| continue | |
| if pol == "oracle_picks_alt": | |
| rows["oracle_picks_alt_units"] = int(sum(v[0] for v in vals)) | |
| continue | |
| m = np.mean(vals, 0) | |
| rows[pol] = {"score": round(float(m[0]), 2), "tokens": round(float(m[1]), 1), | |
| "usd_per_1k": round(1000 * float(m[2]), 3), "regret": round(float(orc[0] - m[0]), 2)} | |
| w = pols.get(pol.replace("pilot", "wrong")) if pol.startswith("pilot") else None | |
| if w is not None: | |
| rows[pol]["wrong_commit_pct"] = round(100 * float(np.mean(w)), 1) | |
| rows["n_units"] = len(pols["default"]) | |
| summary[dec] = rows | |
| (HERE / "pilot_results.json").write_text(json.dumps(summary, indent=1)) | |
| for dec, rows in summary.items(): | |
| print("==", dec, "units", rows.pop("n_units"), "oracle picks alt in", rows.pop("oracle_picks_alt_units")) | |
| for pol, r in rows.items(): | |
| print(f" {pol:18s} score {r['score']:6.2f} regret {r['regret']:5.2f} tokens {r['tokens']:8.1f} " | |
| f"$/1k {r['usd_per_1k']:7.3f} wrong {r.get('wrong_commit_pct', '')}") | |
| if __name__ == "__main__": | |
| main() | |