Documentation
¶
Overview ¶
altcpu.go — the CPU seat family a dual-route node serves BESIDE its GPU seats (operator direction 2026-09-20: <node-f>, an AMD APU, runs both a Vulkan iGPU route and a CPU route on the same box, and the harness offers both).
A tier is one backend; its template is one backend's flags. This file renders a second, CPU-backed seat family into the SAME llama-swap config: the two chat weights the tier already serves (offload-e4b, gemma4-e2b) as `<id>-cpu` entries run by a CPU llama-server build, joined to the interactive set so they stay mutually exclusive with everything else (one model resident at a time — on an APU every seat shares the same DDR pool). The flags are the cpu template's exact shape (no -ngl, no --flash-attn), so a `-cpu` seat is the cpu tier's seat, not an approximation of it.
What this deliberately is NOT: a second tier, a second llama-swap, or a per-request backend switch inside llama-server. The caller picks the route by seat id (`gemma4-e2b` vs `gemma4-e2b-cpu`), exactly as it picks any other seat.
audit.go — the serving-config gate (plan v2 register H-01, INV-1 / INV-2).
The operator's hard rules of 2026-09-10 are that the cards do the inference (no `-ngl 0`, no empty CUDA_VISIBLE_DEVICES, RAM is overflow only) and that every idle model unloads at five minutes (`ttl: 300` on every entry of every engine, no persistent group, no preload hook). The live boxes complied by hand and the templates were fixed by hand twice (0.115.4, 0.115.7); nothing stopped the next regression. This audit is that stop: `install render` refuses a rendered config that breaks a rule, the template test runs the same checker over every shipped template, and `local-offload audit-yaml` runs it over a live file at session start (H-02).
audit_displaycap.go - the display-cap-unseen note.
gpu_display_cap_pct bounds how much of the display card a job may take, and the card allocator enforces it for the jobs it places. A model llama-swap loads onto that card is not one of them, and the yaml that pins it states no VRAM footprint (a llama.cpp seat's weights, KV and compute buffers are nowhere in the file; a `proxy:` seat's cards are set in the engine's own launcher, outside the file), so this audit CANNOT judge an entry against the cap. What it can do is stop passing in silence: it names, in ONE aggregated note, the entries that may sit on the card the driver flags as the display card, and says plainly that nothing is judged. The live verdict is `gpu status` (the display cap row of the card table), which needs no knowledge of how a seat is pinned.
It is a note and nothing else: never a violation, never an exit code, and no config is read (the cap it states is the default, said to be the default). Footprint-based violations are deferred until a placement-neutral footprint source exists (docs/systems/setup-installer.md).
composite.go — D5 of the composite-tier design (ADR 0052): a composite tier's rendered serving config must be the CHECKED UNION of the tiers it composes, not a copy that drifted from them.
The defect this exists to stop has already happened twice on the reference box: blackwell-3x16's media block was a byte-for-byte copy of the 2-card tier's, so the vision seat was pinned to the display card and the third card was named nowhere (0.113.33), and the tier shipped a template whose only long-context seats referenced macros the template never defined. Both were readable in the rendered text; nothing read it. CheckComposite reads it, and `install render` refuses a composite render that fails.
provenance.go -- the rendered serving config carries its own provenance (plan v2 register K-02).
The problem it closes. The llama-swap config is rendered ONCE, at install, from the tier table baked into the binary (`install render`, setup/install.ps1, setup/install.sh). Nothing re-renders it afterwards, and nothing recorded what it was rendered FROM -- so a tier revision landed in the repo and the box kept serving yesterday's config forever. That is not hypothetical: register A-39 raised ampere-16's ctx_size from 32768 to 131072 and the live file stayed at 32768, while `audit-yaml` reported OK the whole time. It reported OK honestly: audit.go checks RULES (ttl 300, no -ngl 0, no empty CUDA_VISIBLE_DEVICES, no persistent group, no preload), and a config that is a tier revision stale breaks no rule. A rule gate cannot see staleness; only a provenance stamp can.
The design is the one internal/agent/props.go already proved for seat pinning: a CLOSED, named, documented field set, canonicalised and hashed -- never a language-default hasher over a struct, never a hash of the raw bytes. A raw-byte hash churns on key order and on fields that cannot change the output; an open set silently stops covering whatever is added next. Here the closed set is SpecBasis, and TestParamsBasisMirrorsParams fails the build the moment a field is added to Params without being added here.
TWO hashes, because they answer different questions:
spec_sha256 -- over the closed INPUT set (tier id, the render Params, the template bytes, the tier's own profiles.json entry, the harness version). It is the file's identity: "this config was rendered from exactly these inputs". /fleet/health publishes it so a fleet-wide drift check is a string comparison. body_sha256 -- over the yaml bytes BELOW the stamp. It is what makes a HAND EDIT distinguishable from a seed change: a hand-edited file has an intact spec hash over inputs that no longer describe it, and only the body hash catches that. Reporting a hand edit as "stale" would send an operator to re-render and silently destroy their edit.
What the stamp deliberately does NOT do: decide staleness by comparing hashes. A basis hash changes on inputs that cannot change the rendered output (a tier's `measured` prose, a version bump with no renderer change), and a gate that cries stale on documentation edits is a gate operators learn to ignore. So AgainstRender's verdict is settled by RE-RENDERING from the current binary's seeds and comparing the RESULT to the stamped body; the basis diff is what NAMES the keys that moved. MATCH therefore means the verifiable thing: re-installing this box today would produce this exact file.
seatentries.go - what a serving config states about each seat, for a reader that has to tell the seats' engines apart.
seatparallel.go reads one thing about one seat (its slot count). The active-backend report (internal/backendchain) needs three other things about EVERY seat: the command line llama-swap runs for it (the engine is named there, or by a wrapper script), the address it listens on, and the path llama-swap polls to decide it is ready (`checkEndpoint`). They are read here, from the same parse and the same macro rules as the slot count, so "what the entry says" is one reading.
seatparallel.go - how many requests a seat serves at once, read from a serving config.
The fleet node publishes a worker count (fleet_max_concurrent_jobs, default 4) and the delegator deals a node as many jobs as that count leaves free. On a single-slot seat (--parallel 1) the engine runs one request at a time, so a node that publishes four workers over it holds three jobs that are only waiting inside the engine, and the delegator counts them as parallel work. Two readers need the seat's real slot count: the tier-table test that keeps a seeded cap from drifting from the template it is served by, and `doctor`'s capacity row that compares the cap a node publishes with the live serving config.
Package servingtmpl renders a llama-swap serving config from a tier's parameters.
Rendering lived in install.ps1, so a Linux node had no way to produce a serving config at all — every Linux deployment hand-wrote one. On the measured 6 GB node the first two hand-written topologies each broke the box (an exclusive media group returned 502s for a full TTL after any render; the embedder inside the swapping tier evicted the chat model on every RAG query), which is what a rendered, reviewed template exists to prevent.
Substitution is deliberately dumb — tokens in, values out — with one guard that matters: Render REFUSES to emit a config that still contains a token. install.ps1 carries a comment about exactly that failure ("the fully-tokenized templates would otherwise leave __CTX__ etc. in a config"), and a llama-swap that starts with `--ctx-size __CTX__` fails in a way that reads like a model problem.
Index ¶
- Constants
- func CanonicalEntrySHA(entry []byte) (string, error)
- func CheckComposite(rendered string, decl CompositeDecl, composed []ComposedTier) error
- func DiffBasis(a, b SpecBasis) []string
- func HasProxyEntry(text string) bool
- func PinsCUDADevices(text string) bool
- func Render(tmpl string, p Params) (string, error)
- func SHA256Hex(b []byte) string
- func SeatEntryName(text, alias string) string
- func SeatParallel(text, alias string) (slots int, ok bool)
- func SeatParallelWhy(text, alias string) (slots int, why string)
- func SpecHash(b SpecBasis) (hash string, canonical []byte, err error)
- func Stamp(rendered string, b SpecBasis, at time.Time) (string, error)
- func SupportsSeats(tmpl string) bool
- func Violations(vs []Violation) string
- type ComposedTier
- type CompositeDecl
- type Params
- type ParamsBasis
- type RenderBasis
- type Report
- type SeatEntry
- type SeatSlots
- type SpecBasis
- type Stamped
- type State
- type Violation
Constants ¶
const TTLRequired = 300
TTLRequired is the one ttl every model entry must carry (seconds).
Variables ¶
This section is empty.
Functions ¶
func CanonicalEntrySHA ¶
CanonicalEntrySHA canonicalises one tier's profiles.json entry and hashes it: sorted keys at every level, number literals preserved. Whitespace and key order in the table are then not a change, which is what lets an operator reformat profiles.json without marking every box stale. An empty entry (an off-matrix render has none) hashes to the empty string, not to the hash of "": absent and present-but-empty must not collide.
func CheckComposite ¶
func CheckComposite(rendered string, decl CompositeDecl, composed []ComposedTier) error
CheckComposite refuses a composite render in which a layer seat is undefined, a layer seat's rendered CUDA_VISIBLE_DEVICES differs from its declared device pin, a router model_map target is undefined or pinned elsewhere, or a composed tier's declared capability (a media-seat kind, its vLLM seat) is missing. It reads the RENDERED text, because that is what llama-swap loads: a declaration that is right in profiles.json and wrong in the yaml is the shape every one of these defects took.
It returns one error naming every failure, not the first: an operator fixing a tier table wants the whole list, and a test that reports one at a time turns a five-minute fix into five render cycles.
func DiffBasis ¶
DiffBasis names every basis key whose value differs, as a dotted path ("params.ctx_size", "params.vllm_seat.max_model_len"), sorted. It walks into nested objects so a report points at the field that moved rather than at the whole struct that contains it.
func HasProxyEntry ¶
HasProxyEntry reports whether any model entry of a llama-swap config is a `proxy:` seat, so a caller reads the box's card table (an nvidia-smi run) for a file whose only claim on a card is a seat running elsewhere. A document that does not parse has none.
func PinsCUDADevices ¶
PinsCUDADevices reports whether any entry pins CUDA devices, so a caller reads the box's card table (an nvidia-smi run) only for a file that needs it. A document that does not parse pins nothing.
func SHA256Hex ¶
SHA256Hex is the one hashing helper this file uses, so template bytes, tier entry bytes, the canonical basis and the yaml body are all hashed identically.
func SeatEntryName ¶
SeatEntryName is the key of the model entry that answers to alias (the key itself, else the one entry whose `aliases` list names it): the entry the box runs when its agent_model is an alias several seats share. It is empty when the config does not parse, no entry answers, or two claim the alias.
func SeatParallel ¶
SeatParallel reports how many requests the llama.cpp entry that serves alias (a model key or one of its aliases) handles at the same time: its `--parallel N`, `--parallel=N`, `-np N` or LLAMA_ARG_N_PARALLEL=N, read from the entry as llama-swap runs it (a `${name}` macro replaced by its text first, the way Audit reads it). A flag on the command line beats the environment twin, and the last of several flags wins, as llama-server parses them. A stated -1 or auto reads as autoSlots.
ok=false is "unknown", never a guess; SeatParallelWhy says which unknown it is.
func SeatParallelWhy ¶
SeatParallelWhy is SeatParallel with the reason an unknown is unknown, as one operator-facing clause (empty when slots is known): the config does not parse, no entry answers to the alias (or two claim it), the entry is not a llama.cpp one (no llama-server in its command), or it states no slot count. An entry with no flag is unknown on purpose, because what the installed llama.cpp build then defaults to is not something this file can read.
func SpecHash ¶
SpecHash returns the canonical JSON of the basis and its sha256. Canonical means: sorted keys at every level (Go marshals a map key-sorted, so the basis is round-tripped through a map tree rather than marshalled straight from the struct), and number literals preserved verbatim through json.Number -- a float64 round-trip renders 131072 as 131072 today but could render some future large seed in exponent form, changing a hash with no input change.
func Stamp ¶
Stamp prepends the provenance block to a rendered serving config and returns the stamped text. `at` is taken from the caller so a test can render deterministically; production passes time.Now().UTC().
The body is left byte-identical -- the block is prepended, never interleaved -- so body_sha256 is a hash of exactly what Render produced. A stamp that rewrote any part of the body would make "hand-edited" undetectable.
func SupportsSeats ¶
SupportsSeats reports whether a serving template can place tier-declared media seats. `install seed` asks BEFORE writing a config, so a target that cannot serve a seat never gets the binding for it written either — the two halves of an install refuse together or not at all.
func Violations ¶
Violations formats an audit result as one line per violation.
Types ¶
type ComposedTier ¶
type ComposedTier struct {
ID string
SeatKinds []string
// VLLMSeatID and FallbackID are the engine seat that tier declares and the
// llama.cpp seat it falls back to when the box has no vLLM runtime (a
// supported outcome the renderer prints a NOTE for). The composition claim
// survives EITHER: what must never happen is neither being served, which
// would mean the composite cannot run that tier's agent lane at all.
VLLMSeatID string
FallbackID string
}
ComposedTier is one tier the composite claims to be a complete instance of, reduced to the capabilities that claim has to survive: the media-seat kinds it declares and its vLLM seat id (empty when it declares none).
type CompositeDecl ¶
type CompositeDecl struct {
Tier string
Composes []string
Layers []config.LayerSpec
MediaKinds []string
// ResolvePin turns a rendered GPU UUID (or UUID prefix) into the CUDA index this box's card table
// gives it, when a card table is available (the render runs on the box, with nvidia-smi). It is
// what lets a UUID-rendered pin be compared with an index-declared one. nil, or !ok for a pin, means
// the two cannot be compared and the render is refused for it (comparePins).
ResolvePin func(pin string) (index string, ok bool)
}
CompositeDecl is what the tier DECLARES: its id, the tiers it composes, the device layers it places work on, and the media-seat kinds it binds.
type Params ¶
type Params struct {
LlamaBin string // dir holding llama-server AND its shared objects (LD_LIBRARY_PATH)
ModelsDir string
Listen string // "127.0.0.1:11436"
Ctx int
KVType string // applied to both K and V; kept symmetric on purpose
FlashAttn string // "on"/"off"
MoE26B string // the flag form the tier chose: -ngl 99 | --n-cpu-moe N (INV-1; the cpu backend's `--cpu-moe` is inert)
Threads int
// CacheRAMMiB is llama-server's host-RAM prompt cache (--cache-ram). 0 renders the
// server default (8192) so an older caller never turns the cache OFF by omission.
CacheRAMMiB int
// Include26B false removes the 26B seat entirely — model block, matrix var, and
// set membership. A set naming a var that does not exist, or a var naming a model
// that does not exist, is a config llama-swap rejects at startup, so dropping one
// without the others bricks the service. The 26B *-agent entry (same weights,
// reasoning on) rides this same gate: it exists whenever the 26B exists.
Include26B bool
// IncludeQ38 gates the Qwen3.8-27B coder/agent entry the same way Include26B
// gates the 26B: false removes the model block, its matrix var, and its set
// membership (the __Q38_ALT__/__Q38_AND__ tokens render empty). It comes from
// the tier's include_qwen38 field and defaults to false — mirrors include_26b.
IncludeQ38 bool
// IncludeQ354B gates the Qwen3.5-4B AGENT entry exactly as IncludeQ38 gates the
// 27B: false removes the model block, its matrix var, and its set membership
// (the __Q354B_ALT__ token renders empty). It comes from the tier's
// include_qwen35_4b field and defaults to false. This is the SMALL-tier agent
// seat: 3.5GB of VRAM on a 6GB card, for tiers whose workhorse plans poorly but
// which have no room for a 27B. A tier may also set IncludeMimo9B alongside this
// (2026-09-24, the amd-gcn onboarding): the 4B entry then stays rendered as the
// un-aliased ROLLBACK seat (its own aliases line carries the __Q354B_AGENT_ALIAS__
// token, which drops its claim on `agent-seat` precisely when IncludeMimo9B is set).
IncludeQ354B bool
// IncludeQ359B gates the Qwen3.5-9B AGENT entry exactly as IncludeQ354B gates
// the 4B: false removes the model block, its matrix var, and its set membership
// (the __Q359B_ALT__ token renders empty). It comes from the tier's
// include_qwen35_9b field and defaults to false. This is the 8GB-class agent
// seat: 6.3 GiB of VRAM at 16K (6.5 GiB at 32K — Gated-DeltaNet hybrid KV), for
// tiers with room the 6GB class does not have. Mutually exclusive with
// IncludeQ354B: both entries claim the `agent-seat` alias, so a tier enabling
// both would render a config llama-swap rejects — validate() refuses it by name.
IncludeQ359B bool
// IncludeMimo9B gates the mimo-9b-agent entry exactly as IncludeQ359B gates the
// Qwen3.5-9B one: false removes the model block, its matrix var and its set
// membership (the __MIMO9B_ALT__ token renders empty). It comes from the tier's
// include_mimo_9b field and defaults to false. It claims the SAME `agent-seat`
// alias as IncludeQ354B/IncludeQ359B do, so it can never render alongside either
// of THEM holding that same alias — but neither pairing is a render REFUSAL any
// more (2026-09-24, the amd-gcn onboarding): both the 4B and the 9B entry stay
// rendered as un-aliased ROLLBACK seats when mimo-9b-agent is also included, each
// losing its own claim on `agent-seat` via its own alias token
// (__Q354B_AGENT_ALIAS__ / __Q359B_AGENT_ALIAS__) precisely when IncludeMimo9B is
// set, so mimo-9b-agent ends up the sole holder of the shared alias either way.
IncludeMimo9B bool
// IncludeQ3827B gates the Qwen3.8-27B AGENT entry (UD-IQ3_S weights + the MTP
// head embedded in the same GGUF, drafted with --spec-type draft-mtp). False
// removes the model block, its matrix var and its set membership (the
// __Q3827B_ALT__ token renders empty). It comes from the tier's
// include_qwen38_27b field and defaults to false. This is the 16GB-class agent
// seat: 14,410 MiB at a 49,152 window on the ampere-16 reference card, measured
// 2026-09-16 (ADR 0047) to beat every smaller candidate 24/24 blind. It does NOT
// claim the `agent-seat` alias, so it coexists with a rendered 4B/9B fallback
// entry and the lane is bound explicitly through config_seed.agent_model.
IncludeQ3827B bool
// IncludeQ3635B gates the Qwen3.6-35B-A3B RAM-SPILL agent entry (UD-IQ3_XXS weights,
// the routed experts in host RAM through a literal `--n-cpu-moe 40`, attention, dense
// layers and the KV cache on the card). False removes the model block, its matrix var
// and its set membership (the __Q3635B_ALT__ token renders empty). It is the
// POST-RAM-GATE value: the tier's include_qwen36_35b says the tier may carry the seat,
// and the caller (install_render.go deriveRender, through spillSeatIncluded) sets this
// only when the box's RAM tier can hold the spilled experts (`low`, `mid` or `high`; an
// unspecified tier does not qualify; the ~11.6 GB host RSS was measured on a 32 GB box).
// A box that cannot hold them therefore renders the tier without the seat. The entry claims the
// `agent-seat` alias, so the Qwen3.5-4B / 9B entries lose their own claim on it while
// it renders (the __Q354B_AGENT_ALIAS__ / __Q359B_AGENT_ALIAS__ tokens) and stay as
// un-aliased rollback seats; pairing it with IncludeMimo9B, which claims the same
// alias, is refused by validate().
IncludeQ3635B bool
// IncludeEG2 gates the embeddinggemma2 entry (EmbeddingGemma-2 Q8_0, with its multimodal
// projector unless EG2TextOnly, llama.cpp >= b11452) as a MEMORY-STACK member: false removes
// the model block, its matrix var and its evict_costs row, and the __EG2_AND__ token renders
// empty. True joins it to the stack's residency set (`emb & rer & eg2`), beside embeddinggemma
// and bge-reranker-v2-m3: resident among the swappable seats, never swapped by them. It comes
// from the tier's include_embeddinggemma2 field and defaults to false; no RAM gate (it is
// VRAM-resident: 1,196 MiB loaded, 1,466 MiB after image embeds on the reference 6 GB node
// with the projector, 460 MiB loaded and 482 MiB at peak without it).
// The embeddinggemma (300M) entry renders on every template unless the tier sets
// OmitEmbed300M: the harness's own embed lane and unknown callers of its aliases keep using it.
IncludeEG2 bool
// EG2TextOnly renders the embeddinggemma2 entry WITHOUT its multimodal projector: the one
// `--mmproj <path>` argument is removed and every other flag stays as measured (the strip is
// dropEG2Projector, a mirror of the other gated strips). Zero means WITH the projector, the
// entry as the memory authority runs it, so a caller that never heard of the field renders
// what it always did. It comes from the tier's embeddinggemma2_projector field being false
// (a text-only replica: text vectors are identical with and without the projector, cosine
// 1.0 measured, and a replica never embeds media) and is meaningful only with IncludeEG2.
EG2TextOnly bool
// EG2LlamaBin, when set and different from LlamaBin, is the directory of the llama.cpp build
// that serves ONLY the embeddinggemma2 entry (retargetEG2Bin): its cmd path moves to that build,
// and on a template with a loader macro (`ld:`) its env swaps `${ld}` for a macro of its own.
// Every other entry keeps LlamaBin. It exists for a node whose main build cannot load the
// entry's architecture (llama.cpp below b11452) but must keep that build for its other seats.
// Empty is the common case and renders byte-identically to a build with no support for it
// (TestEG2BinUnsetRendersTheBytes0175Rendered). Meaningful only with IncludeEG2: set without it,
// Render refuses.
EG2LlamaBin string
// Seats are the tier's alias-backed media seats (vision / STT). Empty is the
// common case and MUST render byte-identically to a build that had no seat
// support at all — TestNoSeatsChangesNothing holds that line.
Seats []mediaseat.Seat
// Home is the install root substituted for __OFFLOAD_HOME__ in seat paths, and
// GOOS is the TARGET platform (never the rendering one) selecting the executable
// suffix. Both matter only when Seats is non-empty.
Home string
GOOS string
// RknpuHome is the rknpu accelerator's home, substituted for __RKNPU_HOME__ in seat
// paths (an rkllm seat's default launcher lives there). Empty falls back to
// <Home>/rknpu, the layout `install seed` uses when no RKNPU_HOME says otherwise.
RknpuHome string
// DisplayLayer is the tier's display layer (ADR 0052) when it declares one:
// the dormant rungs pinned to the display card. nil — the common case, and
// every tier but the composite one — renders the template's display fences
// away entirely, so the output is byte-identical to a build with no display
// support (TestDisplayTwinsRenderOnlyForATierThatDeclaresADisplayLayer).
DisplayLayer *config.LayerSpec
// GPUEnv is added to EVERY model's env list, appended after whatever the template
// already declares. It comes from the tier's `gpu_env`, not from a name match: the
// Blackwell tiers need CUDA_VISIBLE_DEVICES pinned (a hybrid-graphics trap where
// the default can resolve to -1) and CUDA_MODULE_LOADING=LAZY (llama.cpp #22696).
// This lived in install.ps1 as an `if ($profileId -match '^blackwell-')` branch,
// so a Linux install of the same tier silently did not get it.
GPUEnv []string
// Backend is the tier's serving backend (cuda|vulkan|rk3588|cpu|…). A vision seat
// renders GPU flags (-ngl, --flash-attn) UNLESS this is "cpu", where the template's
// own chat models carry neither and a GPU-less build would only ignore them. rk3588
// serves from the NPU (RKLLM seats): its template has no llama.cpp entry, and the GPU
// gets none until llama.cpp runs clean on its Mali.
Backend string
// AltCPULlamaBin, when set, is the directory of a CPU llama-server build and asks
// for the CPU seat family (altcpu.go): the tier's chat weights as `<id>-cpu`
// entries beside the GPU seats, joined to the interactive set. Empty = the plain
// tier, byte-identical to a render without this field. Refused on a cpu tier.
AltCPULlamaBin string
// DisableCUDAGraphs emits GGML_CUDA_DISABLE_GRAPHS=1 on the 26B seats.
//
// FALSE IS THE DEFAULT AND IT IS THE MEASURED ONE. On the reference sm_120 box
// (2026-09-05, b10720, 3 fresh-serve reps, temp 0, exact-string gate) turning CUDA
// graphs back ON took the 26B seats from 41.4 -> 58.0 t/s and 39.0 -> 58.8 t/s with
// prefill unchanged and OUTPUT IDENTICAL. The flag was baked into the win-cuda and
// win-cuda-resident templates, so five Blackwell tiers shipped a ~40% generation
// loss for no recorded reason.
//
// It cannot just be deleted: win-cuda also renders the ampere-* and volta-16 tiers,
// where graphs-on has never been measured. So the tiers that have not been measured
// set this true and keep today's behaviour; every Blackwell tier gets the win.
DisableCUDAGraphs bool
// VLLMSeat is the tier's persistent vLLM agent seat (ADR 0035), rendered as a
// RESIDENT matrix member whose cmd/cmdStop drive a systemd unit. nil is the common
// case and MUST render byte-identically to a build with no vLLM support at all —
// TestNoVLLMSeatChangesNothing holds that line.
//
// The caller decides whether to set it: internal/vllmseat.Detect reports whether
// the box actually has the hand-built venv and the model snapshot, and a box
// without them renders the tier's llama.cpp fallback seat instead. Rendering a
// unit that points at a venv nobody built is worse than the fallback.
VLLMSeat *vllmseat.Spec
// ExtraVLLMSeats are the tier's further vLLM seats (profiles.json `extra_vllm_seats`)
// this box can run: on-demand seats beside VLLMSeat on the SAME card, never the agent
// lane. Empty is the common case and MUST render byte-identically to a build with no
// support for them (TestNoExtraVLLMSeatsChangesNothing).
//
// Every vLLM seat of a tier is rendered as an ALTERNATIVE of the others inside the
// residents set (`emb & rer & (vagt | vagt2)`): each is sized with util 0.90 of the
// card, so two of them can never be loaded together, and a matrix that called the
// pair a valid combination would have llama-swap load the second beside the first.
// Each extra seat's entry names wrappers after its own unit (vllmseat.Spec.ExtraEntry).
// The caller decides which seats to set with the same prerequisite detection it uses
// for VLLMSeat: an extra seat whose weights are absent is not rendered.
ExtraVLLMSeats []*vllmseat.Spec
// VLLMRuntime carries the two per-BOX values the tier cannot know: the account
// llama-swap runs as, and the literal address the engine binds. It is required whenever
// any vLLM seat is set (the lane seat or an extra one): Render refuses an incomplete one,
// because an entry rendered from it names no seat directory and no address.
VLLMRuntime vllmseat.Runtime
// OmitE4B removes the offload-e4b workhorse entry: its model block, its matrix var
// and its set membership (the __E4B_LEAD__ / __E4B_AND__ tokens render empty). It is
// the INVERTED-polarity gate of the include_* family: false (absent) renders every
// template exactly as before, so no existing tier moves. It comes from the tier's
// omit_e4b field and exists for a card the E4B cannot load at all (the 3 GB band:
// 3,100 MiB at 16K on the reference 6 GB node, measured 2026-07-26), where the
// tier's resident_tier is gemma4-e2b. Refused with AltCPULlamaBin (the CPU seat
// family mirrors the workhorse) and on a template that carries neither token.
OmitE4B bool
// OmitEmbed300M removes the embeddinggemma (300M) entry from the render: its model block, its
// matrix var, its evict_costs row and its membership in the residents set; its generic
// aliases (text-embedding, local-embed) move to the embeddinggemma2 entry, so a caller of
// them still gets an embedder. INVERTED polarity like OmitE4B: false (absent) renders every
// template as before. It comes from the tier's omit_embeddinggemma field and exists for a
// card the whole support tier does not fit beside its heavy seats: on the 6 GB reference box
// the 300M (464 MiB), the reranker and embeddinggemma2 (1,216 MiB with its projector) held
// together left neither heavy seat able to load (cudaMalloc out of memory), and removing the
// 300M freed 4,283 MiB beside the rest. Nothing there used it: the memory stack embeds with
// embeddinggemma2 and the kNN pre-filter is off by default. Requires IncludeEG2 (the
// embedder the aliases move to) and a template whose residents set names `emb`.
OmitEmbed300M bool
}
Params are the per-machine values a tier's template needs. Everything here comes from the classified tier (ctx/kv/flash/moe), the install layout (bin/models), or the box itself (threads) — never from the machine doing the rendering.
type ParamsBasis ¶
type ParamsBasis struct {
LlamaBin string `json:"llama_bin"`
ModelsDir string `json:"models_dir"`
Listen string `json:"listen"`
Ctx int `json:"ctx_size"`
KVType string `json:"kv_type"`
FlashAttn string `json:"flash_attn"`
MoE26B string `json:"moe_26b"`
Threads int `json:"threads"`
CacheRAMMiB int `json:"cache_ram_mib"`
Include26B bool `json:"include_26b"`
IncludeQ38 bool `json:"include_qwen38"`
IncludeQ354B bool `json:"include_qwen35_4b"`
IncludeQ359B bool `json:"include_qwen35_9b"`
IncludeMimo9B bool `json:"include_mimo_9b"`
IncludeQ3827B bool `json:"include_qwen38_27b"`
IncludeQ3635B bool `json:"include_qwen36_35b,omitempty"` // omitted when false: it adds nothing to the Params bytes of a tier that never sets it
IncludeEG2 bool `json:"include_embeddinggemma2,omitempty"` // omitted when false, for the same reason
EG2TextOnly bool `json:"eg2_text_only,omitempty"` // omitted when false: the entry with its projector, as the authority runs it, hashes as it did
EG2LlamaBin string `json:"eg2_llama_bin,omitempty"` // omitted when empty: a render whose entry shares the main build hashes as it did
Seats []mediaseat.Seat `json:"seats"`
Home string `json:"home"`
GOOS string `json:"goos"`
// RknpuHome is omitted when empty, so every tier that never sets it keeps the spec
// hash it had before the field existed (AltCPULlamaBin does the same).
RknpuHome string `json:"rknpu_home,omitempty"`
// DisplayLayer is hashed as the whole layer spec, not as its name: the
// template substitutes the layer’s rungs, its device pin and its guards into
// the rendered text (ADR 0052), so a change to any of them changes the
// config while the name stays "display".
DisplayLayer *config.LayerSpec `json:"display_layer"`
GPUEnv []string `json:"gpu_env"`
Backend string `json:"backend"`
AltCPULlamaBin string `json:"alt_cpu_llama_bin,omitempty"`
DisableCUDAGraphs bool `json:"disable_cuda_graphs"`
VLLMSeat *vllmseat.Spec `json:"vllm_seat"`
// ExtraVLLMSeats is omitted when empty, so every tier that declares none keeps the
// spec hash it had before the field existed (RknpuHome and AltCPULlamaBin do the same).
ExtraVLLMSeats []*vllmseat.Spec `json:"extra_vllm_seats,omitempty"`
VLLMRuntime vllmseat.Runtime `json:"vllm_runtime"`
// OmitE4B is omitted when false, so every tier that keeps its workhorse hashes as it
// did before the field existed (the 3 GB band is the only tier that sets it).
OmitE4B bool `json:"omit_e4b,omitempty"`
// OmitEmbed300M is omitted when false, so every tier that keeps the 300M embedder hashes as it did.
OmitEmbed300M bool `json:"omit_embeddinggemma,omitempty"`
}
ParamsBasis mirrors servingtmpl.Params ONE FIELD FOR ONE FIELD, by Go field name. The mirror is not cosmetic: TestParamsBasisMirrorsParams reflects over both structs and fails when the name lists differ, so a field added to Params cannot silently fall outside the hashed set. json tags are the stable wire names an operator reads in a STALE report ("params.ctx_size").
func (ParamsBasis) Params ¶
func (b ParamsBasis) Params() Params
Params is the inverse of BasisOf: the render Params a stamp recorded. The re-derive uses it to replay a render with the SAME per-box values (install paths, listen address, thread count) that the original had -- a binary cannot know another box's layout, and guessing it would report every node stale.
type RenderBasis ¶
type RenderBasis struct {
// RAMTier is --ram-tier (min|low|mid|high, or empty for "the caller does not
// know"). It decides whether a tier's RAM-hungry 26B placement is served at
// all, so the same tier renders differently under two values of it.
RAMTier string `json:"ram_tier"`
// FallbackBackend is --fallback-backend: non-empty means the box is
// off-matrix and the render came from fallbackProfile, not from the table.
FallbackBackend string `json:"fallback_backend"`
}
RenderBasis is the pair of `install render` flags that gate the seeds.
type Report ¶
type Report struct {
State State
// SpecSHA256 / TierID / RenderedBy / RenderedAt come from the stamp; empty
// on an UNSTAMPED file.
SpecSHA256 string
TierID string
RenderedBy string
RenderedAt string
// Keys names the basis keys that differ, dotted ("params.ctx_size"), sorted.
// Non-empty only for STALE.
Keys []string
// Detail is the operator-facing sentence.
Detail string
}
Report is what `audit-yaml --against-render` prints for one file.
func AgainstRender ¶
AgainstRender decides one file's state.
The caller supplies the freshly derived basis and the freshly rendered body, because deriving them needs the tier table and the embedded templates, which live with the installer half (install_render.go) -- this package renders a template, it does not own the seeds. freshBody may be empty when the tier the stamp names can no longer be rendered by this binary; then the verdict rests on the basis alone and says so.
Order matters and is the point: integrity of the stamp, then integrity of the body, then staleness. A hand-edited file reported as STALE would send an operator to re-render and destroy their edit, so the body check comes first.
type SeatEntry ¶
type SeatEntry struct {
// ID is the entry's key: the canonical model id llama-swap lists it under.
ID string
// Aliases are the entry's other names (`aliases:`), in file order.
Aliases []string
// Cmd is the entry's command with every `${macro}` replaced by its text, the way the command
// reaches the process spawner. Empty when the entry states none.
Cmd string
// Proxy is the entry's `proxy:` address, empty when it states none (llama-swap then derives one
// from ${PORT} at load time, so the file cannot say where the seat listens).
Proxy string
// CheckEndpoint is the entry's `checkEndpoint:`: the path llama-swap polls on the seat until it
// answers. Empty when the entry states none (llama-swap's own default is /health); the word
// `none` switches the poll off and is kept as written.
CheckEndpoint string
}
SeatEntry is one `models:` entry of a serving config as llama-swap would run it.
func SeatEntries ¶
SeatEntries parses a serving config and returns every entry under `models:`, sorted by id. A text that is not YAML is an error, never an empty list: "the file lists no seats" and "the file could not be read" are different facts.
type SeatSlots ¶
type SeatSlots struct {
// N is how many requests the seat handles at once; always at least 1.
N int
// Auto: a llama.cpp entry that states --parallel -1 or auto. N is autoSlots, which is what
// llama-server resolves it to.
Auto bool
// Limit: the entry is not a llama.cpp one (a vLLM seat runs through a wrapper script) and N is its
// llama-swap concurrencyLimit, which the vLLM seat's installer sets to the engine's max_num_seqs.
Limit bool
}
SeatSlots is the request concurrency a serving config states for one seat, and where it states it.
func SeatSlotsWhy ¶
SeatSlotsWhy is SeatParallelWhy for a reader that must also say what a seat that is not a llama.cpp one serves: an entry whose command does not run llama-server and that states a llama-swap concurrencyLimit (how a vLLM seat is rendered, limit = max_num_seqs) reads as that limit, and the result says so (SeatSlots.Limit). A llama.cpp entry is read exactly as SeatParallelWhy reads it, and its concurrencyLimit is never a slot count (llama-swap defaults it to 10 whatever the engine runs). The reason is empty when the slots are known.
type SpecBasis ¶
type SpecBasis struct {
// HarnessVersion is buildinfo.Version of the binary that rendered.
//
// It is in the IDENTITY hash (a config rendered by 0.117.2 is not the same
// artifact as one rendered by 0.123.0) but it is NOT what decides staleness:
// AgainstRender re-renders and compares output, so a version bump that
// changed nothing about this tier still reports MATCH. A verdict wired to the
// version instead would read STALE on every node after every release.
HarnessVersion string `json:"harness_version"`
// TierID is the resolved tier -- a profiles.json key, or the literal
// "(off-matrix: <backend> defaults)" string an unknown box renders under.
TierID string `json:"tier_id"`
// TemplateSHA256 is over the serving template's bytes as embedded in the
// rendering binary (setup/templates/llama-swap.<os>-<backend>.yaml).
TemplateSHA256 string `json:"template_sha256"`
// ProfilesEntrySHA256 is over the tier's own entry in profiles.json,
// canonicalised (sorted keys) so a reformat of the table is not a change.
// Empty for an off-matrix render, which has no entry.
ProfilesEntrySHA256 string `json:"profiles_entry_sha256"`
// Render holds the render inputs that are neither a seed nor a Params field
// but change what the seeds RESOLVE to. Without them a re-derive cannot
// reproduce the render, so they are recorded rather than guessed.
Render RenderBasis `json:"render"`
// Params is the full, mirrored Params the render was performed with.
Params ParamsBasis `json:"params"`
}
SpecBasis is the CLOSED input set the spec hash is computed over.
Closed and named for the same reason props.go's seatPinBasis is: hashing whatever a struct happens to hold makes the hash churn on accidents and makes "what changed?" unanswerable. Every field here is an input `install render` was given; nothing derived, nothing observed from the running box.
The template and the tier entry are folded in as their sha256 rather than verbatim: a serving template is several KB and the tier table is ~90 KB, and the stamp has to fit in a yaml comment block a human will read.
ProfilesEntrySHA256 covers the tier's OWN entry, not the whole profiles.json. Hashing the whole file was considered and rejected: every tier edit anywhere in the table would then mark every node's config changed, including nodes the edit cannot touch. That is the false-positive shape that trains an operator to ignore a gate. The per-entry hash still catches a seed field that Render does not consume today but might tomorrow -- which is its whole marginal value over the Params fields below.
type Stamped ¶
type Stamped struct {
SpecSHA256 string
BodySHA256 string
RenderedBy string
TierID string
RenderedAt string
// BasisJSON is the canonical basis exactly as the stamp carries it.
BasisJSON string
// Body is the yaml below the block, byte for byte.
Body string
}
Stamped is a parsed provenance block plus the exact body bytes beneath it.
func ParseStamp ¶
ParseStamp reads a provenance block off the front of a config. ok=false means the file carries no stamp at all (UNSTAMPED) -- a missing stamp is a normal state for every config rendered before this version, never an error.
The block ends at the first line that is not one of the recognised `# <key>: <value>` lines, plus one optional blank separator. Everything after that byte offset is the body, returned unmodified: the split is by OFFSET and not by re-joining lines, so CRLF files, trailing whitespace and a missing final newline all survive the round trip and hash to what they hashed at render time.
type State ¶
type State string
State is the verdict of `audit-yaml --against-render` over one file. Exactly one of these is reported per file -- they are ordered by what an operator must do about them, and the checks run in that order, because a hand-edited file that is ALSO stale must be reported as hand-edited (re-rendering it destroys the edit).
const ( // StateMatch: the file carries a stamp, its body is untouched, and // re-rendering from this binary's seeds reproduces it byte for byte. StateMatch State = "MATCH" // StateStale: stamp intact, body untouched, but this binary's seeds now // render something different. The report names the basis keys that moved. StateStale State = "STALE" // StateUnstamped: no provenance block. Every config rendered before this // version is unstamped; it is a finding, not a failure. StateUnstamped State = "UNSTAMPED" // StateHandEdited: the body no longer hashes to what the stamp recorded (or // the stamp's own hash does not match the basis it carries). Someone edited // the file, or the stamp, after rendering. StateHandEdited State = "HAND-EDITED" )
type Violation ¶
type Violation struct {
Rule string // the rule id: ttl, ngl0, cvd-empty, persistent, preload, n-cpu-moe, cpu-moe, pin-by-index, pin-unresolved
Where string // model / group name, or "top-level"
Text string // the operator-facing sentence
}
Violation is one broken rule in one place of a serving config.
func Audit ¶
Audit checks one llama-swap config (a template or a live file) against the rules and returns every violation, sorted for stable output. A config that does not parse is a single violation of rule "yaml".
func AuditCPUMoE ¶
AuditCPUMoE is the W4 rule Audit cannot carry, because the exemption belongs to the caller: the EVERY-expert placement, `--cpu-moe` (INV-1). The cards do the inference and RAM is overflow only; the one sanctioned host-RAM use for experts is a PARTIAL spill, `--n-cpu-moe N`, up to a measured N (AuditSpill). The bare form parks every expert layer of the model in host RAM. It checks the flag in every spelling and its LLAMA_ARG_CPU_MOE environment twin, and the draft-model forms, on every entry, reading each entry the way llama-swap runs it (a `${name}` macro is replaced by its text first).
It is pure and exemption-free. The cpu backend has no card to overflow from; whether it applies is the caller's evidence to read (`install render` holds the resolved profile and runs before the stamp exists; `audit-yaml` holds the file and its stamp). The installer used to write the literal for a box off the tier matrix too (an exemption until 0186 w4); it no longer does, so nothing else is exempt. It reads parsed entries, never the raw text: a stamped file carries `"moe_26b": "--cpu-moe -ngl 999"` in its stamp comment. One finding per offending entry, sorted by entry; a document that does not parse is Audit's finding, not this rule's.
func AuditDisplayCapUnseen ¶
AuditDisplayCapUnseen is the display-cap-unseen note over a file and this box's card table: at most one Violation (Where names the display card of this reading), to be printed as a note and never counted. It is silent when the file does not parse, has no entries, the box has a single card, no card is flagged as the display card, or no entry is one the audit cannot place off that card. On a box of two or more cards a reading that could not say which card the monitor is on gets one line saying so, and names no entry.
func AuditPins ¶
AuditPins is the A-87 rule: on a box with two cards of the same model, a device pin is by UUID, and every UUID names a card. It reads the entries of a live file against the box's own card table (gpuprobe.ReadCards) and returns two kinds of finding.
- pin-by-index: an entry whose CUDA_VISIBLE_DEVICES is a list of plain indices at least one of which names a card whose model name another card also carries. An index is the card's place on the PCI bus; nothing in the config records which of two identical cards was meant, and a power loss or a BIOS reset that reorders enumeration moves the seat to the other one without a word. The index of a card no other card resembles names exactly one card and is left alone. An index maps to the nvidia-smi index only under CUDA_DEVICE_ORDER=PCI_BUS_ID (CUDA's default order is fastest-first), so an entry that does not set it is judged by the weaker form: any plain index while two cards share a name. A card table that gives no model names cannot show two cards to be identical, so it never makes an index ambiguous.
- pin-unresolved: a pin that names no card: a GPU UUID (or UUID prefix) that matches no card, or several; a plain index that no card has (under PCI_BUS_ID the nvidia-smi index of a card on the table, otherwise a position past the last card); or a token that is neither a plain index nor a GPU- UUID. CUDA hides every device from the first pin it cannot resolve, so the seat runs on fewer cards than it was sized for or on none (INV-1). -1 and a MIG instance id are not judged.
The severity is the caller's, because only it holds the stamp: a seed cannot carry a UUID, so the index pins of a verbatim render are the renderer's own output and a note, while the same pin in a hand-maintained file is its maintainer's choice and a violation. With no card table (cards empty) there is nothing to compare with and the result is empty; the caller says so.
func AuditSpill ¶
AuditSpill is the H-01 rule Audit cannot carry, because Audit reads one config with no tier in hand: `--n-cpu-moe` above the tier's MEASURED spill (INV-1). The cards do the inference and RAM is overflow only; the single sanctioned host-RAM use is a PARTIAL spill of a model that does not fit its card, and only up to the number of expert layers a measurement showed was needed. A tier that recorded no measurement (maxNCPUMoE 0) has no sanctioned spill at all, so any `--n-cpu-moe N` with N above zero is refused; N 0 spills nothing and is compliant.
It checks the flag in every spelling and its LLAMA_ARG_N_CPU_MOE environment twin, on every entry, reading each entry the way llama-swap runs it (a `${name}` macro is replaced by its text first: the templates keep their shared flags in `macros:`), and reports every offender (sorted by entry) so a fix is one pass. The every-expert `--cpu-moe` is a different rule (AuditCPUMoE, whose exemptions belong to its callers; the table level also refuses a GPU tier that seeds `cpu_moe`), and a document that does not parse is Audit's finding, not this rule's: reporting it twice would only bury it.