Files
Kaname/src/worker/ab-summary.ts
T
Pascal LinxweilerandClaude Opus 5.5 b623b16a6d Benchmarks: paired A/B runs, sweeps, resource usage
- 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>
2026-10-13 10:04:40 +02:00

51 lines
1.9 KiB
TypeScript

// `betterbench ab` output (ab.json) → Kaname's AbSummary. Keeps BetterBench's own paired_compare
// results as reported; drops the endpoints (they never leave the machine). Pure, for tests.
import type { AbSummary, PairedResult } from "@/lib/db/schema";
type AbJson = {
betterbench_version?: string;
corpus_version?: string;
config?: Record<string, unknown>;
env?: { timestamp?: string };
pairs: number;
decode_tps: PairedResult;
gap_median?: PairedResult & { batched?: boolean };
itl_median?: PairedResult;
paired_cv: number;
pairs_needed_for_mde: number;
target_mde_pct: number;
conf: number;
raw?: { a_tps?: number[]; b_tps?: number[] };
};
const num = (v: unknown) => (typeof v === "number" && Number.isFinite(v) ? v : null);
export function abSummary(raw: string, maxPairs: number | null): AbSummary {
const j = JSON.parse(raw) as AbJson;
if (!j.decode_tps || typeof j.pairs !== "number") throw new Error("not a BetterBench ab.json");
const gap = j.gap_median ?? (j.itl_median ? { ...j.itl_median, batched: false } : null);
const cfg = j.config ?? {};
return {
pairs: j.pairs,
decode_tps: j.decode_tps,
gap_median: { ...(gap as PairedResult), batched: !!(gap as { batched?: boolean } | null)?.batched },
paired_cv: j.paired_cv,
pairs_needed_for_mde: j.pairs_needed_for_mde,
target_mde_pct: j.target_mde_pct,
conf: j.conf,
maxPairs,
raw: { a_tps: j.raw?.a_tps ?? [], b_tps: j.raw?.b_tps ?? [] },
betterbenchVersion: j.betterbench_version ?? "",
corpusVersion: j.corpus_version ?? "",
timestamp: j.env?.timestamp ?? null,
config: {
greedy: typeof cfg.greedy === "boolean" ? cfg.greedy : null,
temperature: num(cfg.temperature),
warmup: num(cfg.warmup),
unique_nonce: typeof cfg.unique_nonce === "boolean" ? cfg.unique_nonce : null,
ab_min_pairs: num(cfg.ab_min_pairs),
},
};
}