Skip to main content

CacheManager

Struct CacheManager 

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

Manages a quantized KV-cache with configurable eviction.

Provides append, get, evict, and diagnostic methods such as compression_ratio and memory_bytes.

Implementations§

Source§

impl CacheManager

Source

pub fn new(config: KVCacheConfig) -> Self

Create a new cache manager with the given configuration.

Source

pub fn len(&self) -> usize

Number of entries currently in the cache.

Source

pub fn is_empty(&self) -> bool

Whether the cache is empty.

Source

pub fn append(&mut self, key: &[f32], value: &[f32], _layer_idx: usize)

Append a new key-value pair to the cache.

key and value must each have length num_heads * head_dim. _layer_idx is used by the PyramidKV eviction policy to determine the per-layer budget.

Source

pub fn get(&self, positions: &[usize]) -> (Vec<Vec<f32>>, Vec<Vec<f32>>)

Retrieve dequantized key-value pairs at the given logical positions.

Returns (keys, values) where each inner Vec<f32> has length num_heads * head_dim.

Source

pub fn evict(&mut self, budget: usize)

Evict entries until the cache contains at most budget entries.

Source

pub fn update_attention_scores(&mut self, scores: &[f64])

Update cumulative attention scores for the H2O eviction policy.

scores should have one value per current cache entry.

Source

pub fn pyramid_budget(&self, layer_idx: usize, total_layers: usize) -> usize

Compute the budget for a given layer under PyramidKV.

Lower layers get a proportionally larger share of max_seq_len.

Source

pub fn compression_ratio(&self) -> f64

Compression ratio: f32 bytes / quantized bytes for a single entry.

A 4-bit cache over f32 baseline yields roughly 8x compression (before accounting for scale/zero-point overhead).

Source

pub fn memory_bytes(&self) -> usize

Approximate total memory usage of the cache in bytes.

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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V