Unrecognized model in Qwen/Qwen2.5-Coder-7B-Instruct
Author: kevinlu1248
Pull request: no
Labels: name: bug

### System Info

I bumped my transformers versions to `4.51.2` recently and Qwen 2.5 Coder no longer loads. I downgraded back to `4.49.0` and it loads properly. I think it's a regression.

```
ValueError: Unrecognized model in Qwen/Qwen2.5-Coder-7B-Instruct. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: albert, align, altclip, aria, aria_text, audio-spectrogram-transformer, autoformer, aya_vision, bamba, bark, bart, beit, bert, bert-generation, big_bird, bigbird_pegasus, biogpt, bit, blenderbot, blenderbot-small, blip, blip-2, bloom, bridgetower, bros, camembert, canine, chameleon, chinese_clip, chinese_clip_vision_model, clap, clip, clip_text_model, clip_vision_model, clipseg, clvp, code_llama, codegen, cohere, cohere2, colpali, conditional_detr, convbert, convnext, convnextv2, cpmant, ctrl, cvt, dab-detr, dac, data2vec-audio, data2vec-text, data2vec-vision, dbrx, deberta, deberta-v2, decision_transformer, deepseek_v3, deformable_detr, deit, depth_anything, depth_pro, deta, detr, diffllama, dinat, dinov2, dinov2_with_registers, distilbert, donut-swin, dpr, dpt, efficientformer, efficientnet, electra, emu3, encodec, encoder-decoder, ernie, ernie_m, esm, falcon, falcon_mamba, fastspeech2_conformer, flaubert, flava, fnet, focalnet, fsmt, funnel, fuyu, gemma, gemma2, gemma3, gemma3_text, git, glm, glpn, got_ocr2, gpt-sw3, gpt2, gpt_bigcode, gpt_neo, gpt_neox, gpt_neox_japanese, gptj, gptsan-japanese, granite, granitemoe, granitemoeshared, granitevision, graphormer, grounding-dino, groupvit, helium, hiera, hubert, ibert, idefics, idefics2, idefics3, idefics3_vision, ijepa, imagegpt, informer, instructblip, instructblipvideo, jamba, jetmoe, jukebox, kosmos-2, layoutlm, layoutlmv2, layoutlmv3, led, levit, lilt, llama, llama4, llama4_text, llava, llava_next, llava_next_video, llava_onevision, longformer, longt5, luke, lxmert, m2m_100, mamba, mamba2, marian, markuplm, mask2former, maskformer, maskformer-swin, mbart, mctct, mega, megatron-bert, mgp-str, mimi, mistral, mistral3, mixtral, mllama, mobilebert, mobilenet_v1, mobilenet_v2, mobilevit, mobilevitv2, modernbert, moonshine, moshi, mpnet, mpt, mra, mt5, musicgen, musicgen_melody, mvp, nat, nemotron, nezha, nllb-moe, nougat, nystromformer, olmo, olmo2, olmoe, omdet-turbo, oneformer, open-llama, openai-gpt, opt, owlv2, owlvit, paligemma, patchtsmixer, patchtst, pegasus, pegasus_x, perceiver, persimmon, phi, phi3, phi4_multimodal, phimoe, pix2struct, pixtral, plbart, poolformer, pop2piano, prompt_depth_anything, prophetnet, pvt, pvt_v2, qdqbert, qwen2, qwen2_5_vl, qwen2_audio, qwen2_audio_encoder, qwen2_moe, qwen2_vl, qwen3, qwen3_moe, rag, realm, recurrent_gemma, reformer, regnet, rembert, resnet, retribert, roberta, roberta-prelayernorm, roc_bert, roformer, rt_detr, rt_detr_resnet, rt_detr_v2, rwkv, sam, sam_vision_model, seamless_m4t, seamless_m4t_v2, segformer, seggpt, sew, sew-d, shieldgemma2, siglip, siglip2, siglip_vision_model, smolvlm, smolvlm_vision, speech-encoder-decoder, speech_to_text, speech_to_text_2, speecht5, splinter, squeezebert, stablelm, starcoder2, superglue, superpoint, swiftformer, swin, swin2sr, swinv2, switch_transformers, t5, table-transformer, tapas, textnet, time_series_transformer, timesformer, timm_backbone, timm_wrapper, trajectory_transformer, transfo-xl, trocr, tvlt, tvp, udop, umt5, unispeech, unispeech-sat, univnet, upernet, van, video_llava, videomae, vilt, vipllava, vision-encoder-decoder, vision-text-dual-encoder, visual_bert, vit, vit_hybrid, vit_mae, vit_msn, vitdet, vitmatte, vitpose, vitpose_backbone, vits, vivit, wav2vec2, wav2vec2-bert, wav2vec2-conformer, wavlm, whisper, xclip, xglm, xlm, xlm-prophetnet, xlm-roberta, xlm-roberta-xl, xlnet, xmod, yolos, yoso, zamba, zamba2, zoedepth
```

### Who can help?

@gante 

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

```
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct")
```

Run this within the following modal function:

```
training_image = modal.Image.from_registry("nvidia/cuda:12.4.0-devel-ubuntu22.04", add_python="3.11") \
    .pip_install(
        "transformers==4.51.2",
    ) \
    .env({"HF_HUB_ENABLE_HF_TRANSFER": "1"})
```

I ran into this on an 8xH100 in accelerate + deepspeed but I don't think this error is related to GPUs, since the tokenizer doesn't load either.

### Expected behavior

It loads.

Comments:
I took a quick look and it looks like the issue happens when using `HF_HUB_ENABLE_HF_TRANSFER=1` and non having `hf_transfer` installed.

- v4.49 throws a correct `ModuleNotFoundError: No module named 'hf_transfer'`
- 4.51.2 instead throws this `ValueError: Unrecognized model` when the download fails.
- both work fine if `hf_transfer` installed.
- both work if `HF_HUB_ENABLE_HF_TRANSFER` is not specified.

Can you confirm this is the case @kevinlu1248 ?

tagging @Wauplin as this might be a issue with `huggingface_hub` and the recent updates regarding Xet.

cc @lysandrejik for the dummies overhaul, which I think is why the missing dependency isn't being picked up

For me the issue was a SSL issue. v4.49 shows an informative error which helped me resolve the issue, whereas 4.51.3 throws this misleading ValueError. 

Qwen2.5-Math also no longer loads

ValueError: Unrecognized model in Qwen/Qwen2.5-Math-1.5B. Should have a `model_type` key in its config.json, or contain one of the following strings in its name: albert, 

Root cause traced to https://github.com/huggingface/transformers/pull/36033 (commit https://github.com/huggingface/transformers/commit/bf46e44878bd86aebcfa1eceb4a93a6e5b20e863 ).  Prior to v4.50, hub exceptions (e.g. `ModuleNotFoundError: No module named 'hf_transfer'`) either fell through or were caught by specific handlers:
https://github.com/huggingface/transformers/blob/befea8c4f00528b112541dfa7e62f4dae485b82d/src/transformers/utils/hub.py#L356-L410

However, after #36033, the new logic wraps the entire block in a catch-all except, followed by an if/elif chain without a final else: https://github.com/huggingface/transformers/blob/6f7ea1cf006414231610906e7710a84281960c24/src/transformers/utils/hub.py#L499-L519

Proposal: add an `else: raise e` to surface uncaught exceptions, preserving pre-4.50 behavior so that proper errors are displayed.

@Cyrilvallez as original author of the PR, and also since I am on my first weeks, can you take a look at the problem and proposed PR?







Ha indeed, I thought the scope of the if/else block was covering the exception range of what the hub would raise. If this is not the case, we do need to update and raise other Exceptions! Thanks for diving into it, will review the associated PR! 🤗

same issue here 

> same issue here

If you need the fix before the next release, you can install the latest version from source with: `pip install git+https://github.com/huggingface/transformers` 😄 

我也遇到这个问题  ，我是加载模型的路径错了  要加载到config 文件上级目录就可以了