Skip to content

Attribute error for AutoTokenizer when loading HF repo from older transformers versions :) #42378

@nil0x9

Description

@nil0x9

System Info

transformers==4.57.2

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers import AutoTokenizer
HF_MODEL_PATH='some/repo/with/old/transformers/version'
tokenizer = AutoTokenizer.from_pretrained(HF_MODEL_PATH)

Error Msg:

File ~/miniconda3/lib/python3.13/site-packages/transformers/tokenization_utils_base.py:2419, in PreTrainedTokenizerBase._from_pretrained(cls, resolved_vocab_files, pretrained_model_name_or_path, init_configuration, token, cache_dir, local_files_only, _commit_hash, _is_local, trust_remote_code, *init_inputs, **kwargs)
   2416     transformers_version = _config.get("transformers_version")
   2418     if transformers_version and version.parse(transformers_version) <= version.parse("4.57.2"):
-> 2419         if _is_local and _config.model_type not in [
   2420             "mistral",
   2421             "mistral3",
   2422             "voxstral",
   2423             "ministral",
   2424             "pixtral",
   2425         ]:
   2426             return tokenizer
   2428 # Expose the `fix_mistral_regex` flag on the tokenizer when provided, even if no correction is applied.

AttributeError: 'dict' object has no attribute 'model_type'

Expected behavior

load success.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions