Deployments: llama.cpp web UI toggle, clearer start failures, log fixes
- Web UI option for llama.cpp deployments (--no-webui when off); the deployment page links to it on the published host port. - Follow container logs after the start with tail=all: following a created container returned an already-closed stream, so startup output was lost. - Failed starts name the cause from the log (vLLM ValueError, llama.cpp error lines) before the last output. - A deployment's vLLM dtype replaces the runtime's --dtype instead of repeating it. - vLLM memory estimate: 3 GiB overhead (measured ~6.9 GiB for SmolLM2-135M with a 4 GiB KV cache). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8b74fa69db
commit
66e6a8c4f7
11 files changed
+130
-23
No files matched your search
@@ -22,6 +22,11 @@ step 1 (Hugging Face downloader) is released as a minor version.
|
||||
- Deployment page: state, load time, live CPU/RAM, endpoint URLs (Docker network and published
|
||||
port), live log, start/stop/edit/delete, and a "Try it" chat that streams the answer and shows
|
||||
time to first token and tokens/s.
|
||||
- llama.cpp's built-in **web UI** can be switched on or off per deployment (`--no-webui`); with a
|
||||
published host port the deployment page links to it.
|
||||
- A failed start names the cause from the log (e.g. vLLM's `ValueError` instead of the end of the
|
||||
traceback), followed by the last lines of output.
|
||||
- A deployment's vLLM data type replaces the runtime's `--dtype` instead of repeating the flag.
|
||||
- Models and runtimes used by a deployment can't be deleted until the deployment is.
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { PencilIcon, PlayIcon, SendIcon, SquareIcon, Trash2Icon } from "lucide-react";
|
||||
import { ExternalLinkIcon, PencilIcon, PlayIcon, SendIcon, SquareIcon, Trash2Icon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
||||
@@ -74,6 +74,8 @@ export function DeploymentDetail({ initial }: { initial: Deployment }) {
|
||||
() => null,
|
||||
);
|
||||
const published = d.hostPort && hostname ? `http://${hostname}:${d.hostPort}/v1` : null;
|
||||
// llama-server's built-in chat UI, served at / on the same port.
|
||||
const webUi = d.engine === "llama.cpp" && d.options.webui !== false && d.hostPort && hostname ? `http://${hostname}:${d.hostPort}/` : null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
@@ -95,6 +97,18 @@ export function DeploymentDetail({ initial }: { initial: Deployment }) {
|
||||
<code className="font-mono text-xs text-muted-foreground">{d.runtimeImage}</code>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
{webUi && (
|
||||
<a
|
||||
href={webUi}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className={cn(buttonVariants({ variant: "outline" }), d.state !== "running" && "pointer-events-none opacity-50")}
|
||||
aria-disabled={d.state !== "running"}
|
||||
>
|
||||
<ExternalLinkIcon />
|
||||
Web UI
|
||||
</a>
|
||||
)}
|
||||
{active ? (
|
||||
<Button variant="outline" onClick={() => stopDeployment(d.id)}>
|
||||
<SquareIcon />
|
||||
|
||||
@@ -108,6 +108,7 @@ export function DeploymentForm({
|
||||
const [cacheTypeK, setCacheTypeK] = useState(o?.cacheTypeK ?? "");
|
||||
const [cacheTypeV, setCacheTypeV] = useState(o?.cacheTypeV ?? "");
|
||||
const [flashAttn, setFlashAttn] = useState(o?.flashAttn ?? "");
|
||||
const [webui, setWebui] = useState(o?.webui !== false);
|
||||
const [batchSize, setBatchSize] = useState(o?.batchSize != null ? String(o.batchSize) : "");
|
||||
const [ubatchSize, setUbatchSize] = useState(o?.ubatchSize != null ? String(o.ubatchSize) : "");
|
||||
const [dtype, setDtype] = useState(o?.dtype ?? "");
|
||||
@@ -142,6 +143,7 @@ export function DeploymentForm({
|
||||
cacheTypeK: engine === "llama.cpp" && cacheTypeK ? cacheTypeK : null,
|
||||
cacheTypeV: engine === "llama.cpp" && cacheTypeV ? cacheTypeV : null,
|
||||
flashAttn: engine === "llama.cpp" && flashAttn ? (flashAttn as "auto" | "on" | "off") : null,
|
||||
webui: engine === "llama.cpp" ? webui : null,
|
||||
dtype: engine === "vllm" && dtype ? dtype : null,
|
||||
maxNumSeqs: engine === "vllm" ? intOrNull(maxNumSeqs) : null,
|
||||
kvCacheGb: engine === "vllm" ? numOrNull(kvCacheGb) : null,
|
||||
@@ -414,6 +416,12 @@ export function DeploymentForm({
|
||||
<option value="off">off</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Web UI" hint={webui ? (hostPort ? `Opens at http://<server>:${hostPort}/` : "Needs a host port to open it (below).") : "--no-webui"}>
|
||||
<select value={webui ? "on" : "off"} onChange={(e) => setWebui(e.target.value === "on")} className={selectClass}>
|
||||
<option value="on">on</option>
|
||||
<option value="off">off</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Batch / micro-batch" hint="-b / -ub">
|
||||
<div className="flex gap-1.5">
|
||||
<Input value={batchSize} onChange={(e) => setBatchSize(e.target.value.replace(/\D/g, ""))} inputMode="numeric" placeholder="2048" aria-label="Batch size" />
|
||||
|
||||
@@ -449,6 +449,8 @@ export type DeploymentOptions = {
|
||||
cacheTypeK?: string | null;
|
||||
cacheTypeV?: string | null;
|
||||
flashAttn?: "auto" | "on" | "off" | null;
|
||||
/** llama.cpp: serve the built-in web UI at / (llama-server's default; false passes --no-webui). */
|
||||
webui?: boolean | null;
|
||||
/** vLLM */
|
||||
dtype?: string | null;
|
||||
maxNumSeqs?: number | null;
|
||||
|
||||
@@ -36,14 +36,33 @@ describe("buildCommand", () => {
|
||||
const cmd = buildCommand({
|
||||
engine: "vllm",
|
||||
model: { repoId: "HuggingFaceTB/SmolLM2-135M-Instruct", localPath: "HuggingFaceTB/SmolLM2-135M-Instruct" },
|
||||
runtime: { env: { VLLM_CPU_KVCACHE_SPACE: "4" }, extraArgs: ["--dtype=bfloat16"] },
|
||||
runtime: { env: { VLLM_CPU_KVCACHE_SPACE: "4" }, extraArgs: ["--dtype=bfloat16", "--enforce-eager"] },
|
||||
options: { modelFile: "", contextSize: 2048, maxNumSeqs: 4, dtype: "float32", kvCacheGb: 2, extraArgs: [] },
|
||||
});
|
||||
assert.equal(cmd.port, 8000);
|
||||
assert.equal(cmd.args[0], "/models/HuggingFaceTB/SmolLM2-135M-Instruct");
|
||||
assert.equal(cmd.env.VLLM_CPU_KVCACHE_SPACE, "2");
|
||||
const s = cmd.args.join(" ");
|
||||
assert.ok(s.indexOf("--dtype=bfloat16") < s.indexOf("--dtype float32"));
|
||||
assert.ok(!s.includes("bfloat16") && s.includes("--dtype float32") && s.includes("--enforce-eager"));
|
||||
assert.match(renderCommand("vllm/vllm-openai-cpu:v0.31.0", cmd), /^docker run -e VLLM_CPU_KVCACHE_SPACE=2 /);
|
||||
const keep = buildCommand({
|
||||
engine: "vllm",
|
||||
model: { repoId: "a/b", localPath: "a/b" },
|
||||
runtime: { env: {}, extraArgs: ["--dtype", "bfloat16"] },
|
||||
options: { modelFile: "", contextSize: 2048, extraArgs: [] },
|
||||
});
|
||||
assert.ok(keep.args.join(" ").includes("--dtype bfloat16"));
|
||||
});
|
||||
|
||||
it("turns llama.cpp's web UI off only when asked", () => {
|
||||
const args = (webui?: boolean | null) =>
|
||||
buildCommand({
|
||||
engine: "llama.cpp",
|
||||
model: { repoId: "a/b", localPath: "a/b" },
|
||||
runtime: { env: {}, extraArgs: [] },
|
||||
options: { modelFile: "m.gguf", contextSize: 2048, webui, extraArgs: [] },
|
||||
}).args;
|
||||
assert.ok(!args().includes("--no-webui") && !args(true).includes("--no-webui"));
|
||||
assert.ok(args(false).includes("--no-webui"));
|
||||
});
|
||||
});
|
||||
@@ -24,6 +24,16 @@ const inModels = (localPath: string, file?: string | null) =>
|
||||
const num = (flag: string, v: number | null | undefined) => (v != null && Number.isFinite(v) ? [flag, String(v)] : []);
|
||||
const str = (flag: string, v: string | null | undefined) => (v ? [flag, v] : []);
|
||||
|
||||
/** `args` without `flag` ("--flag value" or "--flag=value"). */
|
||||
function withoutFlag(args: string[], flag: string): string[] {
|
||||
const out: string[] = [];
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === flag) i++;
|
||||
else if (!args[i].startsWith(`${flag}=`)) out.push(args[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function buildCommand({ engine, options: o, model, runtime }: CommandInput): ContainerCommand {
|
||||
const port = ENGINE_PORT[engine];
|
||||
if (engine === "llama.cpp") {
|
||||
@@ -48,6 +58,7 @@ export function buildCommand({ engine, options: o, model, runtime }: CommandInpu
|
||||
...str("-fa", o.flashAttn),
|
||||
...(o.mmproj ? ["--mmproj", inModels(model.localPath, o.mmproj)] : []),
|
||||
...(o.draftFile ? ["-md", inModels(model.localPath, o.draftFile), "--spec-type", o.draftType ?? "draft-simple"] : []),
|
||||
...(o.webui === false ? ["--no-webui"] : []),
|
||||
"--metrics",
|
||||
...runtime.extraArgs,
|
||||
...o.extraArgs,
|
||||
@@ -68,8 +79,8 @@ export function buildCommand({ engine, options: o, model, runtime }: CommandInpu
|
||||
model.repoId,
|
||||
...num("--max-model-len", o.contextSize),
|
||||
...num("--max-num-seqs", o.maxNumSeqs),
|
||||
...runtime.extraArgs,
|
||||
// After the runtime's defaults, so a deployment's dtype wins (argparse keeps the last value).
|
||||
// A deployment's dtype replaces the runtime's default instead of repeating the flag.
|
||||
...(o.dtype ? withoutFlag(runtime.extraArgs, "--dtype") : runtime.extraArgs),
|
||||
...str("--dtype", o.dtype),
|
||||
...o.extraArgs,
|
||||
];
|
||||
@@ -86,7 +97,8 @@ export function renderCommand(image: string, cmd: ContainerCommand): string {
|
||||
/** Rough memory need: model files plus KV cache and runtime overhead. */
|
||||
export function estimateMemoryMb(fileBytes: number, contextSize: number, engine: RuntimeEngine, kvCacheGb?: number | null): number {
|
||||
const model = fileBytes / 2 ** 20;
|
||||
if (engine === "vllm") return Math.ceil(model + (kvCacheGb ?? 4) * 1024 + 2048);
|
||||
// vLLM CPU: API server, engine core and worker each load torch (~3 GiB measured with v0.31.0).
|
||||
if (engine === "vllm") return Math.ceil(model + (kvCacheGb ?? 4) * 1024 + 3072);
|
||||
// llama.cpp: ~ctx/8 MiB of f16 KV cache per 4k tokens for small models is too model-specific to
|
||||
// compute without the GGUF header; a margin that scales with context is a safe default.
|
||||
return Math.ceil(model * 1.1 + 512 + contextSize / 16);
|
||||
|
||||
@@ -34,6 +34,7 @@ export const DeploymentBody = z.object({
|
||||
cacheTypeK: z.enum(["f32", "f16", "bf16", "q8_0", "q4_0", "q4_1", "iq4_nl", "q5_0", "q5_1"]).nullable().optional(),
|
||||
cacheTypeV: z.enum(["f32", "f16", "bf16", "q8_0", "q4_0", "q4_1", "iq4_nl", "q5_0", "q5_1"]).nullable().optional(),
|
||||
flashAttn: z.enum(["auto", "on", "off"]).nullable().optional(),
|
||||
webui: z.boolean().nullable().optional(),
|
||||
dtype: z.enum(["auto", "bfloat16", "float16", "float32"]).nullable().optional(),
|
||||
maxNumSeqs: int(1, 1024).nullable().optional(),
|
||||
kvCacheGb: z.number().min(0.25).max(1024).nullable().optional(),
|
||||
@@ -89,7 +90,7 @@ async function validate(input: DeploymentInput, selfId?: string): Promise<Deploy
|
||||
options.draftType = draft?.type ?? null;
|
||||
Object.assign(options, { dtype: null, maxNumSeqs: null, kvCacheGb: null });
|
||||
} else {
|
||||
Object.assign(options, { modelFile: "", mmproj: null, draftFile: null, draftType: null, batchSize: null, ubatchSize: null, cacheTypeK: null, cacheTypeV: null, flashAttn: null });
|
||||
Object.assign(options, { modelFile: "", mmproj: null, draftFile: null, draftType: null, batchSize: null, ubatchSize: null, cacheTypeK: null, cacheTypeV: null, flashAttn: null, webui: null });
|
||||
}
|
||||
if (input.hostPort) {
|
||||
const clash = await db().query.deployments.findFirst({
|
||||
|
||||
+15
-14
@@ -12,6 +12,7 @@ import { coreEnv } from "@/lib/env";
|
||||
import { formatBytes } from "@/lib/format";
|
||||
import { sanitizeLine } from "./job-log";
|
||||
import { log } from "./log";
|
||||
import { errorCauses } from "./log-causes";
|
||||
import { docker } from "./runtimes";
|
||||
import type { DockerClient } from "./docker/client";
|
||||
|
||||
@@ -60,7 +61,7 @@ export async function flushDeploymentLogs(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function follow(c: DockerClient, d: { id: string; containerId: string }, tail = 0) {
|
||||
function follow(c: DockerClient, d: { id: string; containerId: string }, tail: number | "all" = 0) {
|
||||
followers.get(d.id)?.abort();
|
||||
const ctl = new AbortController();
|
||||
followers.set(d.id, ctl);
|
||||
@@ -170,8 +171,10 @@ async function start(c: DockerClient, d: Deployment) {
|
||||
exitCode: null,
|
||||
stats: null,
|
||||
});
|
||||
follow(c, { id: d.id, containerId: created.Id });
|
||||
await c.startContainer(created.Id);
|
||||
// A fresh container: everything it printed belongs to this run. (Following before the start
|
||||
// returns an empty, already-closed stream.)
|
||||
follow(c, { id: d.id, containerId: created.Id }, "all");
|
||||
log.info(`deployment ${d.name}: started ${name}`);
|
||||
} catch (err) {
|
||||
await c.removeContainer(name).catch(() => {});
|
||||
@@ -190,19 +193,17 @@ async function stopContainer(c: DockerClient, d: Deployment) {
|
||||
await update(d.id, { state: "stopped", stoppedAt: new Date(), stats: null, containerId: null });
|
||||
}
|
||||
|
||||
/** Tail of the log for error messages. */
|
||||
async function lastLines(id: string, n = 15): Promise<string> {
|
||||
/** Likely causes plus the tail of the log, for error messages. */
|
||||
async function failureDetails(id: string, tail = 15): Promise<string> {
|
||||
await flushDeploymentLogs();
|
||||
const rows = await db()
|
||||
.select({ line: deploymentLogs.line })
|
||||
.from(deploymentLogs)
|
||||
.where(eq(deploymentLogs.deploymentId, id))
|
||||
.orderBy(desc(deploymentLogs.id))
|
||||
.limit(n);
|
||||
return rows
|
||||
const lines = (
|
||||
await db().select({ line: deploymentLogs.line }).from(deploymentLogs).where(eq(deploymentLogs.deploymentId, id)).orderBy(desc(deploymentLogs.id)).limit(2000)
|
||||
)
|
||||
.reverse()
|
||||
.map((r) => r.line)
|
||||
.join("\n");
|
||||
.map((r) => r.line);
|
||||
const causes = errorCauses(lines);
|
||||
const last = lines.slice(-tail).join("\n");
|
||||
return [causes.join("\n"), last && (causes.length ? `Last output:\n${last}` : last)].filter(Boolean).join("\n\n");
|
||||
}
|
||||
|
||||
async function healthy(name: string, port: number): Promise<boolean> {
|
||||
@@ -244,7 +245,7 @@ async function reconcileOne(c: DockerClient, d: Deployment) {
|
||||
if (!st || !st.Running) {
|
||||
const why = st?.OOMKilled ? "out of memory (raise the memory limit)" : `exit code ${st?.ExitCode ?? "?"}`;
|
||||
unfollow(d.id);
|
||||
const tail = await lastLines(d.id);
|
||||
const tail = await failureDetails(d.id);
|
||||
await c.removeContainer(d.containerId).catch(() => {});
|
||||
return fail(d, `The container stopped (${why}).${tail ? `\n${tail}` : ""}`, st?.ExitCode ?? null);
|
||||
}
|
||||
|
||||
@@ -158,14 +158,14 @@ export class DockerClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow a container's stdout/stderr (from now, plus the last `tail` lines). The stream uses
|
||||
* Follow a container's stdout/stderr (from now, plus the last `tail` lines or "all"). The stream uses
|
||||
* Docker's multiplexed format (8-byte frame headers) for containers without a TTY. Resolves when
|
||||
* the container stops or `signal` aborts.
|
||||
*/
|
||||
async followLogs(
|
||||
id: string,
|
||||
onLine: (stream: "stdout" | "stderr", line: string) => void,
|
||||
options: { tail?: number; signal?: AbortSignal } = {},
|
||||
options: { tail?: number | "all"; signal?: AbortSignal } = {},
|
||||
): Promise<void> {
|
||||
const res = await this.raw(
|
||||
"GET",
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { errorCauses } from "./log-causes";
|
||||
|
||||
describe("errorCauses", () => {
|
||||
it("finds vLLM's root cause and skips the wrapper error", () => {
|
||||
const lines = [
|
||||
"(Worker pid=171) INFO 10-06 09:49:26 [model_runner.py:16] Warming up done.",
|
||||
"(Worker pid=171) ERROR 10-06 09:50:06 [multiproc_executor.py:1058] Traceback (most recent call last):",
|
||||
"(Worker pid=171) ERROR 10-06 09:50:06 [multiproc_executor.py:1058] ValueError: Available memory on node 0 (3.33/8.0 GiB) is too low.",
|
||||
"(Worker pid=171) ERROR 10-06 09:50:06 [multiproc_executor.py:1058] ValueError: Available memory on node 0 (3.33/8.0 GiB) is too low.",
|
||||
"RuntimeError: Engine core initialization failed. See root cause above. Failed core proc(s): {}",
|
||||
];
|
||||
assert.deepEqual(errorCauses(lines), ["ValueError: Available memory on node 0 (3.33/8.0 GiB) is too low."]);
|
||||
});
|
||||
|
||||
it("finds llama.cpp load errors", () => {
|
||||
const lines = ["0.00.012 I srv load_model: loading model '/models/x.gguf'", "0.00.013 E llama_model_load: error: unknown model architecture: 'foo'", "0.00.014 E srv load_model: failed to load model, '/models/x.gguf'"];
|
||||
assert.equal(errorCauses(lines).length, 2);
|
||||
});
|
||||
|
||||
it("returns nothing for a clean log", () => {
|
||||
assert.deepEqual(errorCauses(["listening on http://0.0.0.0:8080"]), []);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
// Picks the likely cause of a failed start out of a container log. Pure, for tests.
|
||||
|
||||
// "(Worker pid=171) ERROR 10-06 09:50:06 [multiproc_executor.py:1058] " and similar vLLM prefixes.
|
||||
const VLLM_PREFIX = /^\([\w ]+pid=\d+\)\s+(?:[A-Z]+\s+\d\d-\d\d \d\d:\d\d:\d\d\s+\[[^\]]*\]\s*)?/;
|
||||
// A Python exception line ("ValueError: …"), llama.cpp's "error:"/"failed to" lines.
|
||||
const CAUSE = /^(?:[\w.]*(?:Error|Exception): \S|.*\berror: \S|.*\bfailed to (?:load|open|allocate)\b)/i;
|
||||
// Generic wrappers that only say "see above".
|
||||
const WRAPPER = /Engine core initialization failed|See root cause above|exiting due to/i;
|
||||
|
||||
/** Distinct cause lines in order of first appearance (at most `max`). */
|
||||
export function errorCauses(lines: string[], max = 3): string[] {
|
||||
const out: string[] = [];
|
||||
for (const raw of lines) {
|
||||
const line = raw.replace(VLLM_PREFIX, "").trim();
|
||||
if (!CAUSE.test(line) || WRAPPER.test(line) || out.includes(line)) continue;
|
||||
out.push(line.length > 500 ? `${line.slice(0, 500)}…` : line);
|
||||
if (out.length >= max) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in new issue
Block a user