Skip to content

Conversation

@Potabk
Copy link

@Potabk Potabk commented Nov 25, 2025

What does this PR do?

Fixes # (issue)

Fix AttributeError: 'dict' object has no attribute 'model_type'. When I'm using transformers==4.57.2, I encountered the following issue:

>>> tokenizer = AutoTokenizer.from_pretrained("/models/Qwen/Qwen2___5-0___5B-Instruct")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python3.11.13/lib/python3.11/site-packages/transformers/models/auto/tokenization_auto.py", line 1156, in from_pretrained
    return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python3.11.13/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2112, in from_pretrained
    return cls._from_pretrained(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/python3.11.13/lib/python3.11/site-packages/transformers/tokenization_utils_base.py", line 2419, in _from_pretrained
    if _is_local and _config.model_type not in [
                     ^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'model_type'

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

Signed-off-by: wangli <wangli858794774@gmail.com>
@Solenhya
Copy link

Solenhya commented Nov 25, 2025

Hahaha i just stumble upon the same issue. From what i have seen the issue is that when there is a cached config_file we are json loading a file and that can only give at best a dict not the usual config object :

                if _config_file is not None:
                    with open(_config_file, encoding="utf-8") as f:
                        _config = json.load(f)
                    transformers_version = _config.get("transformers_version")
                    if transformers_version and version.parse(transformers_version) <= version.parse("4.57.2"):
                        if _is_local and _config.model_type not in [
                            "mistral",
                            "mistral3",
                            "voxstral",
                            "ministral",
                            "pixtral",
                        ]:
                            return tokenizer

@Potabk
Copy link
Author

Potabk commented Nov 25, 2025

#42389 will fix it

@Potabk Potabk closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants