When Qwen2VLConfig is saved and loaded again, an incorrect model_type will be obtained
Author: ZX-ModelCloud
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.57.1
- Platform: Linux-6.14.0-29-generic-x86_64-with-glibc2.39
- Python version: 3.11.10
- Huggingface_hub version: 0.34.4
- Safetensors version: 0.6.2
- Accelerate version: 1.10.1
- Accelerate config:    not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.8.0+cu128 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA GeForce RTX 4090

### Who can help?

_No response_

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

```
import tempfile
from transformers import AutoConfig

cfg = AutoConfig.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
assert cfg.model_type == "qwen2_vl"

with tempfile.TemporaryDirectory() as tmp_dir:
    cfg.save_pretrained(tmp_dir)

    new_cfg = AutoConfig.from_pretrained(tmp_dir)

    assert new_cfg.model_type == "qwen2_vl"  # Expected "qwen2_vl", but got "qwen2_vl_text".
```

### Expected behavior

when Qwen2VLConfig is saved and then loaded again.
Expected model_type is "qwen2_vl", but got "qwen2_vl_text".

**Qwen2_5_VLConfig** also has the same bug.

This bug is caused by [PR#41158](https://github.com/huggingface/transformers/pull/41158)

Comments:
cc @zucchini-nlp

In the __getattribute__ method of the Qwen2VL config class , the key passed is "model_type" when we call new_cfg.model_type .
but text config also has a .model_type attribute whose value is "qwen2_vl_text". The if condition becomes true and we just return "qwen2_vl_text" instead of the actual model type .
The fix is to add "model_type" to the list of excluded keys within the __getattribute__ method. I've confirmed this locally, and it resolves the AssertionError.


<img width="1533" height="625" alt="Image" src="https://github.com/user-attachments/assets/0fd143f4-4dc6-424e-85d3-1316fd2743e7" />

<img width="737" height="83" alt="Image" src="https://github.com/user-attachments/assets/1a3a05cf-4a1c-4976-80a4-994d79372995" />

Is this the correct fix?
A few other models were also changed in the PR by @zucchini-nlp  . Should the fix(if correct) be applied to them as well? 
If this is the expected approach, I'd be happy to submit a PR to resolve the issue.

> The fix is to add "model_type" to the list of excluded keys within the getattribute method

SGTM, common attributes that are present in all configs should not be overriden. Would you like to open a PR and verify that all common params are skipped?

>  Should the fix(if correct) be applied to them as well?

Yep :)

>SGTM, common attributes that are present in all configs should not be overriden. Would you like to open a PR and verify that all common params are skipped?

Yep I can look into that . Thanks for the heads up 

@zucchini-nlp 
<img width="2546" height="285" alt="Image" src="https://github.com/user-attachments/assets/6ddfa381-6fef-4a4a-bf2f-1b48687c8cae" />
There's 52 common attributes so should I just add the list/set in the if statement? 

@i3hz no, not all of these attr are common in reality. The token ids and generation params are text-config specific for example. We need to skip only those like `_name_or_path/model_type/dtype`

So just to confirm I should add _name_or_path and model_type? Dtype and _attn_implementation_internal are already included in the current implementation .
Thanks a lot , I was a little(maybe a lot) confused about it . 

Let's hope we get this patched for 4.57.2  as it is a bad regression. @Rocketknight1 

I've made the changes for qwen2_vl and qwen2_5_vl.
https://github.com/huggingface/transformers/pull/41758


This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

resolved on main branch