Files
Kaname/src/app/(app)/deployments/deployment-form.tsx
T
Pascal LinxweilerandClaude Opus 5.5 e007a35143
Release / release (push) Successful in 3m40s
Release 0.12.0: Intel GPU support
Intel/AMD GPU telemetry in benchmark runs (hwmon power/temperature,
amdgpu sysfs, Intel VRAM/utilization from DRM fdinfo via a minimal
host-PID probe container), temperature for all GPUs, VRAM estimate for
NVIDIA and Intel/AMD in the deployment form, /dev/dri group IDs added to
Intel/AMD runtime containers, Intel llama.cpp presets seeded on first
detection, ZES_ENABLE_SYSMAN=1 for the SYCL preset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 14:47:00 +02:00

1292 lines
48 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { BoxesIcon, CheckIcon, SearchIcon, TerminalIcon } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { ArgsEditor } from "@/components/args-editor";
import { CopyButton } from "@/components/copy-button";
import { FileRoleBadge } from "@/components/labels";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { NativeSelect } from "@/components/ui/native-select";
import type {
DeploymentOptions,
HardwareGpu,
HostGpu,
RuntimeAccelerator,
RuntimeEngine,
} from "@/lib/db/schema";
import type { ModelCandidates } from "@/lib/deploy-candidates";
import {
API_KEY_PLACEHOLDER,
buildCommand,
ENGINE_PORT,
estimateMemoryMb,
estimateVramMb,
renderCommand,
} from "@/lib/deploy-command";
import { argsToRows, rowsToArgs } from "@/lib/extra-args";
import { ACCELERATOR_LABEL } from "@/lib/runtimes-shared";
import { formatBytes } from "@/lib/format";
import { quantGroup } from "@/lib/selection";
import { cn } from "@/lib/utils";
export type FormRuntime = {
id: string;
name: string;
engine: RuntimeEngine;
image: string;
imageState: string;
env: Record<string, string>;
extraArgs: string[];
accelerator: RuntimeAccelerator;
};
export type FormModel = {
id: string;
repoId: string;
localPath: string;
candidates: ModelCandidates;
};
export type FormHost = {
cpus: number | null;
memoryBytes: number | null;
cpuFeatures: string[];
nvidia: boolean;
gpus: HostGpu[];
/** All GPUs on the host with Settings → Hardware applied (Intel/AMD VRAM for the estimate). */
hardwareGpus: HardwareGpu[];
} | null;
export type FormInitial = {
id?: string;
name: string;
runtimeId: string;
modelId: string;
options: DeploymentOptions;
cpus: number | null;
memoryMb: number | null;
hostPort: number | null;
};
const CONTEXT_PRESETS = [2048, 4096, 8192, 16384, 32768];
const KV_TYPES = ["f16", "q8_0", "q4_0"];
const intOrNull = (s: string) =>
(s.trim() === "" ? null : Math.max(0, Math.round(Number(s)))) || null;
/** Like intOrNull, but 0 and -1 are meaningful (e.g. --cache-ram 0 = off). */
const intOrNullSigned = (s: string) =>
s.trim() === "" || !Number.isFinite(Number(s)) ? null : Math.round(Number(s));
/** Default prompt cache for new llama.cpp deployments (llama-server's own default is 8 GiB). */
const DEFAULT_CACHE_RAM_MB = 1024;
const numOrNull = (s: string) => (s.trim() === "" ? null : Number(s)) || null;
function Section({
step,
title,
description,
children,
}: {
step: number;
title: string;
description?: string;
children: React.ReactNode;
}) {
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<span className="grid size-6 place-items-center rounded-full bg-primary text-xs text-primary-foreground">
{step}
</span>
{title}
</CardTitle>
{description && <CardDescription>{description}</CardDescription>}
</CardHeader>
<CardContent className="flex flex-col gap-4">{children}</CardContent>
</Card>
);
}
/** A titled block of related options inside the launch options card. */
function Group({
title,
description,
children,
}: {
title: string;
description?: string;
children: React.ReactNode;
}) {
return (
<div className="grid gap-3 border-t pt-5 first:border-t-0 first:pt-0 md:grid-cols-[11rem_1fr] md:gap-6">
<div className="flex flex-col gap-0.5">
<h3 className="text-sm font-medium">{title}</h3>
{description && (
<p className="text-xs text-muted-foreground">{description}</p>
)}
</div>
<div className="grid content-start gap-4 sm:grid-cols-2">{children}</div>
</div>
);
}
/** `flag`: the command-line flag the field sets, shown next to the label. */
function Field({
label,
flag,
hint,
children,
htmlFor,
wide,
}: {
label: string;
flag?: string;
hint?: React.ReactNode;
children: React.ReactNode;
htmlFor?: string;
wide?: boolean;
}) {
return (
<div className={cn("flex flex-col gap-1.5", wide && "sm:col-span-2")}>
<div className="flex items-baseline justify-between gap-2">
<Label htmlFor={htmlFor}>{label}</Label>
{flag && (
<code className="font-mono text-[11px] text-muted-foreground">
{flag}
</code>
)}
</div>
{children}
{hint && <p className="text-xs text-muted-foreground">{hint}</p>}
</div>
);
}
/** Pick runtime → model and files → launch options. Used for "New deployment" and "Edit". */
export function DeploymentForm({
runtimes,
models,
host,
apiKeyCount,
initial,
}: {
runtimes: FormRuntime[];
models: FormModel[];
host: FormHost;
apiKeyCount: number;
initial?: FormInitial;
}) {
const router = useRouter();
const editing = !!initial?.id;
const [runtimeId, setRuntimeId] = useState(
initial?.runtimeId ??
runtimes.find((r) => r.imageState === "present")?.id ??
"",
);
const runtime = runtimes.find((r) => r.id === runtimeId) ?? null;
const engine = runtime?.engine ?? "llama.cpp";
const accelerator: RuntimeAccelerator = runtime?.accelerator ?? "cpu";
const gpu = accelerator !== "cpu";
const [query, setQuery] = useState("");
const [modelId, setModelId] = useState(initial?.modelId ?? "");
const servable = models.filter((m) =>
engine === "llama.cpp" ? m.candidates.gguf.length > 0 : m.candidates.vllm,
);
const shown = servable.filter((m) =>
m.repoId.toLowerCase().includes(query.trim().toLowerCase()),
);
const model = servable.find((m) => m.id === modelId) ?? null;
const o = initial?.options;
const [modelFile, setModelFile] = useState(o?.modelFile ?? "");
const [mmproj, setMmproj] = useState(o?.mmproj ?? "");
const [draftFile, setDraftFile] = useState(o?.draftFile ?? "");
const [name, setName] = useState(initial?.name ?? "");
const [contextSize, setContextSize] = useState(
String(o?.contextSize ?? 4096),
);
const [threads, setThreads] = useState(
o?.threads != null ? String(o.threads) : "",
);
const [parallel, setParallel] = useState(
o?.parallel != null ? String(o.parallel) : "1",
);
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 [requireApiKey, setRequireApiKey] = useState(!!o?.requireApiKey);
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 ?? "");
const [maxNumSeqs, setMaxNumSeqs] = useState(
o?.maxNumSeqs != null ? String(o.maxNumSeqs) : "",
);
const [kvCacheGb, setKvCacheGb] = useState(
o?.kvCacheGb != null ? String(o.kvCacheGb) : "",
);
const [cacheRam, setCacheRam] = useState(
o
? o.cacheRamMb != null
? String(o.cacheRamMb)
: ""
: String(DEFAULT_CACHE_RAM_MB),
);
const [gpuIds, setGpuIds] = useState<string[]>(o?.gpus ?? []);
const [gpuLayers, setGpuLayers] = useState(o?.gpuLayers ?? "auto");
const [splitMode, setSplitMode] = useState(o?.splitMode ?? "");
const [tensorSplit, setTensorSplit] = useState(o?.tensorSplit ?? "");
const [cpuMoe, setCpuMoe] = useState(!!o?.cpuMoe);
const [nCpuMoe, setNCpuMoe] = useState(
o?.nCpuMoe != null ? String(o.nCpuMoe) : "",
);
const [tensorParallel, setTensorParallel] = useState(
o?.tensorParallel != null ? String(o.tensorParallel) : "",
);
const [gpuMemUtil, setGpuMemUtil] = useState(
o?.gpuMemoryUtilization != null ? String(o.gpuMemoryUtilization) : "",
);
const [argRows, setArgRows] = useState(() => argsToRows(o?.extraArgs ?? []));
const [cpus, setCpus] = useState(
initial?.cpus != null ? String(initial.cpus) : "",
);
const [memoryMb, setMemoryMb] = useState(
initial?.memoryMb != null ? String(initial.memoryMb) : "",
);
const [memoryTouched, setMemoryTouched] = useState(!!initial?.memoryMb);
const [hostPort, setHostPort] = useState(
initial?.hostPort != null ? String(initial.hostPort) : "",
);
const [saving, setSaving] = useState(false);
function pickModel(m: FormModel) {
setModelId(m.id);
const first = m.candidates.gguf[0];
setModelFile(engine === "llama.cpp" ? (first?.path ?? "") : "");
setMmproj(m.candidates.mmproj[0]?.path ?? "");
setDraftFile("");
if (!editing)
setName(
`${m.repoId.split("/")[1]}${first && engine === "llama.cpp" ? ` ${quantGroup(first.path) ?? ""}` : ""}`.trim(),
);
}
const options: DeploymentOptions = {
modelFile: engine === "llama.cpp" ? modelFile : "",
mmproj: engine === "llama.cpp" && mmproj ? mmproj : null,
draftFile: engine === "llama.cpp" && draftFile ? draftFile : null,
draftType:
model?.candidates.drafts.find((d) => d.path === draftFile)?.type ?? null,
contextSize: intOrNull(contextSize) ?? 4096,
threads: intOrNull(threads),
parallel: intOrNull(parallel),
batchSize: engine === "llama.cpp" ? intOrNull(batchSize) : null,
ubatchSize: engine === "llama.cpp" ? intOrNull(ubatchSize) : null,
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,
requireApiKey,
dtype: engine === "vllm" && dtype ? dtype : null,
maxNumSeqs: engine === "vllm" ? intOrNull(maxNumSeqs) : null,
kvCacheGb: engine === "vllm" && !gpu ? numOrNull(kvCacheGb) : null,
cacheRamMb: engine === "llama.cpp" ? intOrNullSigned(cacheRam) : null,
gpus: accelerator === "nvidia" && gpuIds.length ? gpuIds : null,
gpuLayers:
gpu && engine === "llama.cpp" && gpuLayers !== "auto" ? gpuLayers : null,
splitMode:
gpu && engine === "llama.cpp" && splitMode
? (splitMode as "none" | "layer" | "row" | "tensor")
: null,
tensorSplit:
gpu && engine === "llama.cpp" && tensorSplit.trim()
? tensorSplit.trim()
: null,
cpuMoe: gpu && engine === "llama.cpp" ? cpuMoe : null,
nCpuMoe:
gpu && engine === "llama.cpp" && !cpuMoe ? intOrNull(nCpuMoe) : null,
tensorParallel: gpu && engine === "vllm" ? intOrNull(tensorParallel) : null,
gpuMemoryUtilization:
gpu && engine === "vllm" ? numOrNull(gpuMemUtil) : null,
extraArgs: rowsToArgs(argRows),
};
const fileBytes = model
? engine === "llama.cpp"
? (model.candidates.gguf.find((g) => g.path === modelFile)?.size ?? 0) +
(model.candidates.mmproj.find((g) => g.path === mmproj)?.size ?? 0) +
(model.candidates.drafts.find((g) => g.path === draftFile)?.size ?? 0)
: (model.candidates.vllm?.size ?? 0)
: 0;
const estimate = model
? estimateMemoryMb(fileBytes, options.contextSize, engine, {
...options,
accelerator,
})
: null;
const hostGpus = host?.gpus ?? [];
const chosenGpus = gpuIds.length
? hostGpus.filter((g) => gpuIds.includes(g.uuid))
: hostGpus;
const vramMb = chosenGpus.reduce((s, g) => s + g.memoryMb, 0);
// Intel/AMD GPUs come in as /dev/dri: all of them, VRAM as detected (or set in Settings → Hardware).
const driGpus = (host?.hardwareGpus ?? []).filter((g) => (accelerator === "rocm" ? g.vendor === "amd" : g.vendor === "intel" || g.vendor === "amd"));
const gpuVramMb = accelerator === "nvidia" ? vramMb || null : driGpus.some((g) => g.vramMb) ? driGpus.reduce((s, g) => s + (g.vramMb ?? 0), 0) : null;
const vramEstimate = model && gpu ? estimateVramMb(fileBytes, options.contextSize, engine, options, gpuVramMb) : null;
const memory = memoryTouched ? intOrNull(memoryMb) : estimate;
const preview =
runtime && model
? renderCommand(
runtime.image,
buildCommand({
engine,
options,
model,
runtime: {
env: runtime.env,
extraArgs: runtime.extraArgs,
accelerator,
},
apiKeys: Array.from(
{ length: apiKeyCount },
() => API_KEY_PLACEHOLDER,
),
}),
)
: null;
const noBf16 = host && !host.cpuFeatures.includes("avx512_bf16");
async function submit(start: boolean) {
if (!runtime || !model) return;
setSaving(true);
try {
const body = {
name: name.trim() || model.repoId,
runtimeId: runtime.id,
modelId: model.id,
options,
cpus: numOrNull(cpus),
memoryMb: memory,
hostPort: intOrNull(hostPort),
start,
};
const res = await fetch(
editing ? `/api/deployments/${initial!.id}` : "/api/deployments",
{
method: editing ? "PUT" : "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
},
);
const json = await res.json().catch(() => ({}));
if (!res.ok) {
toast.error(json.error?.message ?? `Could not save (${res.status})`);
return;
}
const id = editing ? initial!.id : json.id;
if (editing && start)
await fetch(`/api/deployments/${id}/start`, { method: "POST" });
toast.success(start ? "Deployment starting" : "Deployment saved");
router.push(`/deployments/${id}`);
router.refresh();
} finally {
setSaving(false);
}
}
return (
<div className="flex flex-col gap-4">
<Section
step={1}
title="Runtime"
description="The container image that serves the model."
>
{runtimes.length === 0 ? (
<p className="text-sm text-muted-foreground">
No runtimes yet.{" "}
<Link href="/settings/runtimes" className="underline">
Add one in Settings
</Link>
.
</p>
) : (
<div className="grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
{runtimes.map((r) => {
const ready = r.imageState === "present";
return (
<button
key={r.id}
type="button"
disabled={!ready}
onClick={() => {
setRuntimeId(r.id);
if (r.engine !== engine) setModelId("");
}}
className={cn(
"flex flex-col items-start gap-1 rounded-lg border px-3 py-2.5 text-left transition-colors disabled:cursor-not-allowed disabled:opacity-50",
runtimeId === r.id
? "border-primary bg-primary/5 ring-1 ring-primary"
: "hover:bg-muted/50",
)}
>
<span className="flex w-full items-center justify-between gap-2 text-sm font-medium">
<span className="flex items-center gap-1.5">
<BoxesIcon className="size-4 text-muted-foreground" />
{r.name}
</span>
{runtimeId === r.id && (
<CheckIcon className="size-4 text-primary" />
)}
</span>
<code className="font-mono text-xs break-all text-muted-foreground">
{r.image}
</code>
<span className="text-xs text-muted-foreground">
{r.engine === "vllm"
? "vLLM · safetensors"
: "llama.cpp · GGUF"}
{!ready && " · image not pulled"}
</span>
</button>
);
})}
</div>
)}
{runtimes.some((r) => r.imageState !== "present") && (
<p className="text-xs text-muted-foreground">
Runtimes whose image isn&apos;t pulled yet can&apos;t be picked.{" "}
<Link href="/settings/runtimes" className="underline">
Pull them in Settings
</Link>
.
</p>
)}
</Section>
{runtime && (
<Section
step={2}
title="Model"
description={
engine === "llama.cpp"
? "Downloaded GGUF models. Pick the quant and optional extras."
: "Downloaded safetensors repos (with config.json)."
}
>
{servable.length === 0 ? (
<p className="text-sm text-muted-foreground">
No downloaded model fits this runtime.{" "}
<Link href="/" className="underline">
Add one in the library
</Link>
{engine === "vllm"
? " (a safetensors repo, e.g. HuggingFaceTB/SmolLM2-135M-Instruct)."
: "."}
</p>
) : (
<>
{servable.length > 6 && (
<div className="relative">
<SearchIcon className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
<Input
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search models…"
className="pl-8"
/>
</div>
)}
<div className="flex max-h-72 flex-col divide-y overflow-y-auto rounded-lg ring-1 ring-foreground/10">
{shown.map((m) => (
<button
key={m.id}
type="button"
onClick={() => pickModel(m)}
className={cn(
"flex items-center justify-between gap-3 px-3 py-2 text-left text-sm hover:bg-muted/50",
modelId === m.id && "bg-primary/5",
)}
>
<span className="flex min-w-0 items-center gap-2">
{modelId === m.id ? (
<CheckIcon className="size-4 shrink-0 text-primary" />
) : (
<span className="size-4 shrink-0" />
)}
<span className="truncate">{m.repoId}</span>
</span>
<span className="shrink-0 text-xs text-muted-foreground">
{engine === "llama.cpp"
? `${m.candidates.gguf.length} GGUF${m.candidates.mmproj.length ? " · vision" : ""}${m.candidates.drafts.length ? " · MTP/draft" : ""}`
: formatBytes(m.candidates.vllm?.size ?? 0)}
</span>
</button>
))}
</div>
{model && engine === "llama.cpp" && (
<div className="grid gap-4 md:grid-cols-3">
<Field label="Model file" flag="-m">
<div className="flex flex-col gap-1">
{model.candidates.gguf.map((g) => (
<label
key={g.path}
className={cn(
"flex cursor-pointer items-center gap-2 rounded-md border px-2 py-1.5 text-xs",
modelFile === g.path &&
"border-primary bg-primary/5",
)}
>
<input
type="radio"
name="modelFile"
checked={modelFile === g.path}
onChange={() => setModelFile(g.path)}
className="accent-primary"
/>
<span
className="min-w-0 flex-1 truncate font-mono"
title={g.path}
>
{quantGroup(g.path) ?? g.path}
</span>
<span className="text-muted-foreground tabular-nums">
{formatBytes(g.size)}
</span>
</label>
))}
</div>
</Field>
<Field
label="Vision (mmproj)"
flag="--mmproj"
hint={
model.candidates.mmproj.length === 0
? "None downloaded."
: "Needed for image input."
}
>
<NativeSelect
value={mmproj}
onChange={(e) => setMmproj(e.target.value)}
disabled={model.candidates.mmproj.length === 0}
>
<option value="">None</option>
{model.candidates.mmproj.map((m) => (
<option key={m.path} value={m.path}>
{m.path} ({formatBytes(m.size)})
</option>
))}
</NativeSelect>
</Field>
<Field
label="Speculative decoding"
flag="-md"
hint={
model.candidates.drafts.length === 0
? "No MTP head or draft model downloaded."
: "Faster generation with an MTP head or draft model."
}
>
<NativeSelect
value={draftFile}
onChange={(e) => setDraftFile(e.target.value)}
disabled={model.candidates.drafts.length === 0}
>
<option value="">Off</option>
{model.candidates.drafts.map((d) => (
<option key={d.path} value={d.path}>
{d.type === "draft-mtp" ? "MTP: " : "Draft: "}
{d.path} ({formatBytes(d.size)})
</option>
))}
</NativeSelect>
</Field>
</div>
)}
{model && (
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
{[modelFile, mmproj, draftFile].filter(Boolean).map((p) => (
<span key={p} className="flex items-center gap-1">
<FileRoleBadge path={p} />
</span>
))}
<span>{formatBytes(fileBytes)} of model files</span>
</div>
)}
</>
)}
</Section>
)}
{runtime && model && (
<Section
step={3}
title="Launch options"
description="Empty fields use the engine's defaults."
>
<Group
title="General"
description="Name and how to reach the server."
>
<Field label="Name" htmlFor="d-name">
<Input
id="d-name"
value={name}
onChange={(e) => setName(e.target.value)}
maxLength={80}
/>
</Field>
<Field
label="Host port"
htmlFor="d-port"
hint={`Publishes container port ${ENGINE_PORT[engine]}; empty: only reachable inside Docker.`}
>
<Input
id="d-port"
value={hostPort}
onChange={(e) => setHostPort(e.target.value.replace(/\D/g, ""))}
inputMode="numeric"
placeholder="not published"
/>
</Field>
<label className="flex cursor-pointer items-start gap-2.5 text-sm sm:col-span-2">
<Checkbox
checked={requireApiKey}
onCheckedChange={(v) => setRequireApiKey(v === true)}
className="mt-0.5"
disabled={apiKeyCount === 0 && !requireApiKey}
/>
<span className="flex flex-col gap-0.5">
<span>Require an API key</span>
<span className="text-xs text-muted-foreground">
{apiKeyCount === 0 ? (
<>
No keys yet.{" "}
<Link href="/settings/api-keys" className="underline">
Add one in Settings
</Link>
.
</>
) : (
<>
Accepts any of the {apiKeyCount} key
{apiKeyCount === 1 ? "" : "s"} from{" "}
<Link href="/settings/api-keys" className="underline">
Settings → Runtime API keys
</Link>{" "}
as{" "}
<code className="font-mono">Authorization: Bearer</code>.
{engine === "vllm" ? " vLLM only checks /v1 paths." : ""}
</>
)}
</span>
</span>
</label>
{engine === "llama.cpp" && (
<label className="flex cursor-pointer items-start gap-2.5 text-sm sm:col-span-2">
<Checkbox
checked={webui}
onCheckedChange={(v) => setWebui(v === true)}
className="mt-0.5"
/>
<span className="flex flex-col gap-0.5">
<span>Serve the llama.cpp web UI</span>
<span className="text-xs text-muted-foreground">
{webui
? hostPort
? `Opens at http://<server>:${hostPort}/ (no login on that port).`
: "Set a host port to open it."
: "Off: passes --no-webui; the API keeps working."}
</span>
</span>
</label>
)}
</Group>
<Group
title="Context"
description="How much text the model sees and how many requests run at once."
>
<Field
label="Context size (tokens)"
flag={engine === "vllm" ? "--max-model-len" : "-c"}
htmlFor="d-ctx"
wide
>
<div className="flex flex-wrap items-center gap-1.5">
<Input
id="d-ctx"
value={contextSize}
onChange={(e) =>
setContextSize(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
className="w-28"
/>
{CONTEXT_PRESETS.map((c) => (
<Button
key={c}
type="button"
size="xs"
variant={Number(contextSize) === c ? "default" : "outline"}
onClick={() => setContextSize(String(c))}
>
{c / 1024}k
</Button>
))}
</div>
</Field>
{engine === "vllm" ? (
<Field
label="Max concurrent sequences"
flag="--max-num-seqs"
htmlFor="d-par"
>
<Input
id="d-par"
value={maxNumSeqs}
onChange={(e) =>
setMaxNumSeqs(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder="default"
/>
</Field>
) : (
<Field
label="Parallel slots"
flag="-np"
htmlFor="d-par"
hint="The context is split between slots."
>
<Input
id="d-par"
value={parallel}
onChange={(e) =>
setParallel(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder="auto"
/>
</Field>
)}
</Group>
{gpu && (
<Group
title="GPU"
description={`${ACCELERATOR_LABEL[accelerator]}. Model weights and KV cache go to VRAM.`}
>
{accelerator === "nvidia" && (
<div className="flex flex-col gap-1.5 sm:col-span-2">
<Label>GPUs</Label>
{!host?.nvidia ? (
<p className="text-xs text-destructive">
Docker on this host has no NVIDIA runtime. Install the
NVIDIA Container Toolkit, then restart the worker.
</p>
) : hostGpus.length === 0 ? (
<p className="text-xs text-muted-foreground">
No GPUs detected yet; the deployment gets all of them.
</p>
) : (
<div className="flex flex-col gap-1">
{hostGpus.map((g) => (
<label
key={g.uuid}
className="flex cursor-pointer items-center gap-2 rounded-md border px-2 py-1.5 text-sm"
>
<Checkbox
checked={
gpuIds.length === 0 || gpuIds.includes(g.uuid)
}
onCheckedChange={(v) => {
const all = hostGpus.map((x) => x.uuid);
const cur = gpuIds.length ? gpuIds : all;
const next = v
? [...new Set([...cur, g.uuid])]
: cur.filter((x) => x !== g.uuid);
setGpuIds(next.length === all.length ? [] : next);
}}
/>
<span className="min-w-0 flex-1 truncate">
{g.index}: {g.name}
</span>
<span className="text-xs text-muted-foreground tabular-nums">
{formatBytes(g.memoryMb * 2 ** 20)}
</span>
</label>
))}
<p className="text-xs text-muted-foreground">
{gpuIds.length === 0
? "All GPUs"
: `${gpuIds.length} of ${hostGpus.length}`}{" "}
· {formatBytes(vramMb * 2 ** 20)} VRAM
{fileBytes > 0 &&
` · model files ${formatBytes(fileBytes)}`}
</p>
</div>
)}
</div>
)}
{accelerator !== "nvidia" && driGpus.length > 0 && (
<p className="text-xs text-muted-foreground sm:col-span-2">
{driGpus.map((g) => `${g.name ?? "GPU"}${g.vramMb ? ` (${formatBytes(g.vramMb * 2 ** 20)})` : ""}`).join(", ")} via /dev/dri
</p>
)}
{model && (
<p className={`text-xs sm:col-span-2 ${vramEstimate != null && gpuVramMb != null && vramEstimate > gpuVramMb ? "text-amber-700 dark:text-amber-300" : "text-muted-foreground"}`}>
{vramEstimate == null
? "VRAM need: depends on how many layers/experts go to the GPU."
: `VRAM need, roughly: ${formatBytes(vramEstimate * 2 ** 20)}${gpuVramMb ? ` of ${formatBytes(gpuVramMb * 2 ** 20)}` : ""}${
engine === "vllm" ? " (vLLM reserves its GPU memory share up front)" : " (weights, KV cache, compute buffers)"
}${gpuVramMb != null && vramEstimate > gpuVramMb ? ". Doesn't fit: lower the context, quantize the KV cache or offload fewer layers." : ""}`}
</p>
)}
{engine === "llama.cpp" ? (
<>
<Field
label="GPU layers"
flag="-ngl"
htmlFor="d-ngl"
hint="auto fits as many layers as free VRAM allows."
>
<div className="flex gap-1.5">
<NativeSelect
id="d-ngl"
value={
gpuLayers === "auto" || gpuLayers === "all"
? gpuLayers
: "n"
}
onChange={(e) =>
setGpuLayers(
e.target.value === "n" ? "20" : e.target.value,
)
}
>
<option value="auto">auto</option>
<option value="all">all</option>
<option value="n">number…</option>
</NativeSelect>
{gpuLayers !== "auto" && gpuLayers !== "all" && (
<Input
value={gpuLayers}
onChange={(e) =>
setGpuLayers(
e.target.value.replace(/\D/g, "") || "0",
)
}
inputMode="numeric"
className="w-20"
aria-label="Number of GPU layers"
/>
)}
</div>
</Field>
<Field
label="Split across GPUs"
flag="-sm"
htmlFor="d-sm"
hint="Only matters with more than one GPU."
>
<NativeSelect
id="d-sm"
value={splitMode}
onChange={(e) => setSplitMode(e.target.value)}
>
<option value="">default (layer)</option>
<option value="none">none (one GPU)</option>
<option value="layer">layer</option>
<option value="row">row</option>
<option value="tensor">tensor</option>
</NativeSelect>
</Field>
<Field
label="Tensor split"
flag="-ts"
htmlFor="d-ts"
hint="Share per GPU, e.g. 3,1."
>
<Input
id="d-ts"
value={tensorSplit}
onChange={(e) =>
setTensorSplit(e.target.value.replace(/[^\d.,]/g, ""))
}
placeholder="even"
/>
</Field>
<Field
label="MoE experts in RAM"
flag={cpuMoe ? "-cmoe" : "-ncmoe"}
htmlFor="d-moe"
hint="For mixture-of-experts models larger than VRAM."
>
<div className="flex items-center gap-2">
<NativeSelect
id="d-moe"
value={cpuMoe ? "all" : nCpuMoe ? "n" : ""}
onChange={(e) => {
setCpuMoe(e.target.value === "all");
if (e.target.value === "") setNCpuMoe("");
if (e.target.value === "n" && !nCpuMoe)
setNCpuMoe("10");
}}
>
<option value="">none</option>
<option value="all">all experts</option>
<option value="n">first N layers…</option>
</NativeSelect>
{!cpuMoe && nCpuMoe !== "" && (
<Input
value={nCpuMoe}
onChange={(e) =>
setNCpuMoe(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
className="w-20"
aria-label="Layers with MoE experts in RAM"
/>
)}
</div>
</Field>
</>
) : (
<>
<Field
label="Tensor parallel"
flag="--tensor-parallel-size"
htmlFor="d-tp"
hint="Number of GPUs the model is split across."
>
<Input
id="d-tp"
value={tensorParallel}
onChange={(e) =>
setTensorParallel(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder={String(Math.max(1, chosenGpus.length))}
/>
</Field>
<Field
label="GPU memory share"
flag="--gpu-memory-utilization"
htmlFor="d-gmu"
hint="Fraction of each GPU vLLM reserves (weights + KV cache)."
>
<Input
id="d-gmu"
value={gpuMemUtil}
onChange={(e) =>
setGpuMemUtil(e.target.value.replace(/[^\d.]/g, ""))
}
inputMode="decimal"
placeholder="0.9"
/>
</Field>
</>
)}
</Group>
)}
{engine === "llama.cpp" ? (
<Group
title="Performance"
description="CPU threads and prompt processing."
>
<Field
label="Threads"
flag="-t / -tb"
htmlFor="d-thr"
hint={host?.cpus ? `Host has ${host.cpus} threads.` : undefined}
>
<Input
id="d-thr"
value={threads}
onChange={(e) =>
setThreads(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder="auto"
/>
</Field>
<Field label="Flash attention" flag="-fa" htmlFor="d-fa">
<NativeSelect
id="d-fa"
value={flashAttn}
onChange={(e) => setFlashAttn(e.target.value)}
>
<option value="">auto</option>
<option value="on">on</option>
<option value="off">off</option>
</NativeSelect>
</Field>
<Field label="Batch size" flag="-b" htmlFor="d-b">
<Input
id="d-b"
value={batchSize}
onChange={(e) =>
setBatchSize(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder="2048"
/>
</Field>
<Field label="Micro-batch size" flag="-ub" htmlFor="d-ub">
<Input
id="d-ub"
value={ubatchSize}
onChange={(e) =>
setUbatchSize(e.target.value.replace(/\D/g, ""))
}
inputMode="numeric"
placeholder="512"
/>
</Field>
</Group>
) : (
<Group
title="Performance"
description="vLLM binds its CPU threads itself; limit cores under Resources."
>
<Field
label="Data type"
flag="--dtype"
htmlFor="d-dtype"
hint={
noBf16
? "This CPU has no AVX-512 BF16; float32 is likely faster."
: "Overrides the runtime's default."
}
>
<NativeSelect
id="d-dtype"
value={dtype}
onChange={(e) => setDtype(e.target.value)}
>
<option value="">runtime default</option>
<option value="bfloat16">bfloat16</option>
<option value="float32">float32</option>
<option value="float16">float16</option>
<option value="auto">auto</option>
</NativeSelect>
</Field>
</Group>
)}
<Group
title="KV cache"
description="Memory for the context of running requests."
>
{engine === "llama.cpp" ? (
<>
<Field
label="K type"
flag="-ctk"
htmlFor="d-ctk"
hint="q8_0 halves the memory."
>
<NativeSelect
id="d-ctk"
value={cacheTypeK}
onChange={(e) => setCacheTypeK(e.target.value)}
>
<option value="">f16 (default)</option>
{KV_TYPES.filter((t) => t !== "f16").map((t) => (
<option key={t} value={t}>
{t}
</option>
))}
</NativeSelect>
</Field>
<Field label="V type" flag="-ctv" htmlFor="d-ctv">
<NativeSelect
id="d-ctv"
value={cacheTypeV}
onChange={(e) => setCacheTypeV(e.target.value)}
>
<option value="">f16 (default)</option>
{KV_TYPES.filter((t) => t !== "f16").map((t) => (
<option key={t} value={t}>
{t}
</option>
))}
</NativeSelect>
</Field>
<Field
label="Prompt cache in RAM (MiB)"
flag="-cram"
htmlFor="d-cram"
hint="Earlier prompts kept for reuse; grows until this size. 0 turns it off; empty uses llama-server's 8192."
>
<Input
id="d-cram"
value={cacheRam}
onChange={(e) =>
setCacheRam(e.target.value.replace(/[^\d-]/g, ""))
}
inputMode="numeric"
placeholder="8192"
/>
</Field>
</>
) : gpu ? (
<p className="text-xs text-muted-foreground sm:col-span-2">
On a GPU, vLLM sizes the KV cache from the GPU memory share
above.
</p>
) : (
<Field
label="KV cache size (GiB)"
flag="VLLM_CPU_KVCACHE_SPACE"
htmlFor="d-kv"
hint="Reserved up front; must fit in the memory limit."
>
<Input
id="d-kv"
value={kvCacheGb}
onChange={(e) =>
setKvCacheGb(e.target.value.replace(/[^\d.]/g, ""))
}
inputMode="decimal"
placeholder={runtime.env.VLLM_CPU_KVCACHE_SPACE ?? "4"}
/>
</Field>
)}
</Group>
<Group title="Resources" description="Container limits.">
<Field
label="CPU cores"
htmlFor="d-cpus"
hint={
host?.cpus
? `Empty: no limit (host: ${host.cpus}).`
: "Empty: no limit."
}
>
<Input
id="d-cpus"
value={cpus}
onChange={(e) => setCpus(e.target.value.replace(/[^\d.]/g, ""))}
inputMode="decimal"
placeholder="no limit"
/>
</Field>
<Field
label="Memory (MiB)"
htmlFor="d-mem"
hint={
<>
Estimate:{" "}
{estimate != null ? formatBytes(estimate * 2 ** 20) : "–"}
{host?.memoryBytes
? ` · host: ${formatBytes(host.memoryBytes)}`
: ""}
{memoryTouched && (
<button
type="button"
className="ml-1 underline"
onClick={() => setMemoryTouched(false)}
>
use estimate
</button>
)}
</>
}
>
<Input
id="d-mem"
value={memoryTouched ? memoryMb : String(estimate ?? "")}
onChange={(e) => {
setMemoryTouched(true);
setMemoryMb(e.target.value.replace(/\D/g, ""));
}}
inputMode="numeric"
/>
</Field>
</Group>
<Group
title="Extra arguments"
description={`Any other ${engine === "vllm" ? "vllm serve" : "llama-server"} flag. Added after the runtime's own arguments.`}
>
<div className="sm:col-span-2">
<ArgsEditor
rows={argRows}
onChange={setArgRows}
placeholder={
engine === "vllm"
? { flag: "--enforce-eager", value: "value (optional)" }
: { flag: "--temp", value: "0.7" }
}
/>
</div>
</Group>
</Section>
)}
{runtime && model && (
<Section
step={4}
title="Command"
description="What Kaname runs, including the runtime's environment and arguments."
>
{preview && (
<div className="relative">
<pre className="overflow-x-auto rounded-lg bg-muted/60 py-2.5 pr-12 pl-3 font-mono text-xs break-all whitespace-pre-wrap">
<TerminalIcon className="mr-1.5 inline size-3.5 align-[-2px] text-muted-foreground" />
{preview}
</pre>
<div className="absolute top-1.5 right-1.5">
<CopyButton value={preview} label="Copy command" />
</div>
</div>
)}
<div className="flex flex-wrap justify-end gap-2">
<Button type="button" variant="ghost" onClick={() => router.back()}>
Cancel
</Button>
<Button
type="button"
variant="outline"
disabled={saving || (engine === "llama.cpp" && !modelFile)}
onClick={() => submit(false)}
>
{editing ? "Save" : "Create"}
</Button>
<Button
type="button"
disabled={saving || (engine === "llama.cpp" && !modelFile)}
onClick={() => submit(true)}
>
{editing ? "Save & start" : "Create & start"}
</Button>
</div>
</Section>
)}
</div>
);
}