pub struct BlockHasher { /* private fields */ }Expand description
Hashes blocks for one (model, extra_keys) identity. Cheap to build; the root is computed once and reused for every chain.
Implementations§
Source§impl BlockHasher
impl BlockHasher
Sourcepub fn new<S: AsRef<str>>(model: impl Into<String>, extra_keys: &[S]) -> Self
pub fn new<S: AsRef<str>>(model: impl Into<String>, extra_keys: &[S]) -> Self
model should identify the weights, not the file path – two
servers on different machines must agree on it for a shared or
restored cache to be reusable at all.
extra_keys are ordered: they are hashed in the order given, so
callers must be consistent (sort them if the source is a set).
Sourcepub fn root(&self) -> BlockHash
pub fn root(&self) -> BlockHash
The seed every chain starts from: the identity of “no tokens yet, under this model and these extra keys”. A chain rooted here can never be confused with one rooted under a different model or a different LoRA.
pub fn model(&self) -> &str
pub fn extra_keys(&self) -> &[String]
Sourcepub fn block(&self, parent: &BlockHash, token_ids: &[usize]) -> BlockHash
pub fn block(&self, parent: &BlockHash, token_ids: &[usize]) -> BlockHash
Hashes one block: this token run, following parent.
model and extra_keys are folded in again even though the
parent chain already carries them, so a single block hash is
verifiable from (parent, tokens) alone without walking back to
the root.
Sourcepub fn chain(&self, tokens: &[usize], block_size: usize) -> Vec<BlockHash>
pub fn chain(&self, tokens: &[usize], block_size: usize) -> Vec<BlockHash>
Hashes tokens as a chain of block_size-token blocks, rooted
at root.
Only whole blocks are hashed. A trailing partial block gets
no hash: its content is still growing, so any identity assigned
to it now would name a different token run a moment later.
full_blocks reports how many hashes a length yields.
Because each block’s hash covers its parent, the chain of a prompt is a strict prefix of the chain of anything that extends it – which is exactly the lookup a prefix cache needs.
Trait Implementations§
Source§impl Clone for BlockHasher
impl Clone for BlockHasher
Source§fn clone(&self) -> BlockHasher
fn clone(&self) -> BlockHasher
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BlockHasher
impl RefUnwindSafe for BlockHasher
impl Send for BlockHasher
impl Sync for BlockHasher
impl Unpin for BlockHasher
impl UnsafeUnpin for BlockHasher
impl UnwindSafe for BlockHasher
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