pub struct ContiguousKVCache<B: Backend> { /* private fields */ }Expand description
Simple contiguous cache: stores one K and one V tensor per layer and concatenates along the sequence dimension every step.
Cost: an O(seq) copy per token per layer — kept as the correctness baseline; the paged arena is the production default.
Implementations§
Trait Implementations§
Source§impl<B: Backend> KVCache<B> for ContiguousKVCache<B>
impl<B: Backend> KVCache<B> for ContiguousKVCache<B>
Source§fn attention(
&mut self,
layer: usize,
q: Tensor<B, 4>,
k: Tensor<B, 4>,
v: Tensor<B, 4>,
pos: usize,
scale: f64,
) -> Tensor<B, 4>
fn attention( &mut self, layer: usize, q: Tensor<B, 4>, k: Tensor<B, 4>, v: Tensor<B, 4>, pos: usize, scale: f64, ) -> Tensor<B, 4>
Appends
seq new positions of K/V for layer and computes attention
of q against the full cached window (past + new). Read moreSource§fn popn(&mut self, n: usize) -> usize
fn popn(&mut self, n: usize) -> usize
Rolls back the last
n cached tokens, returning how many were
actually dropped. Caches that cannot roll back (the contiguous
baseline) return 0 — callers gate prefix reuse on a nonzero result.Source§fn pages_used(&self) -> Option<usize>
fn pages_used(&self) -> Option<usize>
Pages currently allocated to the sequence (paged cache only).
Auto Trait Implementations§
impl<B> Freeze for ContiguousKVCache<B>
impl<B> RefUnwindSafe for ContiguousKVCache<B>where
<B as BackendTypes>::FloatTensorPrimitive: RefUnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: RefUnwindSafe,
impl<B> Send for ContiguousKVCache<B>
impl<B> Sync for ContiguousKVCache<B>
impl<B> Unpin for ContiguousKVCache<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
impl<B> UnsafeUnpin for ContiguousKVCache<B>
impl<B> UnwindSafe for ContiguousKVCache<B>where
<B as BackendTypes>::FloatTensorPrimitive: UnwindSafe,
<B as BackendTypes>::QuantizedTensorPrimitive: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more