Attribute error for AutoTokenizer when loading HF repo from older transformers versions :)
Author: nil0x9
Pull request: no
Labels: name: bug

### 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

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

Error Msg:

```bash
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.

Comments:
I'm guessing that `<=` should be a `>=`.

> I'm guessing that `<=` should be a `>=`.

nah, the root cause is that they load a dict config object and then use attribute instead of key to access model_type.

I think hf team should really enhance their code quality, CI and review process.

https://github.com/huggingface/transformers/pull/42379

Fix is in #42389

Sorry about that. This is only happening on local tokenizers and not loading from a repo so it went undetected - let me know if the PR doesn't fix the issue

Similarly, if we try to load a tokenizer with local_files_only, it fails.  For example
```
AutoTokenizer.from_pretrained('meta-llama/Meta-Llama-3-8B', local_files_only=True)
```

This fails with
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/venv/lib/python3.12/site-packages/transformers/models/auto/tokenization_auto.py", line 1149, in from_pretrained
    return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/transformers/tokenization_utils_base.py", line 2108, in from_pretrained
    remote_files = os.listdir(pretrained_model_name_or_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'meta-llama/Meta-Llama-3-8B'
```

This worked fine with previous versions where it would pull from the cache.

yep that's very weird

I created a separate issue for the local_files_only case because it was different enough from this.
https://github.com/huggingface/transformers/issues/42393


Ty we'll patch

It's not fixed yet?? @ArthurZucker 

works for me!

<img width="838" height="749" alt="Image" src="https://github.com/user-attachments/assets/6ad7dca6-1977-4f8b-b39e-68aa703308a1" />