Skip to main content

Module gpu

Module gpu 

Source
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 πŸ”’
ExpertActivity
ExpertCounters
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).
LayerStats
MemoryStats
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).
PhaseStats
Pipes πŸ”’
Ple πŸ”’
PredictionStats
PrefixState πŸ”’
Compact sequence checkpoint; no weights, expert slots, or device event counters.
Q πŸ”’
Affine-Q4 projection: dimensions and byte offsets in its bound weight buffer.
QuantStats
ReadStats
Scratch πŸ”’
T πŸ”’
Byte offset of a bf16 tensor in dense.bin.

EnumsΒ§

GpuTiming
Mix πŸ”’

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.

Type AliasesΒ§

Buf πŸ”’
Enc πŸ”’
Pso πŸ”’
RouteStep
Tokens, expert IDs, routing weights, and misses for one step. Keep the tuple layout for compatibility with existing research dumps.