Files
leleka/scripts/e2e/decode/windowpolicy-replay-summary.py
T

46 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Per-arm summary of windowpolicy-replay.sh: REPLAY PASS lines (warm-up pass discarded), tokens / decode time / rounds summed over the passes of an arm,
the per-pass tok/s, and the paired difference to the first arm of every repetition. usage: windowpolicy-replay-summary.py <replay.full>"""
import re, statistics as st, sys
# the REPLAY PASS line rounds the decode time to 0.1 s (1.2 % of a pass): the per-request lines carry decode_ms to 0.1 ms, so the passes are rebuilt from them
reqs = {}
labels = {}
for ln in open(sys.argv[1], errors="replace"):
m = re.match(r"REPLAY #(\d+) pass=(\d+) (\S+) arm=(\S+) .*? produced=(\d+) rounds=(\d+) tok_per_round=\S+ decode_ms=([\d.]+)", ln)
if m:
n, 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)
passes = []
for ps, r in sorted(reqs.items()):
passes.append(dict(n=ps, lab=r["lab"], arm=r["arm"], tps=r["tok"] / r["sec"], tok=r["tok"], sec=r["sec"], rounds=r["rounds"]))
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"])
print("passes %d (+%d warm-up), arms %d" % (len(rows), len(passes) - len(rows), len(arms)))
print("%-34s %3s %9s %8s %9s %9s per-pass tok/s" % ("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
tps = [p["tps"] for p in 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)
print("%-34s %3d %9.2f %8.2f %9.3f %9.3f %s" % (a, len(v), tok / sec, st.pstdev(tps) if len(tps) > 1 else 0.0, tok / rd, 1000 * sec / rd, " ".join("%.1f" % x for x in tps)))
ref = arms[0]
print("\npaired against %s (same repetition, same forced text): mean difference tok/s (se), arms better in n of N" % ref)
reps = sorted({p["lab"] for p in rows})
for a in arms[1:]:
d = []
for r in reps:
x = [p for p in by[a] if p["lab"] == r]
y = [p for p in by[ref] if p["lab"] == r]
if x and y:
d.append(x[0]["tps"] - y[0]["tps"])
if len(d) > 1:
print("%-34s %+7.2f (se %.2f) %d of %d [%s]" % (a, st.mean(d), st.stdev(d) / len(d) ** 0.5, sum(1 for z in d if z > 0), len(d), " ".join("%+.1f" % z for z in d)))