training / experiments /exp_bench_pair.py
agent
exp_bench_pair: test_web vs fast_wide head-to-head benchmark (operator request); allowlist it
77149cd
Raw History Blame Contribute Delete
2.89 kB
#!/usr/bin/env python3
"""Paired benchmark: test_web (full config, iter 540 exfil) vs fast_wide (gen 600).
Operator-requested measurement (their prediction: fast_wide wins on the newer
arch despite test_web's longer training). Evaluates:
1. H2H both directions, steps=4 (matched depth), n=200
2. H2H, steps=20 (test_web native depth), n=200
3. Each vs material-greedy at both depths, n=60
Both checkpoints pulled from the hub at job start (container has no local runs/.
"""
import argparse, json, os, sys, time
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import torch
from huggingface_hub import hf_hub_download
from tinychess.checkpoint import load_model_only
from tinychess.arena import MaterialAgent, head_to_head, wilson_interval
def pull(repo_path):
src = hf_hub_download("cazyundee/tinychess-ckpt", repo_path,
token=os.environ.get("HF_TOKEN"))
os.makedirs("runs/_bench", exist_ok=True)
dst = os.path.join("runs/_bench", repo_path.replace("/", "_"))
import shutil
shutil.copy(src, dst)
return dst
def h2h(a_model, b_model, steps, n, label, res):
r = head_to_head(a_model, b_model, n_games=n, steps=steps,
max_plies=160, seed=1234, adjudicate="material")
lo, hi = wilson_interval(r["wins"], r["draws"], r["games"])
r["ci95"] = [round(lo, 3), round(hi, 3)]
res[label] = r
print(f"{label}: score={r['score']:.3f} CI[{lo:.2f},{hi:.2f}] "
f"W{r['wins']}/D{r['draws']}/L{r['losses']} elo{r['elo_diff']:+.0f}",
flush=True)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--out", default="runs/bench_tw_vs_fw.json")
args = ap.parse_args()
torch.set_num_threads(15)
tw = load_model_only(pull("test_web_exfil/latest.pt"))[0]
fw = load_model_only(pull("fast_wide/latest.pt"))[0]
print(f"test_web params={tw.param_report()['total']:,} | "
f"fast_wide params={fw.param_report()['total']:,}", flush=True)
res = {"time": time.strftime("%F %T")}
# 1+2: H2H at both depths
h2h(fw, tw, 4, 200, "h2h_st4_fastwhite_as_A", res)
h2h(fw, tw, 20, 200, "h2h_st20_fastwhite_as_A", res)
# 3: vs material at both depths
for name, m in (("test_web", tw), ("fast_wide", fw)):
for st in (4, 20):
r = head_to_head(m, MaterialAgent(), n_games=60, steps=st,
max_plies=160, seed=1234, adjudicate="material")
lo, hi = wilson_interval(r["wins"], r["draws"], r["games"])
res[f"{name}_vs_material_st{st}"] = r
print(f"{name} vs material @steps={st}: {r['score']:.3f} "
f"CI[{lo:.2f},{hi:.2f}]", flush=True)
json.dump(res, open(args.out, "w"), indent=2)
print(f"[saved] {args.out}", flush=True)
print("BENCH COMPLETE", flush=True)
if __name__ == "__main__":
main()