gpu-head-to-head
aien-dev/gpu-head-to-head
Brought by drakestapleton
gpu-head-to-head / bench / extract.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Turn results/raw/*.jsonl into one Wolfram Language data file, with no arithmetic. |
| 3 | |
| 4 | Every derived number (rates, medians, IQRs) is computed in Wolfram from these raw fields |
| 5 | (PROTOCOL.md section 7). Rows are kept as {arm, round, metric, rep, batch, stream, load1_start, |
| 6 | t_send, t_first, t_last, prompt_tokens, completion_tokens, busy_retries, ok}. Warmup rows are |
| 7 | dropped here (they stay in the raw files), and so are rows of cells voided under amendments A2/A4 |
| 8 | (results/voids.jsonl; a record counts only if its reason names the kthread or a non-empty |
| 9 | offender list, A4(b)). Of several non-void tries of one cell only the lowest try is kept (A4(c)). |
| 10 | Timestamps are printed with full repr precision. |
| 11 | """ |
| 12 | import glob |
| 13 | import json |
| 14 | import os |
| 15 | import sys |
| 16 | |
| 17 | REPO = sys.argv[1] |
| 18 | |
| 19 | |
| 20 | def honoured(v): |
| 21 | why = v.get("reason") or "kthread" # A2-era records without a reason were kthread voids |
| 22 | return "kthread" in why or ": [" in why |
| 23 | |
| 24 | |
| 25 | void = set() |
| 26 | if os.path.exists(REPO + "/results/voids.jsonl"): |
| 27 | void = {v["cell_run"] for v in map(json.loads, filter(str.strip, open(REPO + "/results/voids.jsonl"))) |
| 28 | if honoured(v)} |
| 29 | # New runs are admitted per cell. A missing, duplicate or non-PASS record excludes the cell; |
| 30 | # untouched historical runs without a ledger retain their original extraction semantics. |
| 31 | admission = None |
| 32 | admission_path = REPO + "/results/cell-status.jsonl" |
| 33 | if os.path.exists(admission_path): |
| 34 | admission = {} |
| 35 | for line in open(admission_path): |
| 36 | entry = json.loads(line) |
| 37 | cr = entry["cell_run"] |
| 38 | admission[cr] = entry["status"] if cr not in admission else "DUPLICATE" |
| 39 | |
| 40 | raw = [json.loads(line) for path in sorted(glob.glob(REPO + "/results/raw/*.jsonl")) for line in open(path)] |
| 41 | first = {} # cell without its try suffix -> lowest non-void try number |
| 42 | for r in raw: |
| 43 | cr = r.get("cell_run") |
| 44 | if cr and cr not in void and (admission is None or admission.get(cr) == "PASS"): |
| 45 | cell, _, n = cr.rpartition("-t") |
| 46 | first[cell] = min(first.get(cell, int(n)), int(n)) |
| 47 | rows = [] |
| 48 | for r in raw: |
| 49 | cr = r.get("cell_run") |
| 50 | # A10: rows of a profiled arm (*_NSYS) carry tracer overhead and never enter timing results |
| 51 | if (r["warmup"] or r["arm"] == "STUB" or r["arm"].endswith("_NSYS") or cr in void |
| 52 | or (admission is not None and admission.get(cr) != "PASS")): |
| 53 | continue |
| 54 | if cr: |
| 55 | cell, _, n = cr.rpartition("-t") |
| 56 | if int(n) != first[cell]: |
| 57 | continue |
| 58 | u = r.get("usage") or {} |
| 59 | ok = (r["error"] is None and r["http_status"] == 200 and r["t_first"] is not None |
| 60 | and u.get("completion_tokens") is not None) |
| 61 | |
| 62 | def num(x): |
| 63 | return "Missing[]" if x is None else repr(x).replace("e", "*^") |
| 64 | rows.append("{%s}" % ", ".join([ |
| 65 | json.dumps(r["arm"]), json.dumps(r["round"]), json.dumps(r["metric"]), str(r["rep"]), |
| 66 | json.dumps(r["batch_id"]), str(r["stream_index"]), num(r["load1_start"]), |
| 67 | num(r["t_send"]), num(r["t_first"]), num(r["t_last"]), |
| 68 | num(u.get("prompt_tokens")), num(u.get("completion_tokens")), |
| 69 | str(r.get("busy_retries", 0)), "True" if ok else "False"])) |
| 70 | print("h2hRows = {\n" + ",\n".join(rows) + "\n};") |