Near-Ties Between Tokenizations as a Source of LLM Non-Determinism

Ask a large language model the same question twice with sampling randomness switched off and you can still get two different answers. Hosted models at temperature zero agree with themselves string-for-string almost never. Their benchmark accuracy moves by as much as 15 points between identical runs, and the standard explanation is that GPU arithmetic is not perfectly repeatable (Non-Determinism of "Deterministic" LLM System Settings in Hosted Environments). Rounding noise is tiny, though. It only changes the output when the model's top two next-token choices are almost exactly tied.

This proposal asks where those near-ties come from. Our hypothesis is that a large share are manufactured by the tokenizer, not by genuine indecision. When a model writes a rare or unseen word, such as a novel identifier, a neologism, a proper noun, or a typo'd word, the same string can often be spelled with several different token sequences. For example, Zorbex can be written as Zor+bex or as Z+orb+ex. The model splits its probability between these equivalent spellings, which produces an artificial tie. Numerical noise then flips the choice. Once the model is off its usual spelling, it is in the same unfamiliar state that causes known failures on half-written words (Token Alignment via Character Matching for Subword Completion), and the two runs diverge from there.

If the hypothesis holds, a cheap decoding change should remove much of the instability without touching the serving hardware. That change is to decide ties at the level of characters, not tokens, and then keep the model on its standard spelling.

Core Claim

We make two claims, and each can fail independently. The first is diagnostic. Among the positions where two greedy runs of the same prompt first diverge, a disproportionate fraction are "segmentation ties": positions where the top competing tokens are string-compatible, meaning one token's text is a prefix of the other's, or both lead to the same characters within a short lookahead. These cluster inside rare and out-of-vocabulary words, and they predict divergence beyond what output length alone explains.

The second claim is interventional. Merging the probability of string-equivalent candidates before choosing, then re-tokenizing the chosen text into the tokenizer's standard ("canonical") segmentation, should raise run-to-run agreement and task accuracy on rare-word-heavy inputs. It should cost almost nothing on ordinary text.

The mechanism has a simple quantitative form. Let $m_t = \log p(v_1) - \log p(v_2)$ be the gap between the top two token log-probabilities at step $t$. If serving noise perturbs each logit by roughly independent noise of scale $\sigma$, the chance that the greedy choice flips is approximately

$$ P(\text{flip at } t) \approx \Phi\!\left(-\frac{m_t}{\sigma\sqrt{2}}\right), $$

where $\Phi$ is the standard normal cumulative distribution. The form follows because the difference of two independent Gaussian perturbations has standard deviation $\sigma\sqrt{2}$. A segmentation tie drives $m_t$ toward zero. Merging equivalent candidates restores the margin the model actually holds over genuinely different continuations.

Relation to Prior Work

Three papers motivate the gap. Non-Determinism of "Deterministic" LLM System Settings in Hosted Environments measures string agreement ($\text{TAR}_r$) and answer agreement ($\text{TAR}_a$) over 10 runs. It shows that divergence grows with output length and that a locally controlled Llama-3-8B is fully deterministic. It never asks which token positions carry the divergence, and we do. An Empirical Study of the Non-Determinism of ChatGPT in Code Generation finds that 43.64% of CodeContests tasks give non-identical test results across five runs even at temperature zero, but it treats the model as a black box. Stability Analysis of ChatGPT-based Sentiment Analysis in AI Quality Assurance shows that typos, which fragment words into rare subwords, drop SST accuracy from 80.6% to 61.3%. It attributes residual temperature-zero drift to mixture-of-experts routing without isolating a token-level trigger. Our diagnostic is a candidate for that trigger.

Two papers supply the method. Token Alignment via Character Matching for Subword Completion builds a character trie over the vocabulary and masks tokens that are incompatible with a prompt ending mid-word. We reuse its trie (amazon-science/tokenalign), but apply it at every generation step to merge compatible candidates, not only at the prompt boundary to forbid incompatible ones. It also never measured repeat-run variability. Out-of-Vocabulary Sampling Boosts Speculative Decoding redistributes a pruned drafter's probability onto missing tokens through a learned co-occurrence matrix. We redistribute mass exactly, across tokens that spell the same characters, and our goal is stability rather than speed.

One paper constrains the design. Hot or Cold? Adaptive Temperature Sampling for Code Generation with Large Language Models finds sharp loss spikes at code block starters and tunes temperature by hand-coded syntax. Some of its spikes may be tokenization artifacts. We therefore test whether segmentation ties account for part of its "challenging tokens." NYTWIT: A Dataset of Novel Words in the New York Times shows that surface character features classify novel words slightly better than contextual encoders (accuracy 0.484 vs. 0.469). This supports our choice to resolve rare-word decisions at the character level instead of adding more reasoning context.

Research Program

The first component is instrumentation. We run open-weight dense models and one open mixture-of-experts model under a serving engine with continuous batching, so we can reproduce hosted-style noise while logging full logits. We generate noise in two ways. The first is realistic: we vary batch size and batch composition around the same prompt. The second is controlled: we inject Gaussian logit noise at a scale calibrated to match the realistic logit differences. For every pair of runs we find the first divergent position and label it with a type. The candidates are a segmentation tie, a genuine semantic fork, whitespace or formatting, or a within-word continuation. We also record whether the position falls inside a word the tokenizer fragments heavily, measured as token fertility, meaning tokens per word.

The analysis is a matched-length regression. We predict pairwise divergence from output length, prompt and output fertility, count of low-margin positions, and count of segmentation-tie positions, and we test whether segmentation ties carry signal once length is held fixed. This directly separates our hypothesis from the "longer outputs, more chances to diverge" account.

The second component is the decoder, which we call character-merged greedy decoding. At each step, if the top-two margin is above a threshold $\tau$, it takes the ordinary greedy token, so it costs nothing on confident steps. Below $\tau$, it groups the top-$k$ candidates by string compatibility using the trie. Where needed, it rolls compatible candidates forward a few tokens until their strings either diverge or reach a word boundary. It then merges the probability of candidates that yield the same characters and commits to the highest-mass string. Finally, it re-tokenizes the committed text canonically, so the model's context always matches the spelling it saw in training. The threshold $\tau$ and lookahead depth are the only knobs, and we tune them on a held-out split.

Baselines

The naive reference point is plain greedy decoding at temperature zero under the same batched serving setup. This is the "just set temperature to zero" condition that the cited audits show is not deterministic. We report its $\text{TAR}_r@10$, $\text{TAR}_a@10$, and task accuracy on every benchmark. For scale, Non-Determinism of "Deterministic" LLM System Settings in Hosted Environments reports $\text{TAR}_r@10$ near 0% for several hosted models on MMLU and BBH, with accuracy swinging up to 15 points.

The strongest existing method on the rare-word side is Token Alignment (Token Alignment via Character Matching for Subword Completion), run with its released code and default backtracking of three tokens. It is the only published inference-time method that uses character-level structure to repair tokenizer-induced failures. On Subword MBXP Python it raises StarCoder pass@1 from 30.25% to 56.58%. We run it on identical prompts, models, and serving noise. Beating it means two things together: statistically higher $\text{TAR}_r@10$ on the same inputs, and accuracy no lower than its 56.58% pass@1 reproduction on Subword MBXP. Token Alignment only intervenes at the prompt boundary, so we expect it to fix the partial-word failure but leave generation-time ties untouched. Stacking the two methods is also tested.

The key ablation is canonical-only masking. Here any token that would create a non-canonical tokenization is forbidden, but no probability is merged. This isolates the proposal's two ingredients. Masking alone also removes spelling ties, so if it matches the full method, the merging step adds nothing.

We add two further references. The first is self-consistency with 5 and 10 samples plus answer voting, where we match compute by reporting agreement per generated token. The second is deterministic local execution with fixed batch size, which serves as an oracle ceiling on agreement. For the variance comparison under character-merged decoding, we found no reported result on Lacuna for $\text{TAR}_r$ under any tokenization-aware decoder. Every method receives the same prompts, the same model weights, the same noise schedule, and the same tuning budget of one small grid on a held-out split.

Why not just…?

Why not just use deterministic kernels and fixed batching? Atıl et al. show a locally controlled Llama-3-8B is fully deterministic, so hardware fixes do solve bitwise reproducibility where you control the stack. We concede that. The proposal's target is broader: fragility at near-ties. The same small margins that let rounding noise flip an output also let a one-character typo or trivial paraphrase flip it, which matches the typo sensitivity in Stability Analysis of ChatGPT-based Sentiment Analysis in AI Quality Assurance. A deterministic kernel hides that fragility without removing it. We test this by measuring flip rates under typo and paraphrase perturbations with deterministic kernels enabled. If character-merged decoding shows no gain there, the proposal reduces to a hosted-API workaround, and we will say so.

Why not just force canonical tokenization? This is the most serious competitor and is included as the main ablation. Masking breaks spelling ties, but it discards the probability held by non-canonical spellings. It can therefore still lose a rare word to a genuinely different, more common word whose probability was never split. We predict the gap between masking and merging concentrates on out-of-vocabulary identifiers and NYTWIT neologisms. If masking matches merging within noise across benchmarks, we will adopt masking as the recommended method and present the diagnostic as the main contribution.

Why not just explain it all by output length? Longer outputs do diverge more. The matched-length regression and length-matched prompt pairs, identical except for one rare versus common word, directly test whether segmentation ties add predictive power. A null result there falsifies the first claim.

Why not just use self-consistency? Majority voting helps only when answers can be extracted and compared. It multiplies cost by the sample count (Evaluating Stochasticity in Deep Research Agents). It cannot vote over code whose runs share a mean longest-common-subsequence of 0.22 on CodeContests (An Empirical Study of the Non-Determinism of ChatGPT in Code Generation). Our decoder triggers only on low-margin steps, and we report agreement per token spent.

Why not just copy rare words from the prompt? A pointer-style copy mechanism (Pointing the Unknown Words) handles names that appear in the context, and it raised Europarl En-Fr BLEU from 20.19 to 23.76. However, it requires retraining the model's output layer. It also does not cover rare words that the model must produce itself or that arrive through typos. It is outside the inference-only scope here.

Proposed Experiments

For code we use HumanEval, CodeContests, and APPS, where invented identifiers make rare words common, and Subword MBXP evaluated with amazon-science/mxeval. Metrics are the rate of problems with zero equal test outputs across repeated runs, as defined by Ouyang et al., $\text{TAR}_r@10$, and pass@1.

For text we use MMLU and BBH with $\text{TAR}_r$ and $\text{TAR}_a$, and SST with the typo, homoglyph, and synonym perturbations of Ouyang et al. (2024). We also build a controlled copy-and-use task that inserts NYTWIT neologisms into otherwise ordinary prompts. For the fertility axis, we evaluate XNLI in high-fertility languages, where Tokenizer Choice For LLM Training: Negligible or Crucial? documents heavy fragmentation.

Four checks decide the outcome. The first is attribution: segmentation ties must account for a share of first-divergence positions well above their share of all positions, and must stay significant in the matched-length regression. The second is dose-response: on the paired prompts, swapping one common word for a fragmented rare word should raise divergence, and the rise should track how many segmentation ties the rare word creates. The third is the intervention: character-merged decoding should raise $\text{TAR}_r@10$ on rare-word-heavy subsets over plain greedy decoding, Token Alignment, and canonical masking, without lowering accuracy. On common-word control subsets it should behave essentially like greedy decoding. The fourth is the loss-spike reanalysis: re-running the loss-peak analysis of Hot or Cold? Adaptive Temperature Sampling for Code Generation with Large Language Models with merged probabilities should show whether part of its peaks disappear once equivalent spellings are combined. If the attribution check fails, the diagnostic claim is wrong, and the decoder is at best a generic margin-based heuristic.