Repository navigation
Conversation
Qwen3.6 / Qwen3.8 publish a refined Split pattern with \p{M} in
tokenizer_config.json, but Qwen2Tokenizer always applied the module
constant and dropped combining marks into the punctuation branch.
Honour the config key when present; keep the constant as fallback for
older Qwen2 / Qwen3 checkpoints that omit it.
Fixes huggingface#49066
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen2 |
Contributor
CI recapDashboard: View test results in Grafana
|
2 of 4 tasks
4 tasks
Collaborator
|
Thanks @tanvir-ux! As @itazap explained in #49066, the hardcoded pre-tokenizer regex in |
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.
Fixes #49066
What was wrong
Qwen2Tokenizer.__init__always built the Split pre-tokenizer from the module-levelPRETOKENIZE_REGEX, even whentokenizer_config.jsoncarried a differentpretokenize_regex.That was invisible for Qwen2 / Qwen3 because the constant matched the published file. Qwen3.6 and Qwen3.8 refine the pattern with
\p{M}(combining marks). Loading those checkpoints withAutoTokenizerdropped the marks into the punctuation branch, so Hindi / Thai / Arabic text got 50–75% more tokens than the publishedtokenizer.json, andsave_pretrainedbaked the wrong pattern into derived repos.I reproduced the issue's Hindi sample on current main: published IDs
[58069, 84237, 150104, 153348, 184642, 235886], loaded IDs differed. After this change they match.What I changed
pretokenize_regexfrom kwargs (comes fromtokenizer_config.jsonviafrom_pretrained) and use that for the Split pattern when present.PRETOKENIZE_REGEXwhen the key is missing, so older Qwen2 / Qwen3 checkpoints without it keep the same tokenization.I deliberately did not update the module constant itself — that would change default tokenization for older checkpoints that omit the config key.
How I checked
test_honors_pretokenize_regex_from_kwargs— passed.Qwen/Qwen3.8-Flash-Next(Hindi / Thai / Arabic / Latin) — IDs match publishedtokenizer.json.save_pretrainedround-trip keeps\p{M}in bothtokenizer_config.jsonandtokenizer.json.Qwen/Qwen2.5-0.5B-Instruct(nopretokenize_regexin config) still loads.Happy to adjust if you'd rather pull the pre-tokenizer straight off
tokenizer.jsoninTokenizersBackendinstead — this scoped fix matched what the issue suggested forQwen2Tokenizer.