Every run records GPUs (PCIe link under load and maximum, ReBAR, P2P), runtime image/tag/digest and the engine version the server reports, model, quant, KV cache, context and concurrency, plus a whitelisted system summary and a description. Shown on the run page, compare and sweep views; passed to BetterBench as notes and to the launch80 preview as sections. Settings -> Hardware for manual values. Also: scripts/intel-probe.sh (read-only diagnostics for Intel hosts), and --quick is no longer passed together with --passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
981c4170fc
commit
ee6c623e2a
45 files changed
+4627
-60
No files matched your search
+56
-16
@@ -6,10 +6,11 @@ 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, type HostGpu, runtimes, settings, workerState } from "@/lib/db/schema";
|
||||
import { type DockerHostInfo, type HostGpu, type HostHardware, type PcieLink, 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";
|
||||
import { detectHardware, normalizePciAddress, parseP2p } from "./hardware";
|
||||
import { log } from "./log";
|
||||
|
||||
const PROGRESS_MS = 1_000;
|
||||
@@ -66,7 +67,7 @@ let ownImage: string | null = null;
|
||||
|
||||
/** The worker's own image (from the last host check); probe containers run from it. */
|
||||
export const workerImage = () => ownImage;
|
||||
let gpuCache: { at: number; gpus: HostGpu[]; error: string | null } | null = null;
|
||||
let gpuCache: { at: number; gpus: HostGpu[]; p2p: HostHardware["p2p"]; error: string | null } | null = null;
|
||||
|
||||
/** nvidia-smi's CSV (index, uuid, name, memory.total MiB, driver) → GPUs. */
|
||||
export function parseNvidiaSmi(csv: string): HostGpu[] {
|
||||
@@ -74,18 +75,42 @@ export function parseNvidiaSmi(csv: string): HostGpu[] {
|
||||
.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 }));
|
||||
.map(([index, uuid, name, mem, driver, bus, genCur, genMax, widthCur, widthMax]) => ({
|
||||
vendor: "nvidia" as const,
|
||||
index: Number(index),
|
||||
uuid,
|
||||
name,
|
||||
memoryMb: Number(mem) || 0,
|
||||
driver,
|
||||
pciAddress: bus ? normalizePciAddress(bus) : null,
|
||||
linkCurrent: nvLink(genCur, widthCur),
|
||||
linkMax: nvLink(genMax, widthMax),
|
||||
}));
|
||||
}
|
||||
|
||||
const nvNum = (s: string | undefined) => (s && /^\d+$/.test(s) ? Number(s) : null);
|
||||
function nvLink(gen: string | undefined, width: string | undefined): PcieLink | null {
|
||||
const l = { gen: nvNum(gen), width: nvNum(width) };
|
||||
return l.gen == null && l.width == null ? null : l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Lists the GPUs containers get from Docker (nvidia-smi, which the NVIDIA Container Toolkit injects)
|
||||
* and, with two or more, whether they can talk peer-to-peer.
|
||||
*/
|
||||
async function probeNvidia(c: DockerClient, image: string): Promise<HostGpu[]> {
|
||||
async function probeNvidia(c: DockerClient, image: string): Promise<{ gpus: HostGpu[]; p2p: HostHardware["p2p"] }> {
|
||||
const gpus = parseNvidiaSmi((await nvidiaSmi(c, image, ["--query-gpu=index,uuid,name,memory.total,driver_version,pci.bus_id,pcie.link.gen.current,pcie.link.gen.max,pcie.link.width.current,pcie.link.width.max", "--format=csv,noheader,nounits"])).join("\n"));
|
||||
let p2p: HostHardware["p2p"] = null;
|
||||
if (gpus.length >= 2) p2p = parseP2p((await nvidiaSmi(c, image, ["topo", "-p2p", "r"]).catch(() => [])).join("\n"));
|
||||
return { gpus, p2p };
|
||||
}
|
||||
|
||||
/** Runs `nvidia-smi <args>` in a short-lived container (our own image) that gets every GPU; its output lines. */
|
||||
async function nvidiaSmi(c: DockerClient, image: string, args: string[]): Promise<string[]> {
|
||||
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"],
|
||||
Cmd: args,
|
||||
Env: ["NVIDIA_DRIVER_CAPABILITIES=utility"],
|
||||
Labels: { "kaname.managed": "true", "kaname.probe": "gpu" },
|
||||
HostConfig: { DeviceRequests: [{ Driver: "", Count: -1, Capabilities: [["gpu", "utility"]] }], NetworkMode: "none", Privileged: false },
|
||||
@@ -96,7 +121,7 @@ async function probeNvidia(c: DockerClient, image: string): Promise<HostGpu[]> {
|
||||
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"));
|
||||
return lines;
|
||||
} finally {
|
||||
await c.removeContainer(created.Id).catch(() => {});
|
||||
}
|
||||
@@ -104,22 +129,22 @@ async function probeNvidia(c: DockerClient, image: string): Promise<HostGpu[]> {
|
||||
|
||||
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 (!nvidia) return { nvidia, gpus: [], p2p: null, 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 };
|
||||
const { gpus, p2p } = await probeNvidia(c, selfImage);
|
||||
gpuCache = { at: Date.now(), gpus, p2p, 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) };
|
||||
gpuCache = { at: Date.now(), gpus: [], p2p: null, error: message(err) };
|
||||
log.warn(`GPU probe failed: ${message(err)}`);
|
||||
}
|
||||
}
|
||||
return { nvidia, gpus: gpuCache.gpus, gpuError: gpuCache.error, gpuCheckedAt: new Date(gpuCache.at).toISOString() };
|
||||
return { nvidia, gpus: gpuCache.gpus, p2p: gpuCache.p2p, gpuError: gpuCache.error, gpuCheckedAt: new Date(gpuCache.at).toISOString() };
|
||||
}
|
||||
|
||||
const CUDA_SEEDED_KEY = "runtimes.cudaPresetSeeded";
|
||||
@@ -151,6 +176,11 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
const [v, i] = await Promise.all([c.version(), c.info()]);
|
||||
const self = await selfDetect(c);
|
||||
ownImage = self.image;
|
||||
const { p2p, ...gpu } = await gpuFacts(c, i, self.image);
|
||||
const hardware = await detectHardware({ modelsDir: coreEnv().MODELS_DIR, nvidia: gpu.gpus, p2p }).catch((err) => {
|
||||
log.warn(`hardware detection failed: ${message(err)}`);
|
||||
return null;
|
||||
});
|
||||
info = {
|
||||
connected: true,
|
||||
error: null,
|
||||
@@ -162,7 +192,8 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
...base,
|
||||
network: self.network,
|
||||
modelsSource: self.modelsSource,
|
||||
...(await gpuFacts(c, i, self.image)),
|
||||
...gpu,
|
||||
hardware,
|
||||
};
|
||||
} catch (err) {
|
||||
info = {
|
||||
@@ -182,6 +213,14 @@ export async function refreshDockerInfo(instanceId: string): Promise<void> {
|
||||
await db().update(workerState).set({ docker: info }).where(and(eq(workerState.id, "worker"), eq(workerState.instanceId, instanceId)));
|
||||
}
|
||||
|
||||
/** The registry digest ("sha256:…") of an image reference, from Docker's RepoDigests ("repo@sha256:…"). */
|
||||
export function repoDigest(ref: string, repoDigests: string[] | null | undefined): string | null {
|
||||
const repo = ref.split("@")[0].replace(/:[^/:]+$/, "");
|
||||
const all = repoDigests ?? [];
|
||||
const hit = all.find((d) => d.split("@")[0] === repo) ?? all[0];
|
||||
return hit?.split("@")[1] ?? null;
|
||||
}
|
||||
|
||||
const SEEDED_KEY = "runtimes.presetsSeeded";
|
||||
|
||||
/** Create the preset runtimes once (deleted presets don't come back). */
|
||||
@@ -225,8 +264,8 @@ export async function syncImageStates(): Promise<void> {
|
||||
.update(runtimes)
|
||||
.set(
|
||||
img
|
||||
? { imageState: "present", imageId: img.Id, imageSize: img.Size, imageCreated: img.Created, imageCheckedAt: new Date() }
|
||||
: { imageState: r.imageState === "failed" ? "failed" : "missing", imageId: null, imageSize: null, imageCreated: null, imageCheckedAt: new Date() },
|
||||
? { imageState: "present", imageId: img.Id, imageSize: img.Size, imageCreated: img.Created, imageDigest: repoDigest(r.image, img.RepoDigests), imageCheckedAt: new Date() }
|
||||
: { imageState: r.imageState === "failed" ? "failed" : "missing", imageId: null, imageSize: null, imageCreated: null, imageDigest: null, imageCheckedAt: new Date() },
|
||||
)
|
||||
.where(eq(runtimes.id, r.id));
|
||||
} catch (err) {
|
||||
@@ -278,6 +317,7 @@ export async function handlePullRequests(): Promise<void> {
|
||||
imageId: img?.Id ?? null,
|
||||
imageSize: img?.Size ?? null,
|
||||
imageCreated: img?.Created ?? null,
|
||||
imageDigest: img ? repoDigest(next.image, img.RepoDigests) : null,
|
||||
pullProgress: null,
|
||||
pullError: img ? null : "Pull finished but the image isn't there.",
|
||||
imageCheckedAt: new Date(),
|
||||
|
||||
Reference in new issue
Block a user