Speculative Decoding Math: Algorithms & Speedup Limits › Optimal Draft Length
Language AI HandbookAll chapters Speculative Decoding Math: Algorithms & Speedup Limits › Optimal Draft LengthOne section · Sections in this chapter6 / 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
Choosing the draft length involves balancing the cost of generating more drafts against the diminishing probability of accepting them all. This optimization problem has both theoretical and practical importance. In theory, it determines the maximum achievable speedup for a given model pair and hardware configuration. In practice, it guides the single most important configuration choice when deploying speculative decoding.
The optimal draft length is not fixed. It depends on the acceptance probability (which varies by task and context), the cost ratio (which depends on hardware and model sizes), and potentially on dynamic factors like recent acceptance rate history. Understanding these dependencies allows you to make good static choices and design adaptive strategies that respond to changing conditions.
The Optimization Problem
We want to find that maximizes speedup. Substituting our formula for , the optimization problem is:
where:
- : optimal draft length
- : expected tokens generated with draft length
- : cost ratio
Taking the derivative with respect to and setting to zero is analytically intractable because is an integer, but we can analyze the continuous relaxation and then round to find the optimal integer value. The continuous analysis reveals the structure of the problem and shows why an interior optimum always exists for finite .
Diminishing Returns
The expected tokens grows sublinearly in . This can be seen from the geometric series formula:
where:
- : expected tokens for draft length
- : asymptotic limit of expected tokens as grows without bound
- : acceptance probability
The growth rate decreases exponentially because decays exponentially. Meanwhile, the cost grows linearly in . This tension creates an interior optimum. Intuitively, each additional draft token has a diminishing marginal benefit (it is only useful if all previous tokens were accepted, which becomes increasingly unlikely) but a constant marginal cost (one more draft model forward pass). At some point, the marginal cost exceeds the marginal benefit, and we should stop drafting.
Think of it as a classic diminishing returns problem. The first draft token you add is very valuable because there is a high probability it gets accepted (). The second draft token is somewhat less valuable because it only contributes when the first was also accepted ( probability of usefulness). The tenth draft token only contributes when all nine preceding tokens were accepted ( probability), which for is only about 10.7%. At some point, the additional draft tokens contribute so rarely that running the draft model to generate them costs more than it saves.
Approximate Optimal
For large (fast draft model), we can derive an approximate optimal draft length. When , the optimal is infinite since there's no cost to drafting more tokens. For finite , the optimal satisfies the first-order condition from setting the derivative of the speedup function to zero. Treating as continuous and applying the quotient rule:
where:
- : acceptance probability
- : draft length
- : cost ratio
- : derivative of the numerator term (positive since for )
- : derivative of the denominator term
- : squared denominator from the quotient rule
Setting the numerator to zero gives:
where:
- : acceptance probability
- : draft length
- : cost ratio
- : marginal gain from extending the draft by one position
- Right side: normalized marginal cost of extension
This equation balances marginal benefit against marginal cost. The left side represents the expected additional tokens from extending the draft by one position (how often does the th token get accepted, and how much does that help). The right side represents the cost of that extension in terms of reduced speedup per existing token. While this equation cannot be solved in closed form, it can be solved numerically for any specific values of and .
For typical values (, ), optimal ranges from 4 to 8 tokens. This explains why practical systems typically use draft lengths in this range. The formula predicts that using is close to optimal for many common configurations, which is why it has become a common default setting in speculative decoding implementations.
Adaptive Draft Length
In practice, the optimal varies based on context. Different parts of a response have different acceptance rates: the beginning of a sentence is often more predictable than the middle, and common phrases have much higher acceptance rates than rare ones. Systems that use a fixed throughout generation leave performance on the table because they cannot adjust to these variations.
Practical adaptive strategies include:
- Fixed : Simple to implement, works well when acceptance rates are stable. A good default for production systems where simplicity matters.
- Adaptive : Adjust based on recent acceptance rates. If the last several iterations had high acceptance rates, increase ; if rates were low, decrease . This can improve average throughput by 10-20% over fixed in practice.
- Tree-based drafting: Generate multiple candidate continuations as a tree rather than a single sequence, increasing effective acceptance probability. When the draft model is uncertain about the best next token, it can propose several alternatives, and the target model accepts the best match. This approach trades increased memory usage for higher effective acceptance rates.
The adaptive approach monitors acceptance rates during generation and increases when rates are high (showing the draft model is performing well on the current content) or decreases when rates are low (showing more challenging content where longer drafts would be wasteful). Implementing this correctly requires careful bookkeeping to avoid introducing biases from the adaptation process itself, but when done correctly, it maintains the exact-sampling guarantee while improving average throughput.