The affine kernel set converted rows and every read attend with, named
by the composition (composedAffineKernels).
Optionalrow: CacheOptionalcompose: (storage: Cache) => Cache
How the lego these rows came from composes the rows this layout hands
back to serial use (ComposedStorage.over).
ReadonlybitsOptional ReadonlycomposeHow the lego these rows came from composes the rows this layout hands
back to serial use (ComposedStorage.over).
ReadonlygroupReadonlykernelThe affine kernel set converted rows and every read attend with, named
by the composition (composedAffineKernels).
ReadonlystartReadonlystatestate() returned temporary views that the caller must release.
ReadonlytransitionEarliest prefix whose retained representation can resume generation. Irreversible transitions may preserve bytes while invalidating older precision boundaries. Reuse policy must not trim below this offset.
ProtectedpackedProtectedpositionsA preparation method commits each request's own precision boundary. Splitting a forward for a sibling must not move that boundary.
Compiled-decode trace adapters expose the RoPE offset as an int32 array input here; real caches leave it unset (static int path).
ProtectedrowsProtectedadvanceThe committed read (Qwen 3.5's appendKnown under knownSpans): the same
mask and attention view, attended with independent positions, so a
converted row keeps the single-position reduction order.
Decode: one new position per row (L = 1). Each row's query sees that
row's valid stored positions up to and including the one just appended,
limited to the cache's sliding window.
Window: L new positions per row, causal within the window, for prefill
chunks, prefill tails and speculative verify windows. Query i of a row
sees the row's earlier valid positions and window positions 0..i, limited
to the cache's sliding window. Left padding and prepared prefill padding are
never visible. Outputs at padded query positions are unspecified and the
caller ignores them. To append context without attending, make this call
and dispose the read unused.
Physical cache storage consumed by one additional token for one row. Recurrent caches return 0 because their state does not grow with the sequence. Optional for stateless/training adapters that are never admitted or persisted.
Apply the closure's outputs (takes ownership); returns arrays to evaluate with the step.
The closure inputs of slot, in order.
The fetch of the coming compiled step: the lego's while it holds the row,
else the rows' (decodePhaseOfRows), without moving the row.
ProtecteddecodeThe fetch a lone row's lego would choose, from this layout's positions.
A row handed back to serial use: its storage, composed again by the lego
the row came from (KvRowTransition.compose).
A row's storage, owned by the caller: what another row layout merges.
Can trim(n) drop the last n tokens? (Ring caches lose trimability
once wrapped.)
Maximum committed positions before this state changes precision.
ProtectedplainThe plain row an empty layout starts each prefill row with.
Host-side bookkeeping for a 1-token step (growth, rotation), without the write.
Stable storage identity for compatibility guards and persistence. REQUIRED: every capability predicate (isPlainKvCache, isRotating*, packages/inference/src/state/persistence.ts codecs) is a string compare on this value, so a missing override used to fail OPEN into wrong routing (PRs #42/#43: BatchedRotatingCache shipped without one and batched joins dropped running rows). Wrappers report their own kind plus the inner kind.
Speculative verify-round support for NON-trimmable recurrent caches
(SSMCache — gated-DeltaNet conv + recurrent state). A cache exposing
these is spec-eligible without isTrimmable(): the serve loop arms a
round before the verify forward (the layer snapshots pre-round state —
free, MLX arrays are immutable — and records its position-local kernel
inputs), then resolves it: commit on full accept, or rollback(keep)
which restores the snapshot and bit-exactly REPLAYS the first keep
window tokens through the recurrence (identical arithmetic prefix ⇒
identical state). Trimmable caches leave these unset and keep trim().
ProtectedsyncDrop the last n tokens (future writes overwrite them). bypass (default
false → unchanged behavior) skips the isTrimmable guard for the
speculative-decode rollback case (trim the last n ≤ γ tips right after a
1 concat write); rotating caches then physically shrink the buffer tail.
The dense fetch at the model's B (the softcapped read's): after the transition the append runs, every row's keys and values as its storage fetches them dense (a converted row's dequantized), joined left-padded as the plain attention view joins them, or the packed layout's dense fetch once every row is converted; the caller owns them.
The rows of the affine bf16-first lego (
Bf16FirstQuantizedKVCache) for continuous batching. Each row is bf16 until it holdsstartpositions and converts by the same transition; rows cross independently, a converted row keeps its native quantized-attention arithmetic, and once all rows convert, their packed planes use the existing batched attention implementation. When a row converts is described onTransitioningKvRows. The reads are the graph's call today: this layout's mask before the append, then its attention view. Converted rows, the packed layout and every view attend withkernelSet, taken when the layout is built. A row this layout hands back to serial use is the lego it came from again (compose), or its storage when it came as storage.