Datasets:
File size: 2,702 Bytes
4ef198a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """q1_matched.py LABBENCH_SRC_EXPERIMENTS OUT_DIR GPU_USD_H [HOST_USD_H]
A1's valid-attempt accounting (amendment-a1/summary/a1_matched.py) applied to a Q1 run root: each arm is charged its op run
(labbench.throughput_report.run_stats at GPU_USD_H x 1.0 + host) plus max(0, last 'op' + last 'op_down' ledger seconds - op wall)
at (GPU + host) USD/h. Pairs: Drums (drums-api) vs every other arm, eligible and success, labbench.cost.paired_ratio,
10,000 resamples, seed 20261031 (A1's). Prints the table and writes q1-matched-gpu<price>.json into OUT_DIR."""
import glob, json, os, sys
sys.path.insert(0, sys.argv[1])
from labbench.throughput_report import run_stats, jl
from labbench.cost import paired_ratio
R, GPU = sys.argv[2], float(sys.argv[3]); HOST = float(sys.argv[4]) if len(sys.argv) > 4 else 4.44544
led = os.path.join(R, "ledger.jsonl")
def last_seg_s(arm):
segs = [x for x in jl(led) if x["phase"] == "dp8" and x["arm"] == arm]
ops = [x for x in segs if x["seg"] == "op"]; downs = [x for x in segs if x["seg"] == "op_down"]
return (ops[-1]["s"] if ops else 0) + (downs[-1]["s"] if downs else 0)
arms = {}
for name in ("drums-api", "qemu-tuned-shared", "osworld-docker"):
d = glob.glob(f"{R}/dp8/{name}/op/rung-n*")
if not d:
continue
s = run_stats(d[0], GPU, 1.0, HOST, None)
extra = max(0.0, last_seg_s(name) - s["wall_s"])
s["usd_m"] = s["usd"] + extra * (GPU + HOST) / 3600; s["extra_s"] = round(extra, 1)
arms[name] = s
out = {"gpu_usd_h": GPU, "host_usd_h": HOST, "rule": __doc__, "arms": {}, "pairs": {}}
for k, s in arms.items():
out["arms"][k] = {x: s[x] for x in ("n", "wall_s", "rollouts", "eligible", "successes", "usd")} | {
"bringup_teardown_s": s["extra_s"], "usd_matched": round(s["usd_m"], 4),
"usd_per_1000_eligible": round(1000 * s["usd_m"] / s["eligible"], 2) if s["eligible"] else None,
"usd_per_1000_successes": round(1000 * s["usd_m"] / s["successes"], 2) if s["successes"] else None,
"eligible_per_usd": round(s["eligible"] / s["usd_m"], 3) if s["usd_m"] else None}
print(k, out["arms"][k])
if "drums-api" in arms:
ds = arms["drums-api"]
for ik, is_ in arms.items():
if ik == "drums-api":
continue
for key in ("eligible", "success"):
pr = paired_ratio(ds["_rows"], ds["usd_m"], is_["_rows"], is_["usd_m"], iters=10000, seed=20261031, key=key)
out["pairs"][f"drums-api / {ik} / {key}"] = pr
print(f"drums-api vs {ik:18s} {key:8s} {pr['ratio']:.3f} [{pr['ci95'][0]:.3f}, {pr['ci95'][1]:.3f}] units {pr['units']}")
json.dump(out, open(os.path.join(R, f"q1-matched-gpu{GPU}.json"), "w"), indent=1, default=str)
|