Release / release (push) Successful in 12m32s
Kaname keeps two jobs: the model downloader and benchmarks. Benchmarks now run against endpoints (any OpenAI-compatible server added by URL, with an optional server-side API key and hand-written hardware notes) instead of deployments Kaname started itself. Removed: runtimes, deployments, sweeps, resource telemetry, hardware detection, the /api/v1 API with tokens and guardrails, and all Docker access. The quality eval's coding tests run in a network-less sandbox container that shares only an exchange folder with the worker. The previous state is kept in branch backup / tag backup-0.14.3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
216 lines
11 KiB
TypeScript
216 lines
11 KiB
TypeScript
"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<Mode>("run");
|
|
const [model, setModel] = useState(endpoint.model ?? "");
|
|
const [mode, setMode] = useState("quick");
|
|
const [passes, setPasses] = useState("10");
|
|
const [phases, setPhases] = useState<BenchmarkPhase[]>(["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<QualitySection[]>([...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<string, unknown>) {
|
|
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 = (
|
|
<>
|
|
<Input value={label} onChange={(e) => setLabel(e.target.value)} maxLength={120} placeholder="Label, e.g. q8_0 KV cache (optional)" />
|
|
{tab !== "quality" && (
|
|
<Input value={description} onChange={(e) => setDescription(e.target.value)} maxLength={4000} placeholder="What this run tries out (optional; published with it, default: the endpoint's notes)" />
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<Card size="sm">
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-1.5">
|
|
<GaugeIcon className="size-4 text-muted-foreground" />
|
|
Benchmark
|
|
</CardTitle>
|
|
</CardHeader>
|
|
<CardContent className="flex flex-col gap-3 text-sm">
|
|
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
<div className="inline-flex rounded-lg bg-muted p-1" role="tablist">
|
|
{TABS.map((t) => (
|
|
<button
|
|
key={t.id}
|
|
type="button"
|
|
role="tab"
|
|
aria-selected={tab === t.id}
|
|
onClick={() => setTab(t.id)}
|
|
className={cn("flex items-center gap-1 rounded-md px-2.5 py-1 text-xs", tab === t.id ? "bg-background font-medium shadow-sm" : "text-muted-foreground hover:text-foreground")}
|
|
>
|
|
<t.icon className="size-3.5" />
|
|
{t.label}
|
|
</button>
|
|
))}
|
|
</div>
|
|
{endpoint.models.length > 1 && (
|
|
<NativeSelect value={model} onChange={(e) => setModel(e.target.value)} className="h-8 max-w-72 text-xs" aria-label="Model">
|
|
<option value="">Choose a model…</option>
|
|
{endpoint.models.map((m) => (
|
|
<option key={m} value={m}>
|
|
{m}
|
|
</option>
|
|
))}
|
|
</NativeSelect>
|
|
)}
|
|
</div>
|
|
|
|
{tab === "run" && (
|
|
<>
|
|
<div className="grid grid-cols-[1fr_auto] items-center gap-2">
|
|
<NativeSelect value={mode} onChange={(e) => setMode(e.target.value)} aria-label="Run length">
|
|
<option value="quick">Quick: 5 passes (smoke test)</option>
|
|
<option value="full">Full: 20 passes (comparable)</option>
|
|
<option value="custom">Custom number of passes</option>
|
|
</NativeSelect>
|
|
{mode === "custom" && (
|
|
<Input value={passes} onChange={(e) => setPasses(e.target.value.replace(/\D/g, ""))} inputMode="numeric" className="w-16" aria-label="Passes per category" />
|
|
)}
|
|
</div>
|
|
<div className="flex flex-col gap-1.5">
|
|
{PHASES.map((p) => (
|
|
<label key={p.id} className="flex cursor-pointer items-start gap-2">
|
|
<Checkbox checked={phases.includes(p.id)} onCheckedChange={(v) => setPhases((cur) => (v ? [...cur, p.id] : cur.filter((x) => x !== p.id)))} className="mt-0.5" />
|
|
<span className="flex flex-col">
|
|
<span>{p.label}</span>
|
|
<span className="text-xs text-muted-foreground">{p.hint}</span>
|
|
</span>
|
|
</label>
|
|
))}
|
|
</div>
|
|
{labelInputs}
|
|
<Button
|
|
onClick={() => start({ quick: mode === "quick", passes: mode === "custom" ? Number(passes) || 10 : null, phases: phases.length === PHASES.length ? [] : phases })}
|
|
disabled={busy || phases.length === 0}
|
|
>
|
|
{busy ? <Loader2Icon className="animate-spin" /> : <GaugeIcon />}
|
|
Run benchmark
|
|
</Button>
|
|
<p className="text-xs text-muted-foreground">Kaname checks the server first. Keep other load off it while the run lasts; on a CPU a full run can take hours.</p>
|
|
</>
|
|
)}
|
|
|
|
{tab === "ab" && (
|
|
<>
|
|
<p className="text-xs text-muted-foreground">
|
|
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.
|
|
</p>
|
|
{peers.length === 0 ? (
|
|
<p className="text-xs text-muted-foreground">Add a second endpoint serving the same model (e.g. with another KV cache type or engine build) to compare.</p>
|
|
) : (
|
|
<>
|
|
<NativeSelect value={peerId} onChange={(e) => setPeerId(e.target.value)} aria-label="Endpoint B">
|
|
<option value="">Choose B…</option>
|
|
{peers.map((p) => (
|
|
<option key={p.id} value={p.id}>
|
|
{p.name}
|
|
{runModel && p.models.length > 0 && !p.models.includes(runModel) ? " (doesn't serve this model)" : ""}
|
|
</option>
|
|
))}
|
|
</NativeSelect>
|
|
{!peerServes && <p className="text-xs text-amber-700 dark:text-amber-300">{peer?.name} doesn't list {runModel}. Both sides get the same model name.</p>}
|
|
<div className="grid grid-cols-2 gap-2">
|
|
<label className="flex flex-col gap-1 text-xs">
|
|
<span className="text-muted-foreground">Target precision (±%)</span>
|
|
<Input value={mde} onChange={(e) => setMde(e.target.value.replace(/[^\d.]/g, ""))} inputMode="decimal" />
|
|
</label>
|
|
<label className="flex flex-col gap-1 text-xs">
|
|
<span className="text-muted-foreground">Max pairs</span>
|
|
<Input value={maxPairs} onChange={(e) => setMaxPairs(e.target.value.replace(/\D/g, ""))} inputMode="numeric" />
|
|
</label>
|
|
</div>
|
|
{labelInputs}
|
|
<Button onClick={() => start({ endpointBId: peerId, mdePct: Number(mde) || 1, maxPairs: Math.max(12, Number(maxPairs) || 200) })} disabled={busy || !peer || !peerServes}>
|
|
{busy ? <Loader2Icon className="animate-spin" /> : <GitCompareArrowsIcon />}
|
|
Start A/B
|
|
</Button>
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
|
|
{tab === "quality" && (
|
|
<>
|
|
<p className="text-xs text-muted-foreground">
|
|
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.
|
|
</p>
|
|
<div className="flex flex-col gap-1.5">
|
|
{QUALITY_SECTIONS.map((s) => (
|
|
<label key={s} className="flex cursor-pointer items-start gap-2">
|
|
<Checkbox checked={sections.includes(s)} onCheckedChange={(v) => setSections((cur) => (v ? [...cur, s] : cur.filter((x) => x !== s)))} className="mt-0.5" />
|
|
<span className="flex flex-col">
|
|
<span>{SECTION_LABEL[s]}</span>
|
|
<span className="text-xs text-muted-foreground">{SECTION_HINT[s]}</span>
|
|
</span>
|
|
</label>
|
|
))}
|
|
</div>
|
|
{labelInputs}
|
|
<Button onClick={() => start({ kind: "eval", evalSections: sections.length === QUALITY_SECTIONS.length ? [] : sections })} disabled={busy || sections.length === 0}>
|
|
{busy ? <Loader2Icon className="animate-spin" /> : <BadgeCheckIcon />}
|
|
Run quality eval
|
|
</Button>
|
|
</>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|