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
+86
-7
@@ -6,7 +6,7 @@ import { hostname } from "node:os";
|
||||
import { resolve } from "node:path";
|
||||
import { and, eq, isNotNull, ne } from "drizzle-orm";
|
||||
import { db } from "@/lib/db/client";
|
||||
import { type DockerHostInfo, runtimes, settings, workerState } from "@/lib/db/schema";
|
||||
import { type DockerHostInfo, type HostGpu, runtimes, settings, workerState } from "@/lib/db/schema";
|
||||
import { coreEnv } from "@/lib/env";
|
||||
import { RUNTIME_PRESETS } from "@/lib/runtimes-shared";
|
||||
import { DockerClient, DockerError } from "./docker/client";
|
||||
@@ -40,14 +40,14 @@ async function cpuFacts(): Promise<{ model: string | null; features: string[] }>
|
||||
}
|
||||
|
||||
/** Find our own container to learn the network and where MODELS_DIR comes from on the host. */
|
||||
async function selfDetect(c: DockerClient): Promise<Pick<DockerHostInfo, "network" | "modelsSource">> {
|
||||
async function selfDetect(c: DockerClient): Promise<Pick<DockerHostInfo, "network" | "modelsSource"> & { image: string | null }> {
|
||||
const env = coreEnv();
|
||||
let network: string | null = env.KANAME_DOCKER_NETWORK ?? null;
|
||||
let modelsSource: DockerHostInfo["modelsSource"] = env.KANAME_MODELS_SOURCE
|
||||
? { type: env.KANAME_MODELS_SOURCE.startsWith("/") ? "bind" : "volume", source: env.KANAME_MODELS_SOURCE }
|
||||
: null;
|
||||
if (network && modelsSource) return { network, modelsSource };
|
||||
|
||||
// Always inspected: the worker's own image also serves as the GPU probe image.
|
||||
const self = await c.inspectContainer(hostname()).catch(() => null);
|
||||
if (self) {
|
||||
network ??= Object.keys(self.NetworkSettings.Networks).find((n) => !["bridge", "host", "none"].includes(n)) ?? null;
|
||||
@@ -56,7 +56,80 @@ async function selfDetect(c: DockerClient): Promise<Pick<DockerHostInfo, "networ
|
||||
modelsSource = mount.Type === "volume" ? { type: "volume", source: mount.Name ?? mount.Source } : { type: "bind", source: mount.Source };
|
||||
}
|
||||
}
|
||||
return { network, modelsSource };
|
||||
return { network, modelsSource, image: self?.Image ?? null };
|
||||
}
|
||||
|
||||
// --- GPUs ---------------------------------------------------------------------
|
||||
|
||||
const GPU_PROBE_MS = 60 * 60_000;
|
||||
let gpuCache: { at: number; gpus: HostGpu[]; error: string | null } | null = null;
|
||||
|
||||
/** nvidia-smi's CSV (index, uuid, name, memory.total MiB, driver) → GPUs. */
|
||||
export function parseNvidiaSmi(csv: string): HostGpu[] {
|
||||
return csv
|
||||
.split(/\r?\n/)
|
||||
.map((l) => l.split(",").map((p) => p.trim()))
|
||||
.filter((p) => p.length >= 5 && /^\d+$/.test(p[0]))
|
||||
.map(([index, uuid, name, mem, driver]) => ({ vendor: "nvidia" as const, index: Number(index), uuid, name, memoryMb: Number(mem) || 0, driver }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the GPUs containers get from Docker: a short-lived container (our own image) requests all
|
||||
* GPUs and runs nvidia-smi, which the NVIDIA Container Toolkit injects.
|
||||
*/
|
||||
async function probeNvidia(c: DockerClient, image: string): Promise<HostGpu[]> {
|
||||
const created = await c.createContainer(`kaname-gpu-probe-${Date.now().toString(36)}`, {
|
||||
Image: image,
|
||||
Entrypoint: ["nvidia-smi"],
|
||||
Cmd: ["--query-gpu=index,uuid,name,memory.total,driver_version", "--format=csv,noheader,nounits"],
|
||||
Env: ["NVIDIA_DRIVER_CAPABILITIES=utility"],
|
||||
Labels: { "kaname.managed": "true", "kaname.probe": "gpu" },
|
||||
HostConfig: { DeviceRequests: [{ Driver: "", Count: -1, Capabilities: [["gpu", "utility"]] }], NetworkMode: "none", Privileged: false },
|
||||
});
|
||||
try {
|
||||
const lines: string[] = [];
|
||||
await c.startContainer(created.Id);
|
||||
await c.followLogs(created.Id, (_s, line) => lines.push(line), { tail: "all", signal: AbortSignal.timeout(30_000) });
|
||||
const st = await c.containerState(created.Id);
|
||||
if (st && st.ExitCode !== 0) throw new Error(`nvidia-smi exited with ${st.ExitCode}: ${lines.slice(-3).join(" ")}`);
|
||||
return parseNvidiaSmi(lines.join("\n"));
|
||||
} finally {
|
||||
await c.removeContainer(created.Id).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
async function gpuFacts(c: DockerClient, info: Awaited<ReturnType<DockerClient["info"]>>, selfImage: string | null) {
|
||||
const nvidia = !!info.Runtimes?.nvidia || !!info.DiscoveredDevices?.some((d) => d.ID.startsWith("nvidia.com/gpu"));
|
||||
if (!nvidia) return { nvidia, gpus: [], gpuError: null, gpuCheckedAt: null };
|
||||
if (!gpuCache || Date.now() - gpuCache.at > GPU_PROBE_MS) {
|
||||
try {
|
||||
if (!selfImage) throw new Error("Kaname's own image is unknown (the worker isn't running in a container), so GPUs can't be probed.");
|
||||
const gpus = await probeNvidia(c, selfImage);
|
||||
gpuCache = { at: Date.now(), gpus, error: null };
|
||||
if (gpus.length) {
|
||||
log.info(`GPUs: ${gpus.map((g) => `${g.index}: ${g.name} (${Math.round(g.memoryMb / 1024)} GiB)`).join(", ")}`);
|
||||
await seedGpuPresets();
|
||||
}
|
||||
} catch (err) {
|
||||
gpuCache = { at: Date.now(), gpus: [], error: message(err) };
|
||||
log.warn(`GPU probe failed: ${message(err)}`);
|
||||
}
|
||||
}
|
||||
return { nvidia, gpus: gpuCache.gpus, gpuError: gpuCache.error, gpuCheckedAt: new Date(gpuCache.at).toISOString() };
|
||||
}
|
||||
|
||||
const CUDA_SEEDED_KEY = "runtimes.cudaPresetSeeded";
|
||||
|
||||
/** The first time NVIDIA GPUs show up, add the llama.cpp CUDA runtime (once). */
|
||||
async function seedGpuPresets() {
|
||||
const d = db();
|
||||
if (await d.query.settings.findFirst({ where: eq(settings.key, CUDA_SEEDED_KEY) })) return;
|
||||
const p = RUNTIME_PRESETS.find((x) => x.id === "llama.cpp-cuda");
|
||||
if (p) {
|
||||
await d.insert(runtimes).values({ name: p.name, engine: p.engine, accelerator: "nvidia", image: p.image, description: p.description ?? null, preset: p.id });
|
||||
log.info(`NVIDIA GPU found: added the "${p.name}" runtime`);
|
||||
}
|
||||
await d.insert(settings).values({ key: CUDA_SEEDED_KEY, value: true }).onConflictDoNothing();
|
||||
}
|
||||
|
||||
/** Report Docker connectivity and host facts in worker_state (null when DOCKER_HOST isn't set). */
|
||||
@@ -72,6 +145,7 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
};
|
||||
try {
|
||||
const [v, i] = await Promise.all([c.version(), c.info()]);
|
||||
const self = await selfDetect(c);
|
||||
info = {
|
||||
connected: true,
|
||||
error: null,
|
||||
@@ -81,7 +155,9 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
cpus: i.NCPU,
|
||||
memoryBytes: i.MemTotal,
|
||||
...base,
|
||||
...(await selfDetect(c)),
|
||||
network: self.network,
|
||||
modelsSource: self.modelsSource,
|
||||
...(await gpuFacts(c, i, self.image)),
|
||||
};
|
||||
} catch (err) {
|
||||
info = {
|
||||
@@ -110,10 +186,13 @@ export async function seedRuntimePresets(): Promise<void> {
|
||||
if (seeded) return;
|
||||
const existing = await d.select({ id: runtimes.id }).from(runtimes).limit(1);
|
||||
if (existing.length === 0) {
|
||||
// CPU presets only; GPU ones are added from Settings (or automatically when an NVIDIA GPU shows up).
|
||||
const presets = RUNTIME_PRESETS.filter((p) => (p.accelerator ?? "cpu") === "cpu");
|
||||
await d.insert(runtimes).values(
|
||||
RUNTIME_PRESETS.map((p) => ({
|
||||
presets.map((p) => ({
|
||||
name: p.name,
|
||||
engine: p.engine,
|
||||
accelerator: p.accelerator ?? "cpu",
|
||||
image: p.image,
|
||||
description: p.description ?? null,
|
||||
env: p.env ?? {},
|
||||
@@ -124,7 +203,7 @@ export async function seedRuntimePresets(): Promise<void> {
|
||||
preset: p.id,
|
||||
})),
|
||||
);
|
||||
log.info(`created ${RUNTIME_PRESETS.length} preset runtime(s)`);
|
||||
log.info(`created ${presets.length} preset runtime(s)`);
|
||||
}
|
||||
await d.insert(settings).values({ key: SEEDED_KEY, value: true }).onConflictDoNothing();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user