Glm5NextDsaState

Struct Glm5NextDsaState 

Source
pub struct Glm5NextDsaState {
    pub k_normed: DevicePtr,
    pub gate: DevicePtr,
    pub valid: DevicePtr,
    /* private fields */
}
Expand description

2026-09-25: One sequence’s indexer cache for one DSA layer, allocated once at max_dsa_context rows and never grown.

Fields§

§k_normed: DevicePtr

2026-09-25: [capacity, index_head_dim] BF16 indexer keys, after the k_norm LayerNorm.

§gate: DevicePtr

2026-09-25: [capacity, index_head_dim] BF16 compress-gate projection.

§valid: DevicePtr

2026-09-25: [capacity] u8 per-position validity.

Implementations§

Source§

impl Glm5NextDsaState

Source

pub fn snapshot_blob( &self, gpu: &dyn GpuBackend, stream: u64, ) -> Result<Vec<u8>>

2026-09-25: Serialize the reachable indexer rows [0, len) for a prefix-cache snapshot. Rows past len were never written or are unreachable (rewind_to leaves them in place).

Source

pub fn restore_blob( &mut self, blob: &[u8], gpu: &dyn GpuBackend, stream: u64, ) -> Result<()>

2026-09-25: Restore a snapshot’s indexer rows into this state.

A blob that is truncated, of another index_head_dim, inconsistent with its header, or longer than this sequence’s reservation is an Err; model-engine’s apply_aux_states propagates it with ?, so the prefix-cache hit fails.

Source§

impl Glm5NextDsaState

Source

pub fn alloc(gpu: &dyn GpuBackend, cfg: &Glm5NextDsaConfig) -> Result<Self>

2026-09-25: Reserve for the whole addressable context. alloc_state has no length argument, so the cap, not the prompt, sizes this.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Source

pub fn index_head_dim(&self) -> usize

2026-09-25: Indexer key width. The aux-state codec (aux_state.rs) refuses a blob taken at a different width.

Source

pub fn row_offset(&self, pos: usize) -> usize

2026-09-25: Byte offset of row pos in k_normed / gate.

Source

pub fn ensure_room(&self, n: usize) -> Result<()>

2026-09-25: Fails when n more rows would pass capacity.

Glm5NextDsaLayer::indexer_forward writes row len() before it advances, so it calls this first: at len == capacity that row is past the end of every buffer.

Source

pub fn ensure_room_through(&self, end: usize) -> Result<()>

2026-09-25: The same refusal for an absolute end row.

Before a graph replay the counter may still be ahead of the sequence (a rejected draft; sync_to fixes it after the replay), so the replay check (check_replay_room) asks about the end row seq_len + k instead.

Source

pub fn advance(&mut self, n: usize) -> Result<()>

2026-09-25: Advance after writing n rows at [len, len + n). Fails, without changing len, when that would pass capacity.

Source

pub fn rewind_to(&mut self, n: usize) -> Result<()>

2026-09-25: Rewind to n rows after a rejected speculative draft.

The rows in [n, len) are left in the cache but become unreachable: the selector reads [0, len) and the next write starts at n, so they are overwritten before anything can select over them. Only shrinks — growing is advance’s job, and a request to “rewind” forward would mean the caller lost track of where the sequence is.

Source

pub fn sync_to(&mut self, seq_len: usize, k: usize) -> Result<()>

2026-09-25: Put the counter where decode_k would have left it, for a step served by a replayed CUDA graph. seq_len is the sequence length before this step’s k rows.

The same reconcile decode_k does on entry: the counter is rewound to seq_len when it is ahead (a rejected draft), a counter behind seq_len is an error, and then it advances by k.

Source

pub fn geometry( &self, cfg: &Glm5NextDsaConfig, q_rows: usize, ) -> Result<DsaSelectGeometry>

2026-09-25: Plan a selection over everything cached so far.

Source

pub fn free(&mut self, gpu: &dyn GpuBackend) -> Result<()>

2026-09-25: Release the per-sequence device buffers.

Takes &mut self because callers hold the state behind a dyn state object. A second call does nothing (released is set first), since release_state on the layer and the MTP proposer’s free_state can both reach one state. After the three frees succeed the pointers are nulled and len is 0.

Trait Implementations§

Source§

impl LayerState for Glm5NextDsaState

Source§

fn as_any(&self) -> &dyn Any

Source§

fn as_any_mut(&mut self) -> &mut dyn Any

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