| """Plotly HTML figures from the job's JSON results.""" |
| import json, os, argparse |
| import plotly.graph_objects as go |
|
|
| BLUE, RED, GREEN, ORANGE = "#2563eb", "#dc2626", "#16a34a", "#f59e0b" |
|
|
|
|
| def claim2_plots(outdir): |
| d = json.load(open(os.path.join(outdir, "claim2_results.json"))) |
| kb = d.get("kernel_bench", {}) |
| |
| fig = go.Figure() |
| pal = {"T-stage3": BLUE, "T-stage4": ORANGE, "B-stage3": GREEN, "B-stage4": RED} |
| for name, r in kb.items(): |
| b2s = sorted(int(k) for k in r["ms_per_call_by_B2"]) |
| ms = [r["ms_per_call_by_B2"][str(b)] if str(b) in r["ms_per_call_by_B2"] |
| else r["ms_per_call_by_B2"][b] for b in b2s] |
| fig.add_trace(go.Scatter(x=b2s, y=ms, mode="lines+markers", name=name, |
| line=dict(color=pal.get(name), width=3))) |
| fig.update_layout(title="SSM kernel time vs fold factor B2 (A100, B=128, S=8)", |
| xaxis_title="fold factor B2 (B1=B/B2)", xaxis_type="log", |
| yaxis_title="ms per selective_scan call", |
| template="plotly_white", width=640, height=440) |
| fig.write_html(os.path.join(outdir, "claim2_curves.html"), include_plotlyjs="cdn") |
| |
| names = list(kb) |
| sp = [kb[n]["speedup_pct"] for n in names] |
| fig = go.Figure(go.Bar(x=names, y=sp, marker_color=BLUE, |
| text=[f"{s:.0f}%" for s in sp], textposition="outside")) |
| fig.add_hrect(y0=110, y1=180, fillcolor="rgba(22,163,74,0.15)", line_width=0, |
| annotation_text="paper: 110–180%") |
| fig.update_layout(title="Claim 2: SSM kernel speedup from batch folding", |
| yaxis_title="speedup vs B2=1 (%)", |
| template="plotly_white", width=600, height=440) |
| fig.write_html(os.path.join(outdir, "claim2_speedup.html"), include_plotlyjs="cdn") |
|
|
|
|
| def claim1_plot(outdir): |
| d = json.load(open(os.path.join(outdir, "claim1_results.json"))) |
| fig = go.Figure() |
| pal = {"uni": RED, "swap": BLUE, "bidir": GREEN} |
| for mode, r in d["modes"].items(): |
| acc = r["per_position_acc"] |
| fig.add_trace(go.Scatter(x=list(range(1, len(acc) + 1)), y=acc, |
| mode="lines+markers", name=mode, |
| line=dict(color=pal.get(mode), width=3))) |
| fig.add_hline(y=d["chance"], line_dash="dot", line_color="gray", |
| annotation_text="chance") |
| fig.update_layout(title="Claim 1: per-position accuracy (label = last token's class)", |
| xaxis_title="position (1..T; T is the only causally-legal one)", |
| yaxis_title="test accuracy", |
| template="plotly_white", width=640, height=440) |
| fig.write_html(os.path.join(outdir, "claim1_positions.html"), include_plotlyjs="cdn") |
|
|
|
|
| def claim34_plot(outdir): |
| d = json.load(open(os.path.join(outdir, "claim34_results.json"))) |
| ours = {k: v for k, v in d["throughput_img_s"].items() if isinstance(v, (int, float))} |
| paper = d["paper_img_s"] |
| names = [n for n in ours if n in paper] |
| fig = go.Figure() |
| fig.add_trace(go.Bar(x=names, y=[paper[n] for n in names], name="paper (A100)", |
| marker_color="#94a3b8")) |
| fig.add_trace(go.Bar(x=names, y=[ours[n] for n in names], |
| name=f"ours ({d['gpu']}, fp16)", marker_color=BLUE)) |
| fig.update_layout(title="Claims 3/4: throughput, paper vs our A100 (batch 128)", |
| yaxis_title="images / s", barmode="group", |
| template="plotly_white", width=680, height=440) |
| fig.write_html(os.path.join(outdir, "claim34_throughput.html"), include_plotlyjs="cdn") |
|
|
|
|
| if __name__ == "__main__": |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--out", default="outputs") |
| a = ap.parse_args() |
| for fn in (claim2_plots, claim1_plot, claim34_plot): |
| try: |
| fn(a.out) |
| print(fn.__name__, "ok") |
| except Exception as e: |
| print(fn.__name__, "SKIP:", e) |
|
|