Expand description
Metal decode path for qwen4-exp: row-batched steps (prefill chunks and speculative verification of MTP drafts) over an explicit wired expert pool.
Dense weights are one zero-copy buffer over dense.bin. Routed experts
live in a fixed pool of page-aligned slots (Metal wires whole buffers per
command buffer), LRU managed here
and filled by uncached parallel reads. One command buffer per step: after
each layerβs router the GPU signals a shared event and waits for the CPU
to publish that layerβs expert slots; a one-layer lookahead router lets
most fetches run in the background.
A step runs nb consecutive positions at once (activations are
row-major [nb][...]). The gated DeltaNet scan snapshots its state after
each row so a partially accepted verify batch can roll back.
ModulesΒ§
- activity π
- Cumulative routed-expert activity. Verification and draft rows count even when later rolled back. IO counters describe requested reads, not completion.
- attention π
- QSA indexing, q8 KV append, and selected decode attention.
- budget π
- Expert-pool sizing after fixed buffers and host reservations.
- decode π
- Trunk row-batch execution and single-token stepping.
- deltanet π
- Causal convolution and recurrent DeltaNet decode dispatch.
- dispatch π
- Buffer binding, dispatch geometry, dense projections, and transfers.
- experts π
- Router and resident/fetched expert compute dispatch.
- hyperconnection π
- Grouped normalization and gated residual mixing/injection.
- load π
- Model loading, pipeline creation, and fixed/pool allocation.
- memory π
- Runtime resource counters shared by CLI telemetry and control status.
- mtp π
- Draft-head execution and folded/chained MTP inputs.
- params π
- Host/shader ABI: preserve field order and match the Metal declarations.
- phases π
- Timestamp the existing compute passes; resolve only after their normal wait.
- ple π
- N-gram prefetch/gather and PLE gating/convolution dispatch.
- prefill
- Prefill engine: a prompt chunk of up to a few thousand tokens runs through the model layer by layer, so each layerβs experts are streamed once for the whole chunk instead of once per few tokens.
- residency π
- The expert pool: which records the GPU may touch, LRU managed here, with two backings behind one interface.
- sampling π
- Final hyper-connection read, logits projection, and greedy argmax.
- state π
- Commit/rollback, sequence reset, and prefix checkpoints.
- streaming π
- Decode expert streaming: GPU routing, CPU slot publication, and file IO.
StructsΒ§
- Attn π
- Delta π
- Expert
Activity - Expert
Counters - GLayer π
- Gpu
- HalfSet π
- Half even/odd streams plus per-32 group sums of a row batch, the input format of the multi-row Q4 matvecs.
- Hc π
- HcBufs π
- Buffers of one gated-residual read (the main set, or the lookaheadβs).
- LaEntry
- One lookahead prediction and what became of it (CHERENKOV_DUMP_LA).
- Layer
Stats - Memory
Stats - Capacities and observations, not a partition of process memory. CPU prefix checkpoints and session history are reported separately by the server.
- Moe π
- Mtp π
- The MTP draft head (see cpu.rs
MtpWeights). - Phase
Stats - Pipes π
- Ple π
- Prediction
Stats - Prefix
State π - Compact sequence checkpoint; no weights, expert slots, or device event counters.
- Q π
- Affine-Q4 projection: dimensions and byte offsets in its bound weight buffer.
- Quant
Stats - Read
Stats - Scratch π
- T π
- Byte offset of a bf16 tensor in dense.bin.
EnumsΒ§
ConstantsΒ§
- ARGMAX_
TGS π - ATTN_
MAX_ πWG - ATTN_TB π
- IDS_IN π
- ids buffer layout: trunk inputs, trunk argmax, MTP inputs, MTP argmax.
- IDS_
MTP_ πIN - IDS_
MTP_ πOUT - IDS_OUT π
- MAX_NB
- Rows per step (prefill chunk, or 1 + drafts when verifying).
- MAX_
SNAP - Rollback planes: verify batches may have up to this many draft rows.
- SLOT_
STRIDE π - Slots per layer row of the expert slot table (last entry = union size).
FunctionsΒ§
- kv_
q8_ πside - layer_
cap π - Debug: CHERENKOV_LAYERS=N runs only the first N decoder blocks (for bisecting one execution path against another).
- set_
bytes π - union_
of π - Unique entries in first-seen order.