Skip to content

fix: restore missing tokenizer_class attribute in ModelInfos.__init__ - #44663

Closed
Ker102 wants to merge 1 commit into
huggingface:mainfrom
Ker102:fix/add-new-model-like-tokenizer-class
Closed

fix: restore missing tokenizer_class attribute in ModelInfos.__init__#44663
Ker102 wants to merge 1 commit into
huggingface:mainfrom
Ker102:fix/add-new-model-like-tokenizer-class

Conversation

@Ker102

@Ker102 Ker102 commented Mar 13, 2026

Copy link
Copy Markdown

Summary

Fixes #44661transformers add-new-model-like crashes with AttributeError: 'ModelInfos' object has no attribute 'tokenizer_class' when selecting a model that is in TOKENIZER_MAPPING_NAMES.

Root Cause

PR #40936 refactored TOKENIZER_MAPPING_NAMES from (slow_class, fast_class) tuples to single fast tokenizer class names. During this change, self.tokenizer_class was removed from the if branch in ModelInfos.__init__ (line 144), but get_user_input() still accesses it at line 719:

if old_model_infos.tokenizer_class is not None:

The else branch (when the model is NOT in TOKENIZER_MAPPING_NAMES) correctly sets self.tokenizer_class = None, but the if branch (when it IS in the mapping) never assigns it at all.

Fix

Add self.tokenizer_class = None in the if branch of ModelInfos.__init__, matching the behavior of the else branch:

  if self.lowercase_name in TOKENIZER_MAPPING_NAMES:
+     self.tokenizer_class = None
      self.fast_tokenizer_class = TOKENIZER_MAPPING_NAMES[self.lowercase_name]

Reproduction

transformers add-new-model-like
# Select qwen2_5_vl (or any model in TOKENIZER_MAPPING_NAMES)
# → AttributeError: 'ModelInfos' object has no attribute 'tokenizer_class'

PR huggingface#40936 changed TOKENIZER_MAPPING_NAMES from (slow, fast) tuples to
single fast tokenizer class names, but forgot to set self.tokenizer_class
in the 'if' branch of ModelInfos.__init__. This causes an AttributeError
when get_user_input() accesses old_model_infos.tokenizer_class at line 719
for models that are in TOKENIZER_MAPPING_NAMES (e.g. qwen2_5_vl).

The else branch already correctly sets both tokenizer_class and
fast_tokenizer_class to None. This fix adds the same assignment
in the if branch.

Fixes huggingface#44661
@Rocketknight1

Copy link
Copy Markdown
Member

@Ker102

Ker102 commented Mar 13, 2026

Copy link
Copy Markdown
Author

Sorry, I had only read the CONTRIBUTING.md file, I just wanted to provide a solution to this issue, could I still work on it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add-new-model-like fails if model is inside the TOKENIZER_MAPPING_NAMES

2 participants