Arithmetic Sampling: Parallel Diverse Decoding for Large Language Models

Luke Vilnis, Yury Zemlyanskiy, Patrick Murray, Alexandre Tachard Passos, Sumit Sanghai

When generating text from a Large Language Model (LLM), researchers typically face a frustrating trade-off between diversity and computational efficiency. On one hand, beam search and its variants produce high-quality, diverse candidates by keeping track of multiple hypotheses, but they are notoriously difficult to parallelize because they require synchronization across hardware at every single token step. On the other hand, ancestral sampling (like top-k or nucleus sampling) is incredibly fast and "embarrassingly parallel," but it offers no guarantees against generating duplicate sequences. This leads to wasted computation and noisy estimates of a model's true performance.

To break this trade-off, researchers have introduced Arithmetic Sampling, a novel decoding framework that combines the high-quality, diverse outputs of beam search with the parallelizable speed of standard sampling. By reinterpreting language model decoding as a geometric problem on the unit interval, it provides provable diversity guarantees and significantly reduces the variance of reward estimators like BLEU scores.

How Arithmetic Sampling Works

The core innovation draws inspiration from arithmetic coding and Randomized Quasi-Monte Carlo (RQMC) methods.

Standard sampling works by picking $N$ independent random numbers between 0 and 1 and mapping them to sequences. Arithmetic Sampling instead treats the entire space of possible sequences as sub-intervals of the unit interval $[0, 1]$, where the width of each interval corresponds to the sequence's probability.

Instead of picking $N$ random points, the algorithm uses a randomly shifted lattice:

  1. It picks a single random offset $b$.
  2. It generates $N$ points that are perfectly evenly spaced: $c_i = \frac{i}{N+1} + b \pmod 1$.
  3. It decodes each point independently.
A toy example showing how points on the unit interval map to sequences. Evenly spaced points (red dots) naturally fall into different high-probability sequence "buckets."

Because these points are "far apart" in the code space, they are mathematically guaranteed to fall into different sequence intervals (provided those sequences aren't extremely probable). Crucially, each sample can be computed entirely independently of the others, requiring zero synchronization during the generation process.

Key Insights and Advantages

  • Geometric Diversity: The framework relies on a "Monotonicity" property, where distance in the $[0, 1]$ code space correlates with prefix distance in the sequence space. If two codes are far apart, the sequences they generate will likely branch off from each other early on.
  • Unbiased Estimators: Unlike beam search, which is a biased search heuristic, Arithmetic Sampling provides unbiased and consistent expectations. This makes it a superior tool for researchers estimating the "expected reward" (like average BLEU score) of a model.
  • Stratified Sampling for Text: By forcing the samples to be spread out across the probability mass, the method avoids the "clumping" (duplicates) that plagues standard sampling.
  • Hardware Efficiency: By eliminating the "all-gather" synchronization steps required by beam search, Arithmetic Sampling can run efficiently on smaller, cheaper hardware clusters.

Empirical Results

The authors evaluated their method on three standard natural language processing benchmarks (WMT14 EnFr, WMT16 EnRo, and CNN/DailyMail) using T5-base and mt5 XXL models. The results show that Arithmetic Sampling consistently outperforms standard sampling across the board:

  • Variance Reduction: It more than halves the standard deviation when estimating expected BLEU scores. The "noise" in the estimate drops much faster as more samples are added compared to standard sampling.
  • Closing the Gap: In "oracle" settings (picking the best of $N$ samples), it closes the performance gap between independent sampling and beam search by up to 63%.
  • Diversity vs. Quality: For any given level of n-gram diversity, Arithmetic Sampling achieves a higher BLEU score than standard sampling, effectively pushing the Pareto frontier of decoding.
Comparison of average standard deviation for BLEU and ROUGE estimates. Arithmetic sampling (orange) consistently shows lower variance than standard sampling (blue).

Limitations and Future Work

While powerful, Arithmetic Sampling relies on the specific ordering of the vocabulary to define the codebook. Although the authors demonstrate this works well in practice, different vocabulary orderings might impact the "semantic" diversity of the results.

Future work could explore multi-dimensional coding schemes that capture even more geometric structure in the space of sequences. There is also significant potential in designing coding schemes specifically tailored to improve inference for specific reward functions, such as human preference scores in Reinforcement Learning from Human Feedback (RLHF).

Summary updated

BibTeX
@inproceedings{vilnis2023arithmetic,
  author = {Luke Vilnis and Yury Zemlyanskiy and Patrick Murray and Alexandre Tachard Passos and Sumit Sanghai},
  title = {{Arithmetic Sampling: Parallel Diverse Decoding for Large Language Models}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=EfhmBBrXY2},
}
Figure