draftround-ab.sh: ours-vs-ours paired blocks (alternating order) and the CUPTI profile run at ~245k context; draftround-kernels.py: per-kernel table of the commit graph, MTP round graph and chain steps; draftround-id.sh/-idcmp.py: teacher-forced replay gate (top-16 logprob rows and the IEEE bits of every draft probability); LELEKA_TRACE_DRAFT=1 prints one DRAFT line per draft. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
110 lines
5.6 KiB
Python
110 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Analysis of draftround-ab.sh runs: per run all-turn tok/s (tokens over seconds), tokens/round, ms/round, span means; per arm mean/sd; block-paired b - a.
|
|
|
|
python3 -I draftround-analyze.py <outroot> [<outroot> ...]
|
|
|
|
A run directory is <root>/b<NN>p<P>-<a|b>[tag]; VALIDITY.txt must start with VALID or the run is listed and left out. Per run (all five turns):
|
|
tok/s = total output tokens / total decode seconds (decode seconds of a turn = tokens / the client's decode_tok_s)
|
|
tok/round = tokens / rounds (the 'rounds=' of the request outcome lines)
|
|
ms/round = decode seconds / rounds * 1000
|
|
Spans (LELEKA_SERVE_PROFILE, the 'DBG profile request:' line of each request) are summed over the five requests and divided by the total rounds: ms per round.
|
|
"""
|
|
import glob
|
|
import json
|
|
import math
|
|
import os
|
|
import re
|
|
import statistics
|
|
import sys
|
|
|
|
SPANS = ["round.run_window", "round.apply_pending", "round.draft_committed", "draft.launch", "draft.finish", "commit.wait", "commit.publish",
|
|
"mtp.finish_first_step", "mtp.chain_step", "mtp.finish_ring", "gpu.mtp_chain_step", "drv.sync_compute", "drv.launch", "round.adapt_deferred"]
|
|
|
|
|
|
def run_stats(d):
|
|
j = json.load(open(os.path.join(d, "long-session.json")))
|
|
toks = [r["output_tokens"] for r in j]
|
|
secs = [r["output_tokens"] / r["decode_tok_s"] for r in j]
|
|
rounds, prof = [], []
|
|
cur = None
|
|
for ln in open(os.path.join(d, "inference.log"), errors="replace"):
|
|
if ln.startswith("DBG profile request:"):
|
|
cur = {m[0]: float(m[1]) for m in re.findall(r"(\S+?)=([\d.]+)/\d+", ln)}
|
|
elif "leleka-serve request outcome" in ln:
|
|
m = re.search(r"rounds=(\d+)", ln)
|
|
rounds.append(int(m.group(1)))
|
|
prof.append(cur or {})
|
|
cur = None
|
|
R = sum(rounds)
|
|
out = {
|
|
"turns": [r["decode_tok_s"] for r in j],
|
|
"tok_s": sum(toks) / sum(secs),
|
|
"tok_round": sum(toks) / R if R else float("nan"),
|
|
"ms_round": sum(secs) / R * 1000 if R else float("nan"),
|
|
"rounds": R,
|
|
}
|
|
for s in SPANS:
|
|
out[s] = sum(p.get(s, 0.0) for p in prof) / R if R else float("nan")
|
|
return out
|
|
|
|
|
|
def sd(v):
|
|
return statistics.stdev(v) if len(v) > 1 else float("nan")
|
|
|
|
|
|
def main():
|
|
runs = {}
|
|
for root in sys.argv[1:]:
|
|
for d in sorted(glob.glob(os.path.join(root, "b*p*-*"))):
|
|
if not os.path.isdir(d) or "_poor" in d:
|
|
continue
|
|
m = re.match(r"b(\d+)p(\d+)-([ab])(.*)", os.path.basename(d))
|
|
if not m:
|
|
continue
|
|
ver = open(os.path.join(d, "VALIDITY.txt")).read().strip() if os.path.exists(os.path.join(d, "VALIDITY.txt")) else "no VALIDITY"
|
|
if not ver.startswith("VALID"):
|
|
print("%s %s (left out)" % (os.path.basename(d), ver))
|
|
continue
|
|
try:
|
|
s = run_stats(d)
|
|
except Exception as e: # noqa
|
|
print("%s analysis failed: %s" % (os.path.basename(d), e))
|
|
continue
|
|
runs[(root, int(m.group(1)), int(m.group(2)), m.group(3))] = s
|
|
print("%-24s %-5s %-26s %8s %8s %8s" % ("run", "pos", "turns tok/s", "tok/s", "tok/rnd", "ms/rnd"))
|
|
for (root, b, p, arm), s in sorted(runs.items(), key=lambda kv: (kv[0][1], kv[0][2])):
|
|
print("%-24s b%02dp%d %-26s %8.1f %8.3f %8.3f" % (os.path.basename(root.rstrip("/")) + "/" + arm, b, p, " ".join("%.0f" % t for t in s["turns"]), s["tok_s"], s["tok_round"], s["ms_round"]))
|
|
arms = {}
|
|
for (root, b, p, arm), s in runs.items():
|
|
arms.setdefault(arm, []).append(s)
|
|
print()
|
|
for arm, ss in sorted(arms.items()):
|
|
print("arm %s n=%d tok/s %.2f (sd %.2f, %.1f..%.1f) tok/round %.3f (sd %.3f) ms/round %.3f (sd %.3f)" % (
|
|
arm, len(ss), statistics.mean(s["tok_s"] for s in ss), sd([s["tok_s"] for s in ss]), min(s["tok_s"] for s in ss), max(s["tok_s"] for s in ss),
|
|
statistics.mean(s["tok_round"] for s in ss), sd([s["tok_round"] for s in ss]), statistics.mean(s["ms_round"] for s in ss), sd([s["ms_round"] for s in ss])))
|
|
print("\nspans, ms per round (mean over the arm's runs):")
|
|
print("%-26s" % "span", *["%10s" % a for a in sorted(arms)], "%10s" % "b - a")
|
|
for sp in SPANS:
|
|
vals = {a: statistics.mean(s[sp] for s in ss) for a, ss in arms.items()}
|
|
print("%-26s" % sp, *["%10.3f" % vals[a] for a in sorted(arms)], "%10.3f" % (vals.get("b", float("nan")) - vals.get("a", float("nan"))))
|
|
# block pairs
|
|
byb = {}
|
|
for (root, b, p, arm), s in runs.items():
|
|
byb.setdefault((root, b), {})[arm] = s
|
|
pairs = [(k, v["a"], v["b"]) for k, v in sorted(byb.items()) if "a" in v and "b" in v]
|
|
if pairs:
|
|
print("\nblock-paired (same block, b - a):")
|
|
for key, name in (("tok_s", "tok/s"), ("tok_round", "tok/round"), ("ms_round", "ms/round")):
|
|
d = [pb[key] - pa[key] for _, pa, pb in pairs]
|
|
rel = [100.0 * (pb[key] - pa[key]) / pa[key] for _, pa, pb in pairs]
|
|
se = sd(d) / math.sqrt(len(d)) if len(d) > 1 else float("nan")
|
|
print(" %-10s per block %s mean %+.3f (sd %.3f, se %.3f) %+.2f %% blocks with b > a: %d of %d" % (
|
|
name, " ".join("%+.3f" % x for x in d), statistics.mean(d), sd(d), se, statistics.mean(rel), sum(1 for x in d if x > 0), len(d)))
|
|
for sp in ("round.draft_committed", "draft.finish", "commit.wait", "commit.publish", "mtp.finish_first_step"):
|
|
d = [pb[sp] - pa[sp] for _, pa, pb in pairs]
|
|
print(" %-22s per block %s mean %+.3f ms/round" % (sp, " ".join("%+.3f" % x for x in d), statistics.mean(d)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|