Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
3.5 KiB
Python
76 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Per-arm summary of accept-knobs-replay.sh (teacher-forced replay, several speculation policies in one process, identical text for every arm).
|
|
|
|
Per arm: tokens, rounds, decode seconds summed over its passes (the warm-up pass is dropped); the passes are rebuilt from the per-request REPLAY lines
|
|
(decode_ms to 0.1 ms). Then, paired by repetition against the first arm (the base), the mean difference of tok/s, tokens per round and ms per round in
|
|
percent of the base with a 95 % interval (Student t on the repetition differences). The twin arm (the same policy under another label) is the A/A floor:
|
|
a knob is read only against it. usage: accept-knobs-summary.py <replay.full> [base-arm] [twin-arm]"""
|
|
import re
|
|
import statistics as st
|
|
import sys
|
|
|
|
T95 = {1: 12.706, 2: 4.303, 3: 3.182, 4: 2.776, 5: 2.571, 6: 2.447, 7: 2.365, 8: 2.306, 9: 2.262, 10: 2.228}
|
|
|
|
|
|
def read_passes(path):
|
|
reqs = {}
|
|
pat = re.compile(r"REPLAY #(\d+) pass=(\d+) (\S+) arm=(\S+) .*? produced=(\d+) rounds=(\d+) tok_per_round=\S+ decode_ms=([\d.]+)")
|
|
for ln in open(path, errors="replace"):
|
|
m = pat.match(ln)
|
|
if not m:
|
|
continue
|
|
_, ps, lab, arm, produced, rounds, ms = m.groups()
|
|
r = reqs.setdefault(int(ps), dict(lab=lab, arm=arm, tok=0, sec=0.0, rounds=0))
|
|
r["tok"] += int(produced)
|
|
r["sec"] += float(ms) / 1000.0
|
|
r["rounds"] += int(rounds)
|
|
return [dict(n=ps, tps=r["tok"] / r["sec"], tpr=r["tok"] / r["rounds"], mpr=1000 * r["sec"] / r["rounds"], **r) for ps, r in sorted(reqs.items())]
|
|
|
|
|
|
def paired(rows, by, base, arm, key):
|
|
reps = sorted({p["lab"] for p in rows})
|
|
d = []
|
|
for r in reps:
|
|
x = [p for p in by[arm] if p["lab"] == r]
|
|
y = [p for p in by[base] if p["lab"] == r]
|
|
if x and y:
|
|
d.append(100.0 * (x[0][key] / y[0][key] - 1.0))
|
|
if len(d) < 2:
|
|
return None
|
|
se = st.stdev(d) / len(d) ** 0.5
|
|
return st.mean(d), T95.get(len(d) - 1, 2.0) * se, sum(1 for z in d if z > 0), len(d)
|
|
|
|
|
|
def main():
|
|
passes = read_passes(sys.argv[1])
|
|
rows = [p for p in passes if p["lab"] != "warm"]
|
|
arms = []
|
|
for p in rows:
|
|
if p["arm"] not in arms:
|
|
arms.append(p["arm"])
|
|
base = sys.argv[2] if len(sys.argv) > 2 else arms[0]
|
|
twin = sys.argv[3] if len(sys.argv) > 3 else (arms[1] if len(arms) > 1 else None)
|
|
print("passes %d (+%d warm-up), arms %d, base %s, twin (A/A floor) %s" % (len(rows), len(passes) - len(rows), len(arms), base, twin))
|
|
print("%-40s %3s %8s %7s %9s %9s" % ("arm", "n", "tok/s", "sd", "tok/round", "ms/round"))
|
|
by = {}
|
|
for a in arms:
|
|
v = [p for p in rows if p["arm"] == a]
|
|
by[a] = v
|
|
tok, sec, rd = sum(p["tok"] for p in v), sum(p["sec"] for p in v), sum(p["rounds"] for p in v)
|
|
tps = [p["tps"] for p in v]
|
|
print("%-40s %3d %8.2f %7.2f %9.3f %9.3f" % (a, len(v), tok / sec, st.pstdev(tps) if len(tps) > 1 else 0.0, tok / rd, 1000 * sec / rd))
|
|
print("\npaired against %s, percent of base, mean (95%% interval), arm better in n of N repetitions" % base)
|
|
print("%-40s %-26s %-26s %-26s" % ("arm", "tok/s", "tok/round", "ms/round"))
|
|
for a in arms:
|
|
if a == base:
|
|
continue
|
|
cells = []
|
|
for key in ("tps", "tpr", "mpr"):
|
|
r = paired(rows, by, base, a, key)
|
|
cells.append("n/a" if r is None else "%+.2f (+-%.2f) %d/%d" % (r[0], r[1], r[2], r[3]))
|
|
print("%-40s %-26s %-26s %-26s%s" % (a, cells[0], cells[1], cells[2], " <- A/A floor" if a == twin else ""))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|