pub struct PromptLookupSpeculator {
pub ngram_size: usize,
pub max_draft_len: usize,
}Expand description
Proposes candidate continuation tokens by looking for the longest
available match of the most recent ngram_size tokens earlier in
history, and returning up to max_draft_len tokens that followed
that earlier occurrence. Returns an empty block if no match is found
or history is too short to contain one.
This is deliberately simple (last-match-wins, not best-match or a frequency-weighted choice): the whole point of prompt-lookup decoding is that it’s nearly free to compute, since a wrong guess costs nothing but a rejected batch position, not a correctness bug.
Fields§
§ngram_size: usize§max_draft_len: usizeImplementations§
Source§impl PromptLookupSpeculator
impl PromptLookupSpeculator
pub fn new(ngram_size: usize, max_draft_len: usize) -> Self
Sourcepub fn propose_tokens(&self, history: &[usize]) -> Vec<usize>
pub fn propose_tokens(&self, history: &[usize]) -> Vec<usize>
Looks for the most recent earlier occurrence of history’s
last ngram_size tokens, scanning from the end backwards so
the most recent match wins (most likely to reflect current
context, e.g. a loop the model is currently in). Returns the
tokens that followed that occurrence, truncated to
max_draft_len.
Trait Implementations§
Source§impl Clone for PromptLookupSpeculator
impl Clone for PromptLookupSpeculator
Source§fn clone(&self) -> PromptLookupSpeculator
fn clone(&self) -> PromptLookupSpeculator
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 PromptLookupSpeculator
Source§impl Debug for PromptLookupSpeculator
impl Debug for PromptLookupSpeculator
Source§impl Drafter for PromptLookupSpeculator
impl Drafter for PromptLookupSpeculator
Source§fn propose(
&self,
history: &[usize],
_target_hidden: &[f32],
max_len: usize,
) -> DraftBlock
fn propose( &self, history: &[usize], _target_hidden: &[f32], max_len: usize, ) -> DraftBlock
max_len tokens to follow history.
target_hidden is the target model’s final-layer hidden state
for history’s last token, or empty when none is available yet
(which a drafter that needs it must handle by proposing
nothing).Auto Trait Implementations§
impl Freeze for PromptLookupSpeculator
impl RefUnwindSafe for PromptLookupSpeculator
impl Send for PromptLookupSpeculator
impl Sync for PromptLookupSpeculator
impl Unpin for PromptLookupSpeculator
impl UnsafeUnpin for PromptLookupSpeculator
impl UnwindSafe for PromptLookupSpeculator
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