ForwardContext

Struct ForwardContext 

Source
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: usize

2026-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 GemmDispatch

2026-09-25: This model’s GEMM selection per projection (layers::ops::GemmDispatch).

§derived: &'a DerivedWeights

2026-09-25: This model’s memo of re-encoded weight copies (layers::ops::DerivedWeights).

§levers: &'a ModelLevers

2026-09-25: This model’s kernel-path switches other than GEMM selection (layers::ops::ModelLevers).

§stats: &'a ModelStats

2026-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: bool

2026-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: bool

2026-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: bool

2026-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: bool

2026-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: bool

2026-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: MoeLoraRoute

2026-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).

Auto Trait Implementations§

§

impl<'a> Freeze for ForwardContext<'a>

§

impl<'a> !RefUnwindSafe for ForwardContext<'a>

§

impl<'a> Send for ForwardContext<'a>

§

impl<'a> Sync for ForwardContext<'a>

§

impl<'a> Unpin for ForwardContext<'a>

§

impl<'a> !UnwindSafe for ForwardContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,