Skip to main content

SpeculativeDecodeResult

Struct SpeculativeDecodeResult 

Source
pub struct SpeculativeDecodeResult {
    pub generated_tokens: Vec<usize>,
    pub forward_calls: usize,
    pub tokens_generated: usize,
    pub verification_steps: usize,
    pub drafted_tokens: usize,
    pub accepted_tokens: usize,
    pub evaluated_at_position: Vec<usize>,
    pub accepted_at_position: Vec<usize>,
}
Expand description

Result of a speculative decode run, with the counters that make its actual savings observable rather than just assumed.

Fields§

§generated_tokens: Vec<usize>§forward_calls: usize

Number of Decoder::forward_batch calls made (prefill counts as one call, each subsequent accept/reject round counts as one more, regardless of how many tokens that round produced).

§tokens_generated: usize

Total tokens produced across all rounds – always equal to generated_tokens.len(), kept as a separate field so the ratio tokens_generated / forward_calls (the actual speedup metric) is easy to read directly off this struct.

§verification_steps: usize

Verification rounds: forward_calls minus the prefill call. This is the denominator of the published acceptance length metric.

§drafted_tokens: usize

Draft tokens the target actually evaluated. Positions past a rejection are never evaluated, so they are not counted here – counting them would deflate the accept rate by the drafter’s block size rather than by its accuracy.

§accepted_tokens: usize

Draft tokens accepted.

§evaluated_at_position: Vec<usize>

Per drafted position (0 = first token after the anchor), how many times that position was evaluated, i.e. reached without an earlier rejection ending the round.

§accepted_at_position: Vec<usize>

Per drafted position, how many times it was accepted.

Implementations§

Source§

impl SpeculativeDecodeResult

Source

pub fn tokens_per_call(&self) -> f64

Average tokens produced per forward_batch call. 1.0 means speculation never helped (every round produced exactly the anchor token); higher means draft tokens were accepted.

Source

pub fn acceptance_length(&self) -> Option<f64>

The published metric: completion tokens per verification step. None when nothing was verified (an empty run), because a zero there would read as “speculation made things worse” rather than “speculation did not run”.

Deliberately not the same number as Self::tokens_per_call, which charges the one-off prefill call against the average and so understates a short run.

Source

pub fn accept_rate(&self) -> Option<f64>

Fraction of drafted positions accepted, over all positions.

Source

pub fn accept_rate_per_position(&self) -> Vec<f64>

Accept rate at each drafted position, conditional on that position having been reached.

A single mean cannot distinguish a drafter that is uniformly mediocre from one that is excellent at position 0 and useless by position 7, and the two want opposite responses (raise the block size, or lower it). The published motivation for dFlash2’s two-tap convolution is exactly this curve falling from 99.5% to 87.8% across a block, so it has to be visible per position or the diagnosis is not testable here.

Trait Implementations§

Source§

impl Clone for SpeculativeDecodeResult

Source§

fn clone(&self) -> SpeculativeDecodeResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpeculativeDecodeResult

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for SpeculativeDecodeResult

Source§

fn default() -> SpeculativeDecodeResult

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, <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.