`[Bug][v5.0.0rc2] AutoTokenizer.from_pretrained fails on second run with AttributeError: 'PreTrainedConfig' object has no attribute 'get' (Qwen/Qwen3-4B-Instruct-2507)`
Author: ansh-info
Pull request: no
Labels: name: bug

### System Info

Transformers: 5.0.0rc2
PyTorch: 2.9.0+cu128
CUDA (torch): 12.8
huggingface_hub: 1.3.1
tokenizers: 0.22.2
OS: Linux-6.8.0-1024-aws-x86_64-with-glibc2.39

=== GPU ===
NVIDIA H100 80GB HBM3
NVIDIA H100 80GB HBM3
NVIDIA H100 80GB HBM3
NVIDIA H100 80GB HBM3

### Who can help?

@Cyrilvallez @ArthurZucker
*(model loading / tokenizer auto logic)*

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

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

### Reproduction

Details:
I am performing **reinforcement learning using TRL’s GRPO** on an H100 GPU. GRPO requires `transformers >= 5.0.0`, so I am using the prerelease `5.0.0rc2`.

Please provide a code sample that reproduces the problem you ran into.

### Minimal reproduction

```python
from transformers import AutoTokenizer

model_id = "Qwen/Qwen3-4B-Instruct-2507"

tokenizer = AutoTokenizer.from_pretrained(
    model_id,
    trust_remote_code=True
)

print("Loaded tokenizer:", type(tokenizer))

### What happens

1. **First run on a fresh VM**

   * Model and tokenizer download correctly
   * Files are cached under `~/.cache/huggingface/`
   * Script works as expected

2. **Second run (or after restarting training / switching models)**

   * If I am logged in (`huggingface-cli login`) **or** have `HF_TOKEN` set:

     * The script crashes during `AutoTokenizer.from_pretrained`
   * If I am *not* logged in:

     * I often get network/auth-related errors
     * I am forced to manually load from the local cache path

### Error message / stack trace

```text
Traceback (most recent call last):
  File ".../transformers/models/auto/tokenization_auto.py", line 720, in from_pretrained
    model_type = config_class_to_model_type(type(config).__name__) or config.get("model_type", None)
AttributeError: 'PreTrainedConfig' object has no attribute 'get'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../transformers/models/auto/configuration_auto.py", line 1381, in from_pretrained
    raise ValueError(
ValueError: Unrecognized model in Qwen/Qwen3-4B-Instruct-2507. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: ...

* This happens **only after the model has already been cached**
* `trust_remote_code=True` is enabled
* HF auth is configured both via CLI and environment variables
* Restarting the entire machine temporarily fixes the issue, but deleting/recreating virtual environments does not reliably help

### Expected behavior

`AutoTokenizer.from_pretrained(..., trust_remote_code=True)` should work consistently across runs (fresh or cached) and should not fail based on HF authentication state.

In particular:

* Cached models should load identically to freshly downloaded ones
* `AutoTokenizer` should not call `.get()` on a `PreTrainedConfig` object
* Users should not be forced to manually reference local cache paths or restart machines

Comments:
I AM WORKING ON THE ISSUE #43207 

Hi @ansh-info, I can't reproduce the bug. Using the latest commit on `main` I tried running:

```python
from transformers import AutoTokenizer

model_id = "Qwen/Qwen3-4B-Instruct-2507"

tokenizer = AutoTokenizer.from_pretrained(
    model_id,
    trust_remote_code=True
)
```

and even if I reloaded the tokenizer multiple times it worked fine.

> Hi [@ansh-info](https://github.com/ansh-info), I can't reproduce the bug. Using the latest commit on `main` I tried running:
> 
> from transformers import AutoTokenizer
> 
> model_id = "Qwen/Qwen3-4B-Instruct-2507"
> 
> tokenizer = AutoTokenizer.from_pretrained(
>     model_id,
>     trust_remote_code=True
> )
> and even if I reloaded the tokenizer multiple times it worked fine.

Hi @Rocketknight1, Thank you for trying it out, could it be the related to the platform wheels, are you on Linux?

> I AM WORKING ON THE ISSUE [#43207](https://github.com/huggingface/transformers/pull/43207)

Great!

It could also be version-related, have you tried installing from `main`?

> It could also be version-related, have you tried installing from `main`?

Yes, I tried from `main`

Hmn, interesting. I don't see how this would be platform related, but I'm running on Linux and that's the only place I've tried it! 

However, on investigation, I do think the code is incorrect and that `config.get()` is invalid, even if I don't reach that line when I run the same code. I'll make the fix!