SPB Git

spb/wp33_uqo

Public MIT
4.5 KB · 58 lines python
1#!/usr/bin/env python32"""Generate LaTeX table fragments under paper/tables/ from processed/raw logs. Every number in the paper's tables comes from here."""3import json, os, sys, glob, statistics4ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))5OUT = os.path.join(ROOT, "paper", "tables"); os.makedirs(OUT, exist_ok=True)67def sim_table(path, label, caption):8    d = json.load(open(path)); rows = d["results"]9    caps = sorted({r["capacity"] for r in rows}); preds = []10    for r in rows:11        if r["predictor"] not in preds: preds.append(r["predictor"])12    lines = ["\\begin{table}[t]", "\\centering\\small", f"\\caption{{{caption}}}", f"\\label{{{label}}}",13             "\\begin{tabular}{ll" + "rr" * len(caps) + "}", "\\toprule",14             "Predictor & split & " + " & ".join(f"\\multicolumn{{2}}{{c}}{{$C={c}$}}" for c in caps) + " \\\\",15             " & & " + " & ".join("hit & stall" for _ in caps) + " \\\\", "\\midrule"]16    for p in preds:17        for split in ("fit", "heldout"):18            cells = []19            for c in caps:20                m = [r for r in rows if r["predictor"] == p and r["split"] == split and r["capacity"] == c and r["policy"] == "lru"]21                cells.append(f"{m[0]['hit_rate']:.3f} & {m[0]['stall_ms_per_token']:.1f}" if m else "-- & --")22            lines.append(f"{p.replace('_', '\\_')} & {split} & " + " & ".join(cells) + " \\\\")23    lines += ["\\bottomrule", "\\end{tabular}", "\\begin{tablenotes}\\footnotesize", f"\\item Source: \\code{{{os.path.relpath(path, ROOT).replace('_', '\\_')}}}; t\\_read {d['t_read_ms']} ms, t\\_layer {d['t_layer_ms']} ms, {d['loaders']} loader(s); hit = per-layer hit rate, stall in ms per token (modelled).", "\\end{tablenotes}", "\\end{table}"]24    open(os.path.join(OUT, f"{label.split(':')[-1]}.tex"), "w").write("\n".join(lines) + "\n")25    print("wrote", label)2627def bench_summary(paths, label, caption, keys=("backend", "capacity", "predictor", "m", "nocache", "split")):28    """Median decode tok/s, hit rate and stall per configuration from bench_decode JSONL files (warm-up excluded)."""29    recs = []30    for p in paths:31        recs += [json.loads(l) for l in open(p) if l.strip()]32    recs = [r for r in recs if not r.get("warmup")]33    groups = {}34    for r in recs:35        k = tuple(r.get(x) for x in keys); groups.setdefault(k, []).append(r)36    lines = ["\\begin{table}[t]", "\\centering\\small", f"\\caption{{{caption}}}", f"\\label{{{label}}}",37             "\\begin{tabular}{llrrrrrr}", "\\toprule", "Backend & cfg & $n$ & decode tok/s (median) & p95 ITL ms & hit & stall s & TTFT ms \\\\", "\\midrule"]38    for k in sorted(groups, key=lambda x: tuple(str(v) for v in x)):39        g = groups[k]40        med = lambda f: statistics.median([r[f] for r in g if r.get(f) is not None]) if any(r.get(f) is not None for r in g) else None41        cfg = f"C={k[1]}, {k[2]}, m={k[3]}" + (", cold" if k[4] else "") if k[0] == "titan" else "--"42        f = lambda v, fmt: (fmt % v) if v is not None else "--"43        lines.append(f"{k[0].replace('_', '\\_')} & {cfg.replace('_', '\\_')} & {len(g)} & {f(med('gen_tps'), '%.1f')} & {f(med('itl_ms_p95'), '%.1f')} & {f(med('cache_hit_rate'), '%.3f')} & {f(med('stall_s'), '%.2f')} & {f(med('ttft_ms'), '%.0f')} \\\\")44    lines += ["\\bottomrule", "\\end{tabular}", "\\begin{tablenotes}\\footnotesize", "\\item Sources: " + ", ".join(f"\\code{{{os.path.relpath(p, ROOT).replace('_', '\\_')}}}" for p in paths) + ".", "\\end{tablenotes}", "\\end{table}"]45    open(os.path.join(OUT, f"{label.split(':')[-1]}.tex"), "w").write("\n".join(lines) + "\n")46    print("wrote", label)4748if __name__ == "__main__":49    v2 = os.path.join(ROOT, "benchmarks/processed/gateC/sim_olmoe_v2_ssd043_m8.json")50    v1 = os.path.join(ROOT, "benchmarks/processed/gateC/sim_olmoe_laptop_ssd_v1.json")51    sim_table(v2 if os.path.exists(v2) else v1, "tab:sim", "Trace-driven simulation (OLMoE, per-layer LRU tables, cold per prompt): hit rate and modelled stall per token by predictor, split and capacity $C$.")52    cold = os.path.join(ROOT, "benchmarks/raw/gateC/cold_nvme_laptop/sweep.jsonl")53    if os.path.exists(cold):54        bench_summary([cold], "tab:cold", "Cold-NVMe tier on the M5 Max laptop (purge + F\\_NOCACHE), OLMoE 4-bit, held-out prompts, 64 tokens.")55    q = os.path.join(ROOT, "benchmarks/raw/gateC/qwen3_m3u96a/baseline.jsonl")56    if os.path.exists(q):57        bench_summary([q], "tab:qwen3", "Qwen3-30B-A3B-Instruct-2507 4-bit on M3U96a (M3 Ultra, 96 GB): mlx-lm vs TITAN all-resident (128 slots, preloaded), 64 tokens, 3 repeats.")58
Files · 25746122a917831e6577ac3afd533c66a3338d63
Menu

Theme