Fix tokenizer auto_map being ignored for custom models#43219
Merged
vasqu merged 3 commits intohuggingface:mainfrom Jan 22, 2026
Merged
Fix tokenizer auto_map being ignored for custom models#43219vasqu merged 3 commits intohuggingface:mainfrom
vasqu merged 3 commits intohuggingface:mainfrom
Conversation
…3202) PR huggingface#42894 added an early-exit to TokenizersBackend when tokenizer_class doesn't match the registered tokenizer for a model_type. However, this early-exit was placed before the auto_map check, causing custom tokenizers with trust_remote_code to be ignored. This fix moves the auto_map extraction before the early-exit check and adds tokenizer_auto_map is None to the condition, so models with custom tokenizers properly use the dynamic module loading path.
Contributor
ArthurZucker
approved these changes
Jan 20, 2026
Collaborator
ArthurZucker
left a comment
There was a problem hiding this comment.
This looks good to me!
Thankd for also adding a test!
|
@Anri-Lombard @ArthurZucker thanks for the fix here. We are depending on it in mlx-lm and looking forward to the next RC. |
Collaborator
|
Can you fix the quality checks please?! 🤗 |
Contributor
|
@bot /style |
Contributor
|
Style fix is beginning .... View the workflow run here. |
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: auto |
|
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. |
Contributor
|
I was so free to make the style check myself to merge, thanks for contributing ❤️ |
SangbumChoi
pushed a commit
to SangbumChoi/transformers
that referenced
this pull request
Jan 23, 2026
…3219) * Fix tokenizer auto_map being ignored for custom models (huggingface#43202) PR huggingface#42894 added an early-exit to TokenizersBackend when tokenizer_class doesn't match the registered tokenizer for a model_type. However, this early-exit was placed before the auto_map check, causing custom tokenizers with trust_remote_code to be ignored. This fix moves the auto_map extraction before the early-exit check and adds tokenizer_auto_map is None to the condition, so models with custom tokenizers properly use the dynamic module loading path. * style --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: vasqu <antonprogamer@gmail.com>
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 #43202
PR #42894 introduced an early-exit to
TokenizersBackendwhentokenizer_classdoesn't match the registered tokenizer for amodel_type. However, this check was placed before theauto_mapextraction, causing custom tokenizers (withtrust_remote_code=True) to be ignored.Reproduction:
For models with unregistered
model_type(likeiquestloopcoder), the conditionTOKENIZER_MAPPING_NAMES.get(model_type, "") != tokenizer_config_classis always True, causing early-exit toTokenizersBackendwithout checking ifauto_mapexists.This fix moves the
auto_mapextraction before the early-exit check and addstokenizer_auto_map is Noneto the condition.Added regression test
test_custom_tokenizer_with_mismatched_tokenizer_class.