Glm5NextKdaLayer

Struct Glm5NextKdaLayer 

Source
pub struct Glm5NextKdaLayer {
    pub layer_idx: usize,
    pub cfg: Glm5NextKdaConfig,
    pub weights: Glm5NextKdaWeights,
    pub kernels: Glm5NextKdaKernels,
}
Expand description

One bound KDA attention block.

Fields§

§layer_idx: usize

Index in the checkpoint’s 45-layer text stack, for diagnostics.

§cfg: Glm5NextKdaConfig§weights: Glm5NextKdaWeights§kernels: Glm5NextKdaKernels

Implementations§

Source§

impl Glm5NextKdaLayer

Source

pub fn new( layer_idx: usize, cfg: Glm5NextKdaConfig, weights: Glm5NextKdaWeights, kernels: Glm5NextKdaKernels, ) -> Result<Self>

Source

pub fn decode( &self, gpu: &dyn GpuBackend, hidden: DevicePtr, state: &KdaSeqState, ws: &Glm5NextKdaWorkspace, stream: u64, ) -> Result<()>

Single-token decode, carrying both states.

The conv fuses SiLU and L2, so q/k reach kda_recurrent already normalised — exactly the pre-normalised contract that kernel takes. Re-normalising here would silently restore the bf16 rounding the fused write destroyed and look like a kernel bug.

Result lands in ws.final_out; state is updated in place.

Source

pub fn decode_k( &self, gpu: &dyn GpuBackend, hidden: DevicePtr, k: usize, state: &KdaSeqState, ws: &Glm5NextKdaWorkspace, snapshots: &[(DevicePtr, DevicePtr)], stream: u64, ) -> Result<()>

K tokens of ONE sequence: the projections batched, the recurrence NOT.

This is the speculative-verify body. The weight-heavy halves — Self::front_end’s q/k/v, both low-rank gate pairs and b_proj, and Self::back_end’s o_proj — run once over all K rows, so a K-token verify reads KDA’s 4.7 GB/rank/token ONCE instead of K times. That is the entire reason speculation can pay on this model.

🔴 Bit-identical to K serial Self::decode calls, which is not a nicety: an accepted draft token must be the token the unspeculated engine would have emitted, or speculation is silently lossy. It holds because dense_gemv_bf16_batchm reproduces each row’s exact K-iteration order and reduction tree (ops::dense_mm_bf16), the pack / gate / sigmoid / o_norm kernels are grid-parallel over the token axis, and Self::stateful_row walks the state one token at a time exactly as decode does.

snapshots[t](h_dst, conv_dst) — receives the state AFTER row t, which is what a partial accept rewinds to. Pass k - 1 of them (a full accept never rewinds) or none.

Source

pub fn prefill( &self, gpu: &dyn GpuBackend, hidden: DevicePtr, t: usize, state: &KdaSeqState, ws: &Glm5NextKdaWorkspace, stream: u64, ) -> Result<()>

Chunked prefill over t tokens from the carried state.

Source

pub fn prefill_with_pad_fill( &self, gpu: &dyn GpuBackend, hidden: DevicePtr, t: usize, state: &KdaSeqState, ws: &Glm5NextKdaWorkspace, pad_fill: f32, stream: u64, ) -> Result<()>

Self::prefill with the padded q/k/v tails primed to an arbitrary value.

Production passes zero. The numeric gate passes poison, because kda_chunk_* guard past T in-kernel and that guard needs a test with teeth: the Slice-5 bug wrote entirely correct outputs while leaving the carried recurrent state off by 1.623e13, so a pad tail the caller zeroes proves nothing.

Auto Trait Implementations§

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, 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