Retokenization Reveals the Gap Between Semantics and Behavior
Organizations: The Chinese University of Hong Kong, Shenzhen · Principles of Intelligence
Abstract
Language models are trained under a deterministic canonical tokenization, yet every byte string admits exponentially many non-canonical token sequences that decode to it. Although such sequences never occur during training, models exhibit partial invariance to them, and in some settings, such as character-level word games, non-canonical inputs even improve accuracy. This invariance is nevertheless fragile: byte-identical prompts can induce divergent behavior, and adversarial tokenizations were found to circumvent safety alignment. We give a mechanistic account of this fragility and introduce a family of consistency-training objectives that enforce agreement across retokenizations of the prompt while keeping the output space canonically tokenized. We prove that retokenizing only the prompt leaves the training optimum unchanged, whereas retokenizing the target raises the irreducible entropy of the target distribution. Across three model families, consistency-tuned models are more robust to adversarial tokenization, at some loss of benchmark accuracy, while transfer to other attacks depends on the objective. Probing shows that the attack suppresses the linearly decodable refusal signal in the residual stream, and that after consistency training the signal persists under attack in its original subspace.
Figures & tables
| AdvTok | XSTest-safe | ||
| refusal | |||
| No fine-tuning | .067 | .052 | .024 |
| Canonical-only self-distillation | .065 | .046 | .029 |
| StochasTok, | .055 | .050 | .029 |
| Trained on retokenized prompts | |||
| Context-perturbed SFT | .018 | .026 | .039 |
| Probe accuracy under attack | |
|---|---|
| No fine-tuning | |
| Consistency, KL, benign-only | |
| Consistency, CE (uniform) | |
| Consistency, KL | |
| Consistency, repr-next |
Appendix figures & tables19 assets
Supplementary material from the paper’s appendix.
Appendix
| AdvTok, AdvBench | AdvTok, WildJailbreak | GSM8K, change | Consistency gap | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Objective | Prompts ( ) | retok. | retok. | retok. | retok. | retok. | retok. | retok. | retok. |
| KL | .010 | .035 | .023 | ||||||
| .018 | .017 | .035 | .039 | .024 | .024 | ||||
| .020 | .012 | .033 | .034 | .030 | .028 | ||||
| .035 | .018 | .044 | .032 | .028 | .026 | ||||
| Repr., last position | .008 | .030 | .021 | ||||||
| Top- CVaR | RU CVaR | Entropic | ball | |
| Backward passes per prompt | 3 | 3 (mean) | 9 | 9 |
| Adversarial tokenization (training distribution) | ||||
| AdvTok, AdvBench | 0.005 / 0.022 | 0.000 / 0.018 | 0.000 / 0.021 | 0.000 / 0.028 |
| Attacks and datasets not used in training | ||||
| BEAST, AdvBench | 0.225 / 0.410 | 0.235 / 0.407 | 0.155 / 0.387 | 0.220 / 0.473 |
| Charmer, AdvBench | 0.170 / 0.328 | 0.030 / 0.193 | 0.080 / 0.203 | 0.185 / 0.255 |
| depth | ASR greedy | ASR | |
|---|---|---|---|
| No fine-tuning | — | 0.400 | 0.458 |
| Benign prompts, dataset answers | |||
| Canonical SFT | 0.500 | 0.537 | |
| Prompt-retokenized SFT | 0.410 | 0.464 | |
| Prompt-retokenized SFT | 0.330 | 0.387 | |
| Benign prompts, reference continuations | |||
| AdvTok | ||
|---|---|---|
| supervised layers | ||
| .033 | .023 | |
| .025 | .023 | |
| all | .013 | .011 |
| No fine-tuning | .067 | .052 |
| Prompts, encodings | Arm | L8 | L16 | L24 | L32 |
|---|---|---|---|---|---|
| Harmful, random | No fine-tuning | ||||
| KL, benign-only | |||||
| KL, mixed | |||||
| Harmful, AdvTok | No fine-tuning | ||||
| KL, benign-only | |||||
| KL, mixed |
| Train inflation | AdvTok | Canonical unsafe | Non-canonical emission | |
|---|---|---|---|---|
| 0.415 | 0.000 | 0.0001 | ||
| 0.370 | 0.000 | 0.0172 | ||
| 0.205 | 0.000 | 0.0586 | ||
| 0.115 | 0.000 | 0.8368 | ||
| 0.080 | 0.000 | 0.9230 | ||
| 0.045 | 0.000 | 0.4218 |
| Model | Benign refusal | XSTest-safe refusal |
|---|---|---|
| ( ) | ( ) | |
| No fine-tuning | ||
| Self-distillation, canonical only | ||
| Context-perturbed SFT, dataset answers | ||
| Output, cross-entropy, uniform | ||
| Output, cross-entropy, CVaR |
| Llama-Guard-3-8B | HarmBench | |||
| No fine-tuning | .067 | .052 | .060 | .037 |
| Self-distillation | .065 | .046 | .047 | .028 |
| StochasTok, | .055 | .050 | .050 | .033 |
| Context-perturbed SFT | .018 | .026 | .013 | .014 |
| Consistency, CE (uniform) | .027 | .023 | .018 | .010 |
| Predictor of attack outcome | AUC |
|---|---|
| Refusal margin, canonical | |
| Probe margin, canonical | – |
| summaries (median, spread, worst, CVaR-25%) | – |
| Probe margin, attacked tokenization (post hoc) | |
| Joint over probe margin alone |
| Model | Canonical | Splits | MDD-uniform | Adversarial |
|---|---|---|---|---|
| No fine-tuning | ||||
| Canonical SFT | ||||
| Output, KL | ||||
| Output, cross-entropy | ||||
| Output KL, benign-only | ||||
| Output KL, final prompt position |
| No attack | AdvTok | BEAST | Charmer | |
| Llama-3.2-3B-Instruct | ||||
| No fine-tuning | 0.010 / 0.022 | 0.320 / 0.394 | 0.410 / 0.530 | 0.480 / 0.428 |
| StochasTok | 0.005 / 0.018 | 0.050 / 0.110 | 0.265 / 0.548 | 0.200 / 0.320 |
| Consistency, KL | 0.000 / 0.019 | 0.005 / 0.022 | 0.225 / 0.410 | 0.170 / 0.328 |
| Consistency, Repr., last pos. | 0.005 / 0.020 | 0.015 / 0.030 | 0.170 / 0.212 | 0.365 / 0.358 |
| Consistency, Repr., last pos. + answer | 0.000 / 0.009 | 0.005 / 0.013 | 0.295 / 0.328 | 0.180 / 0.152 |
| Wrapper | Prefill (user turn) | |||
| alone | + retok. search | alone | + retok. search | |
| Llama-3.2-3B-Instruct | ||||
| No fine-tuning | 0.040 / 0.050 | 0.250 / 0.264 | 0.060 / 0.033 | 0.140 / 0.223 |
| StochasTok | 0.000 / 0.025 | 0.040 / 0.185 | 0.000 / 0.007 | 0.080 / 0.102 |
| Consistency, KL | 0.000 / 0.037 | 0.050 / 0.102 | 0.020 / 0.030 | 0.020 / 0.030 |
| Consistency, Repr., last pos. | 0.010 / 0.020 | 0.030 / 0.046 | 0.000 / 0.013 | 0.000 / 0.010 |
| Model | Arm | Attack | As judged | Excluded | Degenerate |
|---|---|---|---|---|---|
| Llama-3.2-3B | Repr., last pos. | No attack | 0.190 / 0.123 | 0.005 / 0.020 | 24% / 13% |
| Llama-3.2-3B | Repr., last pos. | AdvTok | 0.170 / 0.101 | 0.015 / 0.030 | 22% / 10% |
| Llama-3.2-3B | Repr., last pos. | Charmer | 0.575 / 0.402 | 0.365 / 0.358 | 24% / 5% |
| gemma-3-4b | KL | BEAST | 0.775 / 0.715 | 0.735 / 0.603 | 4% / 12% |
| gemma-3-4b | Repr., last pos. | AdvTok | 0.080 / 0.083 | 0.040 / 0.051 | 6% / 5% |
| gemma-3-4b | Repr., last pos. | BEAST | 0.640 / 0.533 | 0.245 / 0.335 | 41% / 21% |
| MMLU (5-shot) | GSM8K (8-shot CoT) | IFEval (0-shot) | |
| Llama-3.2-3B-Instruct | |||
| No fine-tuning | 0.575 | 0.759 | 0.693 |
| StochasTok | 0.068 .008 | 0.257 .029 | 0.322 .047 |
| Consistency, KL | 0.024 .006 | 0.075 .023 | 0.216 .043 |
| Consistency, Repr., last pos. | 0.293 .010 | 0.024 .023 | 0.189 .044 |
| Consistency, Repr., last pos. + answer | 0.005 .005 | 0.024 .021 | 0.133 .039 |
| XSTest-safe | Alpaca | Degenerate | ||
| Llama-3.2-3B-Instruct | ||||
| No fine-tuning | 0.060 .045 | 0.062 .040 | 0.000 | 0% |
| StochasTok | 0.270 .090 | 0.226 .064 | 0.040 | 0% |
| Consistency, KL | 0.190 .075 | 0.163 .052 | 0.000 | 0% |
| Consistency, Repr., last pos. | 0.110 .060 | 0.141 .053 | 0.000 | 0% |
| Harmful share | AdvTok | BEAST | Charmer |
|---|---|---|---|
| 0.10 | 0.035 / 0.054 | 0.495 / 0.398 | 0.575 / 0.512 |
| 0.286 ( main experiments ) | 0.015 / 0.014 | 0.360 / 0.345 | 0.430 / 0.353 |
| 0.50 | 0.015 / 0.021 | 0.295 / 0.305 | 0.405 / 0.340 |