interplane.Get Omega
Read in your language

gpu-head-to-head

aien-dev/gpu-head-to-head

Brought by drakestapleton

branch main Branches Tags History

gpu-head-to-head / bench / extract.py

70 lines · 3197 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Turn results/raw/*.jsonl into one Wolfram Language data file, with no arithmetic.
3
4Every 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,
6t_send, t_first, t_last, prompt_tokens, completion_tokens, busy_retries, ok}. Warmup rows are
7dropped 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
9offender list, A4(b)). Of several non-void tries of one cell only the lowest try is kept (A4(c)).
10Timestamps are printed with full repr precision.
11"""
12import glob
13import json
14import os
15import sys
16
17REPO = sys.argv[1]
18
19
20def 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
25void = set()
26if 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.
31admission = None
32admission_path = REPO + "/results/cell-status.jsonl"
33if 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
40raw = [json.loads(line) for path in sorted(glob.glob(REPO + "/results/raw/*.jsonl")) for line in open(path)]
41first = {} # cell without its try suffix -> lowest non-void try number
42for 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))
47rows = []
48for 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"]))
70print("h2hRows = {\n" + ",\n".join(rows) + "\n};")