pub struct PrefixCache { /* private fields */ }Expand description
LRU-bounded store of StoredPrefix snapshots, searched for the
longest common prefix with an incoming token sequence.
Implementations§
Source§impl PrefixCache
impl PrefixCache
pub fn new(max_entries: usize) -> Self
Sourcepub fn find_longest_prefix(&mut self, tokens: &[usize]) -> PrefixMatch
pub fn find_longest_prefix(&mut self, tokens: &[usize]) -> PrefixMatch
Finds the stored prefix with the longest common leading
subsequence with tokens, and returns a ready-to-use clone of
its KV state truncated to exactly that common length (a stored
prefix may itself be longer than the common part, if a later,
different continuation was stored under it – the KV cache is
truncated to the matching length before being handed back, so
the caller never sees state from a divergent continuation).
Sourcepub fn store(
&mut self,
tokens: Vec<usize>,
kv_caches: Vec<KvCache>,
pending_logits: Vec<f32>,
)
pub fn store( &mut self, tokens: Vec<usize>, kv_caches: Vec<KvCache>, pending_logits: Vec<f32>, )
Stores a snapshot for tokens (all tokens processed so far,
prompt plus any generated continuation) with the given KV cache
state and next-token logits, evicting the least-recently-stored
entry if already at capacity.
pub fn stats(&self) -> PrefixCacheStats
Auto Trait Implementations§
impl Freeze for PrefixCache
impl RefUnwindSafe for PrefixCache
impl Send for PrefixCache
impl Sync for PrefixCache
impl Unpin for PrefixCache
impl UnsafeUnpin for PrefixCache
impl UnwindSafe for PrefixCache
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
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> ⓘ
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> ⓘ
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