pub struct CacheBlock {
pub keys: Vec<Vec<f32>>,
pub values: Vec<Vec<f32>>,
pub token_ids: Vec<u32>,
pub last_used: u64,
pub ref_count: usize,
}Expand description
One cache block: KV tensors for block_size tokens in every layer.
Fields§
§keys: Vec<Vec<f32>>key tensors: [num_layers][num_kv_heads * head_dim * block_size] f32
values: Vec<Vec<f32>>value tensors: [num_layers][num_kv_heads * head_dim * block_size] f32
token_ids: Vec<u32>The exact token IDs this block covers.
last_used: u64LRU generation counter — higher means more recently used.
ref_count: usizeHow many live requests are currently using this block.
Implementations§
Source§impl CacheBlock
impl CacheBlock
Sourcepub fn new(
num_layers: usize,
num_kv_heads: usize,
head_dim: usize,
block_size: usize,
) -> Self
pub fn new( num_layers: usize, num_kv_heads: usize, head_dim: usize, block_size: usize, ) -> Self
Allocate a new, zeroed cache block.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Total memory consumed by this block’s KV tensors in bytes.
Formula: 2 (K+V) × num_layers × per_layer_elements × 4 bytes/f32.
Auto Trait Implementations§
impl Freeze for CacheBlock
impl RefUnwindSafe for CacheBlock
impl Send for CacheBlock
impl Sync for CacheBlock
impl Unpin for CacheBlock
impl UnsafeUnpin for CacheBlock
impl UnwindSafe for CacheBlock
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more