atlas

Research map / Large language models / Language, safety and interpretability

Flexible and Efficient Grammar-Constrained Decoding

ICML 2025 · Large language models › Language, safety and interpretability · approach: Parallel and early-exit decoding · 1 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Presents GreatGramma, a grammar-constrained decoding algorithm built on a token spanner table over lexer states and realizable terminal sequences, achieving 17.71x faster offline preprocessing than SynCode while keeping low online masking overhead.

Problem

Grammar-constrained decoding must align LLM subword tokens with CFG terminals; existing methods either have high online per-token masking overhead or tens of minutes of offline preprocessing for common grammars.

Approach

Combine lexer and LLM vocabulary analysis into a token spanner table that maps (lexer state, LLM token) to realizable terminal sequences, then preprocess the parser against only these realizable sequences, using always-accepted tokens and context-dependent sequences at decoding time.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use GreatGramma's realizable-terminal-sequence preprocessing instead of SynCode's bounded speculative unrollingGrammar-constrained decoding · Go, Java, and Python grammars with Llama, Llama-3, and Qwen-2 tokenizersoffline preprocessing time: 17.71x fasterHelped
Use GreatGramma's context-dependent-sequence checks and inverse token spanner table instead of checking all terminal sequencesGrammar-constrained decoding · Go, Java, and Python grammars; remaining data pointsonline masking time: 2.73x faster than SynCode; 550.57x faster than OutlinesHelped
Use GreatGramma instead of OutlinesGrammar-constrained decoding · Go, Java, and Python grammars with the evaluated tokenizersoffline preprocessing time: 30.01x slowerHurt
Use SynCode's bounded future-terminal unrollingSynCode · Certain terminal sequencestoken-mask soundnessHurt

Surprising findings

Limitations

Experimental setup

Datasets: simplified Go grammar simplified Java grammar simplified Python grammar (from SynCode benchmark)

Benchmarks: Go, Java, Python grammars offline/online timing

Metrics: offline preprocessing time (seconds) online per-token masking overhead (milliseconds) geomean speedup

Baselines: Outlines SynCode XGrammar

Builds on: SynCode Lark Outlines

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy