WGRAMMAR: Leverage Prior Knowledge to Accelerate Structured Decoding

Ran Wang, Xiaoxuan Liu, Hao Ren, Gang Chen, Fanchao Qi +1 more
7/22/2025
cs.AI

No confident code implementation found for this paper. 1 possible match can be shown below.

Abstract

Structured decoding enables large language models (LLMs) to generate outputs in formats required by downstream systems, such as HTML or JSON. However, existing methods suffer from efficiency bottlenecks due to grammar compilation, state tracking, and mask creation. We observe that many real-world tasks embed strong prior knowledge about output structure. Leveraging this, we propose a decomposition of constraints into static and dynamic components -- precompiling static structures offline and instantiating dynamic arguments at runtime using grammar snippets. Instead of relying on pushdown automata, we employ a compositional set of operators to model regular formats, achieving lower transition latency. We introduce wgrammar, a lightweight decoding engine that integrates domain-aware simplification, constraint decomposition, and mask caching, achieving up to 250x speedup over existing systems. wgrammar's source code is publicly available at https://github.com/wrran/wgrammar.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. 1 weaker match is hidden by default — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Cite this paper

@article{wang2025wgrammar,
  title  = {WGRAMMAR: Leverage Prior Knowledge to Accelerate Structured Decoding},
  author = {Ran Wang and Xiaoxuan Liu and Hao Ren and Gang Chen and Fanchao Qi and Maosong Sun},
  year   = {2025},
  eprint = {2507.16768},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2507.16768v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2507.16768.svg)](https://codeofpaper.com/paper/2507.16768)

Discussion