JSON escaping breaks prompt lookup but native MTP restores speed
Prompt lookup speculative decoding fails with JSON tool calls due to token mismatches, while native multi-token prediction maintains high acceptance rates and significant speedups.
Recent benchmarks on Apple Silicon reveal a critical performance pitfall for local large language model deployments using llama.cpp. While prompt lookup speculative decoding offers massive speedups for plain-text code generation, its effectiveness collapses when models output structured JSON tool calls. Conversely, native multi-token prediction heads remain robust against these formatting changes, delivering consistent acceleration regardless of payload structure.
What happened
Engineers testing coding agents on a Mac Studio M5 Ultra with 512 GB of unified memory observed a dramatic drop in speculative decoding efficiency. When running plain-text Python file edits, the ngram-mod prompt lookup method achieved a 79% draft acceptance rate, resulting in a 56% faster decode time. However, when the same eight automated test tasks were wrapped in standard JSON tool-call payloads, the acceptance rate plummeted to 10.9%. This collapse eliminated any net speedup, causing performance to revert to baseline levels for both GLM 5.3 Flash and GLM 5.3 models.
The issue stems from how serialization alters token sequences. In plain Markdown, the model’s output shares long, identical token spans with the source code in the prompt. But in JSON, newlines become literal \n escape sequences, quotes become \", and indentation shifts. These changes create completely different Byte Pair Encoding (BPE) token IDs compared to the unescaped source code. Since ngram-mod relies on exact literal matches of token IDs from the prompt buffer, it fails to find matching prefixes, leading to roughly 89% of drafted tokens being rejected.
In contrast, models equipped with embedded Multi-Token Prediction (MTP) heads, such as GLM 5.3 Flash, GLM 5.3, and DeepSeek V4.1 Flash, do not depend on copying literal token spans. Instead, a small learned draft head predicts upcoming tokens directly from the model’s hidden states. This approach allows the model to predict escaped characters like \n and \" just as accurately as raw code, maintaining high acceptance rates between 79% and 82% even within JSON structures.
How it works
Prompt lookup speculative decoding operates by scanning the prompt’s token ID buffer for exact matching n-grams and proposing the subsequent tokens as speculative drafts. This method is highly efficient when the output closely mirrors the input, as seen in plain-text code editing where large blocks of code are reused or slightly modified. The mechanism assumes that if a sequence of tokens exists in the prompt, it is likely to appear again in the output in the same form.
Native MTP functions differently by leveraging a dedicated neural network head trained to predict multiple future tokens simultaneously based on the current hidden state of the model. Rather than looking up past tokens, it generates predictions probabilistically. This means the format of the output—whether plain text or escaped JSON—does not disrupt the prediction logic. The model learns the statistical likelihood of token sequences, allowing it to handle syntactic variations like escape characters without losing accuracy or speed.
Key details
- Prompt lookup acceptance dropped from 79% to 10.9% when switching from plain Markdown to JSON payloads.
- Native MTP maintained a 79-82% acceptance rate for GLM models and 81.3% for DeepSeek V4.1 Flash in JSON tasks.
- GLM 5.3 Flash with Native MTP reached 52.9 tokens per second, a 63% increase over the baseline of 32.4 tokens per second.
- DeepSeek V4.1 Flash with Native MTP achieved 73.1 tokens per second, representing a 1.65x wall-clock speedup.
- Late-November engine upgrades alone contributed negligible speed gains, confirming MTP as the primary driver of performance improvements.
- Warm prompt caching combined with MTP reduced cold start times significantly, with GLM 5.3 Flash dropping from 115.3 seconds to 0.58 seconds.
Why it matters
For developers building local AI coding assistants, this distinction dictates which inference backend and model architecture to choose. Relying on prompt lookup for agent workflows that involve structured data exchange can lead to unexpected performance bottlenecks. Engineers might assume speculative decoding is always beneficial, but without understanding the token-level impact of serialization formats, they may see no improvement or even increased overhead due to rejected drafts.
Adopting models with native MTP heads ensures consistent performance across diverse output formats. As AI agents increasingly interact with tools via JSON schemas, the ability to maintain high throughput regardless of escaping rules becomes essential. This shift also highlights the importance of benchmarking with realistic payloads rather than idealized plain-text scenarios, ensuring that performance metrics reflect actual production conditions.
What you can do
- Switch to models with native MTP heads, such as GLM 5.3 or DeepSeek V4.1 Flash, for agent workflows involving JSON.
- Avoid relying solely on
ngram-modprompt lookup if your application heavily uses structured tool calls. - Benchmark your specific use cases with both plain text and JSON payloads to identify potential token mismatch issues.
- Enable warm prompt caching to maximize the benefits of MTP, reducing cold start times significantly.
- Monitor thermal and power usage when scaling MTP, as DeepSeek MTP showed saturation at four simultaneous clients.
- Ensure
oMLXMTP is warmed up after boot to avoid initial compilation delays of Metal verifier shaders.



