Canonical Autoregressive Generation

Ivi Chatzi, Nina Corvelo Benz, Stratis Tsirtsis, Manuel Gomez-Rodriguez

Introduction

Large Language Models (LLMs) are increasingly deployed via cloud-based APIs where pricing is typically determined by the number of tokens processed. Users generally expect that identical output strings should incur identical costs. However, this paper reveals that due to "tokenization multiplicity," LLMs can represent the same text using different sequences of tokens, leading to arbitrary price variations. We introduce canonical generation, a method that restricts LLMs to the unique tokenization used during their training, ensuring consistent pricing and better distributional alignment.

The Problem: Tokenization Multiplicity

Most modern LLMs use subword tokenization methods like Byte Pair Encoding (BPE), Unigram, or Wordpiece. These methods often allow a single string to be decomposed into multiple valid token sequences. For example, a word might be represented as a single token in one instance but split into two or more in another.

Comparison of tokenization sequences for the same German sentence, showing a difference of 2 tokens (7.7% cost variation) for identical text.

This "linguistic lottery" results in users being charged different amounts for the exact same result. The authors found that identical strings generated by models like Qwen2.5 could vary in length by up to 15%. This phenomenon is particularly prevalent in non-English languages, placing an unfair financial burden on users of minority languages.

Methodology: Canonical Generation

To address this, the authors propose Canonical Generation, a constrained decoding approach that forces the model to adhere to the "canonical" tokenization—the specific sequence the tokenizer would produce for a given string during the training phase.

Theoretical Foundation

The researchers prove that for BPE, Unigram, and Wordpiece tokenizers, if a full sequence is canonical, all its prefixes must also be canonical. This "non-recovering" property allows the model to enforce canonicity step-by-step during the generation process without needing to look ahead at the entire potential sequence.

The Algorithm

The implementation utilizes an efficient sampling method based on the Gumbel-Max trick. Instead of simply selecting the most likely token, the algorithm ranks tokens by perturbed log-probabilities and selects the highest-ranked token that maintains a canonical sequence. Because LLMs naturally favor canonical sequences, the computational overhead is negligible, typically requiring the check of only one or two tokens per step.

Experimental Evaluation

The study evaluated canonical generation across several natural language tasks, including translation, spell checking, and rephrasing, using 100 short articles from Wikipedia for languages including German, French, Portuguese, English, Turkish, and Swahili. Reasoning capabilities were tested using the MGSM (Multilingual Grade School Math) benchmark. The evaluation spanned open-weights models (Llama-3.1-8B, Qwen2.5-7B) and proprietary APIs (GPT-4o, Gemini 1.5 Flash, Claude 3 Haiku).

Key Results

  • Elimination of Price Variance: Canonical generation completely eliminates tokenization multiplicity, ensuring a specific string always costs the same amount.
  • Performance Parity: The method maintains high quality. For instance, on German translation tasks, Llama-8B scored 0.70 with canonical generation compared to 0.72 with standard generation.
  • Speed Efficiency: The runtime overhead is nearly non-existent. Generation time per token for Llama-8B was 0.020s for canonical versus 0.019s for standard generation.
  • Distributional Alignment: Mathematically, canonical generation produces a distribution of token sequences that is closer to the model's true training data distribution (lower KL-divergence) than standard generation.

Conclusion

Canonical generation offers a robust solution to the arbitrary pricing and distributional inconsistencies caused by tokenization multiplicity. By enforcing training-time tokenization during inference, providers can offer fairer, more predictable billing while maintaining model performance and generation speed. Future work may explore fine-tuning models specifically on canonical paths to further bridge the minor performance gaps observed in some tasks.

Summary updated

BibTeX
@inproceedings{chatzi2025canonical,
  author = {Ivi Chatzi and Nina Corvelo Benz and Stratis Tsirtsis and Manuel Gomez-Rodriguez},
  title = {{Canonical Autoregressive Generation}},
  booktitle = {TokShop @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=uWgNK07LV8},
}
Figure