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: usizeNumber 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: usizeTotal 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: usizeVerification rounds: forward_calls minus the prefill call.
This is the denominator of the published acceptance length
metric.
drafted_tokens: usizeDraft 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: usizeDraft 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
impl SpeculativeDecodeResult
Sourcepub fn tokens_per_call(&self) -> f64
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.
Sourcepub fn acceptance_length(&self) -> Option<f64>
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.
Sourcepub fn accept_rate(&self) -> Option<f64>
pub fn accept_rate(&self) -> Option<f64>
Fraction of drafted positions accepted, over all positions.
Sourcepub fn accept_rate_per_position(&self) -> Vec<f64>
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
impl Clone for SpeculativeDecodeResult
Source§fn clone(&self) -> SpeculativeDecodeResult
fn clone(&self) -> SpeculativeDecodeResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SpeculativeDecodeResult
impl Debug for SpeculativeDecodeResult
Source§impl Default for SpeculativeDecodeResult
impl Default for SpeculativeDecodeResult
Source§fn default() -> SpeculativeDecodeResult
fn default() -> SpeculativeDecodeResult
Auto Trait Implementations§
impl Freeze for SpeculativeDecodeResult
impl RefUnwindSafe for SpeculativeDecodeResult
impl Send for SpeculativeDecodeResult
impl Sync for SpeculativeDecodeResult
impl Unpin for SpeculativeDecodeResult
impl UnsafeUnpin for SpeculativeDecodeResult
impl UnwindSafe for SpeculativeDecodeResult
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