edumirror-repro-code / experiments /compute_cost.py
ygoldi's picture
Upload folder using huggingface_hub
0d2c6f0 verified
Raw
History Blame Contribute Delete
2.88 kB
#!/usr/bin/env python3
"""Compute actual GPU cost of the reproduction from HF Job durations.
Why: the logbook's Scope & cost table must report MEASURED cost, not an
estimate. This reads each job's real total_secs from `hf jobs inspect` and
multiplies by the published flavor rate, including the failed and cancelled
jobs -- an honest cost line counts the mistakes too.
"""
import re
import subprocess
#: Every job this reproduction ran: id -> (label, flavor). Failed/cancelled
#: jobs are included deliberately.
JOBS = {
"6a598dd785d9643ce16d6fa1": ("validation smoke (failed: no `python` in image)", "l40sx1"),
"6a598e5ab1669a49bf078cae": ("validation smoke (failed: vllm flag removed)", "l40sx1"),
"6a598e9f85d9643ce16d6fa8": ("validation smoke (PASS)", "l40sx1"),
"6a598faab1669a49bf078cd6": ("all-in-one (cancelled: projected 8.4h > 6h timeout)", "h200"),
"6a5991cdb1669a49bf078d0e": ("claim2 32B (ERROR: context overflow; judge collapsed)", "h200"),
"6a5991ceb1669a49bf078d10": ("claim5 32B", "h200"),
"6a5991d685d9643ce16d6fe3": ("claim3 14B", "l40sx1"),
"6a5991d785d9643ce16d6fe5": ("claim4 32B (discarded: judge failed probe)", "h200"),
"6a5997e9b1669a49bf078daa": ("judgecheck 32B", "h200"),
"6a5997e985d9643ce16d705d": ("claim2 32B rerun (cancelled: judge invalid)", "h200"),
"6a599a3685d9643ce16d707a": ("judgecheck 72B", "h200"),
"6a599cbbb1669a49bf078e58": ("claim2 72B (validated judge)", "h200"),
"6a599cbc85d9643ce16d70ab": ("claim4 72B (validated judge)", "h200"),
"6a59beafb1669a49bf0792d1": ("judgecheck gpt-oss-120b v1 (UNREADABLE: no reasoning parser)", "h200"),
"6a59b6bd85d9643ce16d72c9": ("accidental job (shell command substitution; cancelled)", "cpu-basic"),
"6a59c4eb85d9643ce16d73ab": ("judgecheck gpt-oss-120b v2 (reasoning parser + 4k budget)", "h200"),
}
#: Published HF Jobs $/hour (see `hf jobs hardware`).
RATE = {"l40sx1": 1.80, "h200": 5.00, "cpu-basic": 0.01}
def job_seconds(job_id: str) -> int:
"""Return a job's measured wall-clock seconds, or 0 if unavailable."""
out = subprocess.run(
["hf", "jobs", "inspect", f"ygoldi/{job_id}"], capture_output=True, text=True
).stdout
m = re.search(r"'total_secs': (\d+)", out)
return int(m.group(1)) if m else 0
def main() -> None:
rows = []
for jid, (name, flavor) in JOBS.items():
secs = job_seconds(jid)
rows.append((name, flavor, secs / 60, secs / 3600 * RATE[flavor]))
rows.sort(key=lambda r: -r[3])
print(f"{'job':52s} {'flavor':9s} {'minutes':>8s} {'cost':>8s}")
for n, f, mn, c in rows:
print(f"{n:52s} {f:9s} {mn:8.1f} ${c:7.2f}")
print("-" * 82)
print(f"{'TOTAL':52s} {'':9s} {sum(r[2] for r in rows):8.1f} ${sum(r[3] for r in rows):7.2f}")
print(f"GPU-hours: {sum(r[2] for r in rows) / 60:.2f}")
if __name__ == "__main__":
main()