Search

Search papers and lessons

EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty

Yuhui Li, Fangyun Wei, Chao Zhang et al. · 2024

EAGLE makes a large language model write faster without changing its output, by drafting at the feature level and feeding in the next sampled token.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Probability
  • Neural network basics
  • Linear algebra
  • Architectures
  • ReadReady to readNot yet

TL;DR

EAGLE (Extrapolation Algorithm for Greater Language-model Efficiency) is a way to make a large language model (LLM) write faster without changing what it writes. A small extra network, the draft head, guesses several future tokens from the big model's internal state, and the big model checks all the guesses in one pass. The paper's two observations are that guessing the internal state is simpler than guessing words, and that the guess improves once the head also sees the word sampled one step earlier. On LLaMA2-Chat 70B the method reached a 2.7x to 3.5x speedup, and the output distribution is preserved.

Builds on: Speculative Decoding, Transformer, Autoregressive Model, Softmax · Leads to: the head-based alternatives it is measured against, Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads and Accelerating Large Language Model Decoding with Speculative Sampling

Why it mattered

Chat assistants and code tools generate one token at a time, and each token needs a full pass through a model with billions of weights. The bottleneck is reading those weights from memory, not the arithmetic. Speculative sampling attacks this by letting a cheap draft propose several tokens that the expensive model verifies together. EAGLE was one of the more widely cited methods in that family in 2024, and it keeps the output distribution equal to the big model's own output. The paper reports 2.7x to 3.5x speedups for LLaMA2-Chat 70B and about 2x throughput. Its training is cheap: a draft head under 1 billion parameters, trained in one to two days on four A100 (40G) GPUs for the 70B model.

Speculative sampling normally uses a separate small draft model. The paper notes that for LLaMA2 7B there is no suitable smaller sibling, and that a 7B draft for a 13B target gave no speedup in its tests.

The problem

Speculative decoding needs a draft that is much cheaper than the target model and still often agrees with it. Two obstacles made this hard for the LLaMA2 and Vicuna families.

  1. Cheap drafts were inaccurate. Medusa predicts tokens from the big model's features with a set of small heads and reaches an acceptance accuracy of about 0.6. Lookahead is lower still. A wrong draft wastes the verification pass.
  2. Training a new small model from scratch is expensive. The paper compares TinyLLaMA, trained on 3,000 billion tokens, with EAGLE, trained on 2 to 4 billion tokens.

The question the paper asks is how to make a draft accurate using only the big model's own features and a small training budget.

How it works

Take one tiny instance. The prompt so far ends with the word "I", and the model must choose the next word. Two words are likely, "am" and "always". Plain decoding runs the whole model once to choose one word, then again for the next.

  1. The big model reads the prompt. For the position of "I" it produces a feature vector fIf_I. A feature is the second-to-top layer's hidden state, the vector just before the output layer. The output layer (the LM head) turns fIf_I into probabilities over all words.

  2. The draft head guesses the next feature. EAGLE's draft head is one transformer decoder layer. Its input is the feature fIf_I together with the embedding of a candidate word. For the candidate "am" it predicts a feature famf_{am} from (fI,tam)(f_I, t_{am}), and for "always" it predicts falwaysf_{always} from (fI,talways)(f_I, t_{always}). Check: two candidates, two predicted features, one extra input each.

  3. Why the candidate word is part of the input. Features are continuous vectors, and the feature after "I" depends on which word actually follows. "am" and "always" lead to different feature vectors, so fIf_I alone cannot say which comes next. Adding the word tells the head which branch it is on. This is the paper's main idea. The paper's ablation (Figure 4, Vicuna 7B, temperature 0) finds that adding the shifted token to the features gives the largest gain of the input choices it tests.

  4. The LM head turns features into words, and the draft grows a tree. The big model's LM head, shared and not retrained, converts each predicted feature into word probabilities. The draft samples words from them and feeds the new (feature, word) pair back in. Each draft pass extends the tree one level deeper. Check: a draft tree of depth mm comes from mm draft passes and holds more than mm tokens.

  5. The big model checks the whole tree at once. Tree attention lets each candidate token see only its own ancestors in the tree. One forward pass of the big model gives the true probabilities at every node.

  6. Accept or reject. Walk down the branches. A candidate word is accepted with a probability that compares the big model's probability with the draft's. If it is rejected, a replacement word is drawn from the part of the big model's distribution the draft missed. Accepted words stay, and the next draft starts from the last accepted feature.

  7. Output. Each big-model pass now produces several words, not one. On MT-bench with Vicuna 7B at temperature 0, the average is 3.94 accepted tokens per pass (Table 2), against 1 for plain decoding.

The flow of one round:

flowchart LR
  A[Accepted features and words] --> B[Draft head predicts next features]
  B --> C[LM head samples candidate words, grows a tree]
  C --> D[Big model verifies the whole tree in one pass]
  D --> E[Accept or resample each word]
  E --> A

The acceptance step is where randomness meets the big model's probabilities. For a word that the draft proposed with probability 0.5, the chance of keeping it depends on the big model's probability for that word:

00.20.40.60.8100.20.40.60.81big-model probability pacceptance probability
  • draft probability 0.5
  • draft probability 0.2
A word the draft favours more than the big model is kept only part of the time. The marked point is p = 0.2 against a draft probability of 0.5: kept with probability 0.4.

The math

Definition: Feature and token notation

A feature fjf_j is the hidden vector at position jj, just before the LM head. A token tjt_j is a word, and its embedding eje_j is the learned vector for it. The big model maps the token sequence T1:jT_{1:j} to features F1:jF_{1:j}, and the LM head maps fjf_j to a distribution pj+1=LM head(fj)p_{j+1} = \text{LM head}(f_j) over the next word. The draft model's guesses carry a hat: f^\hat f and p^\hat p.

Step 1 in symbols: the big model's distribution

For a position jj, the target distribution is pj+1=LM head(fj)p_{j+1} = \text{LM head}(f_j), and vanilla decoding samples tj+1t_{j+1} from it. This costs one expensive pass per word.

Step 2 in symbols: the draft prediction

The draft head DD takes the feature history and the tokens shifted one position ahead:

f^i+1=D(F1:i, T2:i+1).\hat f_{i+1} = D\big(F_{1:i},\ T_{2:i+1}\big).

F1:iF_{1:i} is the feature history, and T2:i+1T_{2:i+1} is the token sequence advanced by one position, so it includes the word sampled for position i+1i+1. The draft word distribution is p^i+2=Softmax(LM head(f^i+1))\hat p_{i+2} = \text{Softmax}(\text{LM head}(\hat f_{i+1})).

Step 3 in symbols: training the draft head

The loss has two parts. The regression loss matches the predicted feature to the true one. The Smooth L1 distance acts like squared error for small gaps and like absolute error for large ones:

Lreg=SmoothL1(fi+1, f^i+1).L_{reg} = \text{SmoothL1}\big(f_{i+1},\ \hat f_{i+1}\big).

The classification loss matches the predicted word distribution to the big model's:

pi+2=Softmax(LM head(fi+1)),Lcls=CE(pi+2, p^i+2).p_{i+2} = \text{Softmax}\big(\text{LM head}(f_{i+1})\big), \qquad L_{cls} = \text{CE}\big(p_{i+2},\ \hat p_{i+2}\big).

The total is L=Lreg+wclsLclsL = L_{reg} + w_{cls} L_{cls} with wcls=0.1w_{cls} = 0.1. The paper chooses this weight because the classification loss is about ten times larger in value. Training uses a fixed set of ShareGPT dialogues rather than text generated by the big model. During training, uniform noise from U(−0.1,0.1)\mathcal{U}(-0.1, 0.1) is added to the big model's features so that small errors do not build up over several draft steps.

Step 4 in symbols: the acceptance rule

A candidate word t^\hat t with draft probability p^(t^)\hat p(\hat t) is accepted with probability

α=min⁡(1, p(t^)p^(t^)).\alpha = \min\left(1,\ \frac{p(\hat t)}{\hat p(\hat t)}\right).

If it is rejected, a replacement is drawn from the normalised positive part of the difference:

resample∼norm(max⁡(0, p−p^)),\text{resample} \sim \text{norm}\big(\max(0,\ p - \hat p)\big),

where norm divides by the total so the numbers sum to 1. This is the speculative sampling rule. The paper relies on the proof that the combined procedure samples exactly from the big model, so EAGLE needs no approximation.

Worked numbers

Example
1. A three-word case, by hand

Words: am, always, the. The big model gives p=(0.2, 0.5, 0.3)p = (0.2,\ 0.5,\ 0.3). The draft gives p^=(0.5, 0.2, 0.3)\hat p = (0.5,\ 0.2,\ 0.3). Both sum to 1.

  1. The draft proposes "am", with draft probability p^=0.5\hat p = 0.5.
  2. Acceptance probability: min⁡(1, 0.2/0.5)=min⁡(1, 0.4)=0.4\min(1,\ 0.2 / 0.5) = \min(1,\ 0.4) = 0.4.
  3. With probability 0.4 "am" is kept. With probability 0.6 it is rejected.
  4. Residual after rejection: max⁡(0, p−p^)=(0, 0.3, 0)\max(0,\ p - \hat p) = (0,\ 0.3,\ 0). Its total is 0.3.
  5. Normalised: (0, 1, 0)(0,\ 1,\ 0), so the replacement is "always" for certain.

Check that the output matches the big model. The chance of "am" overall is 0.5×0.4=0.20.5 \times 0.4 = 0.2, which equals p(am)=0.2p(\text{am}) = 0.2. The chance of "always" is 0.20.2 from the draft's own proposal (accepted with probability 1, because 0.5/0.20.5 / 0.2 exceeds 1) plus 0.30.3 from rejected "am" steps, a total of 0.5=p(always)0.5 = p(\text{always}). The word "the" gets 0.30.3, matching p(the)p(\text{the}).

Example
2. The standard case: tokens per pass against speedup

Table 2 gives Vicuna 7B at temperature 0 on MT-bench an average of τ=3.94\tau = 3.94 accepted tokens per pass of the big model. Plain decoding gives 1 token per pass.

  1. Gain counting only passes: 3.94/1=3.943.94 / 1 = 3.94 times more tokens per big-model pass.
  2. Measured gain at batch size 1 for the same model and benchmark (Table 7): 2.90 times.
  3. The gap is 3.94/2.90≈1.363.94 / 2.90 \approx 1.36. Each token costs about 36 percent more time than the pass count suggests.
  4. The paper does not break the gap down. A likely source is the cost of running the draft head and checking a larger tree.

Try it: the tree version has τ=3.94\tau = 3.94 and the chain version has τ=3.20\tau = 3.20 (Table 5, Vicuna 7B). How many extra accepted tokens per pass does the tree add? Answer: 3.94−3.20=0.743.94 - 3.20 = 0.74, the "+0.74" the paper reports.

Example
3. The realistic case: a 70B chat reply

Suppose a reply of 300 tokens from LLaMA2-Chat 70B, and suppose vanilla decoding runs at 20 tokens per second (an assumed number for this example, not a measurement). Table 7 gives speedups of 3.01 at batch size 1 and 2.40 at batch size 4.

  1. Vanilla time: 300/20=15300 / 20 = 15 seconds.
  2. With EAGLE at batch size 1: 15/3.01≈4.9815 / 3.01 \approx 4.98 seconds.
  3. The same reply when the server handles four requests together, at a 2.40 speedup: 300/(20×2.40)300 / (20 \times 2.40).
  4. Compute the denominator first: 20×2.40=4820 \times 2.40 = 48.
  5. Divide: 300/48=6.25300 / 48 = 6.25 seconds.
  6. Interpretation: batching shrinks the advantage, because the GPU is busier and has less spare capacity to fill.

Try it: with batch size 4 at a speedup of 2.40, how long does a 300-token reply take at 20 tokens per second? Answer: 6.25 seconds.

Results

  • Speed at temperature 0 on MT-bench. LLaMA2-Chat 70B reached 2.7x to 3.5x. For LLaMA2-Chat 13B the range was 3.01x to 3.76x, and at temperature 1 it was 2.66x to 2.89x. Against the other head-based methods on the same benchmark, EAGLE was 1.70x to 2.08x faster than Lookahead and 1.47x to 1.60x faster than Medusa.
  • Other tasks (Table 1, temperature 0). Vicuna 7B reached 3.33x on HumanEval, 3.01x on GSM8K and 2.79x on Alpaca. Code was the best case, which the paper credits to fixed templates in code that are easy to draft.
  • Acceptance length (Table 2). The big model produced 3.2 to 4.5 tokens per pass across the models tested.
  • Mixture of experts (Table 3). Mixtral 8x7B Instruct reached 1.50x, with an average acceptance length of 3.25. A verification pass can touch more experts than a single token would, which cuts the gain.
  • Combined with fast kernels (Table 4). LLaMA2-Chat 7B on one RTX 3090 went from 24.5 tokens per second (plain Hugging Face, FP16) to 100.2 with EAGLE in FP16 and to 160.4 with EAGLE plus gpt-fast int4.
  • Tree attention (Table 5). The tree added about 0.6 to 0.8 to the acceptance length, and about 0.3 to 0.5 to the speedup.- Batch size and throughput (Table 7). Throughput reached 1.97x for Vicuna 7B and 1.99x for LLaMA2-Chat 70B. At batch size 1 the speedups were 2.90x and 3.01x, falling to 2.76x and 2.40x at batch size 4.
  • Training data (Table 6). A fixed dataset gave 2.78x, and data from the target model gave 2.88x. The gap is small, which supports the cheap fixed dataset.
  • Baseline check. With a 7B model as the draft for the 33B and 70B models, the paper reports 1.12x and 1.88x. The limitation is the draft's overhead, not its accuracy.

Limits. Most results are at batch size 1 and on specific GPUs, so the numbers describe those settings. Memory matters: on a 24 GB RTX 3090 with Vicuna 7B, the largest batch was 8 for plain decoding and 7 for EAGLE. The method preserves the distribution by construction, so the paper does not score output quality. Its speedups are also smaller on mixture-of-experts models and at larger batch sizes.

Reading guide

Check yourself

QuestionRecall: what are the two inputs the EAGLE draft head receives at each step?Show answer

The feature of the current position from the big model, and the token embedding of a word advanced by one position (the word sampled for the next step). Giving it the word resolves the uncertainty that comes from the next feature depending on which word is sampled.

QuestionA draft proposes a word with draft probability p^=0.25\hat p = 0.25, and the big model gives it p=0.10p = 0.10. What is the acceptance probability?Show answer

min⁡(1, 0.10/0.25)=min⁡(1, 0.4)=0.4\min(1,\ 0.10 / 0.25) = \min(1,\ 0.4) = 0.4. The word is kept with probability 0.4.

QuestionWhy does the output stay the same as the big model's, even though a draft is used?Show answer

The acceptance rule keeps a draft word with probability min⁡(1,p/p^)\min(1, p/\hat p), and on rejection draws a replacement from norm(max⁡(0,p−p^))\text{norm}(\max(0, p - \hat p)). Together these sample exactly from the big model's distribution, so the draft changes how many passes are needed, not the distribution of the output.

QuestionWhy does the speedup fall as batch size rises, and what does that suggest about where it comes from?Show answer

Speculative decoding wins when one token per pass leaves the GPU underused. With more requests in a batch the GPU is already busy, so verifying extra tokens costs more, and the speedup falls (3.01 at batch size 1, 2.40 at batch size 4 for LLaMA2-Chat 70B). The gain comes from spare compute, not from less work per token.

QuestionScenario: a team serves one 13B chat model to one user at a time on a single GPU. Is EAGLE's training cost likely worth it?Show answer

Probably yes. The paper trains a 13B draft head of about 0.37 billion parameters in one to two days on an RTX 3090 node, and batch size 1 is where its speedups are largest. The team should still measure on its own workload, because the paper's numbers come from its benchmarks.

Sources

Read the full paper

Yuhui Li, Fangyun Wei, Chao Zhang et al., 2024. arXiv:2401.15077