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
@@ -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({
|
||||
|
||||
Reference in new issue
Block a user