- A/B with betterbench ab between two deployments of the same model, with verdict, confidence interval and caveats. - Sweeps vary one or two deployment settings, deploy, benchmark and remove each variant, and compare them in one table. - Every run records CPU, RAM, VRAM, GPU utilization and power. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
186 lines
9.5 KiB
TypeScript
186 lines
9.5 KiB
TypeScript
import { TriangleAlertIcon } from "lucide-react";
|
|
import { BenchmarkResources } from "@/components/benchmark-resources";
|
|
import { abCaveats, abHeadline, abMethod, abSummaryText, halfWidth } from "@/lib/ab-report";
|
|
import { CONFIG_ROWS } from "@/lib/benchmark-view";
|
|
import type { PairedResult } from "@/lib/db/schema";
|
|
import { cn } from "@/lib/utils";
|
|
import type { ListRow } from "../benchmark-list";
|
|
|
|
const sign = (v: number) => `${v > 0 ? "+" : ""}${v.toFixed(2)}%`;
|
|
|
|
/** The difference with its 95% interval on a %-axis: zero line, the ±target band, the interval and the point. */
|
|
function IntervalChart({ r, target }: { r: PairedResult; target: number }) {
|
|
const reach = Math.max(Math.abs(r.ci_low_pct), Math.abs(r.ci_high_pct), target) * 1.25 || 1;
|
|
const pos = (v: number) => `${((v + reach) / (2 * reach)) * 100}%`;
|
|
const ticks = [-reach, -reach / 2, 0, reach / 2, reach].map((t) => Math.round(t * 10) / 10);
|
|
return (
|
|
<div className="flex flex-col gap-1" role="img" aria-label={`Difference ${sign(r.pct_diff)}, 95% interval ${sign(r.ci_low_pct)} to ${sign(r.ci_high_pct)}`}>
|
|
<div className="relative h-12">
|
|
{/* ±target band: differences inside it are smaller than the precision asked for */}
|
|
<div className="absolute inset-y-2 bg-muted" style={{ left: pos(-target), width: `calc(${pos(target)} - ${pos(-target)})` }} />
|
|
<div className="absolute inset-y-0 w-px bg-foreground/50" style={{ left: pos(0) }} />
|
|
<div
|
|
className={cn("absolute top-1/2 h-2 -translate-y-1/2 rounded-full", r.significant ? "bg-series" : "bg-foreground/40")}
|
|
style={{ left: pos(r.ci_low_pct), width: `calc(${pos(r.ci_high_pct)} - ${pos(r.ci_low_pct)})` }}
|
|
/>
|
|
<div
|
|
className={cn("absolute top-1/2 size-4 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2 ring-card", r.significant ? "bg-series" : "bg-foreground/60")}
|
|
style={{ left: pos(r.pct_diff) }}
|
|
/>
|
|
</div>
|
|
<div className="relative h-4 text-[11px] text-muted-foreground tabular-nums">
|
|
{ticks.map((t) => (
|
|
<span key={t} className="absolute -translate-x-1/2" style={{ left: pos(t) }}>
|
|
{t > 0 ? "+" : ""}
|
|
{t}%
|
|
</span>
|
|
))}
|
|
</div>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
Dot: B's difference from A. Bar: the 95% interval. Grey band: ±{target}%, the precision asked for. B is better to the {r.higher_is_better ? "right" : "left"}.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Side({ label, name, value, unit }: { label: string; name: string; value: number; unit: string }) {
|
|
return (
|
|
<div className="flex flex-col gap-0.5 rounded-lg bg-muted/50 px-3 py-2">
|
|
<span className="text-[11px] tracking-wide text-muted-foreground uppercase">{label}</span>
|
|
<span className="text-lg font-semibold">
|
|
{value.toFixed(unit === "ms" ? 2 : 1)} <span className="text-sm font-normal text-muted-foreground">{unit}</span>
|
|
</span>
|
|
<span className="truncate text-[11px] text-muted-foreground" title={name}>
|
|
{name}
|
|
</span>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function AbReport({ run }: { run: ListRow }) {
|
|
const ab = run.ab;
|
|
const a = run.snapshot;
|
|
const b = run.snapshotB;
|
|
if (!ab || !b) return null;
|
|
const d = ab.decode_tps;
|
|
const g = ab.gap_median;
|
|
const caveats = abCaveats(ab);
|
|
const rows = CONFIG_ROWS.map((row) => ({ row, va: row.value(a), vb: row.value(b) })).filter((x) => x.va != null || x.vb != null);
|
|
const differs = rows.filter((x) => x.va !== x.vb);
|
|
const same = rows.filter((x) => x.va === x.vb);
|
|
|
|
return (
|
|
<article className="flex flex-col gap-8 rounded-2xl bg-card px-5 py-6 ring-1 ring-foreground/10 sm:px-8 sm:py-8">
|
|
<header className="flex flex-col gap-3">
|
|
<span className="font-mono text-[11px] tracking-wider text-muted-foreground uppercase">
|
|
BetterBench {ab.betterbenchVersion} · paired A/B · {ab.pairs} pairs
|
|
</span>
|
|
<h2 className="text-2xl font-semibold tracking-tight">{run.label ?? `${a.deploymentName} vs ${b.deploymentName}`}</h2>
|
|
<p className="max-w-3xl text-sm leading-relaxed">{abSummaryText(ab, a.deploymentName, b.deploymentName)}</p>
|
|
</header>
|
|
|
|
<section className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
|
|
<div className="flex flex-col gap-3">
|
|
<span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">Decode throughput</span>
|
|
<span className={cn("text-3xl font-semibold", d.significant ? "" : "text-muted-foreground")}>{abHeadline(d)}</span>
|
|
<span className="text-sm text-muted-foreground">
|
|
{sign(d.pct_diff)} · 95% CI {sign(d.ci_low_pct)} to {sign(d.ci_high_pct)} · {d.significant ? "significant" : "within noise"}
|
|
</span>
|
|
<IntervalChart r={d} target={ab.target_mde_pct} />
|
|
</div>
|
|
<div className="flex flex-col gap-3">
|
|
<span className="text-[11px] font-medium tracking-wide text-muted-foreground uppercase">{g.batched ? "Stream-update gap" : "Token-to-token smoothness"}</span>
|
|
<span className={cn("text-3xl font-semibold", g.significant ? "" : "text-muted-foreground")}>{abHeadline(g)}</span>
|
|
<span className="text-sm text-muted-foreground">
|
|
{sign(g.pct_diff)} · 95% CI {sign(g.ci_low_pct)} to {sign(g.ci_high_pct)} · lower is better
|
|
</span>
|
|
<IntervalChart r={g} target={ab.target_mde_pct} />
|
|
</div>
|
|
</section>
|
|
|
|
<div className="grid gap-2 sm:grid-cols-4">
|
|
<Side label="A · decode, mean" name={a.deploymentName} value={d.mean_a} unit="t/s" />
|
|
<Side label="B · decode, mean" name={b.deploymentName} value={d.mean_b} unit="t/s" />
|
|
<div className="flex flex-col gap-0.5 rounded-lg bg-muted/50 px-3 py-2">
|
|
<span className="text-[11px] tracking-wide text-muted-foreground uppercase">Pairs</span>
|
|
<span className="text-lg font-semibold">{ab.pairs}</span>
|
|
<span className="text-[11px] text-muted-foreground">
|
|
±{halfWidth(d).toFixed(2)}% reached · target ±{ab.target_mde_pct}%
|
|
</span>
|
|
</div>
|
|
<div className="flex flex-col gap-0.5 rounded-lg bg-muted/50 px-3 py-2">
|
|
<span className="text-[11px] tracking-wide text-muted-foreground uppercase">Paired CV</span>
|
|
<span className="text-lg font-semibold">{(ab.paired_cv * 100).toFixed(2)}%</span>
|
|
<span className="text-[11px] text-muted-foreground">~{ab.pairs_needed_for_mde} pairs for ±{ab.target_mde_pct}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
{caveats.length > 0 && (
|
|
<div className="flex gap-3 rounded-xl border border-amber-500/30 bg-amber-500/10 px-4 py-3 text-sm">
|
|
<TriangleAlertIcon className="mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-400" />
|
|
<div className="flex flex-col gap-1.5">
|
|
<span className="font-medium text-amber-800 dark:text-amber-200">Read these first</span>
|
|
{caveats.map((x) => (
|
|
<p key={x} className="text-foreground/80">
|
|
{x}
|
|
</p>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<section className="flex flex-col gap-3">
|
|
<h3 className="text-base font-semibold">What differs</h3>
|
|
<div className="overflow-x-auto rounded-lg ring-1 ring-foreground/10">
|
|
<table className="w-full text-xs">
|
|
<thead>
|
|
<tr className="border-b text-left text-muted-foreground">
|
|
<th className="px-3 py-2 font-medium" />
|
|
<th className="px-3 py-2 font-medium">A · {a.deploymentName}</th>
|
|
<th className="px-3 py-2 font-medium">B · {b.deploymentName}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{differs.length === 0 && (
|
|
<tr>
|
|
<td colSpan={3} className="px-3 py-2 text-muted-foreground">
|
|
Same settings on both sides (a null A/B: it shows how much noise the setup has).
|
|
</td>
|
|
</tr>
|
|
)}
|
|
{differs.map(({ row, va, vb }) => (
|
|
<tr key={row.key} className="border-b bg-amber-500/5 last:border-0">
|
|
<td className="px-3 py-1.5 font-medium">{row.label}</td>
|
|
<td className="px-3 py-1.5 font-mono break-all">{va ?? <span className="text-muted-foreground">default</span>}</td>
|
|
<td className="px-3 py-1.5 font-mono break-all">{vb ?? <span className="text-muted-foreground">default</span>}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{same.length > 0 && <p className="text-xs text-muted-foreground">Same on both: {same.map((x) => `${x.row.label.toLowerCase()} ${x.va}`).join(" · ")}.</p>}
|
|
</section>
|
|
|
|
{run.resources && (
|
|
<section className="flex flex-col gap-3">
|
|
<h3 className="text-base font-semibold">Resources</h3>
|
|
<BenchmarkResources stats={run.resources} names={{ a: a.deploymentName, b: b.deploymentName }} />
|
|
</section>
|
|
)}
|
|
|
|
<section className="flex flex-col gap-2">
|
|
<h3 className="text-base font-semibold">Method</h3>
|
|
<div className="flex max-w-3xl flex-col gap-2 text-sm text-muted-foreground">
|
|
{abMethod(ab).map((p) => (
|
|
<p key={p}>{p}</p>
|
|
))}
|
|
</div>
|
|
</section>
|
|
|
|
<footer className="border-t pt-4 text-xs text-muted-foreground">
|
|
Generated by Kaname from a BetterBench {ab.betterbenchVersion} paired A/B{ab.corpusVersion ? ` on corpus v${ab.corpusVersion}` : ""}. Every figure is BetterBench's own.
|
|
</footer>
|
|
</article>
|
|
);
|
|
}
|