Parallel LLM Decoding: Speculative and Diffusion

Autoregressive LLMs emit one token per pass. Build masked-diffusion and speculative decoders in NumPy to see how parallel decoding breaks the wall.

Cover Image for Parallel LLM Decoding: Speculative and Diffusion

You're waiting for a chatbot's answer as the words arrive one at a time. Each new token normally depends on those before it, so making the model faster does not remove the need to generate in sequence. Parallel LLM decoding explores ways to produce several tokens during a step. At small batch sizes, moving weights through memory limits generation speed even when computation is available.

Speculative decoding asks a smaller model to draft ahead for a larger model to check. Diffusion decoding instead refines a block of token choices together. Both change how generation is organised, while the growing KV cache remains part of the cost. Orthrus combines the two, reporting up to 7.8x lossless acceleration while training about 16% of the parameters.

These methods only make sense once you have felt the trade-off they manage. By the end of this post you will have built a masked-diffusion decoder and a speculative decoder from scratch in NumPy, watched diffusion trade quality for parallelism and speculative decoding stay exact while running faster, and have the mental model to understand what Orthrus does. The full systems run on real LLMs and CUDA kernels. Our toy models illustrate the mechanisms without reproducing full-system performance.

Let's Build It

Click the badge to open the interactive notebook:

Open In Colab

Autoregressive decoding fills a sequence left to right, one box per pass. Parallel decoding fills the whole block at once and cleans it up.

Schematic comparing two decoding modes. Top row, autoregressive: eight dark boxes labelled t1 to t8 connected by left-to-right arrows, labelled '8 sequential forward passes'. Bottom row, parallel: the same eight boxes in teal with a single downward arrow labelled 'one parallel pass'.

Here is masked-diffusion decoding in action. The block starts as all ? placeholders, and each denoising step reveals a few tokens at once, conditioning on whatever is already filled in. After a handful of steps the whole block is decoded, without ever going strictly left to right.

Animation of masked-diffusion decoding. A row of twelve grey boxes each showing a question mark gradually fills with coloured, numbered tokens over six steps, two or three revealed per step, until the full sequence is decoded.

To make this concrete and measurable, we use a known toy "language", an order-1 Markov chain over a six-token vocabulary, so we have its exact conditional probabilities. That lets us isolate the one thing we care about, the effect of parallelism, with no model-quality confound. The denoiser is the true conditional of a masked token given its already-revealed neighbours:

def denoiser_conditional(left, right, T, pi):
    # p(x_t | visible neighbours) under the true order-1 chain
    if left != MASK and right != MASK:
        p = T[left, :] * T[:, right]      # both neighbours known
    elif left != MASK:
        p = T[left, :].copy()             # only the left neighbour
    elif right != MASK:
        p = pi * T[:, right]              # only the right neighbour
    else:
        p = pi.copy()                     # nothing revealed yet: the marginal
    return p / p.sum()

Decoding runs the reveal schedule: over K steps, unmask roughly L/K positions per step, sampling each from its current conditional, then committing them and moving on.

def diffusion_decode(T, pi, L, K, rng):
    seq = np.full(L, MASK)
    for n_reveal in schedule(L, K):                 # how many to reveal this step
        masked = [t for t in range(L) if seq[t] == MASK]
        conds = {t: denoiser_conditional(neighbour(seq, t, -1),
                                         neighbour(seq, t, +1), T, pi) for t in masked}
        order = sorted(masked, key=lambda t: -conds[t].max())  # most confident first
        for t in order[:n_reveal]:
            seq[t] = rng.choice(len(pi), p=conds[t])  # sample the revealed token
    return seq

Run it at different step counts and measure how realistic the output is (its log-likelihood under the true model). One step, the fully parallel extreme, is much worse than the autoregressive floor; quality climbs back as you add steps.

Line chart of negative log-likelihood per token versus number of denoising steps K on a log scale, for block length 16. The masked-diffusion curve starts at about 2.43 at K=1 (annotated 'fully parallel, dependencies broken'), falls as K increases, and meets the dashed autoregressive floor of 1.46 at K=16 (annotated 'one token at a time').

You just decoded a sequence without going left to right, and measured exactly what that parallelism costs. Now let us understand why.

What Just Happened?

The autoregressive wall

An autoregressive model factorises the probability of a sequence into a strict chain, each token conditioned on every token before it:

p(x1,x2,…,xL)=∏t=1Lp(xt∣x1,…,xt−1)p(x_1, x_2, \ldots, x_L) = \prod_{t=1}^{L} p(x_t \mid x_1, \ldots, x_{t-1})

To sample from it correctly you must draw xtx_t before you can draw xt+1x_{t+1}, because the latter depends on the former. That is the wall: the factorisation is inherently sequential, so generating LL tokens takes LL forward passes no matter how much compute you have spare. As we covered in the KV-cache post, each of those passes is memory-bandwidth bound, which is why decoding is slow even when the GPU's compute units sit idle.

Why one-shot parallel decoding fails

The tempting shortcut is to predict all LL tokens at once. The masked-diffusion run at K = 1 does exactly that: with nothing revealed, every position samples from its marginal, independently. The result is the worst point on the chart, because independent sampling throws away the dependencies between tokens. Picture asking ten people to each write one word of a sentence with no coordination: every word is individually plausible, the sentence is gibberish.

Diffusion decoding buys quality back with iteration. Reveal a few tokens, and the next step's predictions get to condition on them through the denoiser_conditional neighbours. More steps means each token sees more context before it commits, so the joint distribution is reconstructed more faithfully. At K = L you reveal one token at a time conditioned on all the rest, which recovers the autoregressive quality exactly. The chart is the whole story of diffusion language models in one curve: denoising steps are a dial between speed and quality, and the research question is how few steps you can get away with.

Two routes to parallelism

There are two honest ways to beat the wall, and they make opposite bargains.

  • Diffusion decoding is unconditionally parallel but approximate. It generates a block in a fixed, small number of steps regardless of length, but each step's within-block independence costs quality unless you spend more steps.
  • Speculative decoding is exact but only opportunistically parallel. It never changes the output distribution, but its speedup depends on a cheap model guessing well.

Orthrus, which we reach at the end, is an attempt to get the exactness of the second with the parallelism of the first.

Going Deeper

Speculative decoding: parallel, but exact

Speculative decoding (Leviathan et al., 2023, and Chen et al., 2023) keeps the autoregressive distribution untouched. A small, cheap draft model proposes the next γ\gamma tokens autoregressively. The large target model then scores all γ\gamma proposals in a single parallel forward pass, because once the draft has fixed the tokens, every position's context is known, so they can be checked together. A rejection-sampling test decides how many to keep:

def speculative_step(T, Td, ctx, gamma, rng):
    # 1. cheap draft proposes gamma tokens autoregressively
    proposed, q = [], []; c = ctx
    for _ in range(gamma):
        x = rng.choice(len(Td[c]), p=Td[c]); proposed.append(x); q.append(Td[c]); c = x
    # 2. expensive target scores all gamma positions in ONE parallel pass
    out, c = [], ctx
    for i, x in enumerate(proposed):
        p = T[c]
        if rng.random() <= min(1.0, p[x] / q[i][x]):   # accept the guess
            out.append(x); c = x
        else:                                           # reject: resample and stop
            adj = np.maximum(p - q[i], 0)
            out.append(rng.choice(len(p), p=adj / adj.sum())); break
    return out

The accept-or-resample test is the clever part. Accepting with probability min⁡(1,p/q)\min(1, p/q) and, on rejection, drawing from the renormalised residual max⁡(0,p−q)\max(0, p - q) is algebraically guaranteed to produce a sample from the target distribution pp, whatever the draft qq was. The draft only affects speed, never correctness. We can check that empirically: every transition probability from speculative decoding lands exactly on the line y=xy = x against direct sampling from the target.

Scatter plot of transition probabilities from speculative decoding versus direct target sampling. All points lie on the dashed y=x diagonal, with an annotated KL divergence of 0.0003, showing the two distributions are identical.

The payoff is the number of tokens produced per expensive target pass. When the draft agrees with the target, you accept the whole block and get γ+1\gamma + 1 tokens for one target pass; when it disagrees early, you fall back toward one. So the speedup rises with the draft's acceptance rate and with the block size γ\gamma.

Line chart of tokens generated per target pass versus draft acceptance rate, for draft block sizes gamma of 2, 4 and 8. All curves rise with acceptance; gamma=8 reaches about 9 tokens per pass at full acceptance, gamma=4 reaches 5, and gamma=2 reaches 3. A dashed line marks the autoregressive baseline of 1 token per pass.

This is why a good draft matters. The draft is usually a smaller distilled model (see on-policy distillation for how to train one to mimic a larger target), and methods like EAGLE go further by drafting from the target's own hidden states. The better the draft predicts the target, the more tokens clear per pass.

The hidden cost of a draft model

Speculative decoding buys exact speedups, but the draft is not free. A separate draft model has its own weights and, crucially, its own KV cache, which grows with the context length just like the target's. At short contexts that overhead is small. At the long contexts that matter most, summarising a codebase, a book, a chat history, you are now paying for two caches that both scale with the sequence, and the draft's cache competes for the exact memory bandwidth you were trying to save.

Line chart of relative KV-cache memory versus context length in thousands of tokens. The draft-model speculative line (target cache plus separate draft cache) rises fastest; the shared-cache dual-view line (one cache plus O(1) head overhead) tracks just above the plain autoregressive target line. An italic caption notes the figure is a schematic assuming the draft cache is 25% of the target, not a measured benchmark.

Orthrus: one cache, two views, exact output

Orthrus (2026) is the bridge between the two routes, and its central trick is to remove the draft's separate cache entirely. Instead of a second model, it attaches a lightweight, trainable diffusion view to a frozen autoregressive model. Both views attend to the exact same KV cache: the diffusion view proposes a block of tokens in parallel, the autoregressive view verifies them, and because they read the same keys and values there is no redundant draft cache to maintain. The diagram in the memory chart above is the whole pitch: shared-cache decoding tracks the plain autoregressive memory curve, while a separate draft model pulls away as context grows.

Three properties make it practical:

  • Lossless. An exact-consensus mechanism, the same accept-or-resample logic as speculative decoding, guarantees the parallel output is identical to what the frozen autoregressive model would have produced alone. No quality is traded, unlike raw diffusion decoding.
  • Cheap to train. Only the diffusion view is trained, about 16% of the parameters, in the spirit of parameter-efficient fine-tuning like LoRA. The base model stays frozen.
  • Memory-flat. The shared cache means the speedup, up to 7.8x in the paper, holds as context length grows, where draft-model methods like EAGLE-3 lose ground to their own caches.

The intuition stacks the two halves of this post: take diffusion's ability to propose a whole block in parallel, then wrap it in speculative decoding's exact verification so the proposal is free of quality loss, and share one cache so it stays cheap at long context. For the full system and the real numbers, see the official implementation; here we have built only the mechanisms it composes.

When parallel decoding helps, and when it does not

Parallel decoding pays off when you are memory-bandwidth bound and latency-sensitive: interactive chat, long generations, batch-of-one serving. It helps least when you are already compute-bound (very large batches saturate the GPU, so there is little idle bandwidth to reclaim) or when generations are very short (the overhead of drafting or denoising is not amortised). And raw diffusion decoding, without an exactness wrapper, is a genuine quality trade you must measure, not a free lunch.

Where This Comes From

Parallel decoding sits on three research lines that converged in the mid-2020s.

Vaswani et al. (2017), "Attention Is All You Need", defined the autoregressive transformer whose sequential decoding everything here tries to escape. Training is parallel across positions; inference is not, and that asymmetry is the whole problem.

Leviathan et al. (2023), "Fast Inference from Transformers via Speculative Decoding", and the concurrent Chen et al. (2023) from DeepMind, introduced the draft-and-verify scheme with the rejection test that keeps it exact.

"We sample from the target model in parallel by using a more efficient approximation model to generate speculative prefixes... guaranteeing that the outputs are identical to those of the target model." (Leviathan et al., 2023)

Austin et al. (2021), D3PM, "Structured Denoising Diffusion Models in Discrete State-Spaces", brought diffusion to discrete tokens, and the masked or absorbing-state variant became the basis for diffusion language models. Sahoo et al. (2024) MDLM and Lou et al. (2024) SEDD sharpened the training objectives, and the LLaDA models and Inception's Mercury scaled the idea to commercial systems in 2025.

Li et al. (2024), EAGLE / EAGLE-3, improved drafting by predicting from the target's own features, the strongest draft-model line and the baseline Orthrus measures itself against.

"Orthrus: Memory-Efficient Parallel Token Generation via Dual-View Diffusion" (arXiv:2605.12825, 2026) ties the threads together: a diffusion proposer and an autoregressive verifier sharing one cache, exact by construction. The shift across all of this is from accepting the autoregressive wall to treating decoding as something you can parallelise as long as you are willing to verify.

Interactive Tools

  • LLM Cost Calculator: Inference latency and cost are exactly what parallel decoding attacks; estimate the spend these methods aim to cut
  • Markov Chain Simulator: The toy "language" in this post is an order-1 Markov chain; build one and watch how next-token probabilities depend on the current state
  • Distribution Explorer: Speculative decoding is rejection sampling; explore the distributions whose ratios drive its accept-or-resample test

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Related Posts

Frequently Asked Questions