TRANSMISSION // 2611.28349v1

When a grammar helps an AI write structured answers faster

Source published

Grammar-as-a-Draft lets an output grammar supply tokens a model’s speculative drafter would otherwise have to guess. Tests found faster structured decoding, alongside changes to output distribution and mixed-traffic latency costs.

AI-generated conceptual illustration for When a grammar helps an AI write structured answers faster
AI-generated conceptual illustration; not documentary evidence.

JSON keys, punctuation and indentation may be predictable to a grammar engine but still cost an AI model time to generate. A new technique merges those forced tokens with the model’s draft. It sped up tested structured-output workloads, but does not preserve exactly the same output distribution as ordinary decoding.

When a language model generates JSON or a tool call, a grammar can restrict its output to valid formats. But a speculative-decoding system may still spend time proposing keys, commas and indentation that the grammar already determines.

In a preprint, John Zhang and Silky Arora propose using that knowledge directly. Their method, Grammar-as-a-Draft (GaaD), treats the grammar as a second source of proposed tokens. The authors report faster structured-output decoding in tests on TPU hardware, while documenting an important caveat: the method can change which valid answer the model produces.

Letting the grammar fill the draft

Speculative decoding aims to reduce sequential steps in text generation. A faster drafter proposes several tokens; the larger target model checks them together and accepts a matching run. In standard speculative decoding, this checking preserves the target model’s output distribution.

With structured output, a grammar engine tracks what text is allowed next. Some positions are fixed—for example, a required key or colon—while others, such as a JSON value, remain choices for the model. GaaD merges the drafter’s proposal with tokens the grammar says are forced. If both propose the same forced token, it is marked as a grammar token. If they diverge, the model’s proposal is cut off and the grammar supplies further forced tokens, where available. The resulting draft row can be longer than the model drafter’s proposal.

The target model’s verification step accepts grammar-marked tokens without checking their logits. In the authors’ implementation, this avoids computing some model outputs and reuses the existing verification step rather than adding a new kernel. Unconditionally accepting these tokens, however, does not preserve the output distribution as standard speculative decoding does.

What the tests found

The authors implemented GaaD in vLLM’s TPU backend and in a separate Rust serving runtime. Their main benchmark used 50 prompts cycled into request batches, with outputs constrained to a JSON character profile: eleven fixed keys, fixed indentation and ten value fields. Tests used greedy decoding and a maximum output length of 256 tokens. The TPU experiments covered MTP, DFlash and n-gram drafters; the Rust tests used MTP.

In the TPU implementation, average accepted output per verification step rose from 2.06 to 5.43 tokens for MTP with the Qwen3.5-0.8B model. The authors also report gains with larger MTP and with DFlash and n-gram drafters. Compared with the best configuration of each drafter alone, GaaD was 2.66–2.81 times faster at batch size one and 1.14–1.70 times faster at batch size 64. In the Rust runtime, MTP with GaaD was 2.23 times faster on Qwen3.5-0.8B and 2.02 times faster on Qwen3.5-397B-A17B-FP8 at concurrency one; the reported gain on the smaller model was 1.22 times at concurrency 128.

These results apply to the tested software, hardware, models and benchmark—not necessarily to other deployments. The benefit shrank as batch size increased in the TPU tests. The authors attribute some of this to wider draft rows and the overhead of synchronizing with the host, but say their measurements do not fully separate the causes.

Faster does not mean identical

A grammar fixes text, not necessarily the model’s choice of tokens to represent it. The same indentation, for example, can be encoded as one token or several. GaaD uses the tokenizer’s canonical encoding for forced text, while ordinary grammar-masked decoding can choose another encoding. That difference can affect the model’s later choices, even when the visible text remains valid.

In the TPU benchmark, GaaD and the drafter alone produced different outputs for all 64 requests in the authors’ comparison. Every output matched the required regular expression, but agreement was lower for numbers and free-text values than for enumerated fields. An fp32 reference comparison found neither output systematically more likely. This does not establish that the answers were equally useful: the authors did not measure task accuracy, and they did not evaluate sampling. GaaD changes the output distribution relative to grammar-masked decoding, so it is not an exact-equivalence optimization.

Other users sharing the system may also pay a cost. In vLLM TPU mixed-traffic tests, with 25–50% structured requests, the per-batch scheduling rule made the workload finish 1.03–1.23 times sooner at batch sizes 16 and 64; structured requests finished 2.2–3.2 times sooner. Plain-text requests in the same batches experienced a 7–42% increase in time per output token. These figures depend on scheduling: engine-wide synchronization gave different results, and the per-batch rule could be slower at batch size one.

What remains uncertain

The evaluations used one JSON benchmark, greedy decoding and one TPU v7x slice, across two serving runtimes and a limited set of models and drafters. The benchmark contains many grammar-forced tokens, which the paper notes may favor GaaD. The Rust runtime was internal and not publicly released when the preprint was written. The authors did not measure task-level accuracy or sampling behavior, and identify host synchronization and mixed-traffic effects as areas needing further work.

This is an arXiv preprint, not evidence of peer-reviewed validation. Its measurements suggest that a grammar can serve as a useful drafting source in the tested setting; they do not show that GaaD will improve every structured-output workload or that its changed outputs are interchangeable for every application. Read the preprint.

Automatically matched by shared topic keywords. These links do not imply that the sources agree or establish a consensus.