The Optimal Decoder is Tilted Temperature

Nikolaos Papagiannis, Ananth Grama, Wojciech SzpankowskiarXiv 2026

TL;DR

This paper provides a formal theoretical foundation for LLM decoding, proving that the optimal strategy for maximizing pass@k is a "tilted temperature" sampling rule. By balancing diversity (entropy floor) and plausibility (cross-entropy ceiling), the authors turn the common "larger $k$ wants hotter temperature" folklore into a proven theorem and introduce practical algorithms that significantly outperform standard decoding baselines.

What Problem Does This Paper Address?

LLMs are trained to maximize the likelihood of the next token, but they are often evaluated on their ability to solve a task within $k$ attempts—a metric known as pass@k. Currently, practitioners tune the "temperature" hyperparameter empirically, generally observing that a larger sample budget ($k$) requires a "hotter" (higher) temperature to maintain diversity.

However, there has been no principled explanation for why this works or what specific objective temperature tuning actually optimizes. Without constraints, maximizing pass@k leads to a degenerate solution: a Dirac mass on the single most likely sequence, which fails to generalize and collapses diversity. This paper seeks to bridge the gap between token-level training and sequence-level success.

Methods

The authors formulate decoding as a constrained optimization problem: maximize pass@k subject to an entropy floor (to ensure diversity) and a cross-entropy ceiling (to ensure the model stays within the realm of plausible, coherent text).

The Tilted Temperature Rule

They prove that the solution to this problem is a closed-form sampling rule: $$q^\star \propto \bigl(p e^{\eta V}\bigr)^{1/T}$$ * $p$: The base model's distribution. * $V$: A "verifier potential" (calculated via Bellman recursion) that estimates how likely a partial sequence is to eventually pass. * $T$: The temperature, acting as the price of the entropy constraint. * $\eta$: The "tilt," acting as the price of the cross-entropy constraint.

Practical Algorithms

  1. J-EOS (Joint Online Tracking): An online algorithm that learns the verifier potential $V$ from binary pass/fail feedback and causally tracks the optimal dual prices (multipliers) for the constraints.
  2. CTD (Calibrated Temperature Decoding): An offline approach. The authors show that if a model is "calibrated" (i.e., its log-probability correlates with correctness), the verifier tilt becomes redundant. In this case, the optimal strategy reduces to standard temperature sampling, where the temperature is chosen to hit a specific entropy target.
  3. TMAD-GATED: A practical, lightweight decoder that uses a trained "continuation-success head" to predict the potential $V$ and intervenes only at structurally critical or low-confidence tokens.

Datasets

The researchers evaluated their methods on two primary code generation benchmarks:

  • HumanEval: 164 programming problems used to measure the functional correctness of synthesized code.
  • MBPP (Mostly Basic Python Problems): Around 500 entry-level Python programming concepts.

They tested these across three models: Qwen2.5-Coder-1.5B, Qwen3-4B-Base, and CodeLlama-7B.

Key Insights and Ideas

  • Folklore to Theorem: The paper mathematically proves the "larger $k$ wants hotter" rule. As the sample budget $k$ increases, the optimal entropy floor rises, which in turn forces the optimal temperature $T$ to increase.
  • The Power of Calibration: A major "aha moment" is that for well-calibrated models, sophisticated verifiers aren't strictly necessary for optimal decoding. If the model's own likelihood is a good proxy for correctness, simply picking the right temperature to maintain diversity is near-optimal.
  • Free Energy Interpretation: The verifier potential $V$ is not just a simple probability; it is a "free energy" quantity that combines the terminal reward with the downstream likelihood weighting.
  • Sequence-Level to Token-Level: The authors use a Bellman-style recursion to transform a sequence-level objective (pass@k) into a token-by-token decoding rule that can be implemented efficiently.

Key Results

  • Performance Gains: The practical TMAD-GATED algorithm achieved the best pass@k in 16 out of 18 experimental settings.
  • Significant MBPP Improvements: On the MBPP benchmark with the Qwen2.5-1.5B model, pass@5 jumped from 36.7% (fixed temperature) to 54.5% (TMAD-Gated).
  • Zero-Overhead Success: The CTD method, which adds zero inference-time overhead compared to standard temperature sampling, generally tracked or beat tuned-temperature baselines, confirming the theoretical link between calibration and temperature.

Limitations and Future Work

  • Potential Estimation at Scale: While the theory is robust, accurately estimating the verifier potential $V$ for extremely large models or complex reasoning tasks remains a challenge.
  • Calibration Assumptions: The CTD method relies on the model being (s, ε)-calibrated. While many LLMs show this property, it may not hold for all domains or for models that have been heavily RLHF-ed into overconfidence.
  • Hard vs. Soft Constraints: The practical implementation (TMAD-GATED) currently uses a soft Lagrangian penalty rather than the hard budget-feasibility filters derived in the theory.

Overall, this work provides the first rigorous "instruction manual" for LLM temperature tuning, moving the field from heuristic-based sampling to principled, optimal decoding.

Summary updated

BibTeX
@misc{papagiannis2026optimal,
  author = {Nikolaos Papagiannis and Ananth Grama and Wojciech Szpankowski},
  title = {{The Optimal Decoder is Tilted Temperature}},
  year = {2026},
  eprint = {2610.15058},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.15058},
}
Figure