Repository navigation
Revert "Fix CodeLlama tokenizer dropping leading whitespace on decode (#47488)" - #47861
Merged
Merged
Conversation
…#47488)" This reverts commit 1b20eb1. #47488 replaced the `Metaspace` pre-tokenizer with a `Prepend("▁") + Replace(" ", "▁")` normalizer. That changes tokenization in two ways that break existing checkpoints. 1. Added-token contents are themselves normalized when the added-vocabulary matcher (daachorse) is rebuilt, so `<s>` is stored as `▁<s>` and stops matching `<s>` in the text. Any checkpoint shipping its specials with `normalized=True` loses them: tok.tokenize("Hey how are<s>you?<unk> <unk>") ['▁Hey', '▁how', '▁are', '<', 's', '>', 'you', '?', '<', 'unk', '>', '▁<unk>'] 2. The prepend runs on every chunk produced by the added-token split, so a metaspace is inserted after every special token. `[INST] How are you doing?<s>[/INST]` moves `[` from 29961 to 518, i.e. every multi-turn Llama-2 chat prompt tokenizes differently. #47488 wrote this into its own expected outputs rather than treating it as a bug. The leading-whitespace round-trip reported in #47487 is real, but it is decode-only and does not need a pipeline change.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: code_llama |
Cyrilvallez
pushed a commit
that referenced
this pull request
Aug 10, 2026
…#47488)" (#47861) This reverts commit 1b20eb1. #47488 replaced the `Metaspace` pre-tokenizer with a `Prepend("▁") + Replace(" ", "▁")` normalizer. That changes tokenization in two ways that break existing checkpoints. 1. Added-token contents are themselves normalized when the added-vocabulary matcher (daachorse) is rebuilt, so `<s>` is stored as `▁<s>` and stops matching `<s>` in the text. Any checkpoint shipping its specials with `normalized=True` loses them: tok.tokenize("Hey how are<s>you?<unk> <unk>") ['▁Hey', '▁how', '▁are', '<', 's', '>', 'you', '?', '<', 'unk', '>', '▁<unk>'] 2. The prepend runs on every chunk produced by the added-token split, so a metaspace is inserted after every special token. `[INST] How are you doing?<s>[/INST]` moves `[` from 29961 to 518, i.e. every multi-turn Llama-2 chat prompt tokenizes differently. #47488 wrote this into its own expected outputs rather than treating it as a bug. The leading-whitespace round-trip reported in #47487 is real, but it is decode-only and does not need a pipeline change.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Reverts #47488. Needed for the release.
Follow-up: #47862 fixes #47487 properly — decode-only, encoding byte-identical, no id changes.
#47488 swapped the
Metaspacepre-tokenizer for aPrepend("▁") + Replace(" ", "▁")normalizer. Both look equivalent, but the normalizer form changes tokenization in two ways that break checkpoints already in the wild.1. Added tokens stop matching. The normalizer is applied to the added tokens themselves when the added-vocabulary matcher (daachorse) is rebuilt, so
<s>is stored as▁<s>and no longer matches<s>in the text. Any checkpoint that ships its specials withnormalized=Trueloses them:2. A spurious metaspace after every special token. The prepend runs on each chunk produced by the added-token split, not once on the sequence. So
[INST] How are you doing?<s>[/INST]moves[from29961to518— every multi-turn Llama-2 chat prompt tokenizes differently. #47488 wrote this into its own expected outputs rather than treating it as a regression:meta-llama/Llama-2-7b-hf'stokenizer.jsonis not a reference here — we built it ourselves, before metaspace was fixed.The round-trip issue reported in #47487 is real but it is decode-only and does not need a pipeline change. It is fixed in #47862, which keeps encoding byte-identical.
This is an exact
git revert;tests/models/code_llama/test_tokenization_code_llama.pyandtests/models/llama/test_tokenization_llama.pypass (116 passed, 14 skipped).Who can review?
@itazap