Files
Kaname/src/worker/betterbench.ts
T
Pascal LinxweilerandClaude Opus 5.5 9e167a44f6 Benchmarks with BetterBench, launch80-style reports and publishing, GPU support
- Benchmarks: BetterBench 0.6.1 (pinned by checksum) runs against a running
  deployment, one at a time; quick/full/custom passes, phase selection, live
  step and output, cancel, run again, compare runs side by side.
- Report page after launch80's bench.betterbench.v1: headline tiles,
  "Read these first" caveats (quick, sample gate, max_tokens truncation,
  batched streams, failures, skipped depths, prefix-cache hits), charts, full
  tables with daggered under-sampled cells, method text. All figures come from
  BetterBench's own report functions.
- Publish to launch80 as a double opt-in: L80 dry run builds the exact payload
  for inspection, an explicit confirmation publishes that file (L80 CLI 0.4.0
  pinned by checksum, L80_TOKEN worker-only). Endpoint and host never leave.
- GPUs: runtime accelerator (CPU, NVIDIA, /dev/dri, ROCm) with presets for the
  official CUDA/Vulkan/Intel/ROCm builds; NVIDIA GPUs probed via nvidia-smi in
  a short-lived container; per-deployment GPU picking, -ngl, split mode,
  tensor split, MoE offload, vLLM tensor parallel and GPU memory share.
- llama.cpp --cache-ram option (1 GiB for new deployments) and a memory
  estimate that counts it and the KV cache: the 8 GiB default made containers
  thrash at their memory limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 20:54:38 +02:00

102 lines
3.5 KiB
TypeScript

// BetterBench (https://github.com/GGZ14/BetterBench, Apache-2.0): the benchmark Kaname runs
// against deployments. Flags verified against v0.6.1 (`betterbench run --help`, betterbench/cli.py).
import { dirname, join } from "node:path";
import type { BenchmarkSettings } from "@/lib/db/schema";
import { coreEnv } from "@/lib/env";
export function betterbenchBin(): string {
return coreEnv().BETTERBENCH_BIN;
}
/** The Python of BetterBench's own venv (it imports `betterbench`). */
export function betterbenchPython(): string {
const bin = betterbenchBin();
return bin.includes("/") ? join(dirname(bin), "python") : "python3";
}
export function runArgs(o: {
endpoint: string;
model: string;
out: string;
settings: BenchmarkSettings;
maxModelLen: number | null;
notes: Record<string, string>;
}): string[] {
const s = o.settings;
return [
"run",
"--endpoint",
o.endpoint,
"--model",
o.model,
"--out",
o.out,
// Kaname knows the context window; llama-server's /v1/models doesn't report it.
...(o.maxModelLen ? ["--max-model-len", String(o.maxModelLen)] : []),
...(s.quick ? ["--quick"] : []),
...(s.passes != null ? ["--passes", String(s.passes)] : []),
...(s.warmup != null ? ["--warmup", String(s.warmup)] : []),
...s.phases.map((p) => `--${p}`),
...Object.entries(o.notes).flatMap(([k, v]) => ["--note", `${k}=${v}`]),
"--no-update-check",
];
}
/**
* Prints Kaname's BenchmarkSummary for a results.json, using BetterBench's own report functions
* so the numbers match its HTML report.
*/
export const SUMMARY_SCRIPT = `
import json, math, sys
from betterbench import report as r
res = json.load(open(sys.argv[1]))
def clean(v):
if isinstance(v, dict):
return {str(k): clean(x) for k, x in v.items()}
if isinstance(v, (list, tuple)):
return [clean(x) for x in v]
if isinstance(v, (bool, str)) or v is None:
return v
try:
f = float(v)
except (TypeError, ValueError):
return None
if math.isnan(f) or math.isinf(f):
return None
return int(f) if float(f).is_integer() and not isinstance(v, float) else f
rows = r.single_rows(res)
cfg = res.get("config", {})
env = res.get("env", {})
reasoning = r.reasoning_rows(res)
gate = res.get("sample_gate") or r.sample_gate(res)
trunc, ok_runs = r.truncation_summary(res)
failed = sum(1 for recs in res.get("single_stream", {}).values() for x in recs if not x.get("ok"))
keep_cfg = ("warmup", "runs_per_category", "temperature", "top_p", "top_k", "greedy", "unique_nonce", "weights",
"concurrency_levels", "concurrency_requests", "prefill_runs", "prefill_warmup", "prefill_max_tokens")
out = {
"v": 2,
"combined": r.combined_score(res, rows),
"single": rows,
"prefill": r.prefill_rows(res),
"concurrency": r.concurrency_rows(res),
"reasoning": reasoning if r.has_reasoning_evidence(reasoning) else [],
"gate": gate.get("under_sampled", []),
"truncated": [trunc, ok_runs],
"failedSingle": failed,
"phases": r.phases_present(res),
"cacheHits": r.cache_hits(res),
"betterbenchVersion": res.get("betterbench_version", ""),
"corpusVersion": res.get("corpus_version", ""),
"corpusHash": env.get("corpus_hash"),
"timestamp": env.get("timestamp"),
"maxModelLen": env.get("max_model_len"),
"config": {k: cfg.get(k) for k in keep_cfg},
"passes": cfg.get("runs_per_category"),
}
print(json.dumps(clean(out)))
`;
/** Version of the summary shape above; older stored summaries are recomputed from results.json. */
export const SUMMARY_VERSION = 2;