Skip to main content

SpeculativeDecoder

Struct SpeculativeDecoder 

Source
pub struct SpeculativeDecoder<D: DraftModel, T: TargetModel> { /* private fields */ }
Expand description

Speculative decoder composing a draft model and a target model.

Trait bounds are intentionally deferred to the impl blocks rather than baked into the struct definition so callers can hold a SpeculativeDecoder whose inner models do not implement Debug.

Implementations§

Source§

impl<D: DraftModel, T: TargetModel> SpeculativeDecoder<D, T>

Source

pub fn new( draft: D, target: T, config: SpeculativeDecoderConfig, ) -> SpeculativeDecodingResult<Self>

Build a decoder. Returns an error if the draft and target disagree on vocabulary size, or if the config is invalid.

Source

pub fn metrics(&self) -> &SpeculativeMetrics

Read-only access to the current metrics snapshot.

Source

pub fn reset_metrics(&mut self)

Reset the metrics counters.

Source

pub fn config(&self) -> &SpeculativeDecoderConfig

Read-only access to the configuration.

Source

pub fn generate( &mut self, prefix: &[TokenId], max_tokens: usize, ) -> SpeculativeDecodingResult<Vec<TokenId>>

Run speculative decoding starting from prefix and producing at most max_tokens new tokens. The returned vector contains only the generated continuation, not the original prefix.

Uses an internally-seeded deterministic StdRng (seed 42). See Self::generate_with_rng for caller-controlled seeding.

Source

pub fn generate_with_rng( &mut self, prefix: &[TokenId], max_tokens: usize, rng: &mut dyn SpecRng, ) -> SpeculativeDecodingResult<Vec<TokenId>>

Run speculative decoding with a caller-supplied RNG.

Trait Implementations§

Source§

impl<D: DraftModel + Debug, T: TargetModel + Debug> Debug for SpeculativeDecoder<D, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<D, T> Freeze for SpeculativeDecoder<D, T>
where D: Freeze, T: Freeze,

§

impl<D, T> RefUnwindSafe for SpeculativeDecoder<D, T>

§

impl<D, T> Send for SpeculativeDecoder<D, T>
where D: Send, T: Send,

§

impl<D, T> Sync for SpeculativeDecoder<D, T>
where D: Sync, T: Sync,

§

impl<D, T> Unpin for SpeculativeDecoder<D, T>
where D: Unpin, T: Unpin,

§

impl<D, T> UnsafeUnpin for SpeculativeDecoder<D, T>
where D: UnsafeUnpin, T: UnsafeUnpin,

§

impl<D, T> UnwindSafe for SpeculativeDecoder<D, T>
where D: UnwindSafe, T: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V