arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2507.16768cs.AI
收藏

WGRAMMAR:利用先验知识加速结构化解码

WGRAMMAR: Leverage Prior Knowledge to Accelerate Structured Decoding

UC Berkeley(加州大学伯克利分校);Tsinghua University(清华大学)

Ran Wang, Xiaoxuan Liu, Hao Ren, Gang Chen, Fanchao Qi, Maosong Sun

AI总结:

本文提出WGRAMMAR解码引擎,通过将结构化约束分解为静态预编译与动态实例化、采用组合算子建模正则格式并引入掩码缓存,解决了LLM结构化解码的效率瓶颈,实现高达250倍加速。

摘要:

结构化解码使大语言模型(LLMs)能够生成下游系统所需格式的输出,例如HTML或JSON。然而,现有方法由于语法编译、状态跟踪和掩码创建而存在效率瓶颈。我们观察到,许多现实世界任务嵌入了关于输出结构的强先验知识。利用这一点,我们提出将约束分解为静态和动态组件——离线预编译静态结构,并在运行时使用语法片段实例化动态参数。我们不依赖下推自动机,而是采用一组组合算子来建模正则格式,从而实现更低的转换延迟。我们引入了wgrammar,一个轻量级解码引擎,它集成了领域感知简化、约束分解和掩码缓存,与现有系统相比实现了高达250倍的加速。wgrammar的源代码可在https://github.com/wrran/wgrammar公开获取。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑