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

灵活且高效的语法约束解码

Flexible and Efficient Grammar-Constrained Decoding

ucsd(加州大学圣地亚哥分校)

Kanghee Park, Timothy Zhou, Loris D'Antoni

AI总结:

提出一种新型语法约束解码算法,在保证可靠性的同时,将离线预处理速度提升17.71倍,并保持在线掩码计算的最先进效率。

摘要:

大型语言模型(LLMs)常被要求生成遵循精确语法规则的结构化输出,如代码片段或格式化数据。语法约束解码(GCD)通过屏蔽可证明会导致输出不属于指定上下文无关文法(CFG)的词元,来保证LLM输出匹配此类规则。为保证可靠性,GCD算法必须计算给定LLM子词分词器如何与给定上下文无关文法使用的词元对齐,并基于此信息计算词元掩码。高效地完成此操作极具挑战性,现有GCD算法预处理常见文法需数十分钟。我们提出一种新GCD算法及实现,其离线预处理速度比现有方法快17.71倍,同时保持在线掩码计算的最先进效率。

英文摘要:

Large Language Models (LLMs) are often asked to generate structured outputs that obey precise syntactic rules, such as code snippets or formatted data. Grammar-constrained decoding (GCD) can guarantee that LLM outputs matches such rules by masking out tokens that will provably lead to outputs that do not belong to a specified context-free grammar (CFG). To guarantee soundness, GCD algorithms have to compute how a given LLM subword tokenizer can align with the tokens used by a given context-free grammar and compute token masks based on this information. Doing so efficiently is challenging and existing GCD algorithms require tens of minutes to preprocess common grammars. We present a new GCD algorithm together with an implementation that offers 17.71x faster offline preprocessing than existing approaches while preserving state-of-the-art efficiency in online mask computation.

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

↑