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>
This commit is contained in:
1 parent
f0b4adda63
commit
9e167a44f6
61 files changed
+9898
-194
No files matched your search
@@ -0,0 +1,176 @@
|
||||
import "server-only";
|
||||
import { rm } from "node:fs/promises";
|
||||
import { and, asc, desc, eq, gt, inArray, isNull } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { runDir } from "@/lib/benchmark-paths";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { BENCHMARK_PHASES, benchmarkLogs, benchmarkRuns, type BenchmarkSnapshot, deployments, models, runtimes, workerState } from "@/lib/db/schema";
|
||||
|
||||
export class BenchmarkError extends Error {
|
||||
constructor(
|
||||
public code: "invalid" | "not_found" | "busy",
|
||||
message: string,
|
||||
public status: number,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export const BenchmarkBody = z.object({
|
||||
deploymentId: z.string().min(1),
|
||||
label: z.string().trim().max(120).nullable().optional(),
|
||||
quick: z.boolean().default(false),
|
||||
passes: z.number().int().min(1).max(200).nullable().optional(),
|
||||
warmup: z.number().int().min(0).max(50).nullable().optional(),
|
||||
/** Empty: all phases. */
|
||||
phases: z.array(z.enum(BENCHMARK_PHASES)).max(3).default([]),
|
||||
});
|
||||
export type BenchmarkInput = z.infer<typeof BenchmarkBody>;
|
||||
|
||||
/** Names of the GPUs a deployment uses (all detected ones when none are picked). */
|
||||
async function hostFacts(uuids: string[] | null, nvidia: boolean) {
|
||||
const ws = await db().query.workerState.findFirst({ columns: { docker: true }, where: eq(workerState.id, "worker") });
|
||||
const h = ws?.docker;
|
||||
const gpus = h?.gpus ?? [];
|
||||
return {
|
||||
gpuNames: nvidia ? (uuids ? gpus.filter((g) => uuids.includes(g.uuid)) : gpus).map((g) => g.name) : [],
|
||||
host: { cpuModel: h?.cpuModel ?? null, threads: h?.cpus ?? null, memoryBytes: h?.memoryBytes ?? null, os: h?.os ?? null },
|
||||
};
|
||||
}
|
||||
|
||||
/** Queue a run against a running deployment; the worker runs one benchmark at a time. */
|
||||
export async function createBenchmark(input: BenchmarkInput) {
|
||||
const [d] = await db()
|
||||
.select({
|
||||
id: deployments.id,
|
||||
name: deployments.name,
|
||||
state: deployments.state,
|
||||
options: deployments.options,
|
||||
cpus: deployments.cpus,
|
||||
memoryMb: deployments.memoryMb,
|
||||
command: deployments.command,
|
||||
imageId: deployments.imageId,
|
||||
modelId: deployments.modelId,
|
||||
repoId: models.repoId,
|
||||
runtimeName: runtimes.name,
|
||||
engine: runtimes.engine,
|
||||
accelerator: runtimes.accelerator,
|
||||
image: runtimes.image,
|
||||
})
|
||||
.from(deployments)
|
||||
.innerJoin(runtimes, eq(runtimes.id, deployments.runtimeId))
|
||||
.innerJoin(models, eq(models.id, deployments.modelId))
|
||||
.where(and(eq(deployments.id, input.deploymentId), isNull(deployments.deleteRequestedAt)));
|
||||
if (!d) throw new BenchmarkError("not_found", "Deployment not found.", 404);
|
||||
if (d.state !== "running") throw new BenchmarkError("invalid", "Start the deployment first; benchmarks run against a running server.", 409);
|
||||
|
||||
const snapshot: BenchmarkSnapshot = {
|
||||
deploymentName: d.name,
|
||||
repoId: d.repoId,
|
||||
runtimeName: d.runtimeName,
|
||||
engine: d.engine,
|
||||
accelerator: d.accelerator,
|
||||
...(await hostFacts(d.options.gpus ?? null, d.accelerator === "nvidia")),
|
||||
image: d.image,
|
||||
imageId: d.imageId,
|
||||
options: d.options,
|
||||
cpus: d.cpus,
|
||||
memoryMb: d.memoryMb,
|
||||
command: [d.image, ...(d.command ?? [])].join(" "),
|
||||
};
|
||||
const [row] = await db()
|
||||
.insert(benchmarkRuns)
|
||||
.values({
|
||||
deploymentId: d.id,
|
||||
modelId: d.modelId,
|
||||
label: input.label || null,
|
||||
settings: { quick: input.quick, passes: input.passes ?? null, warmup: input.warmup ?? null, phases: input.phases },
|
||||
snapshot,
|
||||
})
|
||||
.returning({ id: benchmarkRuns.id });
|
||||
return row;
|
||||
}
|
||||
|
||||
const listColumns = {
|
||||
id: benchmarkRuns.id,
|
||||
deploymentId: benchmarkRuns.deploymentId,
|
||||
modelId: benchmarkRuns.modelId,
|
||||
tool: benchmarkRuns.tool,
|
||||
label: benchmarkRuns.label,
|
||||
settings: benchmarkRuns.settings,
|
||||
snapshot: benchmarkRuns.snapshot,
|
||||
state: benchmarkRuns.state,
|
||||
phase: benchmarkRuns.phase,
|
||||
cancelRequestedAt: benchmarkRuns.cancelRequestedAt,
|
||||
startedAt: benchmarkRuns.startedAt,
|
||||
finishedAt: benchmarkRuns.finishedAt,
|
||||
error: benchmarkRuns.error,
|
||||
summary: benchmarkRuns.summary,
|
||||
hasReport: benchmarkRuns.hasReport,
|
||||
createdAt: benchmarkRuns.createdAt,
|
||||
};
|
||||
|
||||
export type BenchmarkRow = Awaited<ReturnType<typeof listBenchmarks>>[number];
|
||||
|
||||
export async function listBenchmarks(filter: { deploymentId?: string; modelId?: string } = {}) {
|
||||
return db()
|
||||
.select(listColumns)
|
||||
.from(benchmarkRuns)
|
||||
.where(
|
||||
and(
|
||||
filter.deploymentId ? eq(benchmarkRuns.deploymentId, filter.deploymentId) : undefined,
|
||||
filter.modelId ? eq(benchmarkRuns.modelId, filter.modelId) : undefined,
|
||||
),
|
||||
)
|
||||
.orderBy(desc(benchmarkRuns.createdAt));
|
||||
}
|
||||
|
||||
export async function getBenchmark(id: string) {
|
||||
const [row] = await db().select(listColumns).from(benchmarkRuns).where(eq(benchmarkRuns.id, id));
|
||||
return row ?? null;
|
||||
}
|
||||
|
||||
export async function getBenchmarks(ids: string[]) {
|
||||
if (ids.length === 0) return [];
|
||||
const rows = await db().select(listColumns).from(benchmarkRuns).where(inArray(benchmarkRuns.id, ids));
|
||||
return ids.map((id) => rows.find((r) => r.id === id)).filter((r) => r != null);
|
||||
}
|
||||
|
||||
/** Queued runs are cancelled right away; a running one is stopped by the worker. */
|
||||
export async function cancelBenchmark(id: string) {
|
||||
const run = await getBenchmark(id);
|
||||
if (!run) throw new BenchmarkError("not_found", "Benchmark not found.", 404);
|
||||
if (run.state === "queued") {
|
||||
await db().update(benchmarkRuns).set({ state: "cancelled", finishedAt: new Date() }).where(and(eq(benchmarkRuns.id, id), eq(benchmarkRuns.state, "queued")));
|
||||
} else if (run.state === "running") {
|
||||
await db().update(benchmarkRuns).set({ cancelRequestedAt: new Date() }).where(eq(benchmarkRuns.id, id));
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateBenchmarkLabel(id: string, label: string | null) {
|
||||
const res = await db().update(benchmarkRuns).set({ label: label?.trim() || null }).where(eq(benchmarkRuns.id, id)).returning({ id: benchmarkRuns.id });
|
||||
if (res.length === 0) throw new BenchmarkError("not_found", "Benchmark not found.", 404);
|
||||
}
|
||||
|
||||
/** Deletes the run, its log and its files. Cancel a running one first. */
|
||||
export async function deleteBenchmark(id: string) {
|
||||
const run = await getBenchmark(id);
|
||||
if (!run) throw new BenchmarkError("not_found", "Benchmark not found.", 404);
|
||||
if (run.state === "running") throw new BenchmarkError("busy", "Cancel the run before deleting it.", 409);
|
||||
await db().delete(benchmarkLogs).where(eq(benchmarkLogs.runId, id));
|
||||
await db().delete(benchmarkRuns).where(eq(benchmarkRuns.id, id));
|
||||
await rm(runDir(id), { recursive: true, force: true });
|
||||
}
|
||||
|
||||
export async function listBenchmarkLogs(id: string, afterId: number, tail = 500) {
|
||||
const rows =
|
||||
afterId > 0
|
||||
? await db()
|
||||
.select()
|
||||
.from(benchmarkLogs)
|
||||
.where(and(eq(benchmarkLogs.runId, id), gt(benchmarkLogs.id, afterId)))
|
||||
.orderBy(asc(benchmarkLogs.id))
|
||||
.limit(2000)
|
||||
: (await db().select().from(benchmarkLogs).where(eq(benchmarkLogs.runId, id)).orderBy(desc(benchmarkLogs.id)).limit(tail)).reverse();
|
||||
return rows.map((r) => ({ id: r.id, ts: r.ts.getTime(), stream: r.stream, line: r.line }));
|
||||
}
|
||||
Reference in new issue
Block a user