Skip to main content

V2State

Struct V2State 

Source
pub struct V2State { /* private fields */ }
Expand description

Per-sequence mutable state: KV cache, token history, Engram ring, and every scratch buffer a step needs. Allocated once so a decode step does no heap work.

Implementations§

Source§

impl V2State

Source

pub fn pos(&self) -> usize

Absolute position of the next token.

Source

pub fn history(&self) -> &[u32]

Tokens fed so far, oldest first.

Source

pub fn kv_window(&self) -> usize

The attention window this sequence runs at.

Source

pub fn set_kv_window( &mut self, window: Option<usize>, model: &V2Model, ) -> Result<(), &'static str>

Override the attention window. None restores the model’s own.

Needed because the two heads upstream ships disagree: the LM path runs the checkpoint’s kv_window (256), while architecture.encode_contrastive and forward_confidence default to window=0, full causal. Below 256 tokens the two are bit-identical; above it they diverge — at 642 tokens the contrastive embeddings differ by cosine 3.5e-4 and the confidence logit by 0.096 — so this is a real fork, not a rounding detail.

Takes effect from the next step; it does not rewrite the existing cache.

Fails when the requested window needs more cached positions than this state allocated — a window of 0 over a ring-sized cache would read stale slots and quietly return wrong embeddings. Use V2Model::make_state_full_causal for that case.

Source

pub fn cache_len(&self) -> usize

Positions the KV ring holds.

Source

pub fn kv_bytes(&self) -> usize

Bytes the KV cache occupies — the dominant part of a session.

Source

pub fn reset(&mut self)

Start a new sequence, keeping the allocations.

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.