# Earley-Driven Dynamic Pruning for Efficient Structured Decoding

효율적인 구조화 디코딩을 위한 Earley 기반 동적 가지치기

Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · arXiv · 2025년 6월 1일

- **연구 문제** 제약 디코딩에서 Earley 파서가 만드는 무효·중복 상태는 메모리와 캐시 효율을 떨어뜨립니다.
- **연구 방법** ZapFormat은 의존성 그래프와 도달 가능성으로 활성 항목 집합을 계산하고, compact 연산으로 필요 없는 Earley 항목을 디코딩 중 실시간으로 제거합니다.
- **주요 결과** Formatron은 표 1에서 Gemma의 JSON Schema 처리량을 XGrammar 1473.99보다 높은 7943.34 tokens/s로 보고하며, pruning 제거 변형은 여러 조건에서 처리량이 낮게 측정됩니다.

## 제약 디코딩의 메모리 부담

문맥 자유 문법으로 LLM 출력을 제한하는 제약 디코딩은 매 디코딩 단계마다 어휘 전체의 토큰이 문법에 맞는지 검사하고, 그 결과로 로짓 마스크를 만듭니다. 이때 파서는 여러 파싱 상태를 저장하고 갱신해야 합니다. 더 이상 유효한 파싱 경로에 기여하지 않는 상태가 쌓이면 메모리 사용과 캐시 미스가 늘고 디코딩이 느려집니다. 이 논문은 이런 상태를 실시간으로 찾아 제거하는 ZapFormat을 다루며, 이를 구현하고 기존 최적화를 통합한 제약 디코딩 엔진 Formatron을 함께 보고합니다. 연구 범위는 JSON 생성, JSON Schema 검증, 의미 파싱 과제에서 처리량과 메모리 사용량을 측정하는 것입니다.

![Figure 2: Constrained decoding. Constrained decoding can be achieved by masking the illegal tokens at the current step](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-fde986f81c8ce7fdf8099d7e25eb7bac.png?thumb=512)

**Figure 2** . Constrained decoding. Constrained decoding can be achieved by masking the illegal tokens at the current step.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 4쪽에서 그림 영역을 추출했습니다.

## Earley 파싱과 상태 집합

Earley 알고리즘은 입력의 각 위치 i마다 상태 집합 S\[i\]를 만들고, 그 안에 Earley 항목을 담습니다. 항목은 규칙의 점 위치와 규칙이 시작된 위치 j를 함께 기록하며, 예측, 스캔, 완료의 세 연산으로 집합을 채웁니다. 예측은 점 뒤의 비단말 기호에 해당하는 규칙을 추가합니다. 스캔은 점 뒤의 단말 기호가 입력과 맞을 때 점을 넘긴 항목을 다음 집합에 넣습니다. 완료는 끝까지 파싱된 항목을 이용해 그 기호를 기다리던 상위 항목을 전진시킵니다. 완료 단계에서 역추적을 하려면 이전 집합을 대체로 보관해야 하므로, 더 이상 참조되지 않는 항목도 남기 쉽습니다.

![Figure 1: Early parse. This diagram provides a detailed illustration of the Earley parsing process for the input string ’a + d’ based on the grammar S → A + B,…](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-cb3c2b0f9786fe468e50c36a364ad0af.png?thumb=512)

**Figure 1** . Early parse. This diagram provides a detailed illustration of the Earley parsing process for the input string ’a + d’ based on the grammar S → A + B, A→ a\|c, B→ b\|d. In the diagram, red arrows indicate Predict operations; yellow arrows represent Scan operations; and green arrows denote Complete operations.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 3쪽에서 그림 영역을 추출했습니다.

## 의존성 그래프와 활성 항목 집합

ZapFormat은 Earley 항목을 (A → α • β, i, j) 형태로 확장해 규칙, 점 위치, 입력 구간을 함께 다룹니다. 예측, 스캔, 완료 각각에서 새로 만들어진 항목이 원래 항목에 의존하는 관계를 정의하고, 이를 정점과 간선으로 이루어진 방향 그래프에 기록합니다. 간선 (x, y)는 y가 x에 의존한다는 뜻입니다. 활성 항목 집합은 도달 가능한 항목들의 합집합으로 정의되며, 이 집합에 속하지 않는 항목은 더 이상 유효한 파싱에 기여하지 않는다고 판단됩니다. 원문은 도달 대상을 마지막 Earley 집합의 항목으로 설명하고, 활성 집합을 적는 식에서는 V의 항목 a에 대한 합집합으로 씁니다.

두 설명이 같은 대상을 가리키는지는 이 절에서 원문 표기 그대로 확인해야 합니다.

## compact 연산과 실시간 가지치기

ZapFormat은 완료 단계 이후이고 다음 예측 단계 이전에 compact 연산을 넣습니다. 이 연산은 현재 집합의 각 항목이 활성 항목 집합에 속하는지 검사하고, 속하지 않는 항목을 제거합니다. 예측으로 새로 만든 항목은 직전 집합의 항목에만 의존하므로 이 순서에서는 불필요한 계산이 줄어듭니다. 활성 집합은 완료와 compact 뒤에 점진적으로 갱신되어 전체 항목 집합을 매번 다시 탐색하지 않습니다. 저자들은 이 방식이 파싱 정확성을 유지하면서 처리할 항목 수를 줄인다고 설명합니다. 다만 정확성 보장은 원문이 이론적 완전성으로 주장하는 내용이며, 본문에서 이를 뒷받침하는 형식적 증명은 제시되지 않습니다.

![Figure 3: Dynamic pruning. Red parts indicate prunable nodes, and green dashed lines represent Complete dependency paths. First,already completed Earley items…](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-dfe8ffdb5273ace6c5e2c6ecc11d14e1.png?thumb=512)

**Figure 3** . Dynamic pruning. Red parts indicate prunable nodes, and green dashed lines represent Complete dependency paths. First,already completed Earley items only lead to modifications on their residing Earley set. Once their residing Earley set is fully processed, we can remove them. In addition, after one Earley set is fully processed, if an Earley set is not referenced by the union of reference chains of all items in the last Earley set, then it can be removed.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 6쪽에서 그림 영역을 추출했습니다.

## 토큰 마스크 캐시와 거부 접두사

Formatron은 문맥 독립 토큰의 유효성을 터미널별로 미리 계산해 비트셋으로 저장하고, 실행 시에는 캐시에서 바로 가져옵니다. 이 방식은 XGrammar의 문맥 독립 토큰 마스크 캐시에서 영감을 받았지만, 불가능 토큰을 판정할 때 터미널의 가능한 접미사 문자열을 고려하지 않아 사전 계산 시간을 줄입니다. 한 상태에 후위 터미널이 여러 개 있으면 각 마스크를 하나의 최종 토큰 마스크로 합칩니다. 거부 접두사 최적화는 문법적으로 불가능한 최소 바이트 접두사를 집합으로 유지하며, 입력에서 이런 접두사가 나타나면 그 확장들을 상태 탐색 없이 버립니다. 저자들은 서로 다른 입력 토큰 시퀀스가 같은 가지치기 상태에 대응할 수 있어 상태 캐시의 적중률이 높아진다고 해석합니다.

## 처리량 비교와 과제별 결과

실험은 NVIDIA GeForce RTX 3090과 AMD EPYC 7452 환경에서 Gemma, Llama3, Mistral, Qwen 네 모델을 FP16으로 실행해 측정했습니다. 비교 기준은 lm-format-enforcer, Outlines, XGrammar이며, Outlines는 정규 제약 중심이어서 JSON Grammar 과제에는 적용되지 않습니다. 표 1에서 Gemma의 JSON Schema 처리량은 XGrammar 1473.99 tokens/s에 비해 Formatron 7943.34 tokens/s로 보고됩니다. 대부분의 과제에서 Formatron의 값이 높지만, 저자들은 Gemma의 geoquery와 Mistral의 Json s에서 XGrammar가 더 우세하다고 서술합니다.

그런데 표 1의 Mistral Json s 값은 XGrammar 8421.43, Formatron 10639.87이므로 본문 서술과 표 값이 엇갈립니다. 초록에 보고된 최대 2배 속도 향상은 이 비교 범위와 조건에서 읽어야 합니다.

![Table 1: Comparative Throughput Performance of Different Meth- ods in Constraint Parsing Tasks (tokens/s). Here, ‘-‘ indicates that the method is not applicabl…](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-2f7616eb87af0b544313736c55fc10a0.png?thumb=512)

**Table 1** . Comparative Throughput Performance of Different Meth- ods in Constraint Parsing Tasks (tokens/s). Here, ‘-‘ indicates that the method is not applicable to the task, and bold indicates the best result. All experimental results were obtained in the same local environment. lm-format represents lm-format-enforcer. Json s represents Json Scheam and Json g represents Json Grammar.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 8쪽에서 그림 영역을 추출했습니다.

## 반복 실행과 제거 실험

Json Schema 과제에서는 1, 3, 5, 10회 실행 설정을 두었고, 데이터 증강에 LLM을 사용했습니다. 표 2에서 Gemma의 Formatron은 3회, 5회, 10회 실행에서 10609.08, 11323.63, 11993.89 tokens/s로 보고되며, 같은 조건의 XGrammar는 1500 tokens/s대 후반에 머뭅니다. 절제 실험에서 Formatron의 pruning을 제거한 변형은 Gemma에서 3회, 5회, 10회 실행 기준 6981.35, 6628.69, 7674.78 tokens/s로 낮게 측정됩니다. 본문은 pruning 제거 시 처리량이 30-50% 감소한다고 요약하지만, 이는 여러 모델과 실행 조건을 묶은 요약입니다.

모든 조건에서 확정된 수치로 읽으면 안 됩니다. Mistral의 3회 실행에서는 pruning 제거 변형이 9727.00 tokens/s로 Formatron 13522.77 tokens/s보다 낮습니다.

![Table 2: Throughput Comparison of Different Models and Meth- ods Across Multiple Runs. lm-format represents lm-format- enforcer](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-93a4a1389ed68bbbab9804b32125fd6e.png?thumb=512)

**Table 2** . Throughput Comparison of Different Models and Meth- ods Across Multiple Runs. lm-format represents lm-format- enforcer.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 8쪽에서 그림 영역을 추출했습니다.

## 메모리 사용량과 출력 품질

최대 메모리 사용량 실험은 제약 디코딩 중 측정한 값이며 모델 전체의 메모리 크기가 아닙니다. Llama3에서 Formatron은 1635.92 MB, pruning을 제거한 변형은 1655.48 MB이고, Mistral에서는 각각 1519.09 MB와 1530.77 MB로 보고됩니다. 이 측정은 Llama3와 Mistral에만 있으며 Gemma와 Qwen의 메모리 값은 이 표에 없습니다. 출력 품질은 부록 B.2의 정확도 표로 따로 확인합니다. JSON schema 과제에서 Llama3의 baseline은 0.47이고 Formatron은 0.67입니다. Mistral의 baseline은 0.09이고 Formatron은 0.52입니다.

JSON grammar 과제에서는 Llama3의 Formatron 값이 0.48, Mistral의 Formatron 값이 0.11입니다. 이 결과는 처리량 실험과 별도 보조 실험에서 얻은 것입니다.

![Table 4: Maximum memory usage comparison during constrained decoding](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-4be222903afd3df99a2294b085c30408.png?thumb=512)

**Table 4** . Maximum memory usage comparison during constrained decoding.

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.

![Table 7: Accuracy comparison across different models and methods for JSON schema and grammar tasks](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-65389fdd380337e0614c3b5c7bd666f8.png?thumb=512)

**Table 7** . Accuracy comparison across different models and methods for JSON schema and grammar tasks

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 14쪽에서 그림 영역을 추출했습니다.

## 적용 범위와 남은 질문

주요 처리량 측정은 파싱과 마스크 생성 단계에 초점을 둔 결과입니다. 전체 파이프라인 처리량은 부록 B.1에서 JSON 객체 수 기준으로 따로 보고되며, 여기서 Gemma의 Formatron은 제약 없는 기준 18.16에 비해 18.02로 근접합니다. Outlines는 정규 문법 중심이며 문맥 자유 문법을 직접 지원하지 않는다고 원문이 밝힙니다. 메모리 절감은 Llama3와 Mistral에서만 측정되었고, 정확도 보조 실험도 제한된 모델과 과제에서 수행되었습니다. 따라서 이 결과를 모든 LLM 구조, 모든 문법, 모든 하드웨어로 넓히는 것은 근거가 부족합니다.

![Table 6: Throughput comparison for parsing and masking stages across different models and methods (JSON objects per second)](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078/figures/figure-713e9fc51b8026d83c9821be6a323dad.png?thumb=512)

**Table 6** . Throughput comparison for parsing and masking stages across different models and methods (JSON objects per second)

[원문](https://arxiv.org/abs/2506.01151v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni · Earley-Driven Dynamic Pruning for Efficient Structured Decoding · 원문 그림 인용 · 원본 PDF 14쪽에서 그림 영역을 추출했습니다.

## 논문 정보

- **저자**: Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni
- **학회·저널**: arXiv · 프리프린트
- **최초 공개일**: 2025년 6월 1일
- **등록일**: 2026년 10월 29일
- **수정일**: 2025년 6월 1일
- **버전**: v1
- **arXiv**: 2506.01151
- **분류**: cs.LG · cs.AI · cs.CL
- **원문 이용 조건**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **제공 범위**: 논문 정보, 해설, 허용된 원문 그림

[논문 원문 ↗](https://arxiv.org/abs/2506.01151v1) · [원문 PDF ↗](https://arxiv.org/pdf/2506.01151v1)

AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.

## 초록

Large Language Models (LLMs) have shown remarkable capabilities, yet ensuring their outputs conform to strict structural or grammatical constraints remains challenging, which is critical in function calls and domain-specific language (DSL) generation. Constrained decoding with context-free grammar is a flexible approach to guarantee LLMs' adherence to a specific format by dynamically building a token logits mask. However, creating this mask requires checking the validity of all tokens in the LLM vocabulary at every decoding step, which often incurs significant overheads in existing constrained decoding engines. To address this challenge, we propose $\\textbf{ZapFormat}$, a novel $\\textbf{dynamic pruning}$ strategy based on the Earley algorithm that identifies and eliminates invalid or redundant Earley states in real-time, significantly reducing memory occupation of the Earley algorithm's states. This further enables us to use a state cache to speed up structured generations on a large number of queries. We implemented ZapFormat in a new constrained decoding engine called Formatron which also incorporates existing optimizations. Through comprehensive experiments on structured generation tasks, including JSON generation, JSON Schema validation, and semantic parsing, we demonstrate that Formatron not only $\\textbf{consistently maintains}$ high-precision compliant outputs but also achieves $\\textbf{significant improvements}$ in inference speed up to 2x compared to state-of-the-art implementations. More importantly, Formatron is generally applicable across various LLM architectures. We release Formatron as open source at https://github.com/Dan-wanna-M/formatron.

## 원문 인용

Xintong Sun, Chi Wei, Minghao Tian, Shiwen Ni (2025). Earley-Driven Dynamic Pruning for Efficient Structured Decoding. arXiv:2506.01151v1. https://arxiv.org/abs/2506.01151v1

**BibTeX**

```
@misc{sun2025earley,
  title = {{Earley-Driven Dynamic Pruning for Efficient Structured Decoding}},
  author = {Xintong Sun and Chi Wei and Minghao Tian and Shiwen Ni},
  year = {2025},
  eprint = {2506.01151},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.01151v1}
}
```

## 이 논문의 용어

- [accuracy](https://refivu.com/terms/1995c0cd6282-accuracy)
- [Throughput](https://refivu.com/terms/f064ae564aec-throughput)
- [context-free grammar](https://refivu.com/terms/2f29f98f66c1-context-free-grammar)

## 다른 논문 해설

- [ProofAug: Efficient Neural Theorem Proving via Fine-grained Proof Structure Analysis](https://refivu.com/papers/dc3cd5d7-b487-4962-a8e9-b14b39f6b02c-proofaug-efficient-neural-theorem-proving-via-fine-grained.md)
- [Dynamic Sparse Training of Diagonally Sparse Networks](https://refivu.com/papers/2b87988d-a129-482c-9c7b-0942ddbcacc0-dynamic-sparse-training-of-diagonally-sparse-networks.md)
- [Info-Coevolution: An Efficient Framework for Data Model Coevolution](https://refivu.com/papers/ca2da8f5-50c2-4679-8a70-bf933cc739b1-info-coevolution-an-efficient-framework-for-data-model.md)
- [EvoPress: Accurate Dynamic Model Compression via Evolutionary Search](https://refivu.com/papers/9b751a25-3027-4f44-b8fd-a5a56de096fa-evopress-accurate-dynamic-model-compression-via-evolutionary.md)
- [SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization](https://refivu.com/papers/5328df78-371a-4c98-b607-4082e43abef7-sageattention2-efficient-attention-with-thorough-outlier.md)
- [SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference](https://refivu.com/papers/6a719301-c428-424d-9dc3-3159ff623aea-spargeattention-accurate-and-training-free-sparse-attention.md)
- [Physics-informed Temporal Alignment for Auto-regressive PDE Foundation Models](https://refivu.com/papers/ff687cce-2026-49a1-b759-9c92a1972fc0-physics-informed-temporal-alignment-for-auto-regressive-pde.md)
- [Understanding Model Reprogramming for CLIP via Decoupling Visual Prompts](https://refivu.com/papers/46732ab5-6f1d-4649-9ad4-af5efd5f1de7-understanding-model-reprogramming-for-clip-via-decoupling.md)
- [Can Compressed LLMs Truly Act? An Empirical Evaluation of Agentic Capabilities in LLM Compression](https://refivu.com/papers/4365b281-b765-47b7-90d5-4a80eab279b6-can-compressed-llms-truly-act-an-empirical-evaluation.md)
- [UniMate: A Unified Model for Mechanical Metamaterial Generation, Property Prediction, and Condition Confirmation](https://refivu.com/papers/39f9214e-2ba4-425a-9865-3c171e494362-unimate-a-unified-model-for-mechanical-metamaterial.md)
- [Graph Generative Pre-trained Transformer](https://refivu.com/papers/f6ca3fa0-e807-499d-af61-83b0cd89bf26-graph-generative-pre-trained-transformer.md)
- [To Each Metric Its Decoding: Post-Hoc Optimal Decision Rules of Probabilistic Hierarchical Classifiers](https://refivu.com/papers/8d170ced-a777-41d4-ab4b-214f90d10748-to-each-metric-its-decoding-post-hoc-optimal.md)

---

AI 해설에는 오류가 있을 수 있습니다. [Refivu](https://refivu.com/papers/77982696-2b06-4b7d-9e4e-546fb563c078-earley-driven-dynamic-pruning-for-efficient-structured)
