Why JSON Escaping Broke llama.cpp Prompt Lookup (79% to 11%), While Native MTP Hit +63%
If you run local coding agents against llama.cpp, prompt lookup speculative decoding (--spec-type ngram-mod) looks like a free lunch in plain-text code-edit benchmarks. When a model rewrites an existing Python file in plain Markdown, ngram-mod echoes matching spans straight out of the prompt buffer. On my Mac Studio M5 Ultra 512 GB, plain-code rewrites hit 79% draft acceptance and +56% faster decode.
Then I wrapped the exact same 8 automated-test Python bug-fix tasks inside real JSON tool-call payloads - the format actual terminal coding agents use to write files:
{"path": "service.py", "content": "def fix(x):\n return \"ok\""}
ngram-mod acceptance collapsed from 79% to 10.9%. Net speedup dropped to 0% on both GLM 5.3 Flash and GLM 5.3.
Why Literal N-Gram Lookup Breaks Inside Agent Tool Calls
Prompt lookup works by scanning the prompt's token ID buffer for exact matching n-grams and proposing the following tokens as speculative drafts. In plain Markdown code edits, the edited file in the model's output shares long identical token sequences with the source file in the prompt.
When a coding agent serializes that exact same file edit as a JSON string value:
- Actual newline tokens become literal two-character
\nescape sequences. - Double quotes become
\"and backslashes become\\. - Leading indentation merges with escaped newline tokens into completely different BPE token IDs than the unescaped source code sitting in the prompt.
Because ngram-mod matches raw token IDs literally, almost every multi-token prefix disappears. Roughly 89% of drafted tokens are rejected, and wall-clock decode falls right back to speculative decoding OFF.
Native Multi-Token Prediction (MTP) Does Not Care About Escaping
Models shipped with embedded Multi-Token Prediction heads (GLM 5.3 Flash, GLM 5.3, and DeepSeek V4.1 Flash) do not copy literal token spans from the prompt. A small learned draft head predicts upcoming tokens directly from the model's hidden states, so it predicts \n and \" just as accurately as raw code.
| Model & Runtime | Spec OFF | ngram-mod (JSON) | Native MTP (JSON) | MTP Accept |
|---|---|---|---|---|
GLM 5.3 Flash (UD-Q6_K_XL, llama.cpp) |
32.4 tok/s | 32.4 tok/s (0%, 10.9% acc) | 52.9 tok/s (+63%) | 79-82% |
GLM 5.3 (UD-Q2_K_XL, llama.cpp) |
23.2 tok/s | 23.2 tok/s (0%, 10.9% acc) | 37.2 tok/s (+61%) | 79-82% |
DeepSeek V4.1 Flash (oQ4e-mtp, oMLX) |
49.8 tok/s | N/A | 73.1 tok/s (1.65x wall) | 81.3% (89.6% copy) |
Four Other Surprises From 2,400+ Runs on 512 GB Unified Memory
- Late-November engine upgrades alone were flat (~0%). Isolating
oMLX 0.7.3 -> 0.8.3(49.5 -> 49.8 tok/son DeepSeek V4.1 Flash) andllama.cpp b12359 -> b12726(31.9 -> 32.5 tok/son GLM 5.3 Flash) with speculation OFF showed that Native MTP - not base engine updates - produced almost all of the real speedup. - 64K warm prompt caching + MTP scaled cleanly: DeepSeek dropped from
28.9 scold to2.0 swarm (14.3x) at77.1 tok/s(+58%, 100% Nominal thermals); GLM 5.3 Flash dropped from115.3 scold to0.58 swarm (198x) at54.8 tok/s(+79%). - Two real places to turn MTP OFF on DeepSeek: (a) Low effort + MTP hit a 4,096-token whitespace loop on a strict nested-enum
json_schematest (High + MTP passed5/5, reported in jundot/omlx#5710); (b) DeepSeek MTP peaked at 2 simultaneous clients (92.1 tok/s) and saturated at 4 clients (p9563.8 -> 93.5 s, peak361.5 W), while GLM 5.3 Flashdraft-mtpscaled smoothly to 4 clients (77.8 agg tok/s,170 GiBRAM spare). - Warm up
oMLXMTP once after boot: The first MTP call compiles Metal verifier shaders (~62.5 scold TTFT); subsequent warm calls drop to0.3 s.
• GitHub repository (2,400+ raw per-task CSV rows, pinned SHA-256s & launch flags): github.com/l8w8/videos
• Part 1 video (22 setups baseline across 5 frontier models, 12 min): youtu.be/vF-LUF6kPsE
• Part 2 video (Native MTP, JSON escaping trap, 64K cache & concurrency, 11 min): youtu.be/cEOhoBGDTeM