Today ainotis Join

My notis

ResearchPublished ExplainedAll news from that day

How speculative decoding lets a small model draft and a large one check

A cheaper model guesses several tokens and a large one checks them in one pass; Mistral's Large 4 model card describes a draft head that does this.

Share

Check our sources · 11 facts from 2 sources
Illustration: A conveyor with a small feeder, a green inspection arch over the belt and a reject chute, standing for a small model drafting and a large one checking.Illustration made with AI for ai notis
source · Illustration made with AI for ai notis; not a picture of what happened

Key points

  1. The speculative decoding paper says decoding K tokens takes K serial runs of the model, and that spare compute is often available because inference is limited by memory bandwidth.
  2. A cheaper model proposes guess tokens and the target model scores them in one parallel pass, so each target run yields at least one new token and up to gamma+1.
  3. The paper says the output distribution equals sampling from the target alone, and reports 2X to 3X acceleration on T5-XXL (11B) at batch size 1 on one TPU-v4.

What happened

A large language model writes text one token at a time. The paper that introduced speculative decoding notes that decoding K tokens takes K serial runs of the model. It adds that inference is often limited by memory bandwidth and communication rather than arithmetic, so spare computing capacity is often available.

Speculative decoding uses that spare capacity. A cheaper approximation model proposes several guess tokens in sequence. The large target model then scores the prefix and all the guesses in one parallel pass. Each guess is accepted or rejected by comparing the two models' probabilities. Guesses that pass are kept in order.

At the first rejection the later guesses are discarded and that position is resampled from an adjusted distribution. If every guess is accepted, one extra token is sampled from the target. So each run of the target yields at least one new token and up to γ+1, where γ is the number of guesses.

The authors say the output distribution is the same as sampling from the target model alone, for any approximation model, and that no retraining or architecture change is needed. They report 2X to 3X acceleration on T5-XXL at batch size 1 on a single TPU-v4, against the T5X implementation. The method has a cost.

It runs more computation at once, so total arithmetic can rise, and the paper says it is not helpful where extra computation resources are not available. The draft model must also be cheap: in the experiments the cost of a draft run relative to a target run (the ratio of their run times) was always below 0.05.

Mistral's model card for Large 4 describes an embedded draft head that proposes 3-token blocks and reports up to 1.9x higher throughput, with gains that vary by hardware and workload.

What it means for you

Our view

When you compare ways of serving a model, ask whether the vendor uses speculative decoding and on what hardware. The paper says its speedup comes from running more computation at once, so total arithmetic can rise, and that the method is not helpful where extra computing resources are unavailable.

It also needs a cheap draft model: in the paper's experiments the draft's cost relative to the target was always below 0.05. Mistral reports up to 1.9x higher throughput from the draft head in Large 4, with gains varying by hardware and workload, so test on your own load before relying on a quoted figure.

It adds no new facts.

Share this story

Your reaction

We count reactions per story and day, never who reacted. The counts help us choose what goes in the monthly issue. If you are signed in, your own page shows yours too.

Check our sources

Every sentence above is checked against these 2 sources.

1 Fast Inference from Transformers via Speculative DecodingarXiv (Leviathan, Kalman, Matias) · 30 Nov 2022 · 10 facts Open the source archived copy
  1. The speculative decoding paper (Leviathan, Kalman and Matias, arXiv 2211.17192) notes that decoding K tokens takes K serial runs of the model.

    Inference from large autoregressive models like Transformers is slow - decoding K tokens takes K serial runs of the model.
    cite
  2. The paper observes that inference is often limited by memory bandwidth and communication rather than arithmetic, so spare compute is often available.

    We additionally observe that inference from large models is often not bottlenecked on arithmetic operations, but rather on memory bandwidth and communication, so additional computation resources might be available.
    cite
  3. In the paper's algorithm a cheaper approximation model autoregressively proposes gamma guess tokens, and the target model scores the prefix and all guesses in one parallel pass, producing gamma+1 distributions.

    Sample γ guesses x1,...,xγ from Mq autoregressively. ... Run Mp in parallel. p1(x), ..., pγ+1(x) <- Mp(prefix), ..., Mp(prefix + [x1, ..., xγ])
    cite
  4. Each guess is checked against a random threshold using the ratio of the target's and the approximation model's probabilities, and guesses that pass are kept in order.

    r1 ~ U(0, 1), ..., rγ ~ U(0, 1); n <- min({i - 1 : 1 <= i <= γ, ri > pi(x)/qi(x)} U {γ})
    cite
  5. At the first rejection the later guesses are discarded and the rejected position is resampled from an adjusted distribution; if all guesses are accepted, one extra token is sampled from the target model.

    sampling an additional token from an adjusted distribution to fix the first one that was rejected, or to add an additional one if they are all accepted.
    cite
  6. The paper says each target run yields at least one new token and up to gamma+1 tokens.

    That way, each parallel run of the target model Mp will produce at least one new token ... but it can potentially generate many new tokens, up to γ + 1, depending on how well Mq approximates Mp.
    cite
  7. The paper says the output distribution is the same as sampling from the target model alone, for any approximation model, with no retraining or architecture changes needed.

    Speculative sampling, and therefore speculative decoding, guarantee an identical output distribution for any choice of approximation model Mq without restriction ... Our method can accelerate existing off-the-shelf models without retraining or architecture changes.
    cite
  8. The paper reports 2X to 3X acceleration with identical outputs on T5-XXL (11B), at batch size 1 on a single TPU-v4, compared with the T5X implementation.

    We demonstrate it on T5-XXL and show a 2X-3X acceleration compared to the standard T5X implementation, with identical outputs. ... We measure walltime improvements with a batch size of 1 on a single TPU-v4
    cite
  9. The paper says the speedup comes from running more computation concurrently, so total arithmetic operations can rise, and that the method is not helpful for configurations where additional computation resources are not available.

    latency is improved through increased concurrency at the cost of an increased number of arithmetic operations. Thus, our method is not helpful for configurations where additional computation resources are not available.
    cite
  10. In the paper's experiments, where the draft model was typically a couple of orders of magnitude smaller than the target, its cost coefficient c (the time for one run of the draft model divided by the time for one run of the target) was always below 0.05 and often close to 0.

    Toned down to what the source says
    experiments where Mq is typically a couple of orders of magnitude smaller than Mp, c was always less than 0.05 and often negligibly close to 0.
    cite
2 Mistral-Large-4-1T-A52B model cardMistral AI (Hugging Face) · 1 fact Open the source archived copy
  1. Mistral's Large 4 model card describes an embedded DSpark draft head that proposes 3-token blocks and reports up to 1.9x higher throughput, with gains varying by hardware and workload.

    cite

Topics

The morning email

On the mornings we publish: the three top stories and up to four short ones. Free.

We email you a link to confirm. An issue may include one sponsor, always labelled Sponsored · Advertisement. Our emails count opens and clicks, not who made them. Unsubscribe in one click. What we keep