pub struct ForwardContext<'a> {Show 20 fields
pub buffers: &'a BufferArena,
pub hc_row_offset: usize,
pub gpu: &'a dyn GpuBackend,
pub config: &'a ModelConfig,
pub dispatch: &'a GemmDispatch,
pub derived: &'a DerivedWeights,
pub levers: &'a ModelLevers,
pub stats: &'a ModelStats,
pub attn_metadata: Option<AttnMetadataDev>,
pub profile: bool,
pub comm: Option<&'a dyn CommBackend>,
pub graph_capture: bool,
pub decode_step: bool,
pub gdn_exact_replay: bool,
pub gdn_write_on_accept: bool,
pub token_ids: Option<DevicePtr>,
pub host_token_ids: Option<&'a [u32]>,
pub routed_lora_layers: Option<&'a [Option<LoraLayerWeights>]>,
pub midchunk_capture: Option<MidchunkCapture<'a>>,
pub moe_lora_route: MoeLoraRoute,
}Expand description
2026-09-25: What one forward pass hands every layer: the GPU, buffers, config, the model’s switches and the pass’s metadata.
Fields§
§buffers: &'a BufferArena§hc_row_offset: usize2026-09-25: First mHC highway row of this pass. The prefill chunk of a fused
decode+prefill step uses padded_n (decode_b.rs), so its highway rows sit above
the decode rows as in hidden/residual. Every other constructor passes 0 or forwards
the value of the context it wraps.
gpu: &'a dyn GpuBackend§config: &'a ModelConfig§dispatch: &'a GemmDispatch2026-09-25: This model’s GEMM selection per projection (layers::ops::GemmDispatch).
derived: &'a DerivedWeights2026-09-25: This model’s memo of re-encoded weight copies
(layers::ops::DerivedWeights).
levers: &'a ModelLevers2026-09-25: This model’s kernel-path switches other than GEMM selection
(layers::ops::ModelLevers).
stats: &'a ModelStats2026-09-25: This model’s diagnostic counters and one-shot latches
(layers::ops::ModelStats). They belong to the model, so none spans a model swap.
attn_metadata: Option<AttnMetadataDev>2026-09-25: This pass’s attention metadata, or None. The kernel-batched prefill
passes None and hands its layers a BatchedAttnMetadata instead.
profile: bool2026-09-25: Profiling: the layers that read it synchronize after each timed step and log its time.
comm: Option<&'a dyn CommBackend>2026-09-25: Collective backend for cross-rank reductions, such as the MoE
expert-parallel all-reduce; None when the pass has none.
graph_capture: bool2026-09-25: True when the pass runs under CUDA graphs (use_graphs in decode_a.rs).
The MoE expert-parallel all-reduce then uses all_reduce, and all_reduce_async
otherwise (layers/moe/forward.rs).
decode_step: bool2026-09-25: True on decode steps (one token per sequence: decode_a.rs,
decode_a2.rs), whose attn_metadata holds one row per sequence.
prefill_default runs a layer that has no prefill of its own by calling its
decode once per token with the prefill context, whose positions and slot are
per-token arrays and whose block_table and seq_len can be NULL. A layer that
reads them as decode metadata checks this flag, not attn_metadata.is_some().
gdn_exact_replay: bool2026-09-25: True when this prefill pass continues from a restored SSM snapshot (a
warm prefix-cache hit). The Qwen3 SSM prefill then skips the FLA chunked GDN
kernels (trait_prefill_recur.rs, trait_prefill_gdn.rs).
gdn_write_on_accept: bool2026-09-25: Asks the batched GDN verify for write-on-accept: a layer that engages it
runs gated_delta_rule_wy4_woa, and the caller folds the accepted rows through
Model::gdn_fold_accepted after the verdict. True only for a batched verify that
requested it (VerifyBatchedOpts::write_on_accept, set by the DFlash batch step) and
had the WY tables staged and the stash bound (verify_e.rs).
token_ids: Option<DevicePtr>2026-09-25: Device [num_tokens] u32 ids of this pass’s tokens, in row order, at a
stable address; single-token decode uploads the id before any graph replay.
Hash-routed MoE layers (tid2eid) read it, and PLE does when host_token_ids is
None. None on passes that stage no ids.
host_token_ids: Option<&'a [u32]>2026-09-25: Host copy of this pass’s token ids when the caller has them: a decode
step whose tokens are on the host, and the prefill chunk of a fused decode+prefill
step (decode_b.rs); None on other passes. PLE hashes n-gram ids on the host and
prefers this slice; without it, PLE reads token_ids back from the device, which
it refuses during graph capture (ple/layer.rs).
routed_lora_layers: Option<&'a [Option<LoraLayerWeights>]>2026-09-25: The request slot’s LoRA pairs, indexed by global layer
(len == num_hidden_layers). Some only on a prefill pass whose request routes to
a non-active slot (TransformerModel::routed_slot_layers). The K/V/O prefill apply
sites then apply the request slot’s pair (lora::select_routed_pair) instead of
the per-row bgmv.
midchunk_capture: Option<MidchunkCapture<'a>>2026-09-25: Mid-chunk SSM tail capture for this prefill pass (model-engine
prefill_b/midchunk_capture.rs); None when the pass plans none. SSM layers split
their conv and recurrence kernels at cap_local and copy the state at that point
into the reserved snapshot slot.
moe_lora_route: MoeLoraRoute2026-09-25: MoE-LoRA fold decision for this pass. TransformerModel passes
moe_lora_route for a request’s prefill, decode_moe_route on decode, verify and
draft passes, and Refuse on a kernel-batched multi-stream prefill. Read by the MoE
LoRA fold hooks (layers/moe/lora.rs).