55 lines
2.5 KiB
Python
55 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Summarise laptop bench runs (scripts/laptop/lap_run.sh output).
|
|
|
|
lap_sum.py [--skip-pass0] OUT/LABEL.timing [...]
|
|
|
|
Per label and per prompt (index and token count): requests, mean prefill tok/s, mean TTFT, decode tok/s weighted
|
|
(sum of produced tokens over sum of decode time, the charter's weighting) and the median/min/max of the per-request
|
|
decode rate. A final line per label gives the weighted decode over every request. Offline tooling only.
|
|
"""
|
|
import re
|
|
import statistics
|
|
import sys
|
|
from collections import defaultdict
|
|
|
|
LINE = re.compile(r"^LAPTOP request p(\d+) pass=(\d+) prompt=(\d+) produced=(\d+) rounds=(\d+) ttft_ms=([\d.]+) prompt_ms=([\d.]+) "
|
|
r"decode_ms=([\d.]+) total_ms=([\d.]+) prefill_tok_s=([\d.]+) decode_tok_s=([\d.]+)")
|
|
|
|
|
|
def load(path):
|
|
rows = []
|
|
for line in open(path, encoding="utf-8", errors="replace"):
|
|
m = LINE.match(line.strip())
|
|
if m:
|
|
p, ps, n, prod, rounds, ttft, pms, dms, tot, pre, dec = m.groups()
|
|
rows.append(dict(p=int(p), pas=int(ps), n=int(n), prod=int(prod), rounds=int(rounds), ttft=float(ttft), pms=float(pms),
|
|
dms=float(dms), pre=float(pre), dec=float(dec)))
|
|
return rows
|
|
|
|
|
|
def main():
|
|
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
|
skip0 = "--skip-pass0" in sys.argv
|
|
for path in args:
|
|
rows = load(path)
|
|
if skip0:
|
|
rows = [r for r in rows if r["pas"] > 0]
|
|
print(f"== {path}: {len(rows)} requests")
|
|
by = defaultdict(list)
|
|
for r in rows:
|
|
by[(r["p"], r["n"])].append(r)
|
|
print(f"{'prompt':>6} {'tokens':>7} {'n':>3} {'prefill tok/s':>14} {'TTFT s':>8} {'decode w. tok/s':>16} {'median':>7} {'min-max':>13} {'tok/round':>9}")
|
|
for (p, n), rs in sorted(by.items(), key=lambda kv: kv[0][1]):
|
|
w = sum(r["prod"] for r in rs) / max(sum(r["dms"] for r in rs) / 1e3, 1e-9)
|
|
decs = [r["dec"] for r in rs]
|
|
tpr = sum(r["prod"] for r in rs) / max(sum(r["rounds"] for r in rs), 1)
|
|
print(f"{'p' + str(p):>6} {n:>7} {len(rs):>3} {statistics.mean(r['pre'] for r in rs):>14.1f} {statistics.mean(r['ttft'] for r in rs) / 1e3:>8.2f} "
|
|
f"{w:>16.2f} {statistics.median(decs):>7.2f} {min(decs):>6.2f}-{max(decs):<6.2f} {tpr:>9.2f}")
|
|
if rows:
|
|
w = sum(r["prod"] for r in rows) / max(sum(r["dms"] for r in rows) / 1e3, 1e-9)
|
|
print(f" all: weighted decode {w:.2f} tok/s over {sum(r['prod'] for r in rows)} tokens")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|