radiance 2.0.0

Radiance becomes a multi-model engine: one process serves several models behind one port, loads
each when a request names it, parks it in host memory or restores it from its container, and
shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the
command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP).

Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an
int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block
FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such
weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5,
Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B,
the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0
serves all of them.

Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new
Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill
reworked, and a reworked adaptive draft window.

Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its
configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool
in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server,
each accelerator's memory by model, model states over time.

Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by
AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests
keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410);
eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d
large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi
(#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon
(#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and
multi-model serving as asked for in #367 and #109.

Plugin ABI 39: out-of-tree plugins need to be rebuilt.

Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
This commit is contained in:
Deadcode committed 2026-11-14 22:32:28 +01:00
1 parent b4c04b6042
commit ddcb9c69bb
696 files changed
+120770 -56596

No files matched your search

+253
View File
@@ -0,0 +1,253 @@
// What a model is and what the engine built for it: its shape, where its bytes are, the kernels
// its program runs, and every op with the kernel chosen for it.
import { useEffect, useMemo, useState } from "react"
import { Empty, Panel, PartBar, type Part } from "@/components/bits"
import { Input } from "@/components/ui/input"
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "@/components/ui/sheet"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { Switch } from "@/components/ui/switch"
import { api, withModel, type Stats } from "@/lib/api"
import { fBytes, fNum } from "@/lib/format"
import { useFetched } from "@/lib/fetched"
interface Kernel { kernel: string; plugin: string; family?: string; computes?: string; shape?: string; dtypes?: string; geometry?: string; constraints?: string[] }
interface Weight { name: string; bytes: number; dtype: string; shape: string; tier?: string; access?: string }
interface Op {
op: string; index: number; geometry: string; count?: number; ranged?: string; range_lo?: number; range_hi?: number
schema?: { doc?: string }
weights?: Weight[]
bands?: { span: string; device?: Kernel; host?: Kernel }[]
}
interface Graph {
model?: { arch?: string; quant?: string; n_layers?: number; n_embd?: number; n_vocab?: number; world?: number; max_seqs?: number }
counts?: { ops?: number; weights?: number; weight_bytes?: number; arena_bytes?: number; host_arena_bytes?: number; scratch_bytes?: number }
plugins?: { name: string; version?: string; kernels?: number; build_target?: string; description?: string }[]
ops: Op[]; order?: number[]
drafter?: { name?: string; kind?: string; depth?: number }
notes?: string[]
}
interface Info { server?: { max_model_len?: number; max_num_seqs?: number }; engine?: Record<string, unknown>; endpoints?: string[]; request_defaults?: Record<string, unknown> }
const kernelOf = (o: Op): Kernel | null => { for (const b of o.bands ?? []) { const k = b.device ?? b.host; if (k?.kernel) return k } return null }
const familyOf = (o: Op) => kernelOf(o)?.family || o.op
export function Details({ model, stats }: { model: string; stats: Stats | null }) {
const { data: g, error } = useFetched<Graph>(withModel("graph", model))
const { data: info } = useFetched<Info>(withModel("server_info", model))
const [query, setQuery] = useState("")
const [open, setOpen] = useState<Op | null>(null)
const fam = useMemo(() => {
const n = new Map<string, number>()
for (const o of g?.ops ?? []) n.set(familyOf(o), (n.get(familyOf(o)) ?? 0) + (o.count ?? 1))
const ranked = [...n.entries()].sort((a, b) => b[1] - a[1])
return { ranked, hue: new Map(ranked.map(([f], i) => [f, i < 7 ? `var(--series-${i + 1})` : "var(--idle)"])) }
}, [g])
if (!g) return <Empty>{error ? "Details are available once the model is loaded" : "Loading"}</Empty>
const m = g.model ?? {}, c = g.counts ?? {}, e = (info?.engine ?? {}) as Record<string, any>
const facts: [string, string][] = [
["Architecture", m.arch ?? e.arch ?? "–"], ["Quantization", m.quant ?? "none"], ["Layers", fNum(m.n_layers)], ["Width", fNum(m.n_embd)],
["Vocabulary", fNum(m.n_vocab)], ["Context", fNum(info?.server?.max_model_len)], ["Sequences", fNum(m.max_seqs)], ["Accelerators", String(m.world && m.world > 1 ? m.world : 1)],
["Ops", fNum(c.ops)], ["Weights", fNum(c.weights)],
]
if (g.drafter?.name) facts.push(["Drafter", g.drafter.name], ["Draft depth", String(g.drafter.depth ?? "–")])
if (e.tp_wire && (m.world ?? 1) > 1) facts.push(["Link between accelerators", String(e.tp_wire)])
const mem: Part[] = ([["Weights", c.weight_bytes, 1], ["Activations", c.arena_bytes, 3], ["Host arena", c.host_arena_bytes, 5], ["Scratch", c.scratch_bytes, 6], ["KV cache", stats?.kv_bytes_total, 4]] as [string, number | undefined, number][])
.filter(([, v]) => (v ?? 0) > 0).map(([label, v, i]) => ({ key: label, label, value: v!, color: `var(--series-${i})`, text: fBytes(v) }))
const byIndex = new Map(g.ops.map((o) => [o.index, o]))
const q = query.trim().toLowerCase()
const ops = g.ops.filter((o) => !q || o.op.toLowerCase().includes(q) || (kernelOf(o)?.kernel ?? "").toLowerCase().includes(q) || o.geometry.toLowerCase().includes(q))
const top = fam.ranked.slice(0, 7), most = top[0]?.[1] ?? 1
const strip = (g.order ?? []).slice(0, 2400)
const libs = (g.plugins ?? []).filter((p) => (p.kernels ?? 0) > 0)
return (
<div className="flex flex-col gap-4">
<div className="overflow-hidden rounded-xl border bg-card">
<div className="-mr-px -mb-px grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6">
{facts.map(([k, v]) => (
<div key={k} className="min-w-0 border-r border-b px-4 py-3">
<div className="truncate text-xs text-muted-foreground">{k}</div>
<div className="num truncate text-sm font-medium" title={v}>{v}</div>
</div>
))}
</div>
</div>
<ControlVector model={model} />
<div className="grid gap-4 lg:grid-cols-2">
<Panel title="Memory" description="Per accelerator, by use">
<div className="flex flex-col gap-4">
<PartBar parts={mem} className="h-3" />
<div className="grid grid-cols-[auto_1fr_auto] items-center gap-x-3 gap-y-1.5 text-xs">
{mem.map((p) => (
<div key={p.key} className="contents">
<span className="inline-flex items-center gap-1.5"><i className="size-2 rounded-full" style={{ background: p.color }} />{p.label}</span>
<div className="h-1.5 overflow-hidden rounded-full bg-muted"><div className="h-full rounded-full" style={{ width: (100 * p.value) / Math.max(...mem.map((q) => q.value), 1) + "%", background: p.color }} /></div>
<span className="num text-right text-muted-foreground">{p.text}</span>
</div>
))}
</div>
</div>
</Panel>
<Panel title="Kernels in use" description="Launches per pass, by kernel type">
<div className="grid grid-cols-[auto_1fr_auto] items-center gap-x-3 gap-y-1.5 text-xs">
{top.map(([f, n]) => (
<div key={f} className="contents">
<span className="truncate">{f}</span>
<div className="h-1.5 overflow-hidden rounded-full bg-muted"><div className="h-full rounded-full" style={{ width: (100 * n) / most + "%", background: fam.hue.get(f) }} /></div>
<span className="num text-right text-muted-foreground">{fNum(n)}</span>
</div>
))}
</div>
</Panel>
</div>
{strip.length > 0 && (
<Panel title="Program" description={`The ${fNum(g.order?.length)} launches of one pass, in order, colored by kernel type`}>
<div className="flex flex-wrap gap-px">
{strip.map((idx, i) => {
const o = byIndex.get(idx)
return o ? <button key={i} title={o.op} onClick={() => setOpen(o)} className="h-3.5 w-[3px] rounded-[1px] opacity-85 hover:opacity-100 hover:outline hover:outline-foreground" style={{ background: fam.hue.get(familyOf(o)) }} /> : null
})}
</div>
</Panel>
)}
<Panel title="Ops" description={`${fNum(ops.length)} of ${fNum(g.ops.length)} distinct`} flush
action={<Input value={query} onChange={(ev) => setQuery(ev.target.value)} placeholder="Filter by op, kernel or geometry" className="h-8 w-64 max-w-[50vw]" />}>
<div className="max-h-[28rem] overflow-auto">
<Table>
<TableHeader className="sticky top-0 z-10 bg-card">
<TableRow className="hover:bg-transparent">
<TableHead className="pl-4">Op</TableHead><TableHead>Kernel</TableHead><TableHead>Library</TableHead>
<TableHead className="text-right">Launches</TableHead><TableHead className="pr-4">Geometry</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{ops.map((o) => {
const k = kernelOf(o)
return (
<TableRow key={o.index} className="cursor-pointer" onClick={() => setOpen(o)}>
<TableCell className="pl-4 font-medium"><span className="inline-flex items-center gap-2"><i className="size-2 rounded-full" style={{ background: fam.hue.get(familyOf(o)) }} />{o.op}</span></TableCell>
<TableCell className="font-mono text-xs">{k?.kernel ?? "–"}</TableCell>
<TableCell className="text-muted-foreground">{k?.plugin ?? "–"}</TableCell>
<TableCell className="num text-right">{fNum(o.count ?? 1)}</TableCell>
<TableCell className="max-w-[28rem] truncate pr-4 font-mono text-xs text-muted-foreground">{o.geometry}</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</div>
</Panel>
<div className="grid gap-4 lg:grid-cols-2">
{libs.length > 0 && (
<Panel title="Kernel libraries" description="In lookup order" flush>
<Table>
<TableHeader><TableRow className="hover:bg-transparent"><TableHead className="pl-4">Library</TableHead><TableHead>Version</TableHead><TableHead className="text-right">Kernels</TableHead><TableHead className="pr-4">Built for</TableHead></TableRow></TableHeader>
<TableBody>
{libs.map((p) => (
<TableRow key={p.name}>
<TableCell className="pl-4 font-medium">
<Tooltip><TooltipTrigger render={<span>{p.name}</span>} /><TooltipContent className="max-w-80">{p.description}</TooltipContent></Tooltip>
</TableCell>
<TableCell className="num text-muted-foreground">{p.version ?? "–"}</TableCell>
<TableCell className="num text-right">{fNum(p.kernels)}</TableCell>
<TableCell className="pr-4 text-muted-foreground">{p.build_target ?? "–"}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Panel>
)}
{(g.notes?.length ?? 0) > 0 && (
<Panel title="Notes" description="Messages from the model plugin during setup">
<ul className="flex flex-col gap-2 text-sm text-muted-foreground">
{g.notes!.map((n, i) => <li key={i} className="border-l-2 pl-3 leading-snug">{n}</li>)}
</ul>
</Panel>
)}
</div>
<Sheet open={!!open} onOpenChange={(v) => { if (!v) setOpen(null) }}>
<SheetContent className="w-full gap-0 overflow-y-auto sm:max-w-xl">
{open && <OpDetail op={open} />}
</SheetContent>
</Sheet>
</div>
)
}
/** The switch of a model that carries a control vector: whether requests get it unless they say. */
function ControlVector({ model }: { model: string }) {
const [cv, setCv] = useState<{ default?: boolean; name?: string } | null>(null)
const load = () => { api<{ default?: boolean; name?: string }>(withModel("admin/control-vector", model)).then(setCv).catch(() => setCv(null)) }
useEffect(load, [model]) // eslint-disable-line react-hooks/exhaustive-deps
if (!cv) return null
const set = (on: boolean) => {
setCv({ ...cv, default: on })
api(withModel("admin/control-vector", model), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ enabled: on }) }).catch(() => undefined).finally(load)
}
return (
<label className="flex items-center gap-3 rounded-xl border bg-card px-4 py-3">
<span className="text-sm font-medium">Control vector</span>
<span className="min-w-0 flex-1 truncate text-sm text-muted-foreground">{cv.name ?? ""}</span>
<Switch checked={!!cv.default} onCheckedChange={set} />
</label>
)
}
function OpDetail({ op }: { op: Op }) {
const k = kernelOf(op)
const rows: [string, string | undefined][] = [
["Geometry", op.geometry], ["Launches per pass", fNum(op.count ?? 1)],
["Range", op.ranged ? `${op.ranged} from ${op.range_lo} to ${op.range_hi}` : undefined],
["Kernel", k?.kernel], ["Library", k?.plugin], ["Computes", k?.computes], ["Shapes", k?.shape], ["Types", k?.dtypes],
["Requires", k?.constraints?.length ? k.constraints.join("; ") : undefined],
]
return (
<>
<SheetHeader>
<SheetTitle>{op.op}</SheetTitle>
<SheetDescription>{op.schema?.doc ?? "Op " + op.index}</SheetDescription>
</SheetHeader>
<div className="flex flex-col gap-4 px-4 pb-6">
<dl className="grid grid-cols-[8rem_1fr] gap-x-3 gap-y-2 text-sm">
{rows.filter(([, v]) => v).map(([l, v]) => (
<div key={l} className="contents"><dt className="text-muted-foreground">{l}</dt><dd className="min-w-0 break-words font-mono text-xs leading-5">{v}</dd></div>
))}
</dl>
{(op.weights?.length ?? 0) > 0 && (
<div>
<div className="mb-1.5 text-xs font-medium text-muted-foreground">Weights</div>
<div className="overflow-hidden rounded-lg border">
{op.weights!.slice(0, 24).map((w) => (
<div key={w.name} className="flex items-baseline gap-3 border-b px-3 py-1.5 text-xs last:border-b-0">
<span className="min-w-0 flex-1 truncate font-mono">{w.name}</span>
<span className="text-muted-foreground">{w.dtype} · {w.shape}</span>
<span className="num w-20 text-right">{fBytes(w.bytes)}</span>
</div>
))}
</div>
</div>
)}
{(op.bands?.length ?? 0) > 1 && (
<div>
<div className="mb-1.5 text-xs font-medium text-muted-foreground">By size</div>
<div className="overflow-hidden rounded-lg border">
{op.bands!.map((b) => (
<div key={b.span} className="flex items-baseline gap-3 border-b px-3 py-1.5 text-xs last:border-b-0">
<span className="num w-28 text-muted-foreground">{b.span}</span>
<span className="min-w-0 flex-1 truncate font-mono">{(b.device ?? b.host)?.kernel ?? "–"}</span>
</div>
))}
</div>
</div>
)}
</div>
</>
)
}
+64
View File
@@ -0,0 +1,64 @@
// One model: what it is and how it is doing, in four views.
import { Empty, StateBadge } from "@/components/bits"
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"
import type { FleetModel } from "@/lib/api"
import { fBytes, fDur } from "@/lib/format"
import { modelScope, useScope } from "@/lib/store"
import { hrefOf, type Tab } from "@/lib/ui"
import { Details } from "./details"
import { Performance, type Kind } from "./performance"
import { Requests } from "./requests"
import { SessionsView } from "./sessions"
const NOUN: Record<string, string> = { image_generation: "Images generated", shape_generation: "Meshes generated", audio_generation: "Clips generated", video_generation: "Videos generated" }
function kindOf(c: Record<string, unknown> | undefined): [Kind, string] {
for (const k of Object.keys(NOUN)) if (c?.[k]) return ["gen", NOUN[k]]
if (c?.chat) return ["chat", ""]
if (c?.embedding) return ["embed", ""]
return ["chat", ""]
}
const DOES: [string, string][] = [["chat", "Chat"], ["tools", "Tools"], ["reasoning", "Reasoning"], ["image", "Reads images"], ["video", "Reads video"], ["audio", "Reads audio"], ["embedding", "Embeddings"],
["image_generation", "Makes images"], ["image_edit", "Edits images"], ["audio_generation", "Makes audio"], ["video_generation", "Makes video"], ["shape_generation", "Makes meshes"]]
export function ModelPage({ id, tab, model }: { id: string; tab: Tab; model: FleetModel | undefined }) {
const scope = useScope(modelScope(id))
const [kind, noun] = kindOf(model?.capabilities)
const tabs: [Tab, string][] = kind === "chat" ? [["performance", "Performance"], ["requests", "Requests"], ["sessions", "Sessions"], ["details", "Details"]] : [["performance", "Performance"], ["details", "Details"]]
const shown = tabs.some(([t]) => t === tab) ? tab : "performance"
const s = scope.live
const serving = model?.state === "resident" && !!s
const slots = typeof s?.max_num_seqs === "number" ? s.max_num_seqs : undefined
const where = model?.cards?.length ? `accelerator${model.cards.length > 1 ? "s" : ""} ${model.cards.join(" and ")}` : null
return (
<div className="flex flex-col gap-4 p-4 md:p-6">
<div className="flex flex-col gap-3">
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
<h1 className="text-xl font-semibold tracking-tight">{id}</h1>
<StateBadge state={model?.state} doing={model?.doing} />
<span className="text-sm text-muted-foreground">
{[model?.file, where, model?.state === "resident" && model.vram_bytes_per_card ? fBytes(model.vram_bytes_per_card) + " per accelerator" : null, s?.uptime_s ? "up " + fDur(s.uptime_s) : null].filter(Boolean).join(" · ")}
</span>
</div>
{model?.error && <div className="rounded-lg border border-bad/40 bg-bad/10 px-3 py-2 text-sm">{model.error}</div>}
<div className="flex flex-wrap items-center justify-between gap-3">
<Tabs value={shown} onValueChange={(v) => { location.hash = hrefOf(id, v as Tab) }}>
<TabsList>{tabs.map(([t, label]) => <TabsTrigger key={t} value={t} className="px-3">{label}</TabsTrigger>)}</TabsList>
</Tabs>
<div className="flex flex-wrap gap-1.5">
{DOES.filter(([k]) => model?.capabilities?.[k]).map(([k, label]) => <span key={k} className="rounded-md border px-1.5 py-0.5 text-xs text-muted-foreground">{label}</span>)}
</div>
</div>
</div>
{!model ? <Empty>This process serves no model named {id}</Empty>
: shown === "performance" ? (
<>
{!serving && scope.series.t.length > 0 && <div className="text-sm text-muted-foreground">This model is not loaded right now. The charts show its earlier activity.</div>}
{scope.series.t.length === 0 && !serving ? <Empty>{model.state === "failed" ? "The model failed to start, so there is no data" : model.state === "cold" ? "This model has not been loaded yet. It loads when a request asks for it." : "No data yet. Charts appear once the model has been loaded."}</Empty>
: <Performance scope={scope} kind={kind} slots={slots} noun={noun} />}
</>
) : shown === "requests" ? <Requests scope={scope} />
: shown === "sessions" ? (serving ? <SessionsView model={id} /> : <Empty>Conversations are listed while the model is loaded</Empty>)
: <Details model={id} stats={s} />}
</div>
)
}
+229
View File
@@ -0,0 +1,229 @@
// The fleet: what is on each card, what every model is doing, and how that moved over the window.
import { useMemo } from "react"
import { Chart, Legend, type Line } from "@/components/chart"
import { Empty, Kpi, Panel, PartBar, PartLegend, StateBadge, StateDot, STATE_OF_CODE, stateOf, type Part } from "@/components/bits"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import type { Fleet, FleetModel } from "@/lib/api"
import { bytesParts, fBytes, fClock, fDur, fin, fNum } from "@/lib/format"
import { fleet as fleetScope, useScope, type Series } from "@/lib/store"
import { hrefOf, useRange } from "@/lib/ui"
const hue = (i: number) => `var(--series-${(i % 8) + 1})`
// What a model holds on one accelerator: the server's figure for it in any state, so a model that
// is loading or partly parked is counted as itself; from a server that sends none, its claim
// while it is loaded.
const onCard = (m: FleetModel, card: number) =>
m.vram_bytes_by_card ? (m.vram_bytes_by_card[String(card)] ?? 0)
: m.state === "resident" && m.cards?.includes(card) ? (m.vram_bytes_per_card ?? 0) : 0
const held = (m: FleetModel) =>
m.vram_bytes_by_card ? Object.values(m.vram_bytes_by_card).reduce((a, b) => a + b, 0)
: m.state === "resident" ? (m.vram_bytes_per_card ?? 0) * (m.cards?.length ?? 0) : 0
export function Overview() {
const scope = useScope(fleetScope)
const range = useRange()
const f = scope.live
if (!f) return <Empty className="m-6">{scope.error ?? "Waiting for data…"}</Empty>
const hueOf = new Map(f.models.map((m, i) => [m.id, hue(i)]))
const resident = f.models.filter((m) => m.state === "resident")
const parked = f.models.filter((m) => m.state === "parked")
const cold = f.models.filter((m) => m.state === "cold")
const failed = f.models.filter((m) => m.state === "failed")
const onCards = f.models.reduce((a, m) => a + held(m), 0)
const vram = f.cards.reduce((a, c) => a + (c.vram_bytes ?? 0), 0)
// All the process pins in host memory: the models' pools, tables and cache tiers as well as
// the copies of parked ones. A server that does not say counts the copies alone.
const copies = f.models.reduce((a, m) => a + (m.host_bytes ?? 0), 0)
const hostBytes = f.host?.held_bytes ?? copies
const flight = f.models.reduce((a, m) => a + (m.in_flight ?? 0), 0)
const waiting = f.models.reduce((a, m) => a + (m.waiting ?? 0), 0)
const returns = f.models.reduce((a, m) => a + (m.restores ?? 0), 0)
const power = f.cards.reduce((a, c) => a + (fin(c.power_w) ? c.power_w : 0), 0)
const [cv, cu] = bytesParts(onCards)
const [hv, hu] = bytesParts(hostBytes)
return (
<div className="flex flex-col gap-4 p-4 md:p-6">
{failed.map((m) => (
<a key={m.id} href={hrefOf(m.id)} className="flex flex-wrap items-baseline gap-x-2 rounded-lg border border-bad/40 bg-bad/10 px-3 py-2 text-sm">
<span className="font-medium">{m.id} did not start</span>
<span className="min-w-0 text-muted-foreground">{m.error ?? "no reason was given"}</span>
</a>
))}
<div className="grid grid-cols-2 gap-3 md:grid-cols-3 xl:grid-cols-6">
<Kpi label="VRAM in use" value={cv} unit={cu} detail={`${resident.length} of ${f.models.length} models · ${fBytes(vram)} in all`} />
<Kpi label="Active requests" value={fNum(flight)} detail={waiting ? `${waiting} waiting` : "being served now"} />
<Kpi label="Parked" value={fNum(parked.length)} detail={parked.length ? parked.map((m) => m.id).join(", ") : "none"} />
<Kpi label="Host memory in use" value={hv} unit={hu} detail={(fin(f.host?.budget_bytes) ? `of ${fBytes(f.host.budget_bytes)} allowed` : "") + (copies > 0 ? ` · ${fBytes(copies)} parked copies` : "")} />
<Kpi label="Restores" value={fNum(returns)} detail={cold.length ? `${cold.length} not loaded` : "from parked to loaded"} />
<Kpi label="Power draw" value={power > 0 ? fNum(power) : "–"} unit={power > 0 ? "W" : undefined} detail={`across ${f.cards.length} accelerator${f.cards.length === 1 ? "" : "s"}`} />
</div>
<div className="grid gap-3 xl:grid-cols-2">
{f.cards.map((c) => <CardPanel key={c.card} fleet={f} card={c.card} hueOf={hueOf} data={scope.series} version={scope.version} range={range} />)}
</div>
<Panel title="State over time" description="Each model's state across the time range">
<StateStrip models={f.models} data={scope.series} version={scope.version} range={range} />
</Panel>
<Panel title="Models" flush>
<Table>
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead className="pl-4">Model</TableHead>
<TableHead>State</TableHead>
<TableHead className="text-right">Priority</TableHead>
<TableHead>Accelerators</TableHead>
<TableHead className="text-right">VRAM</TableHead>
<TableHead className="text-right">Host</TableHead>
<TableHead className="text-right">Active</TableHead>
<TableHead className="text-right">Loads</TableHead>
<TableHead className="text-right">Parks</TableHead>
<TableHead className="pr-4 text-right">Last load</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{f.models.map((m) => (
<TableRow key={m.id} className="cursor-pointer" onClick={() => { location.hash = hrefOf(m.id) }}>
<TableCell className="pl-4">
<a href={hrefOf(m.id)} className="flex items-center gap-2 font-medium" onClick={(e) => e.stopPropagation()}>
<i className="size-2 rounded-full" style={{ background: hueOf.get(m.id) }} />
{m.id}
</a>
<div className="mt-0.5 max-w-72 truncate pl-4 text-xs text-muted-foreground">{m.error ?? m.file}</div>
</TableCell>
<TableCell><StateBadge state={m.state} doing={m.doing} /></TableCell>
<TableCell className="num text-right">{fNum(m.priority)}{m.pinned ? " · pinned" : ""}</TableCell>
<TableCell className="num text-muted-foreground">{m.cards?.length ? m.cards.join(", ") : "–"}</TableCell>
<TableCell className="num text-right">{held(m) > 0 ? fBytes(held(m)) : "–"}</TableCell>
<TableCell className="num text-right">{(m.host_bytes ?? 0) + (m.host_pinned_bytes ?? 0) > 0 ? fBytes((m.host_bytes ?? 0) + (m.host_pinned_bytes ?? 0)) : "–"}</TableCell>
<TableCell className="num text-right">{m.in_flight ? fNum(m.in_flight) : "–"}{m.waiting ? ` +${m.waiting}` : ""}</TableCell>
<TableCell className="num text-right">{fNum(m.loads)}</TableCell>
<TableCell className="num text-right">{fNum(m.parks)}</TableCell>
<TableCell className="num pr-4 text-right">{fin(m.load_seconds as number) ? fDur(m.load_seconds as number) : "–"}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Panel>
</div>
)
}
function CardPanel({ fleet: f, card, hueOf, data, version, range }: { fleet: Fleet; card: number; hueOf: Map<string, string>; data: Series; version: number; range: number }) {
const c = f.cards.find((x) => x.card === card)!
const parts: Part[] = f.models.map((m) => ({ key: m.id, label: m.id, value: onCard(m, card), color: hueOf.get(m.id)!, text: fBytes(onCard(m, card)) }))
const used = (c.vram_bytes ?? 0) - (c.free_bytes ?? 0)
const named = parts.reduce((a, p) => a + p.value, 0)
// What no model's ledger names: the open hardware queues, by the server's count, and the
// rest, which is buffers the loaded models' kernels allocate themselves and the driver's own.
const queues = Math.max(Math.min(c.queue_bytes ?? 0, used - named), 0)
const rest = used - named - queues
if (queues > 0) parts.push({ key: "~queues", label: `Queues (${c.queues ?? 0} open)`, value: queues, color: "var(--idle)", text: fBytes(queues) })
if (rest > 64 << 20) parts.push({ key: "~other", label: "Model buffers and driver", value: rest, color: "var(--muted-foreground)", text: fBytes(rest) })
const lines: Line[] = f.models.map((m, i) => ({ key: `c${card}:${m.id}`, label: m.id, color: i + 1 }))
return (
<Panel title={<span className="flex items-baseline gap-2">Accelerator {card}<span className="text-xs font-normal text-muted-foreground">{c.name}</span></span>}
action={<span className="num text-xs text-muted-foreground">{fBytes(c.free_bytes)} free of {fBytes(c.vram_bytes)}</span>}>
<div className="flex flex-col gap-3">
<PartBar parts={parts} total={c.vram_bytes} className="h-3" />
<PartLegend parts={parts} className="content-start xl:min-h-10" />
<div className="grid grid-cols-3 gap-2">
<Gauge label="Busy" value={fin(c.busy) ? Math.round(c.busy * 100) + "%" : "–"} data={data} k={`busy${card}`} max={1} />
<Gauge label="Power" value={fin(c.power_w) ? Math.round(c.power_w) + " W" : "–"} data={data} k={`power${card}`} />
<Gauge label="Temperature" value={fin(c.temp_c) ? Math.round(c.temp_c) + " °C" : "–"} data={data} k={`temp${card}`} />
</div>
<Chart data={data} version={version} lines={lines} range={range} fmt={fBytes} stack bytes height={170} max={c.vram_bytes} />
</div>
</Panel>
)
}
/** A figure with its last five minutes drawn beside it. */
function Gauge({ label, value, data, k, max }: { label: string; value: string; data: Series; k: string; max?: number }) {
const col = data.col(k) ?? []
const lo = data.firstAfter(data.end - 300)
const pts = col.slice(lo)
const vals = pts.filter((v): v is number => v !== null)
const top = max ?? Math.max(1, ...vals) * 1.05
const base = max !== undefined ? 0 : Math.min(...vals, top) * 0.9
const n = pts.length
let d = ""
let open = false
pts.forEach((v, i) => {
if (v === null) { open = false; return }
d += (open ? "L" : "M") + ((100 * i) / Math.max(1, n - 1)).toFixed(2) + " " + (27 - (24 * (Math.min(v, top) - base)) / Math.max(1e-9, top - base)).toFixed(2)
open = true
})
return (
<div className="flex items-center gap-3 rounded-lg border bg-background/40 px-3 py-2">
<div className="min-w-0">
<div className="truncate text-xs text-muted-foreground">{label}</div>
<div className="num text-base font-semibold whitespace-nowrap">{value}</div>
</div>
<svg viewBox="0 0 100 30" preserveAspectRatio="none" className="h-8 min-w-0 flex-1 text-primary">
<path d={d} fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinejoin="round" vectorEffect="non-scaling-stroke" />
</svg>
</div>
)
}
/** One row a model: its state as coloured runs along the window. */
function StateStrip({ models, data, version, range }: { models: FleetModel[]; data: Series; version: number; range: number }) {
const rows = useMemo(() => {
const end = data.end, start = end - range, lo = data.firstAfter(start)
return models.map((m) => {
const col = data.col("s:" + m.id) ?? []
const runs: { a: number; b: number; s: string }[] = []
for (let i = lo; i < data.t.length; ++i) {
const v = col[i]
if (v == null) continue
const s = STATE_OF_CODE[v] ?? "cold"
const a = i === lo ? Math.max(start, data.t[i] - 1) : data.t[i - 1], b = data.t[i]
const last = runs[runs.length - 1]
if (last && last.s === s && a - last.b < 2.5) last.b = b
else runs.push({ a, b, s })
}
return { id: m.id, runs }
})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [models.map((m) => m.id).join("|"), data, version, range])
const end = data.end, start = end - range
const ticks = [0, 0.25, 0.5, 0.75, 1]
const seen = new Set(rows.flatMap((r) => r.runs.map((x) => x.s)))
return (
<div className="flex flex-col gap-2">
<div className="grid grid-cols-[minmax(6rem,10rem)_1fr] items-center gap-x-3 gap-y-1.5">
{rows.map((r) => (
<div key={r.id} className="contents">
<a href={hrefOf(r.id)} className="truncate text-sm">{r.id}</a>
<div className="relative h-5 overflow-hidden rounded bg-muted/50">
{r.runs.map((x, i) => (
<Tooltip key={i}>
<TooltipTrigger render={<div className="absolute inset-y-0" style={{ left: (100 * (x.a - start)) / range + "%", width: Math.max(0.3, (100 * (x.b - x.a)) / range) + "%", background: stateOf(x.s).tone, opacity: x.s === "cold" ? 0.35 : 0.9 }} />} />
<TooltipContent>{stateOf(x.s).label} · {fClock(x.a, true)} to {fClock(x.b, true)} · {fDur(x.b - x.a)}</TooltipContent>
</Tooltip>
))}
</div>
</div>
))}
<div />
<div className="num relative h-4 text-[11px] text-muted-foreground">
{ticks.map((p) => (
<span key={p} className={"absolute top-0 whitespace-nowrap" + (p === 0.25 || p === 0.75 ? " hidden lg:inline" : "")} style={p === 0 ? { left: 0 } : p === 1 ? { right: 0 } : { left: p * 100 + "%", transform: "translateX(-50%)" }}>
{end ? fClock(start + p * range, range <= 600) : ""}
</span>
))}
</div>
</div>
<div className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
{["resident", "loading", "waiting", "parked", "cold", "failed"].filter((s) => seen.has(s)).map((s) => (
<span key={s} className="inline-flex items-center gap-1.5"><StateDot state={s} />{stateOf(s).label}</span>
))}
</div>
</div>
)
}
export { Legend }
+139
View File
@@ -0,0 +1,139 @@
// A model's figures: a row of tiles, each a figure now, and the chosen one drawn large over the
// window. A figure the model has never produced (acceptance without a drafter) has no tile.
import { useState } from "react"
import { Bars, Empty, Panel, PartBar, PartLegend, type Part } from "@/components/bits"
import { Chart, Legend, type Line } from "@/components/chart"
import type { Experts, Stats } from "@/lib/api"
import { DASH, bytesParts, fBytes, fDur, fNum, fPct, fRate, fSig, fin } from "@/lib/format"
import type { Scope, Series } from "@/lib/store"
import { useRange } from "@/lib/ui"
import { cn } from "@/lib/utils"
export type Kind = "chat" | "embed" | "gen"
const fMs = (v: number) => (v >= 100 ? v.toFixed(0) : v.toFixed(2)) + " ms"
const fPc = (v: number) => fPct(v, v >= 0.9995 ? 0 : 1) + "%"
const fTps = (v: number) => (v === 0 ? "0" : fSig(v))
interface Metric {
id: string; kinds: Kind; label: string; unit?: string; draft?: boolean; always?: boolean
show: (s: Stats, h: Series, slots: number | undefined, noun: string) => [string, string?, string?]
lines: Line[]; fmt: (v: number) => string
stack?: boolean; max?: number; tight?: boolean; integer?: boolean; bytes?: boolean; join?: boolean
}
const one = (key: string, label: string): Line[] => [{ key, label, color: 1 }]
const METRICS: Metric[] = [
{ id: "decode", kinds: "chat", label: "Decode", unit: "tok/s", show: (s) => [fin(s.decode_tps) ? fTps(s.decode_tps) : DASH], lines: one("decode", "tokens a second"), fmt: fTps },
{ id: "step", kinds: "chat", label: "Step", unit: "ms",
show: (s, h) => { const v = h.last("step"); return [fin(v) ? (v >= 100 ? v.toFixed(0) : v.toFixed(2)) : DASH, (s.step_ns_decode_best ?? 0) > 0 ? "best " + fMs(s.step_ns_decode_best! / 1e6) : ""] },
lines: [{ key: "step", label: "step", color: 1 }, { key: "stepBest", label: "best", dash: true }], fmt: fMs, tight: true },
{ id: "prefill", kinds: "chat", label: "Prefill", unit: "tok/s", show: (_s, h) => { const v = h.last("prefillRate"); return [fin(v) ? fTps(v) : DASH] }, lines: one("prefillRate", "tokens a second"), fmt: fTps, join: true },
{ id: "reqs", kinds: "chat", always: true, label: "Requests",
show: (s, _h, slots) => [String(s.running ?? 0), (slots ? "of " + slots + " slots" : "") + (s.waiting ? " · " + s.waiting + " waiting" : "")],
lines: [{ key: "running", label: "running", color: 1 }, { key: "waiting", label: "waiting", color: 5 }, { key: "preempted", label: "preempted", color: 2 }], fmt: (v) => fNum(v), stack: true, integer: true },
{ id: "kv", kinds: "chat", label: "KV cache",
show: (s) => { const [v, u] = bytesParts(s.kv_bytes_used); return [v, "of " + fBytes(s.kv_bytes_total), u] },
lines: [{ key: "kvRead", label: "in use", color: 1 }, { key: "kvKept", label: "cached for the next turn", color: 4 }], fmt: fBytes, stack: true, bytes: true },
{ id: "hit", kinds: "chat", label: "Prefix cache hits", unit: "%", show: (s) => [fin(s.prefix_hit_rate) ? fPct(s.prefix_hit_rate) : DASH], lines: one("hit", "of prompt tokens"), fmt: fPc, max: 1 },
{ id: "accept", kinds: "chat", label: "Acceptance", unit: "%", draft: true, show: (_s, h) => [fPct(h.last("accept"))], lines: one("accept", "of drafted tokens"), fmt: fPc, max: 1 },
{ id: "tok", kinds: "chat", label: "Tokens per step", draft: true, show: (_s, h) => { const v = h.last("tokStep"); return [fin(v) ? v.toFixed(2) : DASH] }, lines: one("tokStep", "tokens"), fmt: (v) => v.toFixed(2), tight: true },
{ id: "ethru", kinds: "embed", always: true, label: "Throughput", unit: "tok/s", show: (s) => [fin(s.prefill_tps) ? fTps(s.prefill_tps) : DASH], lines: one("prefill", "tokens a second"), fmt: fTps },
{ id: "erate", kinds: "embed", always: true, label: "Inputs", unit: "/s", show: (_s, h) => { const v = h.last("reqRate"); return [fin(v) ? fTps(v) : DASH] }, lines: one("reqRate", "inputs a second"), fmt: fTps },
{ id: "estep", kinds: "embed", always: true, label: "Step", unit: "ms", show: (_s, h) => { const v = h.last("stepAny"); return [fin(v) ? v.toFixed(2) : DASH] }, lines: one("stepAny", "step"), fmt: fMs, tight: true },
{ id: "eflight", kinds: "embed", always: true, label: "Active requests", show: (s) => [String(s.in_flight ?? 0)], lines: one("flight", "in flight"), fmt: (v) => fNum(v), integer: true },
{ id: "jrun", kinds: "gen", always: true, label: "Running", show: (s) => [String(s.jobs?.running ?? 0)], lines: one("jobRun", "running"), fmt: (v) => fNum(v), integer: true },
{ id: "jdone", kinds: "gen", always: true, label: "Completed", show: (s) => [fNum(s.jobs?.done), s.jobs?.failed ? s.jobs.failed + " failed" : ""], lines: one("jobDone", "made"), fmt: (v) => fNum(v), integer: true },
{ id: "jlast", kinds: "gen", always: true, label: "Last duration", show: (s) => [s.jobs?.done ? fDur(s.jobs.last_ms / 1000) : DASH], lines: one("jobTime", "took"), fmt: (v) => fDur(v), join: true },
{ id: "jmean", kinds: "gen", always: true, label: "Mean", show: (s) => [s.jobs?.done ? fDur(s.jobs.total_ms / s.jobs.done / 1000) : DASH], lines: one("jobTime", "took"), fmt: (v) => fDur(v), join: true },
]
const TRAFFIC: Line[] = [["lkAr", "between accelerators"], ["lkUp", "host to accelerator"], ["lkDn", "accelerator to host"], ["lkSsd", "drive"], ["lkStream", "streaming"]].map(([key, label], i) => ({ key, label, color: i + 1 }))
export function Performance({ scope, kind, slots, noun }: { scope: Scope<Stats>; kind: Kind; slots?: number; noun: string }) {
const range = useRange()
const [chosen, setChosen] = useState<string | null>(null)
const s = scope.live, h = scope.series
const hasDraft = (s?.draft_positions?.length ?? 0) > 0
const produced = (m: Metric) => m.always || m.lines.some((l) => !l.dash && (h.col(l.key) ?? []).some((v) => (v ?? 0) > 0))
const tiles = METRICS.filter((m) => m.kinds === kind && (!m.draft || hasDraft || h.has(m.lines[0].key)) && (s ? produced(m) : !m.draft))
const metric = tiles.find((m) => m.id === chosen) ?? tiles[0]
if (!metric) return <Empty>No data for this model yet</Empty>
const moved = TRAFFIC.filter((l) => (h.col(l.key) ?? []).some((v) => (v ?? 0) > 0))
const ex = s?.experts
return (
<div className="flex flex-col gap-4">
<div className="overflow-hidden rounded-xl border bg-card">
<div role="tablist" className="grid grid-cols-2 border-b sm:grid-cols-4 xl:grid-flow-col xl:auto-cols-fr xl:grid-cols-none">
{tiles.map((m) => {
const [v, det, unit] = s ? m.show(s, h, slots, noun) : [DASH]
const on = m === metric
return (
<button key={m.id} role="tab" aria-selected={on} onClick={() => setChosen(m.id)}
className={cn("relative -mb-px flex min-w-0 flex-col gap-1 border-r border-b px-4 py-3 text-left transition-colors outline-none last:border-r-0 hover:bg-accent/50 focus-visible:bg-accent/60", on && "bg-accent/40")}>
<span className="truncate text-xs font-medium text-muted-foreground">{m.id === "jdone" && noun ? noun : m.label}</span>
<span className="num flex items-baseline gap-1 text-xl leading-none font-semibold tracking-tight">
<span className="truncate">{v}</span>
{(unit ?? m.unit) && <span className="text-xs font-normal text-muted-foreground">{unit ?? m.unit}</span>}
</span>
<span className="min-h-4 truncate text-xs text-muted-foreground">{det}</span>
{on && <span className="absolute inset-x-0 bottom-0 h-0.5 bg-primary" />}
</button>
)
})}
</div>
<div className="flex flex-col gap-2 p-4">
{metric.lines.length > 1 && <Legend lines={metric.lines} />}
<Chart key={metric.id} data={h} version={scope.version} lines={metric.lines} range={range} fmt={metric.fmt} height={300}
stack={metric.stack} max={metric.max} tight={metric.tight} integer={metric.integer} bytes={metric.bytes} join={metric.join} />
</div>
</div>
{(moved.length > 0 || hasDraft) && (
<div className="grid gap-4 lg:grid-cols-3">
{moved.length > 0 && (
<Panel title="Traffic" description="Bytes per second, by destination" className={hasDraft ? "lg:col-span-2" : "lg:col-span-3"}>
<div className="flex flex-col gap-2">
<Legend lines={moved} />
<Chart data={h} version={scope.version} lines={moved} range={range} fmt={fRate} stack bytes height={190} />
</div>
</Panel>
)}
{hasDraft && s?.draft_positions && (
<Panel title="Acceptance by position" description="Share of drafted tokens accepted, by position" className={moved.length ? "" : "lg:col-span-3"}>
<Bars values={s.draft_positions.map((p) => p.rate || 0)} max={1} height={150}
tip={(i, v) => `Position ${i + 1}\n${fPc(v)} accepted\n${fNum(s.draft_positions![i].reached)} reached`} labels={(i) => String(i + 1)} />
</Panel>
)}
</div>
)}
{ex && <ExpertsPanel ex={ex} h={h} version={scope.version} range={range} />}
</div>
)
}
const TIER: Record<string, string> = { active: "var(--series-1)", resident: "var(--series-1)", staged: "var(--series-4)", warm: "var(--series-3)", host: "var(--series-5)", ram: "var(--series-5)" }
function ExpertsPanel({ ex, h, version, range }: { ex: Experts; h: Series; version: number; range: number }) {
const parts: Part[] = (ex.tiers ?? []).filter((t) => t.units > 0).map((t) => ({ key: t.name, label: t.name, value: t.bytes || t.units, color: TIER[t.name.toLowerCase()] ?? "var(--idle)", text: `${fNum(t.units)} units · ${fBytes(t.bytes)}` }))
return (
<div className="grid gap-4 lg:grid-cols-3">
<Panel title="Experts" description={`${fNum(ex.n_units)} units by where they are`}>
<div className="flex flex-col gap-3">
<PartBar parts={parts} className="h-3" />
<PartLegend parts={parts} />
{ex.layer_units && ex.layer_resident && (
<Bars values={ex.layer_resident} max={Math.max(...ex.layer_units, 1)} height={70}
tip={(i, v) => `Layer ${i}\n${fNum(v)} of ${fNum(ex.layer_units![i])} on the accelerator`} />
)}
</div>
</Panel>
<Panel title="Expert hit rate" description="Share of routed experts already on the accelerator">
<Chart data={h} version={version} lines={[{ key: "expHit", label: "hits", color: 1 }]} range={range} fmt={fPc} max={1} height={170} />
</Panel>
<Panel title="Expert moves" description="Units per second">
<div className="flex flex-col gap-2">
<Legend lines={[{ key: "expIn", label: "onto the accelerator", color: 1 }, { key: "expOut", label: "off the accelerator", color: 2 }]} />
<Chart data={h} version={version} lines={[{ key: "expIn", label: "onto the accelerator", color: 1 }, { key: "expOut", label: "off the accelerator", color: 2 }]} range={range} fmt={(v) => fTps(v) + "/s"} stack height={150} />
</div>
</Panel>
</div>
)
}
+177
View File
@@ -0,0 +1,177 @@
// A model's requests: the ones running now, and the ones that finished within the hour the
// process remembers.
import { useMemo, useState } from "react"
import { Empty, Kpi, Panel } from "@/components/bits"
import { Button } from "@/components/ui/button"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import type { FinishedRequest, Stats } from "@/lib/api"
import { DASH, fAgo, fDur, fNum, fSig, fin } from "@/lib/format"
import type { Scope } from "@/lib/store"
import { Download } from "lucide-react"
const median = (a: number[]) => { if (!a.length) return null; const s = a.slice().sort((x, y) => x - y); return s[s.length >> 1] }
const STATE: Record<string, string> = { prefill: "Processing prompt", decode: "Generating", waiting: "Waiting", preempted: "Paused", done: "Done" }
export function Requests({ scope }: { scope: Scope<Stats> }) {
const s = scope.live
const done = scope.finished
const [shown, setShown] = useState(50)
const now = scope.series.end * 1000
const speeds = done.map((r) => r.tps).filter((v): v is number => fin(v) && v > 0)
const ttfts = done.map((r) => r.ttft).filter((v): v is number => fin(v))
const mean = speeds.length ? speeds.reduce((a, b) => a + b, 0) / speeds.length : null
const running = (s?.requests ?? []).filter((r) => r.state !== "done")
const latest = useMemo(() => done.slice().reverse(), [done, scope.version]) // eslint-disable-line react-hooks/exhaustive-deps
function save() {
const blob = new Blob([JSON.stringify(done, null, 1)], { type: "application/json" })
const a = document.createElement("a")
a.href = URL.createObjectURL(blob)
a.download = `${s?.model ?? "model"}-requests.json`
a.click()
setTimeout(() => URL.revokeObjectURL(a.href), 1000)
}
return (
<div className="flex flex-col gap-4">
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<Kpi label="Served" value={fNum(s?.total_requests)} detail="since the model started" />
<Kpi label="Preempted" value={fNum(s?.preemptions)} detail="requests paused for another and resumed" />
<Kpi label="Mean speed" value={fin(mean) ? fSig(mean) : DASH} unit="tok/s" detail={`over ${fNum(speeds.length)} finished`} />
<Kpi label="Median time to first token" value={ttfts.length ? fDur(median(ttfts)) : DASH} detail={`over ${fNum(ttfts.length)} finished`} />
</div>
<Panel title="Running" description={running.length ? undefined : "No active requests"} flush={running.length > 0}>
{running.length > 0 && (
<Table>
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead className="pl-4">Request</TableHead><TableHead>Status</TableHead>
<TableHead className="w-[28%]">Progress</TableHead>
<TableHead className="text-right">Prompt</TableHead><TableHead className="text-right">Reused</TableHead>
<TableHead className="text-right">Written</TableHead><TableHead className="text-right">Speed</TableHead>
<TableHead className="pr-4 text-right">Age</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{running.map((r) => {
const reading = r.state === "prefill"
const of = reading ? Math.max(1, r.prompt - r.cached) : Math.max(1, r.max)
const at = reading ? Math.max(0, r.computed - r.cached) : r.output
return (
<TableRow key={String(r.id)}>
<TableCell className="num pl-4 font-medium">{String(r.id)}</TableCell>
<TableCell>{STATE[r.state] ?? r.state}</TableCell>
<TableCell>
<div className="flex items-center gap-2">
<div className="h-1.5 min-w-12 flex-1 overflow-hidden rounded-full bg-muted"><div className="h-full rounded-full bg-primary transition-[width] duration-700" style={{ width: Math.min(100, (100 * at) / of) + "%", opacity: reading ? 0.55 : 1 }} /></div>
<span className="num w-24 shrink-0 text-right text-xs text-muted-foreground">{fNum(at)} / {fNum(of)}</span>
</div>
</TableCell>
<TableCell className="num text-right">{fNum(r.prompt)}</TableCell>
<TableCell className="num text-right text-muted-foreground">{r.cached ? fNum(r.cached) : DASH}</TableCell>
<TableCell className="num text-right">{fNum(r.output)}</TableCell>
<TableCell className="num text-right">{r.tps > 0 ? fSig(r.tps) : DASH}</TableCell>
<TableCell className="num pr-4 text-right text-muted-foreground">{fDur(r.age_s)}</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
)}
</Panel>
<div className="grid gap-4 lg:grid-cols-2">
<Panel title="Speed by context" description="Tokens per second vs. final context length, per finished request">
<Scatter pts={done.filter((r) => fin(r.tps) && r.tps! > 0 && r.ctx > 0).map((r) => ({ x: r.ctx, y: r.tps!, r }))} />
</Panel>
<Panel title="Time to first token" description="Distribution across finished requests">
<Histogram values={ttfts} />
</Panel>
</div>
<Panel title="Finished" description={done.length ? `${fNum(done.length)} in the last hour, latest first` : "No requests in the last hour"} flush={done.length > 0}
action={done.length > 0 && <Button variant="outline" size="sm" onClick={save}><Download />Export</Button>}>
{done.length > 0 && (
<>
<Table>
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead className="pl-4">Request</TableHead><TableHead className="text-right">Prompt</TableHead>
<TableHead className="text-right">Written</TableHead><TableHead className="text-right">Context</TableHead>
<TableHead className="text-right">First token</TableHead><TableHead className="text-right">Prefill</TableHead>
<TableHead className="text-right">Speed</TableHead><TableHead className="pr-4 text-right">Finished</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{latest.slice(0, shown).map((r) => (
<TableRow key={r.id + ":" + r.at}>
<TableCell className="num pl-4 font-medium">{r.id}</TableCell>
<TableCell className="num text-right">{fNum(r.prompt)}</TableCell>
<TableCell className="num text-right">{fNum(r.out)}</TableCell>
<TableCell className="num text-right text-muted-foreground">{fNum(r.ctx)}</TableCell>
<TableCell className="num text-right">{fin(r.ttft) ? fDur(r.ttft) : DASH}</TableCell>
<TableCell className="num text-right">{fin(r.pf) ? fSig(r.pf) + " tok/s" : DASH}</TableCell>
<TableCell className="num text-right">{fin(r.tps) && r.tps > 0 ? fSig(r.tps) + " tok/s" : DASH}</TableCell>
<TableCell className="num pr-4 text-right text-muted-foreground">{fAgo(r.at, now)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
{latest.length > shown && <div className="border-t p-2 text-center"><Button variant="ghost" size="sm" onClick={() => setShown(shown + 100)}>Show {Math.min(100, latest.length - shown)} more</Button></div>}
</>
)}
</Panel>
</div>
)
}
const tick = (v: number) => (v >= 1000 ? fSig(v / 1000) + "k" : fSig(v))
function Scatter({ pts }: { pts: { x: number; y: number; r: FinishedRequest }[] }) {
if (pts.length < 2) return <Empty>Available after two finished requests</Empty>
const xs = pts.map((p) => p.x), ys = pts.map((p) => p.y)
const x0 = Math.min(...xs), x1 = Math.max(...xs), y1 = Math.max(...ys) * 1.08
const lx = (v: number) => (x1 > x0 ? (Math.log(v) - Math.log(x0)) / (Math.log(x1) - Math.log(x0)) : 0.5)
return (
<div className="grid grid-cols-[auto_1fr] gap-x-2 gap-y-1">
<div className="num flex flex-col justify-between text-right text-[11px] text-muted-foreground"><span>{fSig(y1)}</span><span>{fSig(y1 / 2)}</span><span>0</span></div>
<div className="relative h-44 rounded-md border bg-background/40">
<div className="absolute inset-x-0 top-1/2 border-t border-dashed border-grid" />
{pts.map((p, i) => (
<Tooltip key={i}>
<TooltipTrigger render={<i className="absolute size-2 -translate-x-1/2 translate-y-1/2 rounded-full bg-primary/70 ring-1 ring-background hover:bg-primary" style={{ left: 2 + 96 * lx(p.x) + "%", bottom: (96 * p.y) / y1 + "%" }} />} />
<TooltipContent>{p.r.id} · {fNum(p.x)} tokens of context · {fSig(p.y)} tok/s</TooltipContent>
</Tooltip>
))}
</div>
<div />
<div className="num flex justify-between text-[11px] text-muted-foreground"><span>{tick(x0)}</span><span>tokens of context</span><span>{tick(x1)}</span></div>
</div>
)
}
function Histogram({ values }: { values: number[] }) {
if (values.length < 2) return <Empty>Available after two finished requests</Empty>
const edges = [0, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, Infinity]
const used = edges.findIndex((e) => e > Math.max(...values))
const bins = edges.slice(0, Math.max(6, used + 1))
const counts = bins.slice(0, -1).map((lo, i) => values.filter((v) => v >= lo && v < bins[i + 1]).length)
const top = Math.max(...counts, 1)
const name = (i: number) => (bins[i + 1] === Infinity ? "over " + fDur(bins[i]) : "under " + fDur(bins[i + 1]))
return (
<div className="flex h-[12.25rem] flex-col justify-end gap-1.5">
<div className="flex flex-1 items-end justify-center gap-1.5">
{counts.map((c, i) => (
<Tooltip key={i}>
<TooltipTrigger render={<div className="flex h-full max-w-24 flex-1 flex-col justify-end"><span className="num mb-1 text-center text-[11px] text-muted-foreground">{c || ""}</span><div className="rounded-sm bg-primary/80" style={{ height: Math.max(c ? 3 : 0, (82 * c) / top) + "%" }} /></div>} />
<TooltipContent>{c} {c === 1 ? "request" : "requests"} {name(i)}</TooltipContent>
</Tooltip>
))}
</div>
<div className="num flex justify-center gap-1.5 border-t pt-1 text-[11px] text-muted-foreground">
{counts.map((_, i) => <span key={i} className="max-w-24 flex-1 truncate text-center">{bins[i + 1] === Infinity ? "> " + fDur(bins[i]) : "< " + fDur(bins[i + 1])}</span>)}
</div>
</div>
)
}
+79
View File
@@ -0,0 +1,79 @@
// The conversations a model keeps so their next turn need not read the prompt again: how many,
// how much of the cache they hold, and which would resume and which would start over.
import { Empty, Kpi, Panel, PartBar, type Part } from "@/components/bits"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { withModel, type Session, type Sessions } from "@/lib/api"
import { bytesParts, fBytes, fDur, fNum } from "@/lib/format"
import { useFetched } from "@/lib/fetched"
export function SessionsView({ model }: { model: string }) {
const { data: s, error } = useFetched<Sessions>(withModel("sessions", model), 5000)
if (!s) return <Empty>{error ?? "Loading"}</Empty>
const list = (s.sessions ?? []).slice().sort((a, b) => a.idle_s - b.idle_s)
const linear = (s.linear?.checkpoints_written ?? 0) > 0 || list.some((r) => r.snapshots > 0)
const live = list.filter((r) => !linear || r.resume_tokens > 0 || r.snapshots > 0)
const cold = list.filter((r) => !live.includes(r))
const reuse = (r: Session) => (linear ? Math.min(r.resume_tokens || 0, r.tokens) : r.tokens)
const [pv, pu] = bytesParts(s.pool?.bytes_used)
const [hv, hu] = bytesParts(s.occupancy?.host_bytes)
return (
<div className="flex flex-col gap-4">
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<Kpi label="Resumable" value={fNum(live.length)} detail={cold.length ? `${cold.length} will restart` : "cached conversations"} />
<Kpi label="Tokens cached" value={fNum(s.pool?.tokens_used)} detail={s.pool ? `of ${fNum(s.pool.tokens_total)}` : ""} />
<Kpi label="VRAM in use" value={pv} unit={pu} detail={s.pool ? `of ${fBytes(s.pool.bytes_total)}` : ""} />
{s.enabled
? <Kpi label="Host memory in use" value={hv} unit={hu} detail={s.occupancy?.host_cap_bytes ? `of ${fBytes(s.occupancy.host_cap_bytes)}` : ""} />
: <Kpi label="Prefix cache hits" value={s.prefix_hit_rate != null ? (s.prefix_hit_rate * 100).toFixed(1) : "–"} unit="%" detail="of prompt tokens reused" />}
</div>
<Panel title="Will resume" description={live.length ? "Conversations whose next turn can reuse cached tokens, most recent first" : undefined} flush={live.length > 0}>
{live.length ? <SessionTable rows={live} reuse={reuse} /> : <Empty>No cached conversations</Empty>}
</Panel>
{cold.length > 0 && (
<Panel title={`${fNum(cold.length)} will restart`} description="Cached, but with no prefix the next turn can reuse" flush>
<SessionTable rows={cold} />
</Panel>
)}
</div>
)
}
function SessionTable({ rows, reuse }: { rows: Session[]; reuse?: (r: Session) => number }) {
const shown = rows.slice(0, 200)
return (
<Table>
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead className="pl-4">Conversation</TableHead>
<TableHead className="text-right">Tokens</TableHead>
{reuse && <TableHead className="text-right">Reusable</TableHead>}
<TableHead className="text-right">Idle</TableHead>
<TableHead className="w-[30%] pr-4">Where</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{shown.map((r) => {
const blocks = r.on_device + r.on_host, unit = blocks > 0 ? r.bytes / blocks : 0
const parts: Part[] = [
{ key: "d", label: "On accelerators", value: r.on_device, color: "var(--series-1)", text: fBytes(r.on_device * unit) },
{ key: "h", label: "Host memory", value: r.on_host, color: "var(--series-5)", text: fBytes(r.on_host * unit) },
]
return (
<TableRow key={String(r.id)}>
<TableCell className="num pl-4 font-medium">{r.label || "#" + r.id}</TableCell>
<TableCell className="num text-right">{fNum(r.tokens)}</TableCell>
{reuse && <TableCell className="num text-right">{fNum(reuse(r))}</TableCell>}
<TableCell className="num text-right text-muted-foreground">{fDur(r.idle_s)}</TableCell>
<TableCell className="pr-4">
<div className="flex items-center gap-2">
<PartBar parts={parts} className="h-1.5 flex-1" />
<span className="num w-28 shrink-0 text-right text-xs text-muted-foreground">{fBytes(r.bytes)}{r.moving ? " · moving" : ""}</span>
</div>
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
)
}