Files
leleka/scripts/perf3/parse_replay.py
T

69 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Per-arm summary of a replay log (job p32 and friends): REPLAY-ARM markers split the arms, `REPLAY #n ...` lines are the requests.
usage: parse_replay.py LOG [--per-request]
For every arm: requests, re-prefilled tokens, sum and median TTFT, decode tokens, decode time, weighted decode tok/s (tokens after the first / decode
time of the requests), tokens per round, and the same restricted to the requests with a long re-prefill (> 4096 tokens: cold reads) and to the others
(warm resumes). Arms with the same mode (A1/A2, B1/B2) are pooled in the last table.
"""
import re
import statistics
import sys
log = sys.argv[1]
per_request = "--per-request" in sys.argv
arms = []
cur = None
for line in open(log, errors="replace"):
m = re.search(r"REPLAY-ARM start label=(\S+) mode=(\S+) capacity=(\d+) block=(\d+)(?: tiers=(\w+))?", line)
if m:
cur = {"label": m[1], "mode": m[2], "cap": int(m[3]), "block": int(m[4]), "tiers": m[5] or "-", "req": []}
arms.append(cur)
continue
m = re.search(r"REPLAY #(\d+) pass=\S+ \S+ arm=\S+ file=\S+ prompt=(\d+) reused=(\d+) reprefill=(\d+) ttft_ms=([\d.]+) produced=(\d+) rounds=(\d+) tok_per_round=[\d.]+ decode_ms=([\d.]+) decode_tok_s=[\d.]+ engine_prompt_ms=([\d.]+) engine_decode_ms=([\d.]+) agree=(\d+)/(\d+)", line)
if m and cur is not None:
cur["req"].append({"n": int(m[1]), "prompt": int(m[2]), "reprefill": int(m[4]), "ttft": float(m[5]), "produced": int(m[6]), "rounds": int(m[7]),
"decode_ms": float(m[8]), "eng_prompt": float(m[9]), "eng_decode": float(m[10]), "agree": int(m[11]), "rec": int(m[12])})
def stats(reqs):
if not reqs:
return None
tok = sum(max(r["produced"] - 1, 0) for r in reqs)
dec = sum(r["decode_ms"] for r in reqs) / 1e3
return {
"n": len(reqs),
"reprefill": sum(r["reprefill"] for r in reqs),
"ttft_sum_s": sum(r["ttft"] for r in reqs) / 1e3,
"ttft_med_s": statistics.median(r["ttft"] for r in reqs) / 1e3,
"tok": tok,
"dec_s": dec,
"tok_s": tok / dec if dec else 0.0,
"tpr": sum(r["produced"] for r in reqs) / max(sum(r["rounds"] for r in reqs), 1),
"agree": sum(1 for r in reqs if r["agree"] == r["rec"]),
}
def show(title, rows):
print(title)
for label, s in rows:
if s is None:
print(f" {label:<28} -")
continue
print(f" {label:<28} n={s['n']:>3} reprefill={s['reprefill']:>7} ttft sum {s['ttft_sum_s']:7.1f}s med {s['ttft_med_s']:5.2f}s | decode {s['tok']:>6} tok / {s['dec_s']:7.1f}s = {s['tok_s']:6.1f} tok/s, {s['tpr']:.2f} tok/round, agree {s['agree']}/{s['n']}")
show("all requests", [(f"{a['label']} ({a['mode']} cap {a['cap']} block {a['block']} tiers {a['tiers']})", stats(a["req"])) for a in arms])
show("cold re-prefill > 4096 tokens", [(a["label"], stats([r for r in a["req"] if r["reprefill"] > 4096])) for a in arms])
show("warm resumes (re-prefill <= 4096)", [(a["label"], stats([r for r in a["req"] if r["reprefill"] <= 4096])) for a in arms])
pooled = {}
for a in arms:
pooled.setdefault((a["mode"], a["cap"], a["block"], a["tiers"]), []).extend(a["req"])
show("pooled by shape", [(f"{k[0]} cap {k[1]} block {k[2]} tiers {k[3]}", stats(v)) for k, v in pooled.items()])
if per_request:
for a in arms:
print(a["label"])
for r in a["req"]:
print(f" #{r['n']:>3} prompt={r['prompt']:>6} reprefill={r['reprefill']:>6} ttft={r['ttft']:8.1f} eng_prompt={r['eng_prompt']:8.1f} produced={r['produced']:>5} decode_ms={r['decode_ms']:9.1f}")