AIAny

XGrammar: Flexible and Efficient Structured Generation Engine for Large Language Models

Enforces output grammars during LLM decoding while reducing CPU validation overhead. Precomputed token masks and persistent stacks support nested formats without checking the full vocabulary at every step.

Introduction

A fast model can still spend time waiting for CPU-side grammar checks. The useful insight is that most token-validity decisions depend only on a local grammar state, so they can be cached before generation rather than recomputed for every token.

Key Findings
  • Separating cacheable checks from stack-dependent checks preserves recursive grammar support while reducing runtime work.
  • Context expansion and persistent stacks handle the remaining cases and enable efficient branching and rollback.
  • The authors report up to 100× faster mask generation than existing methods in their evaluation. Overlapping grammar work with GPU execution makes structured output overhead nearly disappear in tested serving configurations; this is not a universal application speedup.
Who Should Read It

Useful for inference engineers serving tool calls, nested JSON, or domain-specific output languages. It explains where format enforcement belongs in a serving pipeline. Grammar compliance does not establish that an answer is factually correct or that a proposed tool action is appropriate; those need separate checks.

Information

  • Websitearxiv.org
  • OrganizationsCarnegie Mellon University, NVIDIA, Shanghai Jiao Tong University, University of California, Berkeley
  • AuthorsYixin Dong, Charlie F. Ruan, Yaxing Cai, Ruihang Lai, Ziyi Xu, Yilong Zhao, Tianqi Chen
  • Published date2024/11/22

More Items

Reuses Transformer weights across depth and neighboring tokens to improve language-model compute efficiency. It combines within-token iteration with cross-token state feedback, outperforming standard and looped baselines in matched-compute tests.

Evaluates whether language and generative models can handle the full game-development pipeline, from white-box construction and asset creation to playtesting and refinement. Across 60 tasks and four engines, strong standalone assets often fail to translate into playable integrated games.

Improves 4D video question answering by expressing object motion in the reference coordinate system required by each question. Experiments find that question-aligned relative trajectories work better than supplying world-coordinate trajectories.