𝑛 𝑛¸1
end while
Algorithm 2 Speculative Sampling (SpS) with Auto-Regressive Target and Draft Models
Given lookahead 𝐾and minimum target sequence length 𝑇.
Given auto-regressive target model 𝑞¹jº, and auto-regressive draft model 𝑝¹jº, initial prompt
sequence𝑥0𝑥𝑡.
Initialise𝑛 𝑡.
while𝑛 𝑇do
for𝑡=1 :𝐾do
Sample draft auto-regressively ˜𝑥𝑡𝑝¹𝑥j𝑥1𝑥𝑛˜𝑥1 ˜𝑥𝑡1º
end for
In parallel, compute 𝐾¸1sets of logits from drafts ˜𝑥1 ˜𝑥𝐾:
We present speculative sampling, an algorithm for accelerating transformer
decoding by enabling the generation of multiple tokens from each transformer
call. Our algorithm relies on the observation that the latency of parallel
scoring of short continuations, generated by a faster but less powerful draft
model, is comparable to that of sampling a single token from the larger target
model. This is combined with a novel modified rejection sampling scheme which
preserves the distribution of the target model within hardware numerics. We
benchmark speculative sampling with Chinchilla, a 70 billion parameter language
model, achieving a 2-2.5x decoding speedup in a distributed setup, without
compromising the sample quality or making modifications to the model itself.
Charlie Chen Sebastian Borgeaud Geoffrey Irving Jean-Baptiste Lespiau Laurent Sifre John Jumper