<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Speculative-Decoding on vishctl</title><link>https://vishctl.dev/tags/speculative-decoding/</link><description>Recent content in Speculative-Decoding on vishctl</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 17 Nov 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://vishctl.dev/tags/speculative-decoding/index.xml" rel="self" type="application/rss+xml"/><item><title>Speculative Decoding, Simply: A Small Model Guesses, the Big Model Checks</title><link>https://vishctl.dev/posts/speculative-decoding-draft-model-explained/</link><pubDate>Tue, 17 Nov 2026 09:00:00 +0800</pubDate><guid>https://vishctl.dev/posts/speculative-decoding-draft-model-explained/</guid><category>speculative-decoding</category><category>inference</category><category>vllm</category><category>latency</category><category>ai-infra</category><description>A simple, diagram-first guide to speculative decoding: why checking tokens is cheaper than writing them, how acceptance rate decides the speedup, when it makes serving slower, and how to turn it on in vLLM.</description><content:encoded><![CDATA[<p>A large model writes one token per pass. Every token costs a full trip through billions of weights, even an obvious one like the closing bracket of a JSON object.</p>
<p>Speculative decoding asks a simple question: what if something cheap guessed the easy tokens, and the large model only had to check them?</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Normal decoding      = the big model writes every token itself, one pass per token
</span></span><span class="line"><span class="cl">Speculative decoding = a small model drafts a few tokens, the big model checks them in one pass
</span></span></code></pre></div><figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    subgraph NORMAL["Normal decoding"]
        direction LR
        N1["Big pass<br/>token 1"] n1@--> N2["Big pass<br/>token 2"]
        N2 n2@--> N3["...and<br/>so on"]
        N3 n3@--> N4["5 tokens<br/>5 big passes"]
    end

    subgraph SPEC["Speculative decoding"]
        direction LR
        S1["Small model<br/>drafts 5 tokens"] s1@--> S2["Big model<br/>checks all 5<br/>in 1 pass"]
        S2 s2@--> S3["4 tokens kept<br/>1 big pass"]
    end

    NORMAL ~~~ SPEC
    n1@{ animate: true }
    n2@{ animate: true }
    n3@{ animate: true }
    s1@{ animate: true }
    s2@{ animate: true }

    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef tree fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    class N1,N2,N3,N4 warn;
    class S1 tree;
    class S2,S3 gpu;</div>
  <figcaption>Top: five tokens cost five big-model passes. Bottom: a small model drafts five tokens, and one big-model pass checks them all.</figcaption>
</figure>

<p>The surprising part is the guarantee: done properly, <strong>the output is the same as what the big model would have written alone.</strong> This is a speed trick, not a quality trade.</p>
<p>This post explains why that works, how much it helps, and when it makes things worse.</p>
<h2 id="why-checking-is-cheaper-than-writing">Why checking is cheaper than writing</h2>
<p>A model writes slowly because each token depends on the one before it. It cannot start token 5 until token 4 exists.</p>
<p>Checking has no such problem. If someone hands the model five tokens, it can score all five positions <strong>in a single pass</strong>, the same way it reads a whole prompt at once during <a href="https://vishctl.dev/posts/llm-basics-visual-guide/">prefill</a>.</p>
<p>Think of a senior engineer and a junior engineer:</p>
<ul>
<li><strong>Writing a runbook from scratch</strong> takes the senior engineer an hour.</li>
<li><strong>Reviewing the junior&rsquo;s draft</strong> takes ten minutes, and most lines are fine.</li>
</ul>
<p>The senior still decides every line. They just do not have to type the obvious ones.</p>
<h2 id="one-round-step-by-step">One round, step by step</h2>
<p>Suppose the model is finishing this sentence: <em>&ldquo;The pod is in&hellip;&rdquo;</em></p>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart LR
    D["Draft<br/>5 tokens"] r1@--> V["Verify<br/>1 big pass"]
    V r2@--> A["Accept<br/>first 3"]
    A r3@--> F["Fix<br/>token 4"]
    F r4@--> N["Next round<br/>starts here"]

    r1@{ animate: true }
    r2@{ animate: true }
    r3@{ animate: true }
    r4@{ animate: true }

    classDef tree fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef input fill:#13264a,stroke:#38bdf8,color:#e6f6ff,stroke-width:2px;
    class D tree;
    class V,A gpu;
    class F warn;
    class N input;</div>
  <figcaption>One round. The small model drafts five tokens. The big model agrees with the first three, rejects the fourth, and supplies its own.</figcaption>
</figure>

<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Step</th>
            <th scope="col">What happens</th>
            <th scope="col">Tokens so far</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1. Draft</td>
            <td>Small model proposes: <code>Crash</code> <code>Loop</code> <code>BackOff</code> <code>status</code> <code>now</code></td>
            <td>0 confirmed</td>
        </tr>
        <tr>
            <td>2. Verify</td>
            <td>Big model scores all five positions in one pass</td>
            <td>0 confirmed</td>
        </tr>
        <tr>
            <td>3. Accept</td>
            <td>It agrees with <code>Crash</code> <code>Loop</code> <code>BackOff</code></td>
            <td>3 confirmed</td>
        </tr>
        <tr>
            <td>4. Fix</td>
            <td>It disagrees with <code>status</code>, and writes <code>state</code> instead</td>
            <td>4 confirmed</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The fifth draft token is thrown away, because it was built on a token that got rejected.</p>
<p>Result: <strong>four tokens for the price of one big pass</strong>, plus five cheap small ones. The worst case is also safe: if the very first draft token is wrong, the big model still supplies one correct token, so the round is never wasted.</p>
<h3 id="why-the-output-does-not-change">Why the output does not change</h3>
<p>In step 3, the big model is not &ldquo;trusting&rdquo; the draft. It computes what it would have produced at each position, and a draft token only survives if it passes that test.</p>
<p>With greedy decoding, the test is simply &ldquo;is this the token I would have picked?&rdquo;. With sampling, a slightly cleverer accept-or-reject rule is used so that the final text follows the big model&rsquo;s probabilities exactly.</p>
<p>vLLM&rsquo;s documentation describes its implementation as theoretically lossless, within the limits of floating-point precision. Tiny numeric differences are possible, as they are whenever batch sizes change. Token log probabilities are the exception: vLLM does not guarantee they stay stable with speculation on.</p>
<h2 id="the-number-that-decides-everything-acceptance-rate">The number that decides everything: acceptance rate</h2>
<p>The <strong>acceptance rate</strong> is how often the big model agrees with a drafted token. It decides how many tokens each big pass yields.</p>
<p>With a draft length of 5:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Acceptance rate</th>
            <th scope="col">Tokens per big-model pass</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>50%</td>
            <td>1.97</td>
        </tr>
        <tr>
            <td>70%</td>
            <td>2.94</td>
        </tr>
        <tr>
            <td>80%</td>
            <td>3.69</td>
        </tr>
        <tr>
            <td>90%</td>
            <td>4.69</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Those are not the speedup yet. Drafting is cheap, but it is not free.</p>
<h3 id="speedup-after-paying-for-the-drafts">Speedup, after paying for the drafts</h3>
<p>Assume one small-model pass costs 10% of a big-model pass:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Acceptance rate</th>
            <th scope="col">Draft 3 tokens</th>
            <th scope="col">Draft 5 tokens</th>
            <th scope="col">Draft 8 tokens</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>50%</td>
            <td>1.44x</td>
            <td>1.31x</td>
            <td>1.11x</td>
        </tr>
        <tr>
            <td>70%</td>
            <td>1.95x</td>
            <td>1.96x</td>
            <td>1.78x</td>
        </tr>
        <tr>
            <td>80%</td>
            <td>2.27x</td>
            <td>2.46x</td>
            <td>2.40x</td>
        </tr>
        <tr>
            <td>90%</td>
            <td>2.65x</td>
            <td>3.12x</td>
            <td>3.40x</td>
        </tr>
    </tbody>
  </table>
</div>
<p>Read across the 50% row. <strong>Drafting more tokens made it slower.</strong> When the small model is often wrong, long drafts are mostly wasted work.</p>
<p>Now read the 90% row. Long drafts pay off, because most of them survive.</p>
<h3 id="the-draft-model-must-be-much-smaller">The draft model must be much smaller</h3>
<p>Hold acceptance at 70% and draft length at 5, and change only how expensive the small model is:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Small model cost (share of a big pass)</th>
            <th scope="col">Speedup</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>2%</td>
            <td>2.67x</td>
        </tr>
        <tr>
            <td>10%</td>
            <td>1.96x</td>
        </tr>
        <tr>
            <td>25%</td>
            <td>1.31x</td>
        </tr>
        <tr>
            <td>50%</td>
            <td>0.84x</td>
        </tr>
    </tbody>
  </table>
</div>
<p>At 50%, speculative decoding is <strong>slower than doing nothing</strong>. A draft model that is half the size of the target is not a draft model. A common starting point is a model roughly ten times smaller, from the same family, so it guesses in a similar style.</p>
<p>These tables come from a simplified formula that treats every token as an independent coin flip. Real text is burstier than that, so treat the numbers as the shape of the trade-off, not a forecast.</p>
<h2 id="not-every-draft-needs-a-second-model">Not every draft needs a second model</h2>
<p>&ldquo;A small model drafts&rdquo; is the classic version. The draft can come from other places too.</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Draft source</th>
            <th scope="col">How it guesses</th>
            <th scope="col">Best for</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Draft model</td>
            <td>A separate small LLM</td>
            <td>General text, when a good small sibling exists</td>
        </tr>
        <tr>
            <td>N-gram, or prompt lookup</td>
            <td>Copies a run of tokens that already appears in the prompt</td>
            <td>Editing, summarizing, RAG answers that quote the context</td>
        </tr>
        <tr>
            <td>Extra prediction heads</td>
            <td>Small layers added to the big model itself, such as EAGLE</td>
            <td>Highest speedups, but needs heads trained for that exact model</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The n-gram method deserves attention because it costs almost nothing. If you ask a model to fix one line in a 200-line file, most of the output is a copy of the input. Guessing &ldquo;the next tokens are the same as in the prompt&rdquo; is right most of the time.</p>
<p>vLLM rates n-gram gains as low to medium. The price is also close to zero, with no second model to load.</p>
<h2 id="when-it-helps-and-when-it-hurts">When it helps and when it hurts</h2>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Situation</th>
            <th scope="col">Effect</th>
            <th scope="col">Why</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Code, JSON, structured text</td>
            <td>Helps a lot</td>
            <td>Predictable tokens mean high acceptance</td>
        </tr>
        <tr>
            <td>Editing or quoting the prompt</td>
            <td>Helps, even with n-gram</td>
            <td>The answer repeats the input</td>
        </tr>
        <tr>
            <td>Creative writing, high temperature</td>
            <td>Helps little</td>
            <td>The next token is a toss-up, so drafts miss</td>
        </tr>
        <tr>
            <td>One user, latency matters</td>
            <td>Helps</td>
            <td>Spare GPU time is turned into speed</td>
        </tr>
        <tr>
            <td>Busy server near saturation</td>
            <td>Can hurt</td>
            <td>Draft work competes with real requests for the same GPU</td>
        </tr>
        <tr>
            <td>Tight GPU memory</td>
            <td>Can hurt</td>
            <td>The draft model takes memory away from the KV cache</td>
        </tr>
    </tbody>
  </table>
</div>
<p>The last two rows are the ones that surprise people in production.</p>
<p>Speculative decoding spends extra compute to save time. On a quiet GPU, that compute was idle anyway. On a GPU that is already full, every wasted draft token is work taken from another user, so total throughput can go <strong>down</strong>.</p>
<p>And a draft model is not free to hold. Its weights and its own KV cache come out of the same memory budget described in the <a href="https://vishctl.dev/posts/llm-gpu-memory-sizing-weights-kv-cache/">GPU memory sizing guide</a>.</p>
<h2 id="what-it-does-to-your-metrics">What it does to your metrics</h2>
<p>If you track the numbers from my <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/">inference metrics guide</a>, expect this:</p>
<div class="table-scroll">
  <table>
    <thead>
        <tr>
            <th scope="col">Metric</th>
            <th scope="col">What changes</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>TTFT</td>
            <td>About the same. The first token still needs a full prefill</td>
        </tr>
        <tr>
            <td>TPOT</td>
            <td>Improves, by roughly the speedup factor</td>
        </tr>
        <tr>
            <td>ITL</td>
            <td>Gets bursty. Several tokens can arrive in one chunk, then a pause</td>
        </tr>
        <tr>
            <td>Throughput at low load</td>
            <td>Improves</td>
        </tr>
        <tr>
            <td>Throughput at high load</td>
            <td>May get worse. Measure it</td>
        </tr>
    </tbody>
  </table>
</div>
<p>That ITL row is why TPOT and ITL can disagree. A stream that delivers four tokens at once and then waits looks fast on average and uneven up close.</p>
<h2 id="try-it-the-math-in-a-script">Try it: the math in a script</h2>
<p>This script produces the tables above and checks the formula against a simulation. It uses only the Python standard library.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="ch">#!/usr/bin/env python3</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;&#34;&#34;spec_decode.py: how much does speculative decoding help?&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl"><span class="kn">import</span> <span class="nn">random</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Expected tokens produced by one big-model pass.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">accept</span> <span class="o">**</span> <span class="p">(</span><span class="n">draft_len</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">accept</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">speedup</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">,</span> <span class="n">draft_cost</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Speed versus normal decoding. draft_cost = small-model pass / big-model pass.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">draft_len</span> <span class="o">*</span> <span class="n">draft_cost</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">def</span> <span class="nf">simulate</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">draft_len</span><span class="p">,</span> <span class="n">rounds</span><span class="o">=</span><span class="mi">200_000</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;Check the formula by actually flipping coins.&#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">    <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">rounds</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="n">kept</span> <span class="o">=</span> <span class="mi">0</span>
</span></span><span class="line"><span class="cl">        <span class="k">while</span> <span class="n">kept</span> <span class="o">&lt;</span> <span class="n">draft_len</span> <span class="ow">and</span> <span class="n">random</span><span class="o">.</span><span class="n">random</span><span class="p">()</span> <span class="o">&lt;</span> <span class="n">accept</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">            <span class="n">kept</span> <span class="o">+=</span> <span class="mi">1</span>
</span></span><span class="line"><span class="cl">        <span class="n">total</span> <span class="o">+=</span> <span class="n">kept</span> <span class="o">+</span> <span class="mi">1</span>          <span class="c1"># accepted drafts plus one token from the big model</span>
</span></span><span class="line"><span class="cl">    <span class="k">return</span> <span class="n">total</span> <span class="o">/</span> <span class="n">rounds</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;Tokens per big-model pass (draft length 5)&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">accept</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  acceptance </span><span class="si">{</span><span class="n">accept</span><span class="si">:</span><span class="s2">.0%</span><span class="si">}</span><span class="s2">: formula </span><span class="si">{</span><span class="n">tokens_per_round</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">, simulated </span><span class="si">{</span><span class="n">simulate</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\n</span><span class="s2">Speedup when the draft model costs 10</span><span class="si">% o</span><span class="s2">f the big model&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;  acceptance   draft 3   draft 5   draft 8&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">accept</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.7</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.9</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="n">row</span> <span class="o">=</span> <span class="s2">&#34;   &#34;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;</span><span class="si">{</span><span class="n">speedup</span><span class="p">(</span><span class="n">accept</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mf">0.10</span><span class="p">)</span><span class="si">:</span><span class="s2">5.2f</span><span class="si">}</span><span class="s2">x&#34;</span> <span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  </span><span class="si">{</span><span class="n">accept</span><span class="si">:</span><span class="s2">&gt;9.0%</span><span class="si">}</span><span class="s2">    </span><span class="si">{</span><span class="n">row</span><span class="si">}</span><span class="s2">&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">print</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\n</span><span class="s2">Speedup at 70</span><span class="si">% a</span><span class="s2">cceptance, draft length 5, by draft cost&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="k">for</span> <span class="n">cost</span> <span class="ow">in</span> <span class="p">(</span><span class="mf">0.02</span><span class="p">,</span> <span class="mf">0.10</span><span class="p">,</span> <span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.50</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&#34;  draft costs </span><span class="si">{</span><span class="n">cost</span><span class="si">:</span><span class="s2">&gt;4.0%</span><span class="si">}</span><span class="s2"> of a big pass: </span><span class="si">{</span><span class="n">speedup</span><span class="p">(</span><span class="mf">0.7</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="n">cost</span><span class="p">)</span><span class="si">:</span><span class="s2">.2f</span><span class="si">}</span><span class="s2">x&#34;</span><span class="p">)</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">python3 spec_decode.py
</span></span></code></pre></div><p>The first block of output shows the formula and the simulation agreeing:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Tokens per big-model pass (draft length 5)
</span></span><span class="line"><span class="cl">  acceptance 50%: formula 1.97, simulated 1.97
</span></span><span class="line"><span class="cl">  acceptance 70%: formula 2.94, simulated 2.94
</span></span><span class="line"><span class="cl">  acceptance 80%: formula 3.69, simulated 3.69
</span></span><span class="line"><span class="cl">  acceptance 90%: formula 4.69, simulated 4.68
</span></span></code></pre></div><p>Change the numbers to match your own case. If your draft model is 5% of the target&rsquo;s size and you expect 75% acceptance, the script tells you whether a draft length of 4 or 8 is the better bet.</p>
<h2 id="turn-it-on-in-vllm">Turn it on in vLLM</h2>
<p>Speculative decoding is a server setting. Clients do not change anything.</p>
<p>The cheapest experiment is n-gram, because it needs no second model:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm serve &lt;target-model&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --speculative-config <span class="s1">&#39;{
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;method&#34;: &#34;ngram&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;num_speculative_tokens&#34;: 4,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;prompt_lookup_min&#34;: 2,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;prompt_lookup_max&#34;: 5
</span></span></span><span class="line"><span class="cl"><span class="s1">  }&#39;</span>
</span></span></code></pre></div><p>With a separate draft model:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">vllm serve &lt;target-model&gt; <span class="se">\
</span></span></span><span class="line"><span class="cl">  --speculative-config <span class="s1">&#39;{
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;method&#34;: &#34;draft_model&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;model&#34;: &#34;&lt;draft-model&gt;&#34;,
</span></span></span><span class="line"><span class="cl"><span class="s1">    &#34;num_speculative_tokens&#34;: 5
</span></span></span><span class="line"><span class="cl"><span class="s1">  }&#39;</span>
</span></span></code></pre></div><p>Both commands follow the current <a href="https://docs.vllm.ai/en/latest/features/speculative_decoding/">vLLM speculative decoding docs</a>. The option names have changed across releases, so check the page for your version.</p>
<p>Then measure, with the same prompts, before and after:</p>
<ol>
<li><strong>Run a single request</strong> with the timing script from the <a href="https://vishctl.dev/posts/llm-inference-metrics-ttft-tpot-throughput-goodput/#try-it-measure-ttft-and-tpot-yourself">inference metrics guide</a>. TPOT should drop.</li>
<li><strong>Run a load test</strong> at your normal request rate. Check that throughput did not fall.</li>
<li><strong>Try your real prompts</strong>, not a demo prompt. Acceptance on your traffic is the only number that matters.</li>
</ol>
<h2 id="should-you-use-it">Should you use it?</h2>
<figure class="mermaid-figure">
  <div class="mermaid">flowchart TD
    Q1["Is the GPU usually<br/>near saturation?"] d1@-->|"Yes"| X["Skip it<br/>add capacity first"]
    Q1 d2@-->|"No"| Q2["Is the output<br/>predictable?"]
    Q2 d3@-->|"Copies the prompt"| N["Try n-gram<br/>almost free"]
    Q2 d4@-->|"Code or JSON"| D["Try a draft model<br/>about 10x smaller"]
    Q2 d5@-->|"Creative text"| M["Small gain<br/>measure before keeping"]

    d1@{ animate: true }
    d2@{ animate: true }
    d3@{ animate: true }
    d4@{ animate: true }
    d5@{ animate: true }

    classDef question fill:#281d48,stroke:#a78bfa,color:#f1edff,stroke-width:2px;
    classDef warn fill:#302410,stroke:#fbbf24,color:#fff3cf,stroke-width:2px;
    classDef gpu fill:#173f59,stroke:#22d3ee,color:#ecfeff,stroke-width:2px;
    classDef idle fill:#101e27,stroke:#324950,color:#8aa0a8;
    class Q1,Q2 question;
    class X warn;
    class N,D gpu;
    class M idle;</div>
  <figcaption>Start with how busy the GPU is. Speculation spends spare compute, so it pays off when there is some to spend.</figcaption>
</figure>

<h2 id="cheat-sheet">Cheat sheet</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">Speculative decoding = a cheap drafter proposes tokens, the big model verifies them in one pass
</span></span><span class="line"><span class="cl">Draft model          = the small LLM that proposes; should be about 10x smaller than the target
</span></span><span class="line"><span class="cl">Target model         = the big model whose output you actually want
</span></span><span class="line"><span class="cl">Verification         = one big-model pass that scores every drafted position at once
</span></span><span class="line"><span class="cl">Acceptance rate      = how often the target agrees with a drafted token
</span></span><span class="line"><span class="cl">Draft length         = how many tokens are proposed per round (num_speculative_tokens)
</span></span><span class="line"><span class="cl">Tokens per pass      = (1 - acceptance^(draft length + 1)) / (1 - acceptance)
</span></span><span class="line"><span class="cl">Lossless             = the output follows the target model&#39;s own choices, not the draft&#39;s
</span></span><span class="line"><span class="cl">N-gram, prompt lookup = draft by copying tokens that already appear in the prompt
</span></span><span class="line"><span class="cl">EAGLE-style heads    = small extra layers on the target model that do the drafting
</span></span><span class="line"><span class="cl">Where it hurts       = saturated GPUs and tight memory, where draft work crowds out requests
</span></span><span class="line"><span class="cl">Rule of thumb        = predictable output and spare GPU time: use it; busy GPU: skip it
</span></span></code></pre></div><p>Related: speculative decoding makes each stream faster, while <a href="https://vishctl.dev/posts/why-vllm-is-dominating-ai-inference-market/">continuous batching</a> makes the whole server carry more streams. For another way to skip work on structured output, see jump-forward decoding in <a href="https://vishctl.dev/posts/sglang-vs-vllm/">SGLang vs. vLLM</a>.</p>
]]></content:encoded></item></channel></rss>