setBatchSize(e.target.value.replace(/\D/g, ""))} inputMode="numeric" placeholder="2048" aria-label="Batch size" />
diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts
index 3d4792c..e6f415b 100644
--- a/src/lib/db/schema.ts
+++ b/src/lib/db/schema.ts
@@ -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;
diff --git a/src/lib/deploy-command.test.ts b/src/lib/deploy-command.test.ts
index 1717833..8199643 100644
--- a/src/lib/deploy-command.test.ts
+++ b/src/lib/deploy-command.test.ts
@@ -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"));
});
});
diff --git a/src/lib/deploy-command.ts b/src/lib/deploy-command.ts
index 705c5dc..b9e6e5b 100644
--- a/src/lib/deploy-command.ts
+++ b/src/lib/deploy-command.ts
@@ -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);
diff --git a/src/lib/deployments.ts b/src/lib/deployments.ts
index f7eebc8..55da46d 100644
--- a/src/lib/deployments.ts
+++ b/src/lib/deployments.ts
@@ -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 {
}
}
-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 {
+/** Likely causes plus the tail of the log, for error messages. */
+async function failureDetails(id: string, tail = 15): Promise {
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 {
@@ -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);
}
diff --git a/src/worker/docker/client.ts b/src/worker/docker/client.ts
index 632959f..b68e28c 100644
--- a/src/worker/docker/client.ts
+++ b/src/worker/docker/client.ts
@@ -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 {
const res = await this.raw(
"GET",
diff --git a/src/worker/log-causes.test.ts b/src/worker/log-causes.test.ts
new file mode 100644
index 0000000..1d70856
--- /dev/null
+++ b/src/worker/log-causes.test.ts
@@ -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"]), []);
+ });
+});
diff --git a/src/worker/log-causes.ts b/src/worker/log-causes.ts
new file mode 100644
index 0000000..bfcba30
--- /dev/null
+++ b/src/worker/log-causes.ts
@@ -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;
+}