Speculative Decoding Math: Algorithms & Speedup Limits › Expected Speedup Analysis

Michael BrenndoerferJanuary 17, 202610 min read
Language AI HandbookAll chapters
Part 42 of 67Inference Optimization
Chapter 324Speculative Decoding Math: Algorithms & Speedup Limits › Expected Speedup Analysis
Reading section 4 of 11 · Expected Speedup Analysis · 10 minSection 4 of 11 · 10 min

Book contents

Section 4 of 11 · 10 min read

Speculative Decoding Math: Algorithms & Speedup Limits › Expected Speedup AnalysisOne section · Sections in this chapter4 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Understanding the expected speedup from speculative decoding requires analyzing how many tokens we expect to accept from each draft sequence and how this translates to wall-clock improvements. This analysis provides both theoretical insights and practical guidance for deploying speculative decoding systems.

The speedup analysis connects the abstract acceptance probability to concrete performance numbers. You might wonder why we need a full mathematical treatment rather than just running experiments. The answer is that experiments can only test specific configurations, while the mathematical framework reveals the basic tradeoffs. It tells us how speedup depends on draft model quality, draft length, and the relative speed of the two models. Armed with this formula, you can predict performance for new model pairs without running extensive benchmarks, and you can optimize configuration choices analytically.

Think of the speedup formula as a budget analysis. Each speculative decoding iteration has a cost (running the draft model multiple times and the target model once) and a benefit (generating multiple tokens in one iteration). The ratio of benefit to cost is the speedup. The mathematical framework makes this ratio precise and reveals how each parameter affects the balance.

Token Acceptance Probability

Let α\alpha denote the average acceptance probability for a single token. Under simplifying assumptions where each position has the same acceptance rate, we can derive a clean expression for this probability. While real-world acceptance rates vary by position and context, this i.i.d. assumption provides valuable analytical insights and gives formulas that match empirical measurements reasonably well when using the observed acceptance rate as the input.

The expected acceptance probability α\alpha is computed by averaging over all tokens that the draft model might propose, weighting each token's acceptance probability by how often the draft model proposes it:

α=Ex∼q[min⁡(1,p(x)q(x))](definition of expectation)=∑xq(x)⋅min⁡(1,p(x)q(x))(expand expectation)=∑xmin⁡(q(x),q(x)⋅p(x)q(x))(distribute q(x))=∑xmin⁡(q(x),p(x))(simplify)\begin{aligned} \alpha &= \mathbb{E}_{x \sim q}\left[\min\left(1, \frac{p(x)}{q(x)}\right)\right] && \text{(definition of expectation)} \\ &= \sum_x q(x) \cdot \min\left(1, \frac{p(x)}{q(x)}\right) && \text{(expand expectation)} \\ &= \sum_x \min\left(q(x), q(x) \cdot \frac{p(x)}{q(x)}\right) && \text{(distribute } q(x) \text{)} \\ &= \sum_x \min(q(x), p(x)) && \text{(simplify)} \end{aligned}

where:

  • α\alpha: expected acceptance probability
  • Ex∼q\mathbb{E}_{x \sim q}: expectation over tokens proposed by the draft model
  • q(x)q(x): draft model probability of token xx
  • p(x)p(x): target model probability of token xx
  • ∑xmin⁡(q(x),p(x))\sum_x \min(q(x), p(x)): total probability mass overlap between the two distributions

This quantity measures the overlap between the draft and target distributions. When the distributions are identical, α=1\alpha = 1. When they are completely disjoint, α=0\alpha = 0. In practice, α\alpha typically falls between 0.6 and 0.9 for well-matched draft and target model pairs. Because α\alpha equals the distribution overlap, it directly measures draft model quality from first principles and connects acceptance rates to the statistical notion of distributional similarity.

Expected Accepted Tokens

Given a draft of length kk, the number of accepted tokens follows a truncated geometric distribution. This distribution arises because we accept tokens sequentially until the first rejection, but we stop at position kk even if no rejection has occurred. Under the i.i.d. assumption with uniform acceptance probability α\alpha, the probability that the first jj tokens are all accepted is αj\alpha^j, and the probability of a rejection at position j+1j+1 is αj(1−α)\alpha^j(1-\alpha).

Let NN be the number of tokens we generate (accepted drafts plus one from rejection sampling or the (k+1)(k+1)th position). The expected value is:

E[N]=∑i=1ki⋅αi−1(1−α)+(k+1)⋅αk\mathbb{E}[N] = \sum_{i=1}^{k} i \cdot \alpha^{i-1}(1-\alpha) + (k+1) \cdot \alpha^k

where:

  • E[N]\mathbb{E}[N]: expected number of accepted tokens (plus one verification)
  • kk: draft sequence length
  • α\alpha: probability of accepting a single token
  • ii: position of the first rejection
  • αi−1(1−α)\alpha^{i-1}(1-\alpha): probability that the first rejection occurs at position ii
  • (k+1)⋅αk(k+1) \cdot \alpha^k: contribution from the case where all kk tokens are accepted

The first term accounts for rejecting at position ii (we keep ii tokens including the resampled one). The second term accounts for accepting all kk drafts (we get k+1k+1 tokens including the bonus verification token).

We can simplify this sum by observing that NN is 1 plus the count of accepted draft tokens. Since the probability of accepting the first jj tokens is αj\alpha^j for all j≤kj \le k (under the simplified i.i.d. assumption), we can use the linearity of expectation:

E[N]=1+∑j=1kP(token j is accepted)(linearity of expectation)=1+∑j=1kαj(i.i.d. assumption)=∑j=0kαj(include j=0 term)=1−αk+11−α(geometric series sum)\begin{aligned} \mathbb{E}[N] &= 1 + \sum_{j=1}^{k} P(\text{token } j \text{ is accepted}) && \text{(linearity of expectation)} \\ &= 1 + \sum_{j=1}^{k} \alpha^j && \text{(i.i.d. assumption)} \\ &= \sum_{j=0}^{k} \alpha^j && \text{(include } j=0 \text{ term)} \\ &= \frac{1 - \alpha^{k+1}}{1 - \alpha} && \text{(geometric series sum)} \end{aligned}

where:

  • E[N]\mathbb{E}[N]: closed-form expected number of tokens generated per iteration
  • α\alpha: acceptance probability
  • kk: draft length
  • 1−αk+11−α\frac{1 - \alpha^{k+1}}{1 - \alpha}: sum of the geometric series 1+α+α2+⋯+αk1 + \alpha + \alpha^2 + \cdots + \alpha^k

This closed-form expression shows that expected tokens per iteration grow as a geometric series in the acceptance probability. When α\alpha is close to 1, almost all draft tokens are accepted, and E[N]\mathbb{E}[N] approaches k+1k+1. When α\alpha is close to 0, most drafts are rejected immediately, and E[N]\mathbb{E}[N] approaches 1 (we generate just one token from the residual distribution). The geometric series structure is key: each additional draft token contributes αj\alpha^j to the expected yield, which decays exponentially with position, creating natural diminishing returns at longer draft lengths.

Out[4]:
Visualization
Line chart showing expected tokens E[N] on the y-axis versus acceptance probability alpha on the x-axis for k values of 1, 3, 5, and 10; curves rise sharply toward their respective k+1 asymptotes as alpha approaches 1.
Expected number of valid tokens generated per iteration as a function of acceptance probability for different draft lengths. The expected yield scales as a geometric sum of the acceptance probability, approaching the maximum limit of k+1 tokens as the draft model quality nears perfection. Higher acceptance probabilities allow longer drafts to generate near-maximum yields.

The Speedup Formula

Let cc be the cost ratio, defined as the time for one target model forward pass divided by the time for one draft model forward pass. Typically c≫1c \gg 1 since the target model is much larger. For example, if the target model has 70 billion parameters and the draft model has 7 billion parameters, we might expect cc to be roughly 10, depending on hardware and batching configurations. In memory-bandwidth-limited regimes (which describes most autoregressive inference), cc scales roughly with the ratio of model parameter counts.

Without speculative decoding, generating nn tokens requires nn target model passes, taking time n⋅Ttargetn \cdot T_{\text{target}}. This is the baseline we are trying to beat. Each token requires a full forward pass through the large model, with no opportunity for parallelism across tokens in standard autoregressive generation.

With speculative decoding, each iteration requires:

  • One draft model pass generating kk tokens, taking time k⋅Tdraftk \cdot T_{\text{draft}}
  • One target model pass verifying all kk positions, taking time TtargetT_{\text{target}}

The iteration produces E[N]=1−αk+11−α\mathbb{E}[N] = \frac{1 - \alpha^{k+1}}{1 - \alpha} tokens on average and takes time Ttarget+k⋅Tdraft=Ttarget(1+k/c)T_{\text{target}} + k \cdot T_{\text{draft}} = T_{\text{target}}(1 + k/c).

The speedup ratio SS compares how fast we generate tokens with speculative decoding versus standard autoregressive generation. We derive this by computing the time per token under both approaches and taking their ratio. Standard generation takes TtargetT_{\text{target}} per token. Speculative decoding takes Ttarget(1+k/c)/E[N]T_{\text{target}}(1 + k/c) / \mathbb{E}[N] per token. The speedup is:

S=TtargetTtarget(1+k/c)E[N](ratio of time per token)=E[N]1+k/c(cancel Ttarget)=(1−αk+1)/(1−α)1+k/c(substitute E[N])\begin{aligned} S &= \frac{T_{\text{target}}}{\frac{T_{\text{target}}(1 + k/c)}{\mathbb{E}[N]}} && \text{(ratio of time per token)} \\ &= \frac{\mathbb{E}[N]}{1 + k/c} && \text{(cancel } T_{\text{target}} \text{)} \\ &= \frac{(1 - \alpha^{k+1})/(1 - \alpha)}{1 + k/c} && \text{(substitute } \mathbb{E}[N] \text{)} \end{aligned}

where:

  • SS: speedup ratio (values above 1 mean speculative decoding is faster)
  • TtargetT_{\text{target}}: time for standard autoregressive generation per token
  • kk: draft length
  • cc: cost ratio (Ttarget/TdraftT_{\text{target}} / T_{\text{draft}})
  • α\alpha: acceptance probability (used in E[N]\mathbb{E}[N])
  • 1+k/c1 + k/c: cost of one speculative iteration in units of target model passes
  • E[N]\mathbb{E}[N]: average tokens produced per iteration

This formula captures the needed tradeoff in speculative decoding. The numerator measures benefit, specifically how many tokens we expect to generate per iteration. The denominator measures cost, specifically how much computation that iteration requires. Speedup greater than 1 means speculative decoding is faster than standard generation. The formula also shows that speedup depends on all three of α\alpha, kk, and cc in ways that interact: high α\alpha is more valuable when kk is large, and large kk is only worth it when cc is large enough.

When the draft model is very fast (c→∞c \to \infty), this simplifies to:

S≈1−αk+11−αS \approx \frac{1 - \alpha^{k+1}}{1 - \alpha}

where:

  • SS: theoretical maximum speedup with a zero-cost draft model
  • α\alpha: acceptance probability
  • kk: draft length

This limiting case represents the best possible speedup when the draft model adds negligible overhead. In practice, draft models incur costs, so the actual speedup is lower than this bound. However, this formula provides a useful upper limit for what speculative decoding can achieve. When α=0.8\alpha = 0.8 and k=5k = 5, the theoretical maximum speedup is (1−0.86)/(1−0.8)≈3.7×(1 - 0.8^6) / (1 - 0.8) \approx 3.7\times, meaning even with a free draft model, we cannot exceed 3.7 times the speed of standard generation in this configuration.

Out[5]:
Visualization
Line chart with four curves for cost ratios c=5, 10, 20, and 100 showing speedup S on the y-axis versus acceptance probability alpha on the x-axis; a dashed horizontal breakeven line at S=1 marks the minimum acceptance rate required for any speedup benefit.
Theoretical speedup as a function of acceptance probability for different cost ratios, with draft length fixed at k=5. Faster draft models (higher c) enable greater potential speedup, but all configurations require a minimum acceptance probability to surpass the breakeven threshold at S=1. The curves converge toward the theoretical maximum as c grows large.