Fix "AttributeError: NewTokenizer has no attribute special_attribute_present" (Remove REGISTERED_FAST_ALIASES)#45293
Open
yonigozlan wants to merge 1 commit intohuggingface:mainfrom
Open
Conversation
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. |
Collaborator
|
It looks fine to me if tests are passing! Agreed that fixing the leaked global should be done anyway |
itazap
reviewed
Apr 9, 2026
| if getattr(tokenizer, "__name__", None) == class_name: | ||
| return tokenizer | ||
|
|
||
| # We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main |
Collaborator
There was a problem hiding this comment.
Suggested change
| # We did not find the class, but maybe it's because a dep is missing. In that case, the class will be in the main |
unrelated to this PR but might as well rm this duplicate comment 😅
itazap
approved these changes
Apr 9, 2026
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.
Fix global state leak in
AutoTokenizer.registercausing test failuresProblem
test_from_pretrained_dynamic_processorwas failing when run as part of the full test class with:Root cause
AutoTokenizer.registerwas populating a global dictREGISTERED_TOKENIZER_CLASSES: dict[str, type]that mapped class
__name__strings to registered class objects. Tests that calledAutoTokenizer.register(e.g.
test_dynamic_processor_with_specific_dynamic_subcomponents) registered a localNewTokenizerclassthere without cleaning it up. When
test_from_pretrained_dynamic_processorlater ran,tokenizer_class_from_name("NewTokenizer")returned the stale local class (which lackedspecial_attribute_present) instead of loading the correct one from the Hub.Fix
Removed
REGISTERED_TOKENIZER_CLASSESentirely. It seems to be redundant (🚨I might be wrong please double check :) ) :AutoTokenizer.registeralready storesclasses in
TOKENIZER_MAPPING._extra_content, andtokenizer_class_from_namecan walk_extra_content.values()to find a class by__name__. The leaked global was the only path through whichthe stale class was being returned.
Also moved the
_extra_contentlookup intokenizer_class_from_nameto run beforeTOKENIZER_MAPPING_NAMES,so user-registered classes continue to shadow built-ins, consistent with how
AutoConfig.registercurrently works.If this looks breaking to you, I'm happy to just pop the registered "NewTokenizer" from REGISTERED_TOKENIZER_CLASSES to fix the tests, and leave tokenization_auto as is.
Cc @itazap @ArthurZucker