Exact Byte-Level Probabilities from Tokenized Language Models for FIM-Tasks and Model Ensembles

Buu Phan, Brandon Amos, Itai Gat, Marton Havasi, Matthew J. Muckley, Karen Ullrich

Tokenization is often considered the "necessary evil" of modern Large Language Models (LLMs). While it allows models to process massive amounts of text efficiently by chunking bytes into subword units, it introduces subtle, often overlooked distortions in how models perceive and predict text. A new paper, "Exact Byte-Level Probabilities from Tokenized Language Models for FIM-Tasks and Model Ensembles," provides a mathematical framework to diagnose and fix these distortions at inference time.

The Problem: Tokenization Bias

Language models don't "read" characters; they read tokens. This creates a significant problem when a prompt ends in the middle of a potential token. Consider a code completion task where a function def add5(aa): return 5 + a is prompted. A standard tokenized model might predict a newline \n because it has already committed to a specific token boundary, failing to recognize that the next logical character is a to complete the variable aa.

This discrepancy is known as tokenization bias. Even if a tokenized model and a byte-level model are trained on the exact same data and are "statistically equivalent," their step-by-step predictions can differ wildly. This bias is particularly destructive in two key areas:

  1. Fill-In-the-Middle (FIM) tasks: Where prompts often terminate at arbitrary byte positions.
  2. Model Ensembling: Where models with different vocabularies cannot easily "talk" to each other because their output probability spaces are fundamentally incompatible.
Exact byte-level prediction resolves mid-token prompt issues in FIM tasks (left) and enables seamless ensembling across different models (right).

The Solution: Exact Byte-Level Conversion

To solve this, the authors introduce the Byte-Token Representation Lemma. This lemma establishes a formal mathematical mapping between a learned token distribution and its equivalent byte-level distribution.

Using this lemma, the researchers developed a Next-Byte Sampling Algorithm. Instead of standard forward-pass tokenization, the algorithm uses "backward tokenization" to find all possible cover encodings—sets of token sequences that could validly represent a given byte string.

Key advantages of this approach include:

  • Zero-Shot Application: It requires no additional training or fine-tuning of the underlying LLM.
  • Exact Recovery: It recovers the true byte-level probabilities intended by the model's training data.
  • High Efficiency: The algorithm carries an $O(1)$ computational cost in terms of model runs, making it practical for real-world inference.

Key Insights: Statistical vs. Predictive Equivalence

The authors prove that two models can be "equivalent" (assigning the same total probability to a full string) but still have vastly different "predictive distributions" (probabilities for the very next step). Tokenization effectively "locks" the model into certain paths, creating artificial zero-probability dead ends.

As demonstrated in their Markov chain experiments, a tokenized model might have a zero probability of sampling a character that is statistically likely, simply because the tokenizer merged it into a different token earlier in the sequence.

A Markov chain example demonstrating how tokenized models can exhibit severe bias (red arrows showing 0.0 probability) compared to the true distribution.

Furthermore, by converting all models to byte-level probabilities, the authors create a "universal language" for LLMs. This allows for the simple averaging of predictions from models that do not share a single token in their respective vocabularies.

Results and Impact

The researchers evaluated their method across several high-stakes domains, including coding (HumanEval, MBPP) and reasoning/knowledge (MMLU, PIQA, NQ, TriviaQA, GSM8K), using models like CodeLlama, Llama2, Mistral, and Yi.

  • FIM Coding Boost: The method achieved an 18% improvement on FIM coding benchmarks. It consistently outperformed "token healing," a common heuristic fix for mid-token prompts.
  • Superior Ensembles: Ensembling models with different vocabularies led to performance gains of up to 3.7% over individual models across reasoning and coding tasks.
  • Greedy Generation: Surprisingly, byte-level greedy generation often outperformed standard token-level greedy generation, suggesting that tokenization boundaries might be leading models toward suboptimal local minima.

Limitations and Future Work

While powerful, the method does introduce some trade-offs. Predicting byte-by-byte is naturally slower than predicting token-by-token, and the current implementation requires storing more intermediate probabilities and encodings. Additionally, the authors note that their work doesn't yet explain or fix the well-known struggles LLMs have with arithmetic, which may be tied to tokenization in a different way.

Future research will likely investigate the cumulative impact of tokenization bias over very long sequences and explore more complex ensemble aggregation functions beyond simple averaging.

Summary updated

BibTeX
@inproceedings{phan2025exact,
  author = {Buu Phan and Brandon Amos and Itai Gat and Marton Havasi and Matthew J. Muckley and Karen Ullrich},
  title = {{Exact Byte-Level Probabilities from Tokenized Language Models for FIM-Tasks and Model Ensembles}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=zGej22CBnS},
}
Figure