NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Approximately Aligned Decoding

Daniel Melcer, Sujan Kumar Gonugondla, Pramuditha Perera, Haifeng Qian, Wen-Hao Chiang, Yanjun Wang, Nihal Jain, Pranav Garg, Xiaofei Ma, Anoop Deoras

Approximately Aligned Decoding (AprAD) is a novel decoding strategy designed to help Large Language Models (LLMs) follow complex constraints without sacrificing text quality or computational efficiency. By adapting backtracking algorithms from speculative decoding, AprAD finds a "Goldilocks" middle ground: it avoids the "gibberish" outputs of greedy constrained decoding and the massive compute costs of traditional rejection sampling.

The Problem: Two Flawed Extremes

Enforcing specific constraints on LLMs—such as avoiding the letter "E," preventing API hallucinations, or ensuring syntactic correctness—typically relies on two primary methods. Unfortunately, both exhibit significant flaws:

1. Constrained Decoding (Greedy) This method forces the model to pick the next best token that doesn't violate the rule. However, if the model heavily favored a banned token, forcing it to pick the next best one often leads to "probability amplification." The model might start outputting nonsense or resort to "character hacking" (e.g., using a Cyrillic 'а' to look like an English 'a') just to satisfy the constraint locally.

Constrained Decoding Probability Tree

2. Rejection Sampling (ASAp) This approach generates a whole sequence and throws it away if it contains an error. While this preserves the natural distribution of the language, it is incredibly slow. If the model is writing a long paragraph and hits a constraint violation at the very end, it must start entirely from scratch. In "dense" error scenarios where constraints are easily violated, this becomes computationally prohibitive.

ASAp Rejection Sampling Tree

The authors identify a critical need for a method that is efficient like greedy decoding but maintains high-quality output like rejection sampling.

The Solution: AprAD and Speculative Backtracking

The core innovation of AprAD is treating the constraint-following problem as a Speculative Decoding task.

In standard speculative decoding, a small "draft" model suggests tokens and a large "target" model verifies them. AprAD flips this logic:

  • The "Draft": The LLM's original, unconstrained probability distribution.
  • The "Target": The adjusted distribution that strictly excludes "bad" tokens (the error set).

When the model generates a token that leads to a constraint violation, AprAD doesn't just pick a different token (greedy) or restart the whole prompt (ASAp). Instead, it uses the Speculative Sampling algorithm to determine exactly how many tokens to backtrack. It calculates a "residual" distribution and decides, based on a statistical criterion, which parts of the prefix are still "valid" and where the model needs to "rethink" its path.

This allows the model to backtrack just enough to find a different linguistic path that avoids the error, effectively "re-aligning" the output to the desired distribution with minimal extra work.

Experimental Setup

The authors evaluated AprAD across three distinct environments:

  • Simulated Models: A toy environment with a known "ideal" distribution to mathematically measure how much AprAD distorts the output using KL-divergence.
  • Lipograms: A challenging creative writing task where the model must avoid specific vowels (A, E, I, O, or U). This represents a "dense" constraint because vowels are ubiquitous in English.
  • BigCodeBench: A real-world benchmark for code generation where the constraint is API Hallucination Avoidance—preventing the model from calling libraries or functions that do not exist in the environment.

Key Findings and Results

  • Backtracking is a Spectrum: Existing methods are just extremes. Constrained decoding backtracks 0 tokens; ASAp backtracks the entire sequence. AprAD provides a mathematically grounded way to backtrack a variable, optimized number of tokens.
  • Quality vs. Speed: In Lipogram tests, AprAD achieved a human-rated quality score of 4.52/5, nearly matching unconstrained models (4.68). In contrast, greedy constrained decoding scored lower (3.56) due to awkward phrasing and character hacking. AprAD successfully avoided the "Cyrillic Hack" by backtracking to choose entirely different, natural words.
  • Computational Savings: AprAD shines most when constraints are dense. On the Lipogram task, ASAp required a staggering 321 model invocations per output token due to constant restarts. AprAD required only 4.2 invocations, making it nearly 80x more efficient while maintaining similar quality.
  • Coding Accuracy: On BigCodeBench, AprAD improved the Pass@1 rate (the probability that the first generated code snippet is correct) compared to unconstrained models by successfully filtering out hallucinated APIs without the massive overhead of full re-sampling.

Limitations and Future Work

While AprAD represents a massive leap forward, it is not without limitations. It is "approximately" aligned, meaning it still introduces a small amount of distribution distortion compared to perfect rejection sampling. Furthermore, while much faster than ASAp, it carries more inference overhead than simple greedy decoding.

The authors suggest that future work could introduce a hyperparameter to tune the conformance-speed tradeoff. Additionally, because AprAD is a reactive decoding strategy rather than a proactive search algorithm, combining it with look-ahead search methods (like Monte Carlo Tree Search) could unlock even greater potential for complex reasoning tasks.

Summary updated

BibTeX
@inproceedings{melcer2025approximately,
  author = {Daniel Melcer and Sujan Kumar Gonugondla and Pramuditha Perera and Haifeng Qian and Wen-Hao Chiang and Yanjun Wang and Nihal Jain and Pranav Garg and Xiaofei Ma and Anoop Deoras},
  title = {{Approximately Aligned Decoding}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=0mOBdNsI3L},
}
Figure