GaaD Turns Grammar into a Second Speculative Drafter for Faster Structured Decoding
Summary:Grammar-as-a-Draft (GaaD) treats a grammar engine as a second speculative drafter. Before each target verification round, the scheduler merges the model drafter's candidates with grammar-forced tokens, truncates the proposal where it leaves the legal path, and marks forced positions so they can be committed without target logits. The approach requires no new critical-path kernels or compilation and is reported in both vllm-torchtpu and an independent Rust serving runtime. On TPU v7x, average ac
Core Finding
GaaD directly addresses an information gap in speculative decoding for structured outputs. An ordinary drafter does not understand JSON Schema, regular expressions, or tool-call grammars, so it repeatedly spends proposal capacity on invalid keys, delimiters, and indentation. GaaD turns the grammar engine into a second drafter and injects legally forced tokens into the verification batch. On TPU v7x, the paper reports up to a 2.81x decoding speedup at batch size 1.
GaaD does not replace the language model with a rule engine. The grammar determines only the structural path; free-form text, argument values, and tool intent are still generated by the target model. What changes is the ordering of proposal construction and verification.
Mechanism: Merge Forced Tokens into the Verification Batch
Standard speculative decoding asks a low-cost drafter for a block of candidate tokens, then verifies the block in parallel with a larger target-model computation. If only a few tokens survive each verification round, repeated target-model calls dominate latency.
GaaD performs four operations before each verification round:
- The ordinary drafter produces a candidate sequence
D. - The grammar engine produces a forced sequence
Galong the currently legal path. - The scheduler merges them from left to right. Matching positions are marked
GRAMMAR; when the ordinary draft leaves the legal path, it is truncated and the remaining forced tokens fill the row. - During verification,
GRAMMARpositions can be committed without computing target-model logits. Other candidates still pass through target-model verification.
The paper reports that the method can compose with different drafters and requires no new critical-path kernels or compilation. It is implemented in vllm-torchtpu and in an independent Rust serving runtime, indicating that the core scheduling idea is not tied to one draft-generation algorithm.
Why It Works: Acceptance Length Controls Verification Rounds
For a verification row of width w, average acceptance length can be approximated as:
E[L_acc] = Σ(i=1…w) P(the first i candidates are accepted consecutively)
A longer accepted prefix means fewer target-model verification rounds are needed for the same output. GaaD converts positions guaranteed by the grammar into mandatory acceptances, substantially increasing this metric. With MTP and Qwen3.5-0.8B, average acceptance length rises from 2.06 to 5.43. At batch size 1, the reported decoding speedup is 2.66–2.81x, broadly consistent with the reduction in verification rounds.
At batch size 64, the gain narrows to 1.14–1.70x. Acceptance length therefore cannot be treated as a direct predictor of end-to-end throughput. GaaD may create wider draft rows, while grammar scheduling and candidate assembly introduce their own costs. The abstract does not provide a cost breakdown.
Engineering Trade-offs: Wider Drafts Are Not Free
A GaaD row may be wider than the sequence proposed by the ordinary drafter. If every additional candidate position requires materialized Transformer KV cache, a rough estimate of the additional memory is:
ΔM ≈ (w−γ) × 2 × L × H_kv × d_head × b
Here, γ is the original draft width, L is the context length, H_kv is the number of KV heads, d_head is the dimension per head, and b is the number of bytes per element. Temporary hidden states and buffers add an O(wd) term. A production implementation may reduce this cost through fusion, reuse, or avoiding some logit computation, but the abstract does not report peak HBM usage.
Verification cost is not linear in acceptance length alone. For context length L, processing a row of width w introduces approximately O((L+w)wd + wd²) projection- and attention-related work. End-to-end speedup depends on whether the reduction in target-model verification rounds outweighs wider drafts, grammar-state processing, and scheduling overhead.
Semantic Risk: Valid Structure Does Not Guarantee Distribution Equivalence
The central trade-off is not merely speed but output distribution. A grammar constrains a text path rather than the target model's probability over multiple legal tokenizations. Directly committing a canonical forced token bypasses the target model's logit choice at that position.
The paper notes that grammar-masked greedy decoding can still choose non-canonical tokenizations, while GaaD may produce a different but equally valid output that an fp32 reference treats as equally likely. GaaD should therefore not be described as token-for-token equivalent to grammar-masked decoding. It guarantees structural validity, but it does not automatically guarantee semantic equivalence, original-distribution sampling, or bitwise reproducibility. Numeric fields, enum choices, and tool arguments require explicit output-difference policies before deployment.
Benchmark Results and Evidence Limits
Average acceptance length on TPU v7x is reported as follows:
| Drafter and model | Without GaaD | With GaaD | |---|---:|---:| | MTP + Qwen3.5-0.8B | 2.06 | 5.43 | | MTP + Qwen3.5-35B-A3B | 1.99 | 5.31 | | DFlash + Qwen3-4B | 1.57 | 4.13 | | n-gram + Qwen3-4B | 1.30 | 3.64 |
The vllm-torchtpu implementation reports 2.66–2.81x faster decoding at batch size 1 and 1.14–1.70x at batch size 64. In the independent Rust runtime, MTP with GaaD is 2.23x faster on Qwen3.5-0.8B and 2.02x faster on Qwen3.5-397B-A17B-FP8; the reported speedup at 128 concurrent requests is 1.22x.
In mixed traffic with 25%–50% structured requests, the overall workload receives a 1.03–1.23x speedup, while structured requests themselves improve by 2.2–3.2x. Plain-text TPOT, however, rises by 7%–42%. GaaD is consequently better suited to traffic-aware routing than unconditional deployment across every request class.
The current evidence has four important limits. The evaluation centers on a JSON character-profile benchmark, where a high proportion of grammar-constrained positions naturally favors GaaD. Hardware results are concentrated on TPU v7x and cannot be extrapolated directly to CUDA GPUs. The abstract does not disclose absolute latency, tokens per second, peak memory, variance, or the complete baseline configuration. As an arXiv v1 paper, it also does not state whether code and a license are available for independent reproduction.
Deployment Guidance
- Start with tightly constrained workloads: JSON Schema, fixed tool-call protocols, and regular-expression outputs are the clearest use cases. Keep a separate path for workloads dominated by free-form text.
- Run output-differential tests: Compare JSON ASTs, tool arguments, enum values, and numeric fields instead of merely checking schema validity. Disable forced-token commitment where the original probability distribution or bitwise reproduction is required.
- Monitor system metrics as well as acceptance length: Track acceptance per round, schema failure rate, p50/p99 TPOT, throughput, peak HBM, and fallback frequency to avoid optimizing a single proxy metric.
- Isolate mixed-traffic queues: Separate structured and plain-text requests and determine whether the reported 7%–42% plain-text TPOT regression comes from queue contention, grammar processing, or wider draft rows.
- Repeat the benchmark on target hardware: vLLM scheduling, batching, and KV management all affect the result. Acceptance figures measured on TPU should not be assumed to transfer to CUDA or a custom accelerator.
— END —Source: ArXiv NLP/LLM (cs.CL) (2026-11-24)
Tags: #Speculative Decoding #Structured Outputs #JSON Schema #vLLM #TPU
Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.
Community Comments