<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: oooocean66</title>
    <description>The latest articles on DEV Community by oooocean66 (@oooocean66).</description>
    <link>https://dev.to/oooocean66</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4116715%2F95ff6c75-fa88-4d94-ba55-d6ef1a9270c9.jpg</url>
      <title>DEV Community: oooocean66</title>
      <link>https://dev.to/oooocean66</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oooocean66"/>
    <language>en</language>
    <item>
      <title>MTP Explained: How Qwen and Gemma Predict Several Tokens Ahead</title>
      <dc:creator>oooocean66</dc:creator>
      <pubDate>Wed, 09 Sep 2026 07:53:18 +0000</pubDate>
      <link>https://dev.to/oooocean66/mtp-explained-how-qwen-and-gemma-predict-several-tokens-ahead-4703</link>
      <guid>https://dev.to/oooocean66/mtp-explained-how-qwen-and-gemma-predict-several-tokens-ahead-4703</guid>
      <description>&lt;p&gt;&lt;strong&gt;MTP (Multi-Token Prediction)&lt;/strong&gt; is a technique that lets a language model predict several tokens ahead while it generates text, then confirm multiple tokens at once when those predictions turn out correct.&lt;/p&gt;

&lt;p&gt;Have you ever used an AI chat and thought, "I wish this answered a little faster"? That feeling gets stronger with "Thinking" models that reason carefully before answering, or with coding agents that iterate through trial and error. For AI systems that burn through thousands, even tens of thousands, of tokens to reach a good answer, generation speed directly shapes the user experience.&lt;/p&gt;

&lt;p&gt;So why does AI text generation take so long in the first place? The reason is simple: LLMs can only produce one token at a time. To decide the next word, the model has to re-run its massive computations from scratch, taking into account everything generated so far. That cost adds up, and the longer the response, the longer you wait.&lt;/p&gt;

&lt;p&gt;This raises a natural question: instead of recomputing everything one word at a time, why not compute a few words ahead in the same pass? That's exactly what MTP does. Every time the model generates a word, it also computes, in that same forward pass, a prediction for what the next few words are likely to be. If the prediction turns out correct, those predicted tokens are accepted all at once, confirming several words in a single step. If it's wrong, the model simply falls back to generating one token at a time as usual — so a wrong prediction costs little, while a correct one yields a meaningful speedup.&lt;/p&gt;

&lt;p&gt;This technique is often called &lt;strong&gt;speculative decoding&lt;/strong&gt;, a term borrowed from an older CPU optimization technique called "speculative execution." CPUs have long predicted which branch of code they're about to take, computed ahead of time based on that prediction, and either kept the result if it was right or discarded it and redid the work if it was wrong. MTP applies the same underlying idea to language model inference.&lt;/p&gt;

&lt;p&gt;This article (the concept edition) walks through how this mechanism is actually implemented inside real models (Qwen and Gemma), and how the two approaches differ. In the next installment — the implementation/benchmark edition — we'll actually run this technique and measure exactly how much faster it gets. Later in the series, we'll also cover "DFlash," which pushes this idea even further.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is MTP, Exactly?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;MTP (Multi-Token Prediction)&lt;/strong&gt; is a technique where an AI predicts several tokens ahead simultaneously while generating text. By predicting tokens in advance, the model can confirm multiple tokens at once when the prediction turns out correct, speeding up output.&lt;/p&gt;

&lt;p&gt;Similar efforts exist elsewhere: instead of generating text sequentially, some "diffusion" models generate text more like image generation, producing output in a more randomized order to speed things up (as of 2026, Google DeepMind and ELYZA, among others, appear to be researching diffusion language models). However, output quality for these remains unstable and hasn't reached a practical level yet.&lt;/p&gt;

&lt;p&gt;At least as of 2026, MTP is arguably the most reliable LLM speedup technique available today.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which Models Support MTP?
&lt;/h3&gt;

&lt;p&gt;The models currently supporting MTP fall mainly into two categories. Each uses a different implementation approach, so support in inference engines needs to be checked individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Qwen-3.5 / 3.6:&lt;/strong&gt; MTP is natively baked into the model itself — the model and its MTP drafter are a single package. It's supported out of the box in engines like vLLM. llama.cpp added experimental support relatively early on, and Unsloth has released an MTP-enabled model for Qwen-3.5-9B in GGUF format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gemma:&lt;/strong&gt; MTP is achieved by pairing the model with a &lt;em&gt;separate&lt;/em&gt; model called "Gemma-4-Assistant" — think of it as an add-on bolted onto the main model rather than something built in. llama.cpp support for this arrived somewhat later than for Qwen.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basic Mechanics of MTP
&lt;/h2&gt;

&lt;p&gt;Let's look at how behavior differs with MTP disabled versus enabled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[Conventional Inference (Token-by-Token)]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One forward pass predicts one token; the next step runs another forward pass. Because output comes one token at a time, this is relatively slow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step N (full forward pass) → token generated → Step N+1 (full forward pass) → token generated → ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;[Inference with MTP]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A single forward pass computes a certain number of tokens ahead.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Step N (forward pass, run once) ──┬─→ Token N     [confirmed]
                                   ├─→ Token N+1   [speculative]
                                   └─→ Token N+2   [speculative]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Token 1: output as confirmed.&lt;/li&gt;
&lt;li&gt;Token 2 onward: probability values are calculated in parallel as speculative predictions.&lt;/li&gt;
&lt;li&gt;Because output comes in multi-token units, this is relatively faster than the conventional approach.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Handling Predicted Tokens (Speculative Decoding)
&lt;/h2&gt;

&lt;p&gt;Predicted tokens go through a follow-up step where they're checked against the correct answer; once they clear the acceptance criteria, they're confirmed all at once.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Draft&lt;/strong&gt;
A lightweight method quickly predicts upcoming tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verification&lt;/strong&gt;
The production model computes the probability distribution for the predicted tokens in parallel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Acceptance&lt;/strong&gt;
The system checks how closely the probability distribution from verification matches the distribution the model would have produced without MTP, and determines whether it meets the acceptance threshold.
If it matches, the tokens up to that point are accepted and confirmed all at once.
If it doesn't match, drafting is cut off at the point of mismatch, and the result falls back to the production model's own inference.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Draft → Verification → Acceptance ─┬─ match ────→ accept all at once
                                    └─ mismatch ─→ cut off, fall back to the
                                                    production model's answer,
                                                    then Draft again
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because tokens appear to be generated "simultaneously," this is often mistaken for a diffusion model, but &lt;strong&gt;the underlying process is still strictly sequential.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In other words, this approach involves a real trade-off. When the prediction is correct, more tokens get confirmed at once, yielding faster output. But when it's wrong, the extra computation goes to waste, and the overhead can make the result slower than running the base model without MTP at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the Two Approaches to MTP Differ
&lt;/h2&gt;

&lt;p&gt;As mentioned, this article covers two implementations, and they differ considerably in their starting point, goals, and mechanics. Let's look at each in more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Qwen's Approach to MTP
&lt;/h3&gt;

&lt;p&gt;Qwen's approach is said to build on techniques researched for DeepSeek-V3, and has been used starting with Qwen3-Next.&lt;/p&gt;

&lt;p&gt;The reason this approach is built directly into the model is that the technique itself originally started out as &lt;strong&gt;"a method for training a smarter model."&lt;/strong&gt; MTP turned out to be useful, and the circuitry built into the model for that purpose is now also used, as a side effect, for speculative token prediction.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input token (N) → Qwen3.5 Main Model → state h_N^0 → Token N+1 [confirmed]
                                             │
                                             ▼ (also feeds the MTP path)
                                       MTP Module 1 → h_N^1 → Sampling &amp;amp; accept
                                             │
                                   match? ───┴─── no match?
                                     │                │
                        predicted token accepted   main model's token adopted
                          → confirmed as N+2         → confirmed as N+2, chain stops
                             │
                             ▼ (only if accepted)
                       MTP Module 2 → h_N^2 → Sampling &amp;amp; accept → ...same check for N+3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's how it works, broken down. Even with MTP disabled, when a token is input, the model's main processing generates a state h_N^0 based on the token sequence so far, which is then detokenized to produce token N+1.&lt;/p&gt;

&lt;p&gt;When MTP is enabled, as soon as state h_N^0 is produced, the requested number of MTP modules are created. If n tokens' worth of prediction is requested, n modules are prepared, each producing an embedding Emb_N^n that corresponds to a predicted word, based on state h_N^0.&lt;/p&gt;

&lt;p&gt;After that, as shown in the figure above, the embedding information for token N+1 — the token that would have been output even without MTP — is combined to produce state h_N^1. This state h_N^1 is sent to the main model, where its sampling and acceptance mechanism checks whether it matches what the main model would have predicted on its own.&lt;br&gt;
If it matches, that token is accepted and the process moves on to predicting the next token.&lt;br&gt;
If it doesn't match, the state predicted by the main model is used instead, and verification stops there.&lt;/p&gt;

&lt;p&gt;The defining feature is that the prediction and verification mechanisms are chained together one token at a time, forming a sequential flow throughout.&lt;/p&gt;
&lt;h3&gt;
  
  
  Gemma's Approach to MTP
&lt;/h3&gt;

&lt;p&gt;Gemma's approach was built from the ground up for speed, and its key difference from Qwen is that it processes prediction and verification together, in a batch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input token (N) → Gemma 4 Main Model → state h_N^0 → Prediction: N+1
                                             │
                                             ▼ (KV-cache update)
                                         KV-Cache ←──────────────┐
                                             │                   │ (shares cache)
                                             ▼                   │
                                    Gemma 4 Assistants ──────────┘
                                             │  (generates sequentially inside the
                                             │   draft model, then sends as a batch)
                                             ▼
                            Prediction: N+2, N+3, N+4, ... (candidate list)
                                             │
                                             ▼
                     Main model: causal-attention masking, probabilities computed
                     in parallel  ──┬── include only as many as fit into the output
                                    └── if none fit, exclude from output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Gemma, the draft model is external. Once the main model confirms the first token, the draft model predicts, all at once, however many tokens are allowed.&lt;/p&gt;

&lt;p&gt;The main model first receives the input tokens, generates a state, detokenizes it, and outputs token N+1. At this point, the draft model shares a KV cache with the main model (in Qwen's case, the MTP component and the main component maintain independent KV caches).&lt;/p&gt;

&lt;p&gt;Upon receiving the updated KV cache, the draft model generates however many predicted tokens are needed, and hands them off to the main model. The main model then checks, in a batch, whether these predicted tokens are correct using probability distributions, and determines how many of them are acceptable.&lt;/p&gt;

&lt;p&gt;As a result, however many predicted tokens the main model accepts get output together with token N+1, all at once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which Approach to MTP Is Better?
&lt;/h3&gt;

&lt;p&gt;Because the two approaches to MTP (Multi-Token Prediction) start from different premises, it's hard to say one is unconditionally superior. That said, evaluating primarily on maturity and compatibility with inference engines, as of July 2026, Gemma's approach appears more mature.&lt;/p&gt;

&lt;p&gt;First, there's a difference in the scope of sequential processing. Because token prediction fundamentally assumes "predicting the next token based on the state of the previous one," the process is inherently sequential. Comparing the flow of each approach, with time running left to right:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Qwen:   Input(N) → Main model → Predict N+2 → Judge N+2 → Predict N+3 → Judge N+3 → ...
                        │             confirmed:N+2 ↑          confirmed:N+3 ↑
                        └→ confirmed: N+1

Gemma:  Input(N) → Main model ──┬→ Predict N+2 ─┐
                        │       ├→ Predict N+3 ─┼→ Judge (batch) → up to n OK → confirmed: N+2, N+3, N+4, ...
                        │       └→ Predict N+4 ─┘
                        └→ confirmed: N+1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;strong&gt;Qwen's&lt;/strong&gt; approach, the main model predicts token N+1, uses that state to predict token N+2 and passes it to the main model, then predicts token N+3 only after seeing the verification result — repeating this process step by step.&lt;/p&gt;

&lt;p&gt;By contrast, with &lt;strong&gt;Gemma&lt;/strong&gt;, after predicting token N+1, the &lt;strong&gt;draft model&lt;/strong&gt; predicts however many tokens are needed all at once (starting from N+2), and hands them to the main model as a single batch. Processing on the main model's side is also parallelized, making this approach far more efficient than Qwen's. Because of this structural difference, Gemma's approach comes out ahead.&lt;/p&gt;

&lt;p&gt;Second, there's a difference in structural flexibility. Because Qwen's MTP functionality is integrated into the main model, improving the drafting logic requires additional post-training. Gemma, on the other hand, keeps the draft model separate, so it can simply be swapped out whenever better logic becomes available. This separation is also advantageous operationally.&lt;/p&gt;

&lt;p&gt;Finally, there's the ease of implementation in inference engines. Looking at llama.cpp's implementation, Gemma's approach can run even in multimodal configurations, while Qwen's approach doesn't support multimodal use. This difference stems from the fact that Qwen embeds MTP internally, requiring the branching logic to be handled inside the model itself. Gemma's approach, by contrast, simply toggles the feature on or off depending on whether input passes through the draft model, which is a more favorable structure for engine-side implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary (And a Preview of What's Next)
&lt;/h2&gt;

&lt;p&gt;MTP, at its core, works by confirming one token while, in that same pass, speculatively predicting a few tokens ahead at minimal extra cost&lt;sup id="fnref1"&gt;1&lt;/sup&gt;, then confirming them all together if the prediction turns out correct. Qwen builds this mechanism directly into the model itself; Gemma delegates it to a separate, dedicated draft model.&lt;/p&gt;

&lt;p&gt;In the next installment — the implementation/benchmark edition — we'll actually run both approaches on llama.cpp and measure, with real benchmarks, exactly how much faster they get and how often the predictions turn out correct. Later in the series, we'll also cover "DFlash," which takes this idea even further.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Qwen3-Next: Towards Ultimate Training &amp;amp; Inference Efficiency&lt;br&gt;
&lt;a href="https://qwen.ai/blog?id=4074cca80393150c248e508aa62983f9cb7d27cd" rel="noopener noreferrer"&gt;https://qwen.ai/blog?id=4074cca80393150c248e508aa62983f9cb7d27cd&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DeepSeek-V3 Technical Report&lt;br&gt;
&lt;a href="https://arxiv.org/pdf/2412.19437" rel="noopener noreferrer"&gt;https://arxiv.org/pdf/2412.19437&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Multi-token prediction with Gemma using Hugging Face Transformers&lt;br&gt;
&lt;a href="https://ai.google.dev/gemma/docs/mtp/mtp" rel="noopener noreferrer"&gt;https://ai.google.dev/gemma/docs/mtp/mtp&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This article is an English adaptation of the original Japanese post published on Zenn: &lt;a href="https://zenn.dev/highreso/articles/2fdb5402d98e5d" rel="noopener noreferrer"&gt;"小さく賭けて、大きく当てる：LLMを高速化する「投機的デコード（MTP）」の正体【概念編】"&lt;/a&gt;, by Yuichi Tominaga.&lt;/em&gt;&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;Speculating too many tokens ahead raises the cost of a wrong prediction, which can outweigh the benefit and slow things down. "Minimal extra cost" here means relative to the cost of recomputing everything from scratch for every single token in the conventional approach.&amp;nbsp;↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>machinelearning</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
