Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
124 lines
7.6 KiB
Python
124 lines
7.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Side-by-side report of the vanilla-vs-Leleka Codex comparison (test tooling, stdlib only, Python 3.9+).
|
|
|
|
cmp_report.py RUNS_ROOT [--out DIR]
|
|
|
|
Reads every cell under RUNS_ROOT (`<VARIANT>/<task>-r<k>/cell.json`, written by cmp_codex_job.sh; warm-up cells `smoke-mini-r10x` are listed but not compared) through the
|
|
indexer of the lossy-delta study (delta/index.py) and writes RUNS_ROOT/_compare/{compare.md,compare.csv}:
|
|
quality accepted (objective acceptance), acceptance checks passed / total, failed model requests, termination, the six browser checks of the tic-tac-toe page when
|
|
RUNS_ROOT/_compare/browser.json exists ({"LEL/ttt-r1": "6/6", ...}, produced on the laptop by delta/browser_check_ttt.sh)
|
|
iterations model requests (rounds), tool calls, requests that ended in an error, input tokens re-read in total
|
|
speed wall seconds, decode tok/s (output tokens over decode time), mean time to first byte, mean seconds per request
|
|
Per task and variant: every repetition, mean and sd; then the paired difference Leleka minus vanilla for repetitions that exist in both arms. It makes NO verdict about quality
|
|
beyond the numbers; the sessions to read are linked (transcript.md per cell, written by index.py).
|
|
"""
|
|
import csv
|
|
import json
|
|
import os
|
|
import statistics
|
|
import sys
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, os.path.join(HERE, "..", "delta"))
|
|
import index # noqa: E402
|
|
|
|
NAMES = {"LEL": "Leleka (release package, KAR, shipped)", "VAN": "vanilla Strata 0.2.6 (shipped defaults)", "VANL": "vanilla Strata 0.2.6 (lossy defaults off)",
|
|
"LELK": "Leleka, KAR PLE (rtx5090-32g, standalone stack; KAR on / off study)", "LELG": "Leleka, GGUF PLE (rtx5090-32g-gguf-ple, standalone stack; KAR on / off study)"}
|
|
|
|
|
|
def acceptance(d):
|
|
p, f = 0, 0
|
|
try:
|
|
for line in open(os.path.join(d, "acceptance.log"), encoding="utf-8", errors="replace"):
|
|
if line.startswith("PASS "):
|
|
p += 1
|
|
elif line.startswith("FAIL "):
|
|
f += 1
|
|
except OSError:
|
|
pass
|
|
return p, p + f
|
|
|
|
|
|
def ttfb_mean(rs):
|
|
xs = [((r.get("t_first_byte_ms") or 0) - (r.get("t_start_ms") or 0)) / 1000 for r in rs if r.get("t_first_byte_ms")]
|
|
return round(statistics.mean(xs), 2) if xs else None
|
|
|
|
|
|
def mean_sd(xs):
|
|
xs = [x for x in xs if isinstance(x, (int, float))]
|
|
if not xs:
|
|
return "-"
|
|
if len(xs) == 1:
|
|
return "%.1f" % xs[0]
|
|
return "%.1f ± %.1f" % (statistics.mean(xs), statistics.stdev(xs))
|
|
|
|
|
|
def main():
|
|
args = [a for a in sys.argv[1:] if not a.startswith("--")]
|
|
root = os.path.abspath(args[0])
|
|
out = os.path.abspath(sys.argv[sys.argv.index("--out") + 1]) if "--out" in sys.argv else os.path.join(root, "_compare")
|
|
os.makedirs(out, exist_ok=True)
|
|
browser = {}
|
|
try:
|
|
browser = json.load(open(os.path.join(out, "browser.json")))
|
|
except (OSError, ValueError):
|
|
pass
|
|
rows = []
|
|
for sset, d, info in index.find_cells(root):
|
|
row, rs = index.summarize(sset, d, info)
|
|
ok, tot = acceptance(d)
|
|
row["acc_pass"], row["acc_total"] = ok, tot
|
|
row["ttfb_mean_s"] = ttfb_mean(rs)
|
|
row["s_per_request"] = round(row["model_s"] / row["rounds"], 2) if row["rounds"] else None
|
|
row["browser"] = browser.get("%s/%s-r%s" % (row["variant"], row["task"], row["rep"]), "")
|
|
row["cached_share"] = round(row["cached_tokens_total"] / row["in_tokens_total"], 3) if row["in_tokens_total"] else None
|
|
rows.append(row)
|
|
rows.sort(key=lambda r: (r["task"], r["variant"], r["rep"]))
|
|
if rows:
|
|
with open(os.path.join(out, "compare.csv"), "w", newline="", encoding="utf-8") as f:
|
|
w = csv.DictWriter(f, fieldnames=list(rows[0].keys()))
|
|
w.writeheader()
|
|
w.writerows(rows)
|
|
tasks = sorted(set(r["task"] for r in rows if not r["task"].startswith("smoke")))
|
|
variants = [v for v in ("LEL", "VAN", "VANL", "LELK", "LELG") if any(r["variant"] == v for r in rows)]
|
|
md = ["# Codex comparison: %s" % ", ".join("%s = %s" % (v, NAMES[v]) for v in variants), "",
|
|
"Temperature 0 is injected for every arm; same Codex CLI, same prompts, same limits; no AGENTS.md pad. Greedy sessions are not reproducible run to run, so read the repetitions, not one cell.", ""]
|
|
for t in tasks:
|
|
md += ["## %s" % t, "", "| variant | rep | accepted | checks | browser | rounds (failed) | tool calls | wall s | decode tok/s | ttfb s | s/request | in tokens (cached) | ctx peak | termination |", "|---|---|---|---|---|---|---|---|---|---|---|---|---|---|"]
|
|
for r in [x for x in rows if x["task"] == t]:
|
|
md.append("| %s | %s | %s | %s/%s | %s | %s (%s) | %s | %s | %s | %s | %s | %s (%s) | %s | %s |" % (
|
|
r["variant"], r["rep"], r["accepted"], r["acc_pass"], r["acc_total"], r["browser"] or "-", r["rounds"], r["rounds_failed"], r["tool_calls"], r["wall_s"],
|
|
r["decode_tok_s"], r["ttfb_mean_s"], r["s_per_request"], r["in_tokens_total"], r["cached_share"], r["ctx_peak"], r["termination"]))
|
|
md += ["", "| variant | n | accepted | rounds | tool calls | wall s | decode tok/s | s/request |", "|---|---|---|---|---|---|---|---|"]
|
|
for v in variants:
|
|
rs_ = [x for x in rows if x["task"] == t and x["variant"] == v]
|
|
if rs_:
|
|
md.append("| %s | %d | %d/%d | %s | %s | %s | %s | %s |" % (v, len(rs_), sum(1 for x in rs_ if x["accepted"] == "yes"), len(rs_), mean_sd([x["rounds"] for x in rs_]), mean_sd([x["tool_calls"] for x in rs_]),
|
|
mean_sd([x["wall_s"] for x in rs_]), mean_sd([x["decode_tok_s"] for x in rs_]), mean_sd([x["s_per_request"] for x in rs_])))
|
|
# the reference is VANL (vanilla with both lossy defaults off = the Original of the quality studies); VAN is what a vanilla user gets by default
|
|
for x, y, why in (("LEL", "VANL", "Leleka minus the reference"), ("VAN", "VANL", "vanilla shipped minus the reference (the cost of vanilla's lossy defaults)"), ("LEL", "VAN", "Leleka minus vanilla shipped"),
|
|
("LELG", "LELK", "GGUF PLE minus KAR PLE (same runtime, KAR on / off study)")):
|
|
if x not in variants or y not in variants:
|
|
continue
|
|
pairs = []
|
|
for rep in sorted(set(r["rep"] for r in rows if r["task"] == t)):
|
|
p1 = [r for r in rows if r["task"] == t and r["variant"] == x and r["rep"] == rep]
|
|
p2 = [r for r in rows if r["task"] == t and r["variant"] == y and r["rep"] == rep]
|
|
if p1 and p2:
|
|
pairs.append((p1[0], p2[0]))
|
|
if pairs:
|
|
md += ["", "Paired by repetition, %s %s (%d pair%s):" % (x + " - " + y, why, len(pairs), "" if len(pairs) == 1 else "s"), ""]
|
|
for key, label in (("rounds", "rounds"), ("tool_calls", "tool calls"), ("wall_s", "wall s"), ("decode_tok_s", "decode tok/s")):
|
|
ds = [p[0][key] - p[1][key] for p in pairs if isinstance(p[0][key], (int, float)) and isinstance(p[1][key], (int, float))]
|
|
md.append("* %s: %s (per pair: %s)" % (label, mean_sd(ds), ", ".join("%+.1f" % d for d in ds)))
|
|
md.append("")
|
|
md += ["## Sessions to read", ""]
|
|
md += ["* %s %s r%s: `%s` (%s, %s rounds)" % (r["variant"], r["task"], r["rep"], r["transcript"], r["accepted"], r["rounds"]) for r in rows if not r["task"].startswith("smoke")]
|
|
open(os.path.join(out, "compare.md"), "w", encoding="utf-8").write("\n".join(md) + "\n")
|
|
print("\n".join(md[:60]))
|
|
print("written", os.path.join(out, "compare.md"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|