GlitchPatch: Repairing Glitch Tokens in Frozen Language Models via Local Retokenization
Organizations: University of Science and Technology of China · University of Washington · Wuhan University
Abstract
Glitch tokens are anomalous vocabulary entries that can cause large language models (LLMs) to produce outputs inconsistent with their inputs. Existing repair methods require access to model internals, making them impractical for frozen checkpoints. We investigate whether glitch tokens can be repaired outside the model by optimizing the input tokenization. An empirical study on BPE merge-rule deletion reveals that (1)deleting a glitch token's merge rule can fix a substantial fraction of failures, yet disrupting normal tokens sharing intermediate merge nodes causes the overall glitch rate to rise, and (2)different decomposition granularities yield non-monotonic fix rates while collateral damage on normal tokens grows monotonically. Motivated by these findings, we propose GlitchPatch, a repair framework for frozen language models based on local retokenization, consisting of two stages: the offline stage uses Behavioral Path Optimization (BPO) to find the behaviorally optimal replacement token sequence for each glitch token and compiles validated replacements into a rule table; the online stage substitutes only the IDs of matched glitch tokens in the canonical token sequence, with no modification to model parameters or internal states. Experiments on ten models spanning six tokenizer families show that GlitchPatch achieves an 85.10% mean fix rate, outperforming the strongest baseline by 14.37 percentage points, and reduces the average glitch rate from 14.88% to 2.27%. GlitchPatch achieves a 0.00% RR in full-vocabulary evaluation and leaves rule-unmatched inputs unchanged by design. We further evaluate the practical impact of repair from the perspectives of time cost, language understanding, and capability, supporting its deployment feasibility. We hope this work provides a practical option for improving tokenizer reliability.
Figures & tables
| Model | Glitch | Fixed | Reg. | FR% | RR% | GR% |
| Llama-3.1-8B | 22,026 | 18,722 | 0 | 85.00 | 0.00 | 2.58 |
| Llama-3.1-70B | 15,878 | 14,455 | 0 | 91.04 | 0.00 | 1.11 |
| Gemma-4-31B | 36,045 | 32,080 | 0 | 89.00 | 0.00 | 1.51 |
| Gemma-4-E4B | 48,287 | 38,873 | 0 | 80.50 | 0.00 | 3.59 |
| Qwen3.8-27B | 29,451 | 25,770 | 0 | 87.50 | 0.00 | 1.48 |
| Qwen3.6-27B | 31,040 | 26,546 | 0 | 85.52 | 0.00 | 1.81 |
| Model | GlitchProber | GlitchEdit | GlitchCleaner | GlitchPatch |
| Llama-3.1-8B | 21.29 | 59.16 | 68.07 | 85.00 |
| Llama-3.1-70B | 30.97 | 65.03 | 78.48 | 91.04 |
| Gemma-4-31B | 36.19 | 66.37 | 81.28 | 89.00 |
| Gemma-4-E4B | 12.35 | 51.77 | 59.12 | 80.50 |
| Qwen3.8-27B | 27.01 | 60.48 | 74.02 | 87.50 |
| Qwen3.6-27B | 30.09 | 61.67 | 76.06 | 85.52 |
| Paths | Count | Proportion% | FR% |
| 0 | 1,473 | 5.00 | 0.0 |
| 1–3 | 8,847 | 30.04 | 85.4 |
| 4–10 | 11,742 | 39.87 | 93.8 |
| 11–50 | 5,849 | 19.86 | 97.1 |
| 50 | 1,540 | 5.23 | 98.7 |
| FR (%) | Est. build cost | |
| 1 | 71.83 | 47,000 |
| 2 | 77.46 | 76,000 |
| 4 | 82.91 | 135,000 |
| 8 | 87.50 | 253,000 |
| 16 | 87.93 | 488,000 |
| Setting | FR (%) | Note |
| Full GlitchPatch | 87.50 | |
| BPE merge history only | 73.82 | No out-of-tree paths |
| Remove pair term | 81.73 | Proxy ignores adjacency |
| Remove full-path evaluation | 85.34 | Proxy score only |
| Lower utility threshold ( ) | 90.23 | Lower behavioral stability |
Appendix figures & tables24 assets
Supplementary material from the paper’s appendix.
Appendix
| Dimension | Instruction | Expected output | Scoring criterion |
| Repetition | Repeat the string: {target} | The target itself | Exact byte match |
| Spelling | Spell character by character: {target} | Character sequence | Unicode character order match |
| Length | Count the characters: {target} | Correct count | Extracted number matches Unicode char count |
| Model | Vocab | Glitch | Glitch % | Normal |
| Llama-3.1-8B | 128,256 | 22,026 | 17.17 | 106,230 |
| Llama-3.1-70B | 128,256 | 15,878 | 12.38 | 112,378 |
| Gemma-4-31B | 262,144 | 36,045 | 13.75 | 226,099 |
| Gemma-4-E4B | 262,144 | 48,287 | 18.42 | 213,857 |
| Qwen3.8-27B | 248,320 | 29,451 | 11.86 | 218,869 |
| Qwen3.6-27B | 248,320 | 31,040 | 12.50 | 217,280 |
| Method | Fixed | Avg. FR(%) | Regressed | Avg. RR(%) | Avg. GR(%) |
| GlitchProber | 63,614 | 24.63 | 382 | 0.024 | 11.37 |
| GlitchEdit | 154,382 | 58.39 | 182 | 0.012 | 6.30 |
| GlitchCleaner | 185,940 | 70.73 | 713 | 0.046 | 4.53 |
| GlitchPatch | 225,197 | 85.10 | 0 | 0.00 | 2.27 |
| Method | Fixed | Unfixed | FR% | Reg. | Maint. | RR% | GR% |
|---|---|---|---|---|---|---|---|
| Llama-8B ; | |||||||
| GlitchProber | 4,689 | 17,337 | 21.29 | 32 | 106,198 | 0.03 | 13.54 |
| GlitchEdit | 13,031 | 8,995 | 59.16 | 11 | 106,219 | 0.01 | 7.02 |
| GlitchCleaner | 14,993 | 7,033 | 68.07 | 53 | 106,177 | 0.05 | 5.52 |
| GlitchPatch | 18,722 | 3,304 | 85.00 | 0 | 106,230 | 0.00 | 2.58 |
| Llama-70B ; | |||||||
| Model | Type | Vocab | Adaptation |
| Llama-3.1-8B | Byte-level BPE | 128,256 | Raw byte graph |
| Llama-3.1-70B | Byte-level BPE | 128,256 | Shared with 8B |
| Gemma-4-31B | SentencePiece | 262,144 | Normalizer + state |
| Gemma-4-E4B | SentencePiece | 262,144 | Shared with 31B |
| Qwen3.8-27B | Byte-level BPE | 248,320 | Raw byte graph |
| Qwen3.6-27B | Byte-level BPE | 248,320 | Same as above |
| Case | Required handling | Invalid shortcut |
| Byte-level BPE | Build edges from exact raw bytes | Substitute visible Unicode for incomplete bytes |
| SentencePiece BPE | Preserve normalizer, leading space, byte fallback, state | Infer algorithm from file format alone |
| Partial UTF-8 | Expand to complete verifiable span; compare joint decoding | Decode to replacement character and build from it |
| Added/special tokens | Preserve IDs, order, control structure; exclude as edges | Reconstruct control markers via string matching |
| Normalization | Use ’s actual byte content as reference | Claim preservation without checking |
| Incompatible/over-budget | Retain canonical IDs | Delete chars, insert spaces, or rewrite text |
| Dim. | Variant | Prompt structure | Criterion |
| Rep. | Direct | Repeat exactly | Exact match |
| Embedded | Extract from sentence | Exact extraction | |
| Label bind | Bind to label A; query | Exact match | |
| Selection | Select from list | Correct selection | |
| Spell | Forward | List chars of in order | Correct sequence |
| Reverse | List chars in reverse | Correct reverse |
| Parameter | Value | Meaning |
| 8 | Max candidate paths per target | |
| 8 | Max added tokens per span | |
| Span content limit | 64 bytes | Retain if exceeded |
| 0.5 | Adjacent-pair proxy weight | |
| 0.02 | Proxy length cost | |
| 2 | Regression penalty coefficient |
| Method | Mechanism & config | Parameter selection |
| GlitchProber | Activation statistics + neuron correction; 2,000 ref. tokens; threshold 0.99; later MLP layers | Relative layer interval grid; |
| GlitchEdit | Target embedding mixed with normal neighbors; , step 0.1; 1–10 neighbors | Behavioral acceptance; retain failure fallback |
| GlitchCleaner | Target-triggered MLP gated LoRA; rank 4, scaling 4, lr | Freeze base weights; independent calib. from 20 epochs |
| 0.00 | 0.05 | 0.10 | |
| FR (%) | 90.23 | 87.50 | 80.86 |
| Coverage (%) | 94.8 | 89.2 | 81.8 |
| 0.00 | 0.25 | 0.50 | 1.00 | |
| FR (%) | 81.73 | 85.03 | 87.50 | 86.47 |
| 4 | 8 | 16 | |
| FR (%) | 82.48 | 87.50 | 88.52 |
| Mean growth (%) | 1.8 | 2.6 | 4.1 |
| Setting | Llama-8B | Qwen3.8 | Gemma-31B |
| Full GlitchPatch | 85.00 | 87.50 | 89.00 |
| BPE history only | 72.41 | 73.82 | 76.53 |
| Remove pair term | 79.27 | 81.73 | 84.18 |
| Remove path eval. | 82.86 | 85.34 | 87.12 |
| Threshold | 88.16 | 90.23 | 91.74 |
| Model | Mean |
| Llama-3.1-8B | 0.72 |
| Qwen3.8-27B | 0.68 |
| Gemma-4-31B | 0.71 |
| Model | TP | Base (s) | Incr. (%) | Host Prep. (ms) | Build (h) |
| Llama-3.1-8B | 1 | 1.280 | 0.071 | 0.231 | 0.61 |
| Llama-3.1-70B | 4 | 4.600 | 0.058 | 0.247 | 2.08 |
| Gemma-4-31B | 2 | 2.950 | 0.069 | 0.258 | 1.27 |
| Gemma-4-E4B | 1 | 1.100 | 0.061 | 0.219 | 0.49 |
| Qwen3.8-27B | 2 | 2.750 | 0.079 | 0.243 | 1.02 |
| Qwen3.6-27B | 2 | 2.800 | 0.068 | 0.238 | 0.96 |
| Model | Prober | Edit | Cleaner | GlitchPatch |
| Llama-3.1-8B | 0.80 | 2.80 | 7.20 | 0.61 |
| Llama-3.1-70B | 4.80 | 9.80 | 22.50 | 2.08 |
| Gemma-4-31B | 2.80 | 5.20 | 12.80 | 1.27 |
| Gemma-4-E4B | 2.00 | 4.00 | 9.80 | 0.49 |
| Qwen3.8-27B | 2.50 | 4.50 | 11.50 | 1.02 |
| Qwen3.6-27B | 2.40 | 4.30 | 11.00 | 0.96 |
| Method | Build (h) | Latency incr. | Extra params | Extra calls |
| GlitchProber | 2.19 | 9.20% | 0 | 0 |
| GlitchEdit | 4.28 | 0.00% | 0 | 0 |
| GlitchCleaner | 10.41 | 1.00% | Gated LoRA | 0 |
| GlitchPatch | 0.89 | 0.1% | 0 | 0 |
| Model | Method | MMLU-Pro | ARC | GSM8K | HumanEval |
| Llama-8B | Original | 540 | 790 | 805 | 86 |
| GlitchPatch | 540 | 791 | 805 | 86 | |
| Llama-70B | Original | 660 | 875 | 922 | 121 |
| GlitchPatch | 660 | 875 | 922 | 121 | |
| Gemma-31B | Original | 640 | 860 | 910 | 118 |
| GlitchPatch | 641 | 860 | 910 | 118 |
| Model | Original | GlitchPatch | (pp) |
| Llama-3.1-8B | 66.48 | 66.51 | 0.025 |
| Llama-3.1-70B | 79.87 | 79.87 | 0.000 |
| Gemma-4-31B | 78.24 | 78.26 | 0.025 |
| Gemma-4-E4B | 60.48 | 60.45 | 0.025 |
| Qwen3.8-27B | 77.03 | 77.06 | 0.025 |
| Qwen3.6-27B | 76.23 | 76.25 | 0.025 |
| Case | Observable evidence | System action |
| No budget-feasible path | Graph search: path count | Retain original |
| All probes fail on original ( ) | Selection probes: | Retain original |
| Unreliable composition | Full-path probe failure | Reject candidate |
| Insufficient utility | Retain original | |
| Calibration failure | Independent probe failure | Reject rule |
| Per-span limit | or content exceeds 64 bytes | Retain original |
| Model | Prober | Edit | Cleaner | GlitchPatch |
| Llama-3.1-8B | 2.2 | 6.4 | 8.3 | 15.5 |
| Llama-3.1-70B | 1.8 | 4.8 | 7.4 | 11.9 |
| Gemma-4-31B | 3.2 | 5.6 | 8.8 | 12.5 |
| Gemma-4-E4B | 1.5 | 5.8 | 6.4 | 14.4 |
| Qwen3.8-27B | 2.3 | 5.1 | 8.8 | 13.9 |
| Qwen3.6-27B | 2.7 | 5.4 | 8.5 | 12.8 |
| GlitchProber | GlitchEdit | GlitchCleaner | GlitchPatch | |||||
| Model | Acc. | Acc. | Acc. | Acc. | ||||
| Mistral-7B (orig. 87.4) | 86.8 | 0.6 | 87.2 | 0.2 | 87.0 | 0.4 | 87.2 | 0.2 |
| Llama-3.1-70B (orig. 91.6) | 90.8 | 0.8 | 91.2 | 0.4 | 91.0 | 0.6 | 91.8 | 0.2 |
| Qwen3.8-27B (orig. 89.2) | 88.4 | 0.8 | 88.8 | 0.4 | 88.8 | 0.4 | 89.0 | 0.2 |
| Mean (orig. 89.4) | 88.7 | 0.7 | 89.1 | 0.3 | 88.9 | 0.5 | 89.3 | 0.1 |
| Task | Model | Orig. | Prober | Edit | Cleaner | Ours |
| Entity QA | Mistral-7B | 41.8 | 43.2 | 49.6 | 56.4 | 67.8 |
| Llama-70B | 48.2 | 50.8 | 57.0 | 63.8 | 75.0 | |
| Qwen3.8-27B | 44.6 | 46.6 | 52.8 | 59.2 | 71.6 | |
| Verb. Copy | Mistral-7B | 38.2 | 39.8 | 45.4 | 52.8 | 64.6 |
| Llama-70B | 43.6 | 45.6 | 52.0 | 59.6 | 72.4 | |
| Qwen3.8-27B | 40.8 | 42.4 | 48.2 | 55.0 | 68.2 |
Language Model Robustness
Language model robustness studies how reliably language models preserve correct, safe behavior under input changes, distribution shifts, and adversarial pressure.
See all 493 papers