"use client"; import { BadgeCheckIcon, GaugeIcon, GitCompareArrowsIcon, Loader2Icon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { NativeSelect } from "@/components/ui/native-select"; import { type BenchmarkPhase, QUALITY_SECTIONS, type QualitySection } from "@/lib/db/schema"; import { SECTION_HINT, SECTION_LABEL } from "@/lib/quality-view"; import { cn } from "@/lib/utils"; const PHASES: { id: BenchmarkPhase; label: string; hint: string }[] = [ { id: "decode", label: "Generation", hint: "single request, 8 prompt categories" }, { id: "prefill", label: "Prompt processing", hint: "growing input lengths, up to the context size" }, { id: "concurrency", label: "Parallel requests", hint: "1, 2, 4 and 8 at once" }, ]; type Mode = "run" | "ab" | "quality"; type Peer = { id: string; name: string; model: string | null; models: string[] }; /** Benchmark an endpoint: a BetterBench run, a paired A/B against another endpoint, or the quality eval. */ export function BenchmarkStart({ endpoint, peers }: { endpoint: { id: string; name: string; model: string | null; models: string[] }; peers: Peer[] }) { const router = useRouter(); const [tab, setTab] = useState("run"); const [model, setModel] = useState(endpoint.model ?? ""); const [mode, setMode] = useState("quick"); const [passes, setPasses] = useState("10"); const [phases, setPhases] = useState(["decode", "prefill", "concurrency"]); const [label, setLabel] = useState(""); const [description, setDescription] = useState(""); const [busy, setBusy] = useState(false); const [peerId, setPeerId] = useState(""); const [mde, setMde] = useState("1"); const [maxPairs, setMaxPairs] = useState("200"); const [sections, setSections] = useState([...QUALITY_SECTIONS]); // The model a run requests: the one picked here, the endpoint's, or the only one it serves. const runModel = model || (endpoint.models.length === 1 ? endpoint.models[0] : ""); const peer = peers.find((p) => p.id === peerId); const peerServes = !peer || !runModel || peer.models.length === 0 || peer.models.includes(runModel); async function start(body: Record) { setBusy(true); try { const res = await fetch("/api/benchmarks", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ endpointId: endpoint.id, model: runModel || null, label: label.trim() || null, description: description.trim() || null, ...body }), }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error(json.error?.message ?? `Could not start (${res.status})`); router.push(`/benchmarks/${json.id}`); } finally { setBusy(false); } } const TABS: { id: Mode; label: string; icon: typeof GaugeIcon }[] = [ { id: "run", label: "Speed", icon: GaugeIcon }, { id: "ab", label: "A/B", icon: GitCompareArrowsIcon }, { id: "quality", label: "Quality", icon: BadgeCheckIcon }, ]; const labelInputs = ( <> setLabel(e.target.value)} maxLength={120} placeholder="Label, e.g. q8_0 KV cache (optional)" /> {tab !== "quality" && ( setDescription(e.target.value)} maxLength={4000} placeholder="What this run tries out (optional; published with it, default: the endpoint's notes)" /> )} ); return ( Benchmark
{TABS.map((t) => ( ))}
{endpoint.models.length > 1 && ( setModel(e.target.value)} className="h-8 max-w-72 text-xs" aria-label="Model"> {endpoint.models.map((m) => ( ))} )}
{tab === "run" && ( <>
setMode(e.target.value)} aria-label="Run length"> {mode === "custom" && ( setPasses(e.target.value.replace(/\D/g, ""))} inputMode="numeric" className="w-16" aria-label="Passes per category" /> )}
{PHASES.map((p) => ( ))}
{labelInputs}

Kaname checks the server first. Keep other load off it while the run lasts; on a CPU a full run can take hours.

)} {tab === "ab" && ( <>

Paired A/B: the same prompts go to this endpoint (A) and another one serving the same model (B), alternating, until the difference is known to ±the target.

{peers.length === 0 ? (

Add a second endpoint serving the same model (e.g. with another KV cache type or engine build) to compare.

) : ( <> setPeerId(e.target.value)} aria-label="Endpoint B"> {peers.map((p) => ( ))} {!peerServes &&

{peer?.name} doesn't list {runModel}. Both sides get the same model name.

}
{labelInputs} )} )} {tab === "quality" && ( <>

A short, deterministic check of the answers (greedy decoding, fixed seed, thinking off): to see whether a quant, KV cache type or build changes quality, next to the speed numbers.

{QUALITY_SECTIONS.map((s) => ( ))}
{labelInputs} )}
); }