pub struct KvWindowPolicy { /* private fields */ }Expand description
Whether this run may evict, decided once at load time.
A Copy value on the Decoder rather than a cached global, so a
test can build a decoder that evicts and one that does not in the
same process and compare their tokens. A global read once per
process would need a subprocess per arm to say the same thing.
Implementations§
Source§impl KvWindowPolicy
impl KvWindowPolicy
Sourcepub const fn off() -> Self
pub const fn off() -> Self
Never evicts. What every cache in this engine did before #61, and
what a run gets unless KV_WINDOW_ENV says otherwise.
Sourcepub const fn on() -> Self
pub const fn on() -> Self
Always evicts, where the layer has a window. For tests and for a caller that has already made the decision itself.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Reads KV_WINDOW_ENV, then subtracts the runs that must not
evict. See the module doc for which and why.
pub fn enabled(&self) -> bool
Sourcepub fn window_for(&self, attention_window: Option<usize>) -> Option<KvWindow>
pub fn window_for(&self, attention_window: Option<usize>) -> Option<KvWindow>
The window a layer’s cache evicts behind, given the window that layer’s attention actually reads.
These two must be the same number. The kernel reads the last
window rows; keeping fewer answers out of a truncated history,
and this is the only place that says so, so there is nowhere for
a second opinion to live.
Sourcepub fn layer_window(
&self,
config: &ModelConfig,
layer_idx: usize,
) -> Option<KvWindow>
pub fn layer_window( &self, config: &ModelConfig, layer_idx: usize, ) -> Option<KvWindow>
The window layer layer_idx of config evicts behind.
The ONE expression that answers it, for the decoder
(Decoder::kv_window_for_layer) and for the budget
(crate::kv_budget::KvResidency::from_config) alike. Those two
have to agree about which layers keep how much or the budget is
pricing a cache that does not exist, which is #33.
Trait Implementations§
Source§impl Clone for KvWindowPolicy
impl Clone for KvWindowPolicy
Source§fn clone(&self) -> KvWindowPolicy
fn clone(&self) -> KvWindowPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for KvWindowPolicy
Source§impl Debug for KvWindowPolicy
impl Debug for KvWindowPolicy
Source§impl Default for KvWindowPolicy
impl Default for KvWindowPolicy
impl Eq for KvWindowPolicy
Source§impl PartialEq for KvWindowPolicy
impl PartialEq for KvWindowPolicy
impl StructuralPartialEq for KvWindowPolicy
Auto Trait Implementations§
impl Freeze for KvWindowPolicy
impl RefUnwindSafe for KvWindowPolicy
impl Send for KvWindowPolicy
impl Sync for KvWindowPolicy
impl Unpin for KvWindowPolicy
impl UnsafeUnpin for KvWindowPolicy
impl UnwindSafe for KvWindowPolicy
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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