XGrammar 2: 에이전트형 LLM을 위한 동적이고 효율적인 구조적 생성 엔진
XGrammar 2: Dynamic and Efficient Structured Generation Engine for Agentic LLMs
현대의 LLM 에이전트들은 도구 호출(tool calling)이나 조건부 구조적 생성과 같이 점차 복잡해지는 구조적 생성 작업을 처리해야 합니다. 이러한 작업들은 사전 정의된 구조보다 훨씬 더 동적이며, 현재의 구조적 생성 엔진에 새로운 과제를 안겨줍니다. 본 논문에서는 에이전트형 LLM을 위해 고도로 최적화된 구조적 생성 엔진인 XGrammar 2를 제안합니다. XGrammar 2는 새로운 동적 디스패치 시맨틱인 TagDispatch를 통해 이러한 동적 구조적 생성 작업을 위한 마스크 생성을 가속화합니다. 또한 컴파일 시간을 단축하기 위해 JIT(Just-In-Time) 컴파일 방식을 도입하고, 서로 다른 문법 간의 공통된 하위 구조를 활용하기 위해 교차 문법 캐싱 메커니즘을 도입했습니다. 추가로, 기존의 PDA 기반 마스크 생성 알고리즘을 Earley 파서 기반으로 확장하고, 문법 내 반복 구조를 처리하기 위해 반복 압축 알고리즘을 설계했습니다. 평가 결과, XGrammar 2는 기존 구조적 생성 엔진 대비 6배 이상의 속도 향상을 달성했습니다. LLM 추론 엔진과 통합된 XGrammar 2는 오버헤드가 거의 없이 동적 구조적 생성 작업을 처리할 수 있습니다.
Modern LLM agents are required to handle increasingly complex structured generation tasks, such as tool calling and conditional structured generation. These tasks are significantly more dynamic than predefined structures, posing new challenges to the current structured generation engines. In this paper, we propose XGrammar 2, a highly optimized structured generation engine for agentic LLMs. XGrammar 2 accelerates the mask generation for these dynamic structured generation tasks through a new dynamic dispatching semantics: TagDispatch. We further introduce a just-in-time (JIT) compilation method to reduce compilation time and a cross-grammar caching mechanism to leverage the common sub-structures across different grammars. Additionally, we extend the previous PDA-based mask generation algorithm to the Earley-parser-based one and design a repetition compression algorithm to handle repetition structures in grammars. Evaluation results show that XGrammar 2 can achieve more than 6x speedup over the existing structured generation engines. Integrated with an LLM inference engine, XGrammar 2 can handle dynamic structured generation tasks with near-zero overhead.
No Analysis Report Yet
This paper hasn't been analyzed by Gemini yet.