Skip to main content

DraftModelSpeculator

Struct DraftModelSpeculator 

Source
pub struct DraftModelSpeculator { /* private fields */ }
Expand description

A Drafter backed by a second Decoder.

Owns its own KV caches, entirely separate from the target’s. The two models run over the same token sequence but have different layer counts, head counts and head dimensions, so nothing about the two caches is shared.

Implementations§

Source§

impl DraftModelSpeculator

Source

pub fn keeps_host_kv(&self) -> bool

True when this drafter’s KV really lives in the host caches it owns.

A backend that keeps KV on the device leaves these at zero, and a drafter cannot roll back rows it cannot see. Callers check this after one warm-up rather than discovering it as a wrong accept rate.

Source

pub fn synced_len(&self) -> usize

How many tokens of history this drafter’s KV currently holds. Exposed so a caller can assert the drafter kept up.

Source

pub fn new( decoder: Decoder, target_config: &ModelConfig, sampling: SamplingParams, seed: u64, max_draft: usize, min_prob: f32, ) -> Result<Self, VocabMismatch>

Fails when the two checkpoints cannot be compared token for token. See VocabMismatch.

Trait Implementations§

Source§

impl Drafter for DraftModelSpeculator

Source§

fn propose( &mut self, history: &[usize], _target_hidden: &[f32], max_len: usize, ) -> DraftBlock

Proposes at most 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). Takes &mut self because a drafter that is itself a model carries KV state across calls, and hiding that behind interior mutability would put a runtime borrow check on the hot path to buy nothing. A stateless drafter simply ignores it.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.