New Breakthrough in Incremental Constrained Decoding: GramDelta Makes Dynamic Grammar Evolution More Efficient

GramDelta enables efficient constrained decoding under dynamic grammars via incremental grammar-difference propagation and compilation-free mask projection.
GramDelta is an incremental grammar-constrained decoding framework for append-only runtime grammar updates, addressing the latency of rebuilding parser state and re-parsing committed prefixes when grammars change mid-decoding. It maintains parsing state over the committed prefix, propagates only changes along the dependency graph, and maps updated state to exact next-token masks via compilation-free factorized projection. Experiments show negligible overhead without updates and 10.7–11.5× lower median first-update latency versus the strongest rebuild baseline, with 53.1–81.9% less extra TPOT overhead than unconstrained decoding.
In code generation and domain-specific language (DSL) construction, constraints are often not fully known in advance but emerge progressively during the generation process—new declarations, inferred type information, or runtime analysis feedback can all introduce new grammar rules. Traditional grammar-constrained decoding engines can efficiently handle fixed or predefined constraint structures, but when faced with grammar updates that appear for the first time at runtime, they often need to rebuild the constraint state, causing repeated parsing of the already-committed prefix and introducing significant latency. A recent paper proposes GramDelta, an incremental constrained decoding framework for append-only runtime grammar updates, designed to address this pain point.

Background: Decoding Challenges Under Dynamic Grammars
Grammar-constrained decoding ensures that LLM outputs conform to formal constraints, which is crucial in scenarios such as code generation. However, in real applications, constraints may come from new declarations, type inference, or runtime feedback, and are not fully available before decoding begins. Existing structured decoding engines excel at handling fixed or previously seen constraint structures, but when a grammar update that appears for the first time changes the parser state induced by the already-committed prefix, the simple approach is to rebuild the constraint state under the updated grammar. This inevitably re-parses the prefix that has already been processed, causing unnecessary computational overhead.
According to the paper, this rebuilding can significantly slow down decoding in scenarios with continuous grammar evolution, and the latency problem becomes even more pronounced when updates are frequent.
Grammar-constrained decoding is a class of techniques that, during autoregressive generation, uses formal grammars (such as context-free grammars) to mask out grammatically invalid tokens in real time. A typical implementation maintains an incremental parser, advances the parsing state after each decoding step based on the committed tokens, and computes the mask of the allowed set for the next token accordingly. Because large language models have high accuracy requirements for structured outputs such as code, JSON, and SQL, this class of methods has become mainstream in code generation and domain-specific language (DSL) construction. However, traditional engines usually assume that the grammar is fixed before decoding begins. When the grammar is appended mid-decoding, the parser state needs to be realigned with the modified grammar, which is the core difficulty in dynamic scenarios.
GramDelta's Core Mechanism: Incremental Updates and Compilation-Free Projection
The core idea of GramDelta is to avoid prefix replay. It maintains the parsing state over the committed prefix. When new grammar rules are added, it only propagates the changes through historical dependencies instead of re-parsing the entire prefix. Specifically, GramDelta achieves efficient updates through the following two steps:
- Incremental propagation of grammar differences: Only the changes caused by new rules are propagated along the historical dependency graph, keeping the parsing state of the committed prefix unchanged.
- Compilation-free factorized projection: The updated parsing state is mapped to exact next-token masks using a shared historical chart for factorized projection, avoiding recompiling the mask cache on every update.
This approach guarantees the same results as a full rebuild while making the update cost depend on the scope of the actual grammar change rather than linearly on the prefix length.
Next-token mask is a boolean vector of the same length as the vocabulary, where positions with value 1 indicate tokens allowed by the current parsing state for the model to generate. During generation, disallowed tokens are set to negative infinity, ensuring that the output strictly conforms to the grammar. Recomputing the entire mask at every decoding step is expensive, so existing engines typically cache the mapping from parsing state to mask, the so-called mask cache. When the grammar is updated, if the parsing state changes, entries in the cache may become invalid and must be recompiled. GramDelta's factorized projection is precisely designed to avoid recompiling the entire table: it splits the mask into a shareable historical part and a part affected only by the current update, recomputing only the latter, thereby limiting the update cost to the scope of the grammar change.
Experimental Results: Significant Latency Reduction
The paper conducted experiments on four model configurations. Results show that when there are no grammar updates, the overhead introduced by GramDelta is negligible; under continuous runtime grammar evolution, compared with the strongest rebuild baseline, GramDelta reduces the median latency of first-seen grammar updates by 10.7–11.5× and reduces the extra TPOT (Time Per Output Token) overhead relative to unconstrained decoding by 53.1–81.9%. These data indicate that GramDelta can effectively handle scenarios where constraints emerge progressively and evolve with the generated prefix.
One detail: the experiments covered multiple model configurations, but the paper does not mention specific model names or parameter sizes.
TPOT (Time Per Output Token) refers to the average time spent generating each output token during the decoding phase. It is a key metric for measuring the interactive latency of inference services and usually excludes the time to generate the first token (TTFT). In grammar-constrained decoding, because each step requires computing or querying a mask, TPOT is often higher than in unconstrained decoding, and this difference is the extra overhead introduced by constraints. The 53.1–81.9% reported by GramDelta is precisely the reduction ratio of this extra TPOT relative to unconstrained decoding, indicating that it brings the latency cost of constrained decoding back close to that of ordinary decoding.
Significance and Outlook: Making Dynamic Constrained Decoding Practical
GramDelta offers a new approach to dynamic grammar-constrained decoding. In scenarios such as code generation and DSL construction, grammar rules may continuously enrich during the generation process. Traditional methods need to repeatedly rebuild the constraint state, whereas GramDelta significantly reduces latency through incremental updates, making real-time constrained decoding more feasible. Although the paper does not discuss the method's performance under extremely large grammars or extreme update frequencies, its significant improvements in experiments already demonstrate its potential. In the future, as constraint dynamics increase, such incremental techniques are expected to become a standard component of structured decoding engines.
For developers and researchers, GramDelta reminds us that when facing dynamic constraints, avoiding full rebuilds and using historical dependencies for incremental propagation is the key to improving efficiency. The framework is not yet open source, but its design ideas are worth borrowing in self-developed decoders.
One-line Summary
GramDelta achieves efficient constrained decoding under dynamic grammars through incremental propagation of grammar differences and compilation-free mask projection.
Paragraph Summary
GramDelta is an incremental grammar-constrained decoding framework for append-only runtime grammar updates, designed to solve the latency problem in which traditional engines must rebuild the parsing state and re-parse the committed prefix when the grammar changes mid-decoding. Its core is to maintain the parsing state over the committed prefix, propagate only the changes along the historical dependency graph when new rules are added, and map the updated state to exact next-token masks through compilation-free factorized projection, avoiding recompilation of the mask cache. Experiments show that the extra overhead is negligible when there are no grammar updates; under continuous evolution scenarios, the median latency of first-seen grammar updates is reduced by 10.7–11.5× compared with the strongest rebuild baseline, and the extra TPOT overhead relative to unconstrained decoding is reduced by 53.1–81.9%.
Related articles

AI Hacks Its Own Lab: The Security Tipping Point from Sci-Fi to Reality
Paul Christiano warns that AI intruding into its own cluster is no longer sci-fi but an established fact. He analyzes how persistent covert compromise can cause frontier labs to lose control, and why existing safety evaluation systems have blind spots.

New York Bans AI Toys for Five Years: The Escalating Child Safety Controversy
New York bans AI chat toys for five years as Common Sense Media research flags inappropriate content exposure and child emotional development risks. This article analyzes the ban's impact on product definitions, safety proof, and compliance strategies for the AI toy industry.

1Password Security Incident Review: The Trust Boundary of Password Managers
1Password releases an update on the Nov 2026 security incident, drawing 315 points and 139 comments on Hacker News. This article analyzes the actual boundaries of password manager zero-knowledge architecture, the gap between incident communication and user risk perception, and how transparency is becoming a new competitive dimension in the industry.