In the world of Large Language Models (LLMs), "decoding"—the process of picking the next token—is often treated like a cookbook. Engineers reach for a shelf of heuristics: a dash of Top-K, a sprinkle of Temperature, or perhaps the "Nucleus" (Top-P) sampling if they’re feeling fancy. While these "tricks" work, they often feel disconnected from the rigorous mathematical foundations of the rest of machine learning.
A new paper, "Decoding as Optimisation on the Probability Simplex," argues that we should stop treating decoding as a collection of hacks. Instead, the authors propose a unified framework that views every major decoding strategy as a specific solution to a single optimization problem.
TL;DR
This paper unifies popular LLM decoding strategies (Greedy, Softmax, Top-P/K) into a single optimization framework over the probability simplex. By viewing decoding as a trade-off between model scores and structural regularizers, the authors derive a new sampler called Best-of-K (BoK) that significantly boosts performance in multi-sample tasks like math and coding.
What Problem Does This Paper Address?
Currently, decoding is seen as a "heuristic knob-tuning exercise." We know that Top-K helps with diversity and Greedy helps with logic, but we lack a principled theory explaining why these specific procedures exist or how to invent new ones.
Furthermore, standard decoders are designed for a "single-draw" scenario—picking one best token. However, modern LLM pipelines often use "multi-sample" strategies like self-consistency or re-ranking, where we generate $K$ different answers and pick the best one. Standard samplers often waste their "budget" by repeatedly sampling the same high-probability tokens, failing to explore the diverse set of alternatives needed for these pipelines to succeed.
Methods
The authors introduce a "Master Objective" for decoding: $$\max_{q \in \Delta(\mathcal{V})} [\langle q, s_t \rangle - \lambda \Omega(q)] \quad \text{subject to } q \in \mathcal{C}_t$$
In plain English: find a probability distribution ($q$) that maximizes the expected model score ($s_t$) while satisfying some structural preferences (the regularizer $\Omega$) and hard constraints ($\mathcal{C}_t$).
The "Master Key"
By applying Karush-Kuhn-Tucker (KKT) optimality conditions, the authors show that:
- Greedy decoding is the solution when there is no regularization ($\lambda=0$).
- Softmax sampling is the unique optimum when using Shannon entropy as a regularizer.
- Sparsemax (which sets low-probability tokens to exactly zero) emerges from a quadratic regularizer.
Best-of-K (BoK)
Using this framework, they "invent" a new decoder designed for multi-sample pipelines. BoK optimizes for coverage: it maximizes the probability that at least one of your $K$ samples will be a "hit" (a high-quality token). This creates a natural "anti-collapse" bias, encouraging the model to explore valuable but under-sampled alternatives.
Mirror Ascent
Because the BoK objective doesn't have a simple closed-form solution, the authors use Mirror Ascent. Unlike standard gradient descent, which assumes a flat Euclidean geometry, Mirror Ascent respects the geometry of the probability simplex (using KL-divergence), ensuring the resulting distribution is always valid and stable.
Datasets
The authors evaluated their framework and the BoK sampler using:
- Models: Qwen2.5-Math-7B and Qwen2.5-7B.
- Benchmarks:
- MATH500: Challenging competition-level mathematics.
- GPQA-diamond: High-level science and reasoning questions.
- HumanEval: Python coding tasks.
Key Insights and Ideas
- Decoding is Optimization: The most profound insight is that decoders differ not by how they sample, but by what objective they are implicitly optimizing.
- Geometry Matters: The "heavy tail" problem in Softmax (where the model samples nonsense) happens because the entropy gradient "blows up" at zero, preventing the model from ever truly discarding a token. Quadratic regularizers (Sparsemax) fix this by allowing the optimization to hit the boundary of the simplex.
- Diminishing Returns for Diversity: The BoK coverage objective has an inherent property of diminishing returns. Once a token is "likely enough" to be sampled once in $K$ tries, the optimizer shifts its focus to other promising tokens, naturally producing a more useful set of candidates for self-consistency.
Key Results
- Massive Accuracy Gains: On the MATH500 benchmark with a Qwen2.5-Math-7B model, BoK improved accuracy from 53.0% to 71.6% (+18.6%) at high sampling temperatures ($\tau=0.9$).
- Outperforming Baselines: BoK consistently beat both vanilla sampling and Top-K across math, science, and coding tasks, especially in "high-entropy" regimes where standard sampling becomes unreliable.
- Low Overhead: Despite being an iterative solver, BoK is efficient. Using just 5 mirror-ascent steps per token adds only about 1 second to the total generation time for a math problem.
Limitations and Future Work
- Per-Step Limitation: The current framework optimizes decoding one token at a time. The authors note that extending this to sequence-level objectives (optimizing the whole sentence at once) is a logical but more complex next step.
- Hyperparameters: While BoK is robust, it introduces two new hyperparameters ($\beta$ and $\lambda$) that control the trade-off between coverage and model anchoring.
- Compute-Awareness: The authors suggest that future decoders could be "compute-aware," adjusting their optimization budget based on how much time or power is available for a specific query.
Summary updated