Skip to content
โ† All posts

Production AI

Speculative Decoding

Speculative decoding speeds up LLM generation by exploiting a key asymmetry: ๐˜๐—ผ๐—ธ๐—ฒ๐—ป ๐—ด๐—ฒ๐—ป๐—ฒ๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐˜€ ๐˜€๐—ฒ๐—พ๐˜‚๐—ฒ๐—ป๐˜๐—ถ๐—ฎ๐—น, ๐—ฏ๐˜‚๐˜ ๐˜๐—ผ๐—ธ๐—ฒ๐—ป ๐˜ƒ๐—ฒ๐—ฟ๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ถ๐˜€ ๐—ฝ๐—ฎ๐—ฟ๐—ฎ๐—น๐—น๐—ฒ๐—น.

  • ๐— ๐—ฎ๐—ถ๐—ป ๐—ฏ๐—ผ๐˜๐˜๐—น๐—ฒ๐—ป๐—ฒ๐—ฐ๐—ธ: Standard autoregressive decoding is memory-bandwidth bound. Each new token requires another full pass over the model weights in HBM, so GPUs spend much of their time waiting on memory rather than doing math.

  • ๐—–๐—ผ๐—ฟ๐—ฒ ๐—ถ๐—ฑ๐—ฒ๐—ฎ: Use a cheap draft proposer to guess several future tokens, then have the large target model verify them all at once in a single parallel forward pass.

  • ๐—›๐—ผ๐˜„ ๐—ถ๐˜ ๐˜„๐—ผ๐—ฟ๐—ธ๐˜€: The draft model proposes K tokens; the target model checks them left-to-right, accepts matching tokens, and replaces any mismatch with a token sampled from the target distribution.

  • ๐—ช๐—ต๐˜† ๐—ถ๐˜โ€™๐˜€ ๐—น๐—ผ๐˜€๐˜€๐—น๐—ฒ๐˜€๐˜€: With modified rejection sampling, the final output distribution is identical to sampling from the target model alone, so quality is preserved exactly.

  • ๐——๐—ฟ๐—ฎ๐—ณ๐˜ ๐—บ๐—ฒ๐—ฐ๐—ต๐—ฎ๐—ป๐—ถ๐˜€๐—บ๐˜€:

    1. ๐—ฆ๐—บ๐—ฎ๐—น๐—น ๐—ฑ๐—ฟ๐—ฎ๐—ณ๐˜ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—น + ๐—น๐—ฎ๐—ฟ๐—ด๐—ฒ ๐˜๐—ฎ๐—ฟ๐—ด๐—ฒ๐˜ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—น โ€” good accuracy, but extra VRAM.
    2. ๐—ฃ๐—ฟ๐—ผ๐—บ๐—ฝ๐˜ ๐—น๐—ผ๐—ผ๐—ธ๐˜‚๐—ฝ / ๐—ป-๐—ด๐—ฟ๐—ฎ๐—บ ๐—บ๐—ฎ๐˜๐—ฐ๐—ต๐—ถ๐—ป๐—ด โ€” no extra model, very fast, best when output overlaps with context (๐—ฒ.๐—ด., ๐—ฅ๐—”๐—š).
    3. ๐—ฆ๐—ฒ๐—น๐—ณ-๐˜€๐—ฝ๐—ฒ๐—ฐ๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ต๐—ฒ๐—ฎ๐—ฑ๐˜€ โ€” extra heads on the target model predict future tokens without a separate draft model.
  • ๐—ฃ๐—ฟ๐—ผ๐—ฑ๐˜‚๐—ฐ๐˜๐—ถ๐—ผ๐—ป ๐˜๐—ฟ๐—ฎ๐—ฑ๐—ฒ-๐—ผ๐—ณ๐—ณ:

    • At ๐—น๐—ผ๐˜„ ๐—ค๐—ฃ๐—ฆ, speculative decoding usually helps a lot because GPUs have idle compute.
    • At ๐—ต๐—ถ๐—ด๐—ต ๐—ค๐—ฃ๐—ฆ, it can hurt latency because the system is already compute-saturated, so extra verification adds overhead.
  • ๐—ฃ๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ฐ๐—ฎ๐—น ๐˜๐—ฟ๐—ฒ๐—ป๐—ฑ: Modern systems use ๐—ฑ๐˜†๐—ป๐—ฎ๐—บ๐—ถ๐—ฐ ๐˜€๐—ฝ๐—ฒ๐—ฐ๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป, adjusting speculative length based on current load.

Speculative decoding trades a little extra draft work for fewer expensive target-model passes, giving substantial latency gains when the GPU is memory-bound and underutilized.

flowchart TB
  A["Faster generation โ‰  bigger model"] --> B["GPU trace reveals bottleneck"]
  B --> C["Memory bandwidth, not math"]
  C --> D["Speculative decoding"]

  D --> E["Cheap draft model"]
  D --> F["Expensive target model"]
  E --> G["Sequential token proposals"]
  F --> H["Parallel verification pass"]

  D --> I["Same target distribution"]
  D --> J["Faster execution"]

  subgraph R1["Core requirements"]
    K["Tokenizer + vocabulary must match"]
    L["Target model defines quality"]
    M["Draft only proposes"]
  end

  subgraph R2["When it helps or hurts"]
    N["Low-QPS: latency drops"]
    O["High-QPS: may backfire"]
    P["Spec length = dynamic knob"]
  end

  subgraph R3["Implementation options"]
    Q["Small draft model"]
    R["Prompt / N-gram lookup"]
    S["Self-speculation heads"]
  end

  Q --> T["Trade-offs: VRAM, acceptance, complexity"]
  R --> T
  S --> T

  D --> K
  D --> L
  D --> M
  D --> N
  D --> O
  D --> P

  classDef insight fill:#dbeafe,stroke:#2563eb,color:#111827;
  classDef process fill:#dcfce7,stroke:#16a34a,color:#111827;
  classDef constraint fill:#fef9c3,stroke:#ca8a04,color:#111827;
  classDef tradeoff fill:#fee2e2,stroke:#dc2626,color:#111827;
  classDef option fill:#ede9fe,stroke:#7c3aed,color:#111827;

  class A,B,C,D insight;
  class E,F,G,H process;
  class K,L,M constraint;
  class N,O,P tradeoff;
  class Q,R,S,T option;

Discuss this post on LinkedIn โ†’