Honor null tokenizer_file in tokenizer_config.json - #48973
Open
rabeyanoor wants to merge 1 commit into
Open
rabeyanoor wants to merge 1 commit into
rabeyanoor wants to merge 1 commit into
Conversation
Contributor
CI recapDashboard: View test results in Grafana |
Member
|
cc @itazap |
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?
Fixes #48967
Problem
After the v5 update,
AutoTokenizer.from_pretrained("AMR-KELEG/Sentence-ALDi")returns wrong token ids. The model repo ships both avocab.txt(100K vocab) and a staletokenizer.json(32K vocab), and itstokenizer_config.jsoncontains"tokenizer_file": null.In v4 this
nullmeant "do not usetokenizer.json, build the tokenizer from the vocab files". Since #46279 (path traversal fix), the file resolved from the repo always overrides the value fromtokenizer_config.json, so thenullis ignored and the staletokenizer.jsongets loaded."賴匕賴 噩賲賱丞"input_ids[2, 27966, 42, 1, 3][2, 2413, 9200, 3]The "after" output matches the pre-5.0 behavior reported in the issue.
Fix
In
PreTrainedTokenizerBase._from_pretrained, an explicit"tokenizer_file": nullin the config is now kept when another vocab file (e.g.vocab.txt) is available to build the tokenizer.Noneis not a path, so honoring it does not reopen the path traversal issue fixed in Fix path traversal via vocab-file arguments in tokenizer_config.json聽#46279. Non-null values from the config are still ignored.tokenizer.jsonis the only available file, it is still used, so repos that only shiptokenizer.jsonkeep working.Tests
Added
test_null_tokenizer_file_in_config_ignores_tokenizer_jsonintests/tokenization/test_tokenization_utils.py. It creates a local repo with avocab.txt, a staletokenizer.jsonand"tokenizer_file": null, and checks that the tokenizer is built fromvocab.txt. The test fails without the fix and passes with it.The existing
test_vocab_file_in_config_does_not_escape_repostill passes.I also ran the tokenization tests (
tests/tokenization, bert, gpt2, t5, llama, albert, xlnet).Before submitting
ruff formaton the changed files