Canonical Autoregressive Generation

Ivi Chatzi, Nina L. Corvelo Benz, Stratis Tsirtsis, Manuel Gomez Rodriguez

TL;DR

While standard tokenizers deterministically map any text to a unique "canonical" sequence of tokens, autoregressive LLMs frequently wander off and generate non-canonical token sequences. This paper proves that canonicity is prefix-closed across standard tokenizers (BPE, Unigram, WordPiece) and introduces canonical sampling—an efficient Gumbel-Max-based decoding method that strictly prevents non-canonical token generation and provably brings the token distribution closer to the training distribution.

What Problem Does This Paper Address?

Tokenizers (like BPE, WordPiece, and Unigram) map raw text into discrete tokens. For any given string, a deterministic tokenizer picks a single standard representation called the canonical tokenization. During training, models only see canonical token sequences.

However, during autoregressive inference, language models often generate valid strings using non-canonical token combinations (e.g., splitting a word into sub-tokens differently than the tokenizer would). This seemingly harmless quirk has notable consequences:

  1. Safety exploits: Out-of-distribution non-canonical sequences can bypass safety filters.
  2. Economic / billing misalignments: Providers billing per token have financial incentives to manipulate or misreport token counts for the same output string.
  3. Evaluation difficulties: Calculating true string-level perplexity becomes computationally intractable because one must marginalize over all possible valid token sequences.

Previous remedies required evaluating the validity of every token in the vocabulary at each step—a major computational bottleneck.

Methods

The authors build their approach on a key structural result and an efficient sampling trick:

  • Prefix-Closure of Canonicity: The authors prove theoretically that if a partial sequence $s$ is non-canonical, any continuation $s \circ t$ is guaranteed to remain non-canonical for BPE, Unigram, and WordPiece tokenizers. In other words, generating canonical text requires every intermediate prefix to be canonical.
  • Canonicalized Next-Token Distribution: At each step, the sampling probability of any token that would make the prefix non-canonical is set to 0, and mass is renormalized proportionally across the valid canonical tokens: $$\tilde{d}_s(t) = \begin{cases} \frac{d_s(t)}{Z} & \text{if } s \circ t \text{ is canonical} \\ 0 & \text{otherwise} \end{cases}$$
  • Efficient Canonical Sampling via Gumbel-Max: Rather than checking canonicity for all $|V|$ tokens in the vocabulary at every step, the algorithm samples Gumbel noise $u_t \sim \text{Gumbel}(0, 1)$, ranks tokens descending by $\log(d_s(t)) + u_t$, and checks candidates in order until the first canonical continuation is found. Because LLMs already put most probability mass on canonical tokens, this requires very few canonicity checks in practice (fewer than $1 / d_s(\text{canonical})$ in expectation), without evaluating duplicate candidates.

Datasets

Not discussed in the paper. (This is a theoretical and algorithmic workshop contribution presented at the ICML 2025 Tokenization Workshop; it does not introduce new datasets or benchmark empirical runs on standard corpora.)

Key Insights and Ideas

  • One Strike and You're Out: Canonicity cannot be "fixed" later in generation. The moment an autoregressive model emits a single non-canonical token, the full output sequence remains permanently non-canonical. This explains why longer generations are empirically more prone to non-canonicity.
  • Universal Across Tokenizer Families: The prefix-closure property holds across fundamentally distinct algorithms:
  • BPE (rule-based pair merging),
  • Unigram (global probability maximization via Viterbi),
  • WordPiece (greedy left-to-right longest-match).
  • Provably Tighter Token Distribution: The authors prove that the token distribution induced by canonical sampling ($\tilde{d}$) is strictly closer to the true training distribution ($p$) in terms of KL-divergence than standard sampling ($d$): $$KL(p, \tilde{d}) < KL(p, d)$$

Key Results

  • Theoretical Guarantees:
  • Proved that non-canonical tokens propagate irreversibly (Theorem 3.1, B.1, B.2).
  • Proved that canonical sampling strictly reduces the KL-divergence to the true training token distribution (Theorem 3.2).
  • Computational Efficiency: Expected number of canonicity checks per generation step is bounded by $< \frac{1}{d_s(\text{canonical})}$. In typical LLMs where canonical continuation probability is near 1, sampling adds minimal computational overhead compared to naive exhaustive checking over the entire vocabulary $|V|$.

Limitations and Future Work

  • String-level vs. Token-level Gap: Although canonical sampling strictly improves token-level KL-divergence ($KL(p, \tilde{d}) < KL(p, d)$), the authors prove that this guarantee does not necessarily translate to string-level distribution divergence ($KL(p_{\text{dec}}, \tilde{d}_{\text{dec}})$) due to string-level marginalization over multiple tokenizations.
  • Lack of Pre-Tokenization Analysis: Modern tokenizers usually apply rule-based regex pre-tokenization (e.g., splitting by whitespace or punctuation) before running BPE/WordPiece. Extending formal guarantees to pipeline architectures with pre-tokenization remains future work.
  • Empirical Validation: The paper focuses on theoretical proofs; practical runtime overhead and downstream impact on generation quality across frontier LLMs still need empirical evaluation.

Summary updated

BibTeX
@inproceedings{chatzi2025canonical,
  author = {Ivi Chatzi and Nina L. 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},
}

Loading related content...

Figure