Flexible and Efficient Grammar-Constrained Decoding

Jul 1, 2025·
Kanghee Park
Kanghee Park
,
Timothy Zhou
,
Loris D'Antoni
· 1 min read
Abstract
This work studies flexible and efficient methods for grammar-constrained decoding.
Type
Publication
International Conference on Machine Learning 2025

This paper focuses on the practical cost of grammar-constrained decoding. Grammar-constrained decoding can guarantee that generated outputs follow a context-free grammar, but efficient implementations must reconcile two different token systems: the grammar’s terminals and the language model’s subword tokenizer.

The work introduces a more flexible and efficient algorithm for computing the token masks needed during decoding. The main improvement is in offline preprocessing, making it faster to prepare common grammars while preserving efficient online mask computation during generation.

This is useful for structured generation tasks such as code, data formats, and other domains where syntax errors are unacceptable. The work appeared at ICML 2025.