Paper Breakdowns  /  Medusa
Paper 57~11 min read2024worked math + runnable code
Paper Breakdown

Medusa,
explained.

Speculative decoding made generation faster, but it came with baggage: a whole second "draft" model to train, serve, and keep in sync. Medusa asked whether the big model could just draft for itself. Its answer: bolt a few extra prediction heads onto the model, each guessing a token further ahead, and let it propose several future tokens in a single pass — then verify them all at once. No draft model, real speedup. Here's the multi-head trick and the arithmetic of how much it buys.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

The draft-model tax

Recall the bottleneck: language models generate one token at a time, and each token forces the whole model to be read from memory, leaving the hardware's compute mostly idle. Speculative decoding fills that idle compute by having a small, fast draft model guess several tokens ahead, which the big model then verifies in parallel. It works — but the draft model is a real operational cost. You have to find or train one that is both cheap and well-aligned with the target, serve it alongside, and maintain the pairing as models change.

Medusa removes the second model. Its insight: the big model already computes a rich hidden state at each position — enough, with a little extra machinery, to predict not just the next token but the one after, and the one after that. So instead of a separate drafter, give the model a few lightweight heads that read that hidden state and guess further ahead. The model drafts for itself.

The one-sentence version

Add a few extra prediction heads to the model so it guesses several tokens ahead in one pass, then verifies them — speculative decoding with no separate draft model.

02

Prediction heads

A standard model has one output head predicting the next token. Medusa adds K more, each a small feed-forward layer on the same final hidden state, trained to predict the token at position +2, +3, …, +K+1. They are cheap to add (the backbone is frozen; only the heads train) and cheap to run (a few extra small layers). In one forward pass, the model now emits its usual next token plus K guesses for the tokens beyond it.

The catch is accuracy. Predicting the very next token is relatively easy; predicting five tokens ahead, with all the uncertainty of the words in between, is much harder. So head accuracy fades with distance — the first head is fairly reliable, later heads much less so. That decay is exactly what governs how many tokens Medusa can actually keep per pass, and it's the number the math below tracks.

03

Tree attention

Because the far heads are unsure, betting everything on their single top guess is wasteful — often it's wrong, and the whole speculation stops there. Medusa hedges: each head proposes its top few candidates, and the combinations form a tree of possible continuations (this head's option A followed by that head's options X or Y, and so on). A single guess per head accepts if it's right with probability a; offering s candidates accepts if any of them is right — probability 1 − (1 − a)s, which climbs fast.

The clever part is verifying this whole tree in one forward pass. Medusa builds a special attention mask — tree attention — so that each candidate token only attends to its own ancestors in the tree, letting many candidate paths be scored simultaneously without interfering. One pass, many hypotheses checked, and the longest fully-correct path is accepted. It is how Medusa turns uncertain heads into reliable speedups.

04

Verify and accept

Verification keeps the output honest. The tree of candidates is scored by the true model, and Medusa accepts the longest path whose tokens the model agrees with — falling back to the guaranteed correct next token when the heads miss. With greedy acceptance, a position is only kept if every head before it was also right, so each head's contribution is the cumulative product of accuracies. Summing those, plus the always-correct base token, gives the expected tokens per pass:

𝔼[tokens/pass] = 1 + Σi ( a1 · a2 ⋯ ai )  ·  tree accept per head = 1 − (1 − a)s

Because each term multiplies one more (sub-1) accuracy, later heads add less and less — a fading geometric-like series. With four heads at accuracies 0.8/0.65/0.5/0.35 the model produces ~2.7 tokens per pass instead of 1; perfect heads would give K+1. Tree candidates raise each head's effective accuracy toward 1, pushing the sum higher. Crucially, the accepted tokens are exactly the model's own, so — like draft-model speculation — the output is lossless. The runnable version below computes both formulas.

RUN IT YOURSELF

Heads, accuracy decay, and tokens per pass

Medusa's speedup is a fading product you can compute. This sums each head's contribution — the cumulative product of accuracies, since a position is kept only if every earlier head was right — and shows four decaying heads yielding ~2.7 tokens per pass, no heads giving exactly 1, and perfect heads hitting the K+1 ceiling. It also prices tree attention: offering more candidates per head raises its acceptance via 1−(1−a)ˢ, from 0.6 to 0.97 at four candidates. Change the head accuracies or candidate count and watch the tokens-per-pass move.

CPython · WebAssembly
05

The trade-offs

Medusa and draft-model speculative decoding are two routes to the same goal; each has a personality:

AspectMedusa
No draft modelNothing extra to train, serve, or keep aligned — the big model drafts for itself.
Cheap to addA few small heads trained on top of a frozen backbone (Medusa-1); optionally fine-tuned jointly (Medusa-2).
Head accuracy limits reachFar heads are weak, so gains taper — tree attention props them up but there's a ceiling.
~2–3× speedupLossless or near-lossless, with a simpler serving stack than a two-model setup.

Where a well-matched draft model can sometimes propose longer accurate runs, Medusa wins on operational simplicity — one model, a handful of heads, no second system. For many deployments that trade is exactly right.

06

Where it fits

Medusa is part of a fast-moving family of self-speculative decoding methods — including EAGLE, Hydra, and lookahead decoding — all aiming to get speculative decoding's speed without the burden of a separate draft model. They differ in how they draft (extra heads, feature-space prediction, n-gram pools) but share the skeleton established by speculative decoding: propose cheaply, verify in parallel, keep what's correct.

Its contribution to that lineage is a clean, practical recipe: reuse the model's own hidden state through lightweight heads, and hedge their uncertainty with tree attention. That combination — self-drafting plus batched candidate verification — turned out to be a sweet spot of simplicity and speed, and it's why Medusa became a widely-used, easy-to-adopt inference accelerator.

Worth knowing

Because Medusa's heads sit on the model's own hidden states, they can be trained on a modest dataset in hours on a single machine — you don't retrain the base model, just teach a few heads to read what it already computes.

Frequently asked

Quick answers

What is Medusa in one line?

Extra prediction heads on an LLM that guess several tokens ahead in one pass, verified together via tree attention — speculative decoding with no separate draft model.

Why do later heads help less?

Predicting further ahead is harder, so head accuracy fades with distance. A position is kept only if all earlier heads were right, so contributions are a shrinking cumulative product.

What is tree attention for?

Each head proposes several candidates forming a tree; a special mask verifies all paths in one pass, so a correct path can be accepted even when the top guess was wrong.

Is the output changed?

No — accepted tokens are the model's own, verified against it, so generation is lossless (or near-lossless), just faster: roughly 2–3×.

Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads · Cai, Li, Geng, Peng, Lee, Chen, Dao · 2024 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns