Skip to content

Retokenization reveals the gap between semantics and behaviorRetokenization Reveals the Gap Between Semantics and Behavior

Sami Wolf, Sergei Kudriashov, Dmitry Vaintrob
Cornell University; The Chinese University of Hong Kong, Shenzhen; Shenzhen Loop Area Institute; Principles of Intelligence
arXiv: Jailbreaks, Prompt Injection, Poisoning & DefensesarXiv:2611.39274Originally published Indexed by this site · 2 days agoDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

The authors use retokenization consistency training to defend against AdvTok; on OLMo-2-7B, greedy ASR drops from 0.400 to 0.020, but with a loss in benchmark accuracy.

Threat modelThe attacker uses AdvTok to search for non-canonical tokenizations while the byte string remains unchanged, causing safety-aligned models to produce harmful responses; AdvTok requires control over token IDs, applies to open-weight models and APIs that accept token IDs, and does not require access to the model's output distribution. The defense only re-tokenizes the prompt during fine-tuning, while outputs keep canonical tokenization.

Questions
The same byte string can have multiple tokenizations, and although the semantics are unchanged, model behavior may change, so AdvTok can bypass safety alignment. The authors study the mechanism of this vulnerability and explore defenses that do not rely on safety labels.
Methods
Only re-tokenize the prompt, having the student model match the frozen reference model's outputs or residual representations on canonical inputs; use CVaR to select the encodings with the largest loss. Additionally, analyze the refusal signal with linear probes and activation steering.
Experiments and results
Across three model families, consistency training lowers AdvTok success rates; it transfers to character noise, and transfer to BEAST depends on the objective. The probe shows that the attack suppresses the refusal signal, and after mixed-data training this signal remains in the atomic space.
Limitations and future work
The authors note that probing and steering are run only on OLMo-2-7B-Instruct, that several training arms have only one seed, and that ASR is affected by the judge. The prompt-diversity experiment uses one model and one seed per arm; some appendix analyses were not rerun with the corrected attack.
Experimental setupOLMo-2-1124-7B-Instruct、Llama-3.2-3B-Instruct et al. · AdvBench、Alpaca et al. · AdvTok attack success、BEAST attack success et al.
Metrics
AdvTok attack successBEAST attack successCharmer attack successXSTest-safe refusaltarget NLLprobe accuracybenchmark accuracy
AI summaryThe paper gives a mechanistic explanation of language models' retokenization brittleness and proposes consistency training to make models more robust to adversarial tokenizations that bypass safety alignment; the training requires different tokenizations of a prompt to produce consistent outputs. Language models are trained under a deterministic canonical tokenization, but the same byte string has exponentially many non-canonical tokenization sequences; models show partial invariance to this, yet prompts with identical bytes can elicit different behavior, and this invariance is brittle. The authors prove that retokenizing only the prompt does not change the training optimum, whereas retokenizing the target raises the irreducible entropy of the target distribution. Across three model families, models after consistency training are more robust to adversarial tokenization but lose some benchmark accuracy, and transfer to other attacks depends on the target used. Probe experiments show the attack suppresses a linearly decodable refusal signal in the residual stream, and after consistency training this signal remains under attack in the same subspace.

The paper gives a mechanistic explanation of language models' retokenization brittleness and proposes consistency training to make models more robust to adversarial tokenizations that bypass safety alignment; the training requires different tokenizations of a prompt to produce consistent outputs. Language models are trained under a deterministic canonical tokenization, but the same byte string has exponentially many non-canonical tokenization sequences; models show partial invariance to this, yet prompts with identical bytes can elicit different behavior, and this invariance is brittle. The authors prove that retokenizing only the prompt does not change the training optimum, whereas retokenizing the target raises the irreducible entropy of the target distribution. Across three model families, models after consistency training are more robust to adversarial tokenization but lose some benchmark accuracy, and transfer to other attacks depends on the target used. Probe experiments show the attack suppresses a linearly decodable refusal signal in the residual stream, and after consistency training this signal remains under attack in the same subspace.

Related events and news

1 events · 0 news mentions

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Study why byte-invariant re-tokenization bypasses alignment, and use prompt consistency training to restore behavioral consistency.

    Core question: changing only the tokenization of the same text leaves the semantics unchanged but may turn a safety-aligned model from refusal to compliance.

    • Problem setting: The authors state that models have only partial invariance to non-canonical tokenization; AdvTok can specifically search for encodings that weaken refusal, and character-level noise may also change behavior.
    • Shortcomings of existing work: Existing studies mostly measure the effect of retokenization by task completion rate; the authors believe that Monte Carlo estimates of such binary metrics lose local variation between neighboring encodings. Existing retokenization fine-tuning mostly reports task accuracy rather than refusal under attack.
    • Core observation: The authors treat the byte string x as semantics and the token sequence t as surface form; semantic attacks change x, whereas AdvTok keeps x unchanged and moves t. The effect of a single split on target NLL is uneven and sentence-dependent.
    • Proposed approach: Proposes output-based and representation-based consistency training, and analyzes the mechanism using target NLL, linear probes, and activation steering; also studies the roles of the number of prompts and the amount of retokenization.
    • Threat model:
      • Goal: With the byte string of a harmful request unchanged, induce a response judged unsafe by Llama-Guard-3-8B through non-canonical tokenization.
      • Knowledge and capabilities: The authors state that AdvTok requires control of token IDs and applies to open-weight models and APIs that accept token IDs; it does not require access to the model's output distribution.
      • Victim system: Aligned instruction models using a chat template with no system prompt; the attack is searched separately for each model.
      • Defense location: In the fine-tuning stage, only the instruction span is perturbed, and chat-template tokens and the output space keep canonical tokenization.
  2. What related research exists?

    The work connects retokenization robustness, consistency training, and refusal representation research, and switches to refusal under attack as the evaluation.

    Re-tokenization invariance and its mechanism

    • Geh et al. (2024, 2025): Study models reading and writing non-canonical token sequences and propose AdvTok; the authors use this to distinguish byte-preserving tokenization attacks from semantic attacks.
    • Jain et al. (2026), Zheng et al. (2025): Study re-tokenization symmetries emerging in pretraining and instruction tuning; the latter also reports that robustness decreases with the degree of fragmentation.
    • Kaplan et al. (2025), Yang et al. (2026): Analyze the detokenization process in early-to-middle layers that reassembles subword fragments into word-level representations; Ghosh & Jyothi (2026) study cross-lingual differences.

    Re-tokenization training and data augmentation

    • Kudo (2018), Provilkov et al. (2020), Sims et al. (2026): Propose subword regularization, BPE-dropout, and StochasTok; the authors note that StochasTok re-tokenizes both context and continuation, whereas this paper perturbs only the prompt.
    • Steger et al. (2026): Study random tokenization on multiple-choice tasks and observe that random pretraining increases canonical-text perplexity; this paper further formalizes the entropy cost of target-side re-tokenization.
    • Wang et al. (2021), Cosma et al. (2026), Jain et al. (2023): Study multi-view classification with gold labels, auxiliary-encoder pretraining, and inference-time BPE-dropout defenses against adversarial suffixes, respectively.

    Consistency training and refusal representations

    • Chua et al. (2024), Irpan et al. (2025): Study bias-augmented consistency training and activation consistency training; the consistency class in this paper contains only different encodings of the same byte string.
    • Wei et al. (2023), Qi et al. (2025): Discuss mismatched generalization and shallow safety alignment concentrated in the first few tokens of the response, respectively.
    • Zou et al. (2023a), Arditi et al. (2024): Study linear concept directions in the residual stream and a single refusal direction; this paper applies probes and steering to re-tokenization attacks.

    Baselines and benchmarks: Comparisons include canonical-only self-distillation, full-sequence StochasTok, context-perturbed SFT, and several LoRA exposure baselines; attacks are AdvTok, BEAST, and Charmer, data include AdvBench, Alpaca, XSTest, and WildJailbreak, and capability evaluations are MMLU, GSM8K, and IFEval.

    The authors position this paper as: using the model's own canonical behavior as the only supervision, evaluating refusal under attack, and distinguishing prompt semantic diversity from surface token-sequence diversity.

  3. How does the paper address this problem?

    Perturb only the prompt and match the reference model's outputs or representations, while using probes and steering to examine the refusal mechanism.

    The overall idea is consistency training: freeze a reference model and have the student reproduce the reference model's canonical behavior across different prompt encodings; outputs always keep canonical tokenization.

    Formalization and Retokenization Sensitivity

    • For a byte string x, T(x) is the set of all token sequences that decode to x; the canonical encoding is tc(x), and the depth d(t)=|t|−|tc|, i.e., the number of added tokens.
    • Target NLL measures the prediction difficulty of continuation y* when read through a given encoding: fread(t)=−log πθ(y∗∣ Zpre,t,Zsuf), in nats.
    • On OLMo-2-1124-7B base, iterate over 526 split positions of 20 constructed sentences; additionally, for 16 sentences, sample 50 cascades each with depth 20 to analyze how multiple splits combine.

    Why Only Retokenize the Prompt

    • Proposition 1 gives that when the target side is randomly retokenized, the token-level loss exceeds the string-level loss by at least the conditional entropy of the encoding distribution; the optimal model also reproduces the tokenizer's encoding distribution.
    • The core decomposition in Proposition 2 is E[−log Pθ(tc(X)∣ tZ)]=Hμ(X∣ Z)+E[KL]+E[−log Pθ(tc(X)∣ X,tZ)]; the latter two terms are non-negative, and the lower bound is the same as canonical training.
    • Based on this, the authors call prompt retokenization a strictly label-preserving augmentation: given the prompt byte string, retokenization is conditionally independent of the continuation and adds no information about the continuation.

    Consistency Objective and Training Procedure

    1. The student is initialized from the reference model, and the reference model is frozen; no safety labels or ground-truth responses are used. For variants that need a continuation, sample once from the canonical prompt at temperature 1, up to 128 tokens.
    2. For each prompt, uniformly sample 8 non-canonical encodings from MDD, plus the canonical encoding for 9 total; only the instruction span is perturbed, and the average token count inflates by 3.62×.
    3. The total loss combines the canonical term, which always backpropagates, with the CVaR of the sampled terms; ρ=0.25, and after gradient-free ranking, only the 2 non-canonical encodings with the largest loss and the canonical term are backpropagated, i.e., 3 times per prompt rather than 9.
    4. Full fine-tuning for 700 steps, learning rate 10^-5, gradient accumulation 8, 20 warmup steps, gradient norm clipping 1.0, optimizer 8-bit AdamW.

    Output, Representation Variants, and Mechanism Analysis

    • Output-based: Compare per-position next-token distributions along the reference continuation, using forward KL; the CE variant supervises only the tokens the reference actually generated. There is also a single-position variant that compares next-token distributions only at the last prompt position.
    • Representation-based: Square the residual difference normalized by layer and position. repr-next supervises only the last prompt position across all 32 layers; repr-cont also supervises reference continuation positions.
    • Control designs: canonical-only self-distillation removes non-canonical encodings; StochasTok retokenizes both the instruction and the answer; context-perturbed SFT uses Alpaca answers and reference refusals, uniformly weighted over 9 encodings.
    • Probes and steering: Train frozen logistic probes on the canonical activations of the un-fine-tuned model to distinguish harmful/benign and six topic categories; by default read the last prompt position at layer 32. Also take the mean difference between harmful and benign activations at layer 16 as the refusal direction, add it starting from the last prompt position, and test the causal effect.
  4. What experiments did the paper conduct?

    All three model families reduce AdvTok ASR, but capability loss, over-refusal, and cross-attack transfer vary by target.

    Experimental Setup

    • Models tested: The main experiments use OLMo-2-1124-7B-Instruct; the prompt diversity experiments use Llama-3.2-3B-Instruct; Appendix N re-tests gemma-3-4b-it. The sensitivity analysis additionally uses OLMo-2-1124-7B base, Olmo-3, and Tulu-3-8B.
    • Training data: 200 held-out AdvBench examples and 320 training examples, mixed with Alpaca; the main run samples 5,600 examples over 700 steps, of which 1,547 are harmful and 4,053 are benign, covering 3,793 distinct Alpaca instructions.
    • Attack protocol: AdvTok is searched separately for each model, with 100 iterations and 8 encodings per round; greedy or T=1 sampling 8 times, generating 256 tokens. BEAST and Charmer use a different generation protocol, 128 tokens, T=1 sampling 3 times.
    • Judging method: Attack success is judged by Llama-Guard-3-8B; T=0 is the proportion of unsafe prompts, T=1 is the proportion of unsafe samples. Appendix L re-checks with the HarmBench classifier; refusals are detected by a keyword-prefix judge.
    • Samples and intervals: The main table uses 200 held-out AdvBench and 250 XSTest-safe; values are means over training seeds, ± is the half-width of the 95% bootstrap interval over prompts. Consistency, KL, and repr-next use 3 seeds each; the rest use 1.
    • Other evaluations: WildJailbreak uses a fixed 200 vanilla harmful prompts; GSM8K uses the full test set of 1,319 questions, and MMLU and IFEval are also tested. The main probe results use 63 held-out harmful prompts.

    Main Results

    According to Table 1, on OLMo-2-7B-Instruct the AdvTok ASR and XSTest-safe refusal are as follows; lower ASR is better, and the no fine-tuning row is not a defense baseline model.

    Swipe horizontally to read the table

    Training methodAdvTok T=0AdvTok T=1XSTest-safe refusal
    No fine-tuning0.400 ±.0670.458 ±.0520.065 ±.024
    Canonical-only self-distillation0.325 ±.0650.426 ±.0460.102 ±.029
    StochasTok, α=0.30.205 ±.0550.336 ±.0500.108 ±.029
    Context-perturbed SFT0.020 ±.0180.062 ±.0260.235 ±.039
    Consistency, CE0.030 ±.0220.073 ±.0250.085 ±.027
    Consistency, KL0.020 ±.0150.043 ±.0180.068 ±.018
    Consistency, repr-next0.038 ±.0200.033 ±.0160.064 ±.022
    • Differences between objectives: The authors did not detect AdvTok differences among CE, KL, and repr-next; the greedy ASR of repr-next across three seeds is 0.010–0.080, with variation between seeds larger than variation between objectives.
    • Necessary conditions: Canonical-only self-distillation remains close to no fine-tuning; KL with only benign prompts is 0.315, with a paired difference of −0.085. Under a shallow sampler KL is 0.165, whereas at 3.62× depth it is 0.020.
    • Costs and exceptions: Context-perturbed SFT's AdvTok is close to consistency training, but it loses more on three capability benchmarks; the model trained only on harmful prompts in Table 9 refuses 0.465 of benign instructions and 0.614 of XSTest-safe.

    Cross-model, Cross-attack, and Capability Costs

    • Three-model re-test: In Table 13, Llama-3.2-3B-Instruct's AdvTok T=0/T=1 drops from 0.320/0.394 without fine-tuning to 0.005/0.022 for KL and 0.015/0.030 for repr-next; gemma-3-4b-it drops from 0.385/0.372 to 0.095/0.106 and 0.040/0.051.
    • BEAST counterexample: On OLMo, KL is 0.816/0.674, higher than 0.655/0.543 without fine-tuning; on gemma, KL is 0.735/0.603, also higher than 0.465/0.400 without fine-tuning. repr-next is the only objective that lowers both AdvTok and BEAST on all three models, while Charmer results vary by model.
    • Capability loss: In Table 16, every fine-tuning arm has a benchmark loss. Llama's repr-next MMLU change is −0.293 ±.010; gemma's repr-next GSM8K is −0.541 ±.029. The authors state that repr-cont has the smallest loss on Llama and gemma.
    • Over-refusal and degenerate outputs: In Table 17, all fine-tuning arms on Llama have higher XSTest-safe refusal than no fine-tuning; on gemma only StochasTok does. Some repr-next cells have more degenerate responses, and Appendix N.3 excludes degenerate responses from attack success.

    Character Noise, Prompt Diversity, and Mechanism

    • Character substitution transfer: Appendix E applies 8 random character substitutions to 200 held-out harmful prompts; the no fine-tuning model's unsafe rate goes from 0.000 to 0.195; KL is 0.000, repr-next is 0.010. KL with only benign data is instead 0.265.
    • Not achieved by more refusals: After 8 substitutions, KL's refusal change on 200 benign instructions is +0.000, and on 250 XSTest-safe is +0.064; the authors therefore state that robustness is not obtained by generally increasing refusals.
    • Prompt diversity: In the Llama KL experiments of Table 3, with 1/8× prompts and re-tokenization padded to match, AdvBench T=1 ASR is 0.206 ±.035, versus 0.022 ±.010 for the full run; the authors state that adding re-tokenization cannot substitute for new prompts. repr-cont is insensitive to this diversity within the tested range.
    • Probe results: The frozen refusal probe of the no fine-tuning model is 1.000 on canonical inputs, 0.317 under attack, and 0.603 for depth-matched random encodings; the topic probe is 0.762, 0.587, and 0.571 respectively, with a majority-class baseline of 0.35.
    • After training and steering: In Table 2, the under-attack probe accuracy of mixed-data KL and repr-next is 0.921 and 0.984, and benign-only KL is 0.333. Adding a refusal direction to 80 attack encodings that produce unsafe greedy responses yields 0.787 refusal and unsafe rate 0.050; with a random direction of the same norm the unsafe rate is 0.925.

    Other Ablations and Analyses

    • Single split: Among 526 positions, the median target NLL change is +0.11 nats, 39.2% have lower NLL, and the maximum increase is 4.02 nats (Section 3.3, Figure 5A).
    • Cascade variance: Of the variance in NLL change, 36% is shared and rising with depth, 43% is sentence-specific, and 21% is attributed to the cascade; 9 sentences increase with depth, 4 decrease, and 3 show no detectable trend.
    • CVaR: Only ρ∈{0.25,1} is trained; with 8 sampled encodings, the authors did not detect an effect of the choice on robustness, but only 3/9 encodings are backpropagated per prompt (Appendix F).
    • Representation supervision layers: In Table 6, repr-next's greedy ASR is 0.050, 0.035, and 0.010 for {32}, {8,16,24,32}, and all 32 layers respectively, with one seed per row.
    • Full-sequence StochasTok: In Table 8, greedy AdvTok drops from 0.415 at α=0 to 0.045 at α=5.5; the non-canonical output rate at α=5.5 is 0.4218, and context-only training keeps it below 0.001.
    • Judge re-check: In Table 10, with a single seed, HarmBench is lower than Llama-Guard in every cell; no fine-tuning greedy is 0.235, KL and repr-next are both 0.005, and every training arm remains below no fine-tuning.
  5. What are some points that can be further explored?

    The authors list limitations regarding mechanism analysis, number of seeds, and the scope of attack applicability; the experiments additionally cover three instruction models.

    Limitations and Future Directions Noted by the Authors

    • Scope of mechanism analysis: Limitations explicitly states that probing and steering are run only on OLMo-2-1124-7B-Instruct; Appendix N repeats only the attack and capability evaluations for the other two models.
    • Training seeds: Limitations notes that KL and repr-next have 3 seeds, while other arms have only 1; the greedy AdvTok seed intervals of KL and repr-next overlap, so the authors do not rank the two.
    • Judge dependence: Limitations notes that attack success depends on the judge; Appendix L separately reports that the refusal detector's recall varies across training arms, so the authors rely on ordering rather than the magnitude of differences.
    • Attack applicability: Limitations notes that AdvTok requires control of token IDs and applies only to open-weight models and APIs that accept token IDs; however, the attacker does not need output distribution access.
    • Scale of the diversity experiment: Limitations notes that Section 8 uses only one model and one training seed per arm, and the same holds for the gemma-3-4b results.
    • Appendix analyses not rerun: Appendix M explicitly states that refit-probe, drift, predictor, directed-search, and steering controls use the submitted-version attack encodings and have not yet been rerun on the corrected evaluation.

    Experimental Coverage

    • Model coverage: Attack and capability evaluations cover OLMo-2-1124-7B-Instruct, Llama-3.2-3B-Instruct, and gemma-3-4b-it; the main training is full fine-tuning, and the appendix additionally has a LoRA exposure baseline.
    • Attack coverage: Includes AdvTok, BEAST, Charmer, character substitution, and jailbreak wrapper and user-turn prefill plus retokenization search on Llama and OLMo; wrapper/prefill were not run on gemma (Appendix N.2).
    • Data and capabilities: The training mixture is AdvBench and Alpaca; out-of-distribution attacks use 200 WildJailbreak examples, over-refusal uses XSTest-safe and held-out Alpaca, and capabilities use MMLU, GSM8K, and IFEval.
    • Scale of manual verification: In Appendix L, the Llama-Guard precision sample is 56 examples and the second sample is 50 examples, both with only one annotator and produced before the evaluation correction; the keyword-prefix precision sample is 5 examples, and the false-positive rate was not measured.
    • Reproduction information: Appendix C states that retokenization comes from an unseeded random generator, so the same training seed can reproduce only the prompt order, not the sampled encodings and reference continuations; the paper does not report the number of attack queries or training time.
  6. Summarize the main content of the paper

    The paper links retokenization jailbreaks to suppression of the refusal signal and uses self-distillation consistency training to reduce attack success rate.

    This is a paper on tokenization-level safety defense and mechanism analysis: the text bytes are completely unchanged, and merely changing the token segmentation may cause an aligned model to stop refusing.

    • Problem and hypothesis: The authors distinguish semantics x from surface encoding t and treat AdvTok as an attack that keeps x and perturbs t; training has only seen canonical encodings, so the model has no complete behavioral constraint on other encodings of the same string.
    • Method highlights: Only the prompt is retokenized, and the student matches the frozen reference model's canonical output distribution or residual representations; the canonical term is always kept, and the sampled terms use CVaR to select high-loss encodings. The theoretical analysis states that target-side retokenization adds irreducible entropy, whereas prompt-side retokenization does not change the training optimum.
    • Main results: In Table 1, OLMo-2-7B's greedy AdvTok ASR drops from 0.400 un-fine-tuned to KL 0.020 and repr-next 0.038; canonical-only self-distillation is still 0.325, and benign-prompt-only KL is 0.315.
    • Transfer and cost: Eight character substitutions bring the un-fine-tuned model's unsafe rate to 0.195, with KL and repr-next at 0.000 and 0.010, respectively. repr-next reduces AdvTok and BEAST on all three models, but MMLU changes by −0.293 on Llama and GSM8K changes by −0.541 on gemma (Table 16).
    • Mechanistic evidence: Under attack, the frozen refusal probe's accuracy drops from 1.000 on canonical inputs to 0.317, while the topic probe remains above the majority-class baseline; after training on mixed data, the refusal probe stays at 0.79–0.98 under attack. After adding the refusal direction back to 80 attack encodings, 0.787 refuse.
    • Authors' conclusions: The authors believe robustness requires deeper retokenization and harmful prompts in the training mixture; character-noise robustness transfers, but suffix attack transfer depends on the target. Under output-based KL, more retokenization cannot substitute for more prompts, whereas representation matching does not depend on the number of prompts within the tested range.

Research lineage

7 foundations · 0 follow-ups in library
Explore in knowledge graph →

Hover or focus a connected paper to inspect the citation context.

Related papers

Show 3 more papers
Read originalarxiv.org