Home Knowledge Base Speculative Decoding

Speculative Decoding is the inference acceleration technique that uses a small draft model to generate multiple candidate tokens in parallel, then verifies them with the target model in a single forward pass — achieving 2-3× speedup for autoregressive generation while producing identical outputs to standard decoding, making it the most practical lossless inference optimization for large language models deployed in production.

Core Algorithm:

<svg viewBox="0 0 760 470" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,Segoe UI,Roboto,sans-serif">
  <rect x="0" y="0" width="760" height="470" fill="#0d1117"/>
  <text x="380" y="28" fill="#e6edf3" font-size="21" font-weight="700" text-anchor="middle">Speculative Decoding — Draft &amp; Verify</text>
  <text x="380" y="48" fill="#8b98a5" font-size="12" text-anchor="middle">small model drafts K tokens, large model verifies in one pass — same quality, 2–3× faster</text>

  <!-- Main diagram -->
  <rect x="30" y="65" width="700" height="250" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="380" y="86" fill="#e6edf3" font-size="11" font-weight="600" text-anchor="middle">Speculative Decoding Pipeline</text>

  <!-- Draft model -->
  <rect x="50" y="100" width="150" height="100" rx="6" fill="#0b1220" stroke="#f59e0b" stroke-width="1.2"/>
  <text x="125" y="118" fill="#fbbf24" font-size="10" font-weight="600" text-anchor="middle">Draft Model</text>
  <text x="125" y="136" fill="#8b98a5" font-size="8" text-anchor="middle">small (1–7B)</text>
  <text x="125" y="152" fill="#8b98a5" font-size="8" text-anchor="middle">fast: generates K tokens</text>
  <text x="125" y="168" fill="#8b98a5" font-size="8" text-anchor="middle">autoregressively</text>
  <text x="125" y="186" fill="#6b7684" font-size="7.5" text-anchor="middle">K=5–8 draft tokens</text>

  <!-- Draft tokens -->
  <path d="M202,150 L235,150" fill="none" stroke="#f59e0b" stroke-width="1.2"/>
  <polygon points="233,147 239,150 233,153" fill="#f59e0b"/>

  <rect x="242" y="110" width="180" height="80" rx="5" fill="#0d1117" stroke="#334155" stroke-width="0.6"/>
  <text x="332" y="128" fill="#fbbf24" font-size="8" text-anchor="middle">Draft tokens (speculated):</text>
  <rect x="255" y="136" width="35" height="18" rx="2" fill="#2a1a0a" stroke="#f59e0b" stroke-width="0.5"/>
  <text x="272" y="148" fill="#fbbf24" font-size="7" text-anchor="middle">The</text>
  <rect x="294" y="136" width="35" height="18" rx="2" fill="#2a1a0a" stroke="#f59e0b" stroke-width="0.5"/>
  <text x="311" y="148" fill="#fbbf24" font-size="7" text-anchor="middle">cat</text>
  <rect x="333" y="136" width="35" height="18" rx="2" fill="#2a1a0a" stroke="#f59e0b" stroke-width="0.5"/>
  <text x="350" y="148" fill="#fbbf24" font-size="7" text-anchor="middle">sat</text>
  <rect x="372" y="136" width="35" height="18" rx="2" fill="#2a1a0a" stroke="#f59e0b" stroke-width="0.5"/>
  <text x="389" y="148" fill="#fbbf24" font-size="7" text-anchor="middle">on</text>
  <text x="332" y="175" fill="#6b7684" font-size="7.5" text-anchor="middle">generated sequentially (cheap per token)</text>

  <!-- Arrow to verifier -->
  <path d="M424,150 L455,150" fill="none" stroke="#3a4453" stroke-width="1.2"/>
  <polygon points="453,147 459,150 453,153" fill="#3a4453"/>
  <text x="440" y="140" fill="#6b7684" font-size="7" text-anchor="middle">all K</text>

  <!-- Verify model -->
  <rect x="462" y="100" width="150" height="100" rx="6" fill="#0b1220" stroke="#34d399" stroke-width="1.2"/>
  <text x="537" y="118" fill="#6ee7b7" font-size="10" font-weight="600" text-anchor="middle">Target Model</text>
  <text x="537" y="136" fill="#8b98a5" font-size="8" text-anchor="middle">large (70B+)</text>
  <text x="537" y="152" fill="#8b98a5" font-size="8" text-anchor="middle">one forward pass</text>
  <text x="537" y="168" fill="#8b98a5" font-size="8" text-anchor="middle">scores ALL K+1 positions</text>
  <text x="537" y="186" fill="#6b7684" font-size="7.5" text-anchor="middle">parallel verification!</text>

  <!-- Verification result -->
  <path d="M537,202 L537,220" fill="none" stroke="#34d399" stroke-width="1"/>
  <polygon points="534,218 537,224 540,218" fill="#34d399"/>

  <rect x="440" y="228" width="195" height="60" rx="5" fill="#0d1117" stroke="#334155" stroke-width="0.6"/>
  <text x="537" y="246" fill="#e6edf3" font-size="8" text-anchor="middle">Verification result:</text>
  <rect x="455" y="254" width="35" height="16" rx="2" fill="#14261f" stroke="#34d399" stroke-width="0.6"/>
  <text x="472" y="265" fill="#34d399" font-size="7" text-anchor="middle">The ✓</text>
  <rect x="494" y="254" width="35" height="16" rx="2" fill="#14261f" stroke="#34d399" stroke-width="0.6"/>
  <text x="511" y="265" fill="#34d399" font-size="7" text-anchor="middle">cat ✓</text>
  <rect x="533" y="254" width="35" height="16" rx="2" fill="#14261f" stroke="#34d399" stroke-width="0.6"/>
  <text x="550" y="265" fill="#34d399" font-size="7" text-anchor="middle">sat ✓</text>
  <rect x="572" y="254" width="35" height="16" rx="2" fill="#1a0a0a" stroke="#f87171" stroke-width="0.6"/>
  <text x="589" y="265" fill="#f87171" font-size="7" text-anchor="middle">by ✗</text>
  <text x="537" y="284" fill="#8b98a5" font-size="7" text-anchor="middle">accept 3, resample token 4 from target dist</text>

  <!-- Speedup explanation -->
  <rect x="50" y="220" width="370" height="70" rx="4" fill="#0d1117" stroke="#334155" stroke-width="0.5"/>
  <text x="235" y="238" fill="#e6edf3" font-size="9" font-weight="600" text-anchor="middle">Why It's Faster (same quality!)</text>
  <text x="70" y="256" fill="#8b98a5" font-size="8">Normal: 1 target fwd pass per token → K passes for K tokens</text>
  <text x="70" y="272" fill="#34d399" font-size="8">Speculative: 1 target fwd pass verifies K tokens at once</text>
  <text x="70" y="286" fill="#6b7684" font-size="7.5">acceptance rate α ≈ 0.7–0.9 → expected tokens/step = K×α ≈ 3–5</text>

  <!-- Bottom -->
  <rect x="30" y="328" width="700" height="100" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="380" y="348" fill="#e6edf3" font-size="10" font-weight="600" text-anchor="middle">Variants &amp; Deployment</text>
  <text x="50" y="370" fill="#60a5fa" font-size="8.5" font-weight="600">Medusa:</text><text x="110" y="370" fill="#8b98a5" font-size="8">multiple prediction heads on same model (self-speculative)</text>
  <text x="50" y="388" fill="#34d399" font-size="8.5" font-weight="600">EAGLE:</text><text x="105" y="388" fill="#8b98a5" font-size="8">draft from hidden states (no separate model needed)</text>
  <text x="50" y="406" fill="#a78bfa" font-size="8.5" font-weight="600">Lookahead:</text><text x="130" y="406" fill="#8b98a5" font-size="8">n-gram cache as draft (Jacobi iteration)</text>
  <text x="50" y="420" fill="#f59e0b" font-size="8.5" font-weight="600">Key guarantee:</text><text x="155" y="420" fill="#8b98a5" font-size="8">output distribution is identical to target model (no quality loss)</text>

  <text x="380" y="452" fill="#6b7684" font-size="11" text-anchor="middle">Speculative decoding is free speed — identical outputs, just fewer expensive forward passes per token generated.</text>
</svg>

Mathematical Guarantees:

Draft Model Selection:

Implementation Optimizations:

Performance Characteristics:

Production Deployment:

Advanced Variants:

Speculative Decoding is the rare optimization that provides substantial speedup without any quality trade-off — by exploiting the gap between small fast models and large accurate models through parallel verification, it has become the standard technique for reducing LLM inference latency in production systems where response time directly impacts user experience.

speculative decoding llmdraft model verificationparallel token generationspeculative sampling inferenceassisted generation

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.