pub struct V3Cache { /* private fields */ }Expand description
Decode state for one session.
Implementations§
Source§impl V3Cache
impl V3Cache
Sourcepub fn new(cfg: &V3Config, hint: usize) -> Self
pub fn new(cfg: &V3Config, hint: usize) -> Self
A cache for a session expected to reach hint positions.
hint only sizes the first allocation for global layers — exceeding it
grows rather than fails. Local layers are always exactly their window.
Sourcepub fn with_precision(
cfg: &V3Config,
hint: usize,
precision: KvPrecision,
) -> Self
pub fn with_precision( cfg: &V3Config, hint: usize, precision: KvPrecision, ) -> Self
A cache that stores its keys and values at precision from the first
write.
Precision is fixed at construction because it decides the allocation:
an Int8 cache never allocates the f32 buffers at all, which is the
entire point. Switching afterwards would either reinterpret what is
already stored or silently throw it away.
pub fn precision(&self) -> KvPrecision
pub fn is_empty(&self) -> bool
Sourcepub fn bytes(&self) -> usize
pub fn bytes(&self) -> usize
Bytes currently held, so a caller on a constrained target can see what a session actually costs rather than guessing.
Sourcepub fn token_history(&self) -> &[u32]
pub fn token_history(&self) -> &[u32]
Token ids retained for the n-gram hash, oldest first.
Sourcepub fn push_token(&mut self, tok: u32)
pub fn push_token(&mut self, tok: u32)
Record a token, dropping history no longer reachable by any hash.
Sourcepub fn span(&self, li: usize, pos: usize) -> (usize, usize)
pub fn span(&self, li: usize, pos: usize) -> (usize, usize)
The inclusive logical range layer li may attend to at pos.
Clamped to the ring’s capacity. A global layer past max_seq_len would
otherwise ask for more history than it stores, and because slots are
addressed modulo the capacity it would read itself as its own past —
silently, since the bounds check is a debug assertion. Degrading to the
most recent slots positions is wrong too, but it is bounded, visible
through Self::is_saturated, and cannot corrupt.
Callers should avoid reaching this: see V3Engine, which bounds the
prompt and reports StopReason::MaxSeqLen.
Sourcepub fn is_saturated(&self) -> bool
pub fn is_saturated(&self) -> bool
True once any layer has run past what it can store, so attention is no longer seeing the history the model was trained to see.
Sourcepub fn write_kv(&mut self, li: usize, pos: usize, k: &[f32], v: &[f32])
pub fn write_kv(&mut self, li: usize, pos: usize, k: &[f32], v: &[f32])
Write this position’s post-convolution key and value.
Sourcepub fn kv(&self, li: usize) -> KvStore<'_>
pub fn kv(&self, li: usize) -> KvStore<'_>
How layer li hands its keys and values to attention.
Sourcepub fn conv_step(
&mut self,
li: usize,
which: Qkv,
taps: &[f32],
raw: &mut [f32],
)
pub fn conv_step( &mut self, li: usize, which: Qkv, taps: &[f32], raw: &mut [f32], )
Apply the causal conv for one position using the retained raw tail, then roll the tail forward.
raw is this position’s pre-conv projection and is replaced with the
post-conv result. History before the start of the session contributes
zero, exactly as the reference’s zero-padded shift does.
Sourcepub fn engram_conv_step(&mut self, site: usize, taps: &[f32], raw: &mut [f32])
pub fn engram_conv_step(&mut self, site: usize, taps: &[f32], raw: &mut [f32])
The Engram value convolution for one position, using the retained tail.
raw is this position’s pre-conv Engram value and is replaced with the
post-conv result.
Sourcepub fn seed_conv_tail(&mut self, li: usize, which: Qkv, raw: &[f32])
pub fn seed_conv_tail(&mut self, li: usize, which: Qkv, raw: &[f32])
Seed the conv tail for a layer after a batched prefill.
raw holds the last qkv_conv_taps - 1 pre-convolution vectors for
this projection, oldest first. The batched path convolves in place, so
the caller has to keep these before it does.
Sourcepub fn seed_engram_tail(&mut self, site: usize, raw: &[f32])
pub fn seed_engram_tail(&mut self, site: usize, raw: &[f32])
Seed one site’s Engram value tail, oldest first, pre-convolution.
Sourcepub fn seed_tokens(&mut self, tokens: &[u32])
pub fn seed_tokens(&mut self, tokens: &[u32])
Seed the token history the n-gram hash reads, oldest first.