Repository: huggingface/transformers
Pull request: [VLM] fix loading issues

# What does this PR do?

As per title, the recent refactor broke loading for some models. The tests were ran before the last commit when a restriction on model names was added, thus the issue went unnoticed while merging 🥲 



fixes https://github.com/huggingface/transformers/issues/38056, and fixes https://github.com/huggingface/transformers/issues/38070

Changed files:
filename: src/transformers/modeling_utils.py
patch: @@ -219,22 +219,19 @@ def is_local_dist_rank_0():
 # DO NOT MODIFY, KEPT FOR BC ONLY
 VLMS = [
     "aria",
-    "aya_vision",
+    "ayavision",
     "emu3",
     "fuyu",
-    "got_ocr2",
+    "gotocr2",
     "gemma3",
     "internvl",
-    "llava",
-    "llava_next",
-    "llava_next_video",
-    "llava_onevision",
+    "llava",  # all llava prefixed models fall under this check
     "mistral3",
     "mllama",
     "paligemma",
-    "qwen2_vl",
-    "qwem2_5_vl",
-    "video_llava",
+    "qwen2vl",
+    "qwen2_5_vl",
+    "videollava",
     "vipllava",
 ]
 

filename: src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py
patch: @@ -1381,6 +1381,7 @@ def _prepare_4d_causal_attention_mask_with_cache_position(
 
 @auto_docstring
 class Qwen2_5_VLModel(Qwen2_5_VLPreTrainedModel):
+    base_model_prefix = ""
     _checkpoint_conversion_mapping = {"^model": "language_model"}
     config_class = Qwen2_5_VLConfig
     _no_split_modules = ["Qwen2_5_VLDecoderLayer", "Qwen2_5_VLVisionBlock"]

filename: src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py
patch: @@ -414,6 +414,7 @@ class Qwen2_5_VLModelOutputWithPast(Qwen2VLModelOutputWithPast):
 
 class Qwen2_5_VLModel(Qwen2VLModel):
     config_class = Qwen2_5_VLConfig
+    base_model_prefix = ""
     _no_split_modules = ["Qwen2_5_VLDecoderLayer", "Qwen2_5_VLVisionBlock"]
 
     def __init__(self, config):

filename: src/transformers/models/qwen2_vl/modeling_qwen2_vl.py
patch: @@ -1341,6 +1341,7 @@ def _prepare_4d_causal_attention_mask_with_cache_position(
 
 @auto_docstring
 class Qwen2VLModel(Qwen2VLPreTrainedModel):
+    base_model_prefix = ""
     _checkpoint_conversion_mapping = {"^model": "language_model"}
 
     def __init__(self, config: Qwen2VLConfig):

filename: tests/models/aya_vision/test_modeling_aya_vision.py
patch: @@ -144,7 +144,6 @@ def prepare_config_and_inputs_for_common(self):
         config, pixel_values = config_and_inputs
         input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size)
         attention_mask = torch.ones(input_ids.shape, dtype=torch.long, device=torch_device)
-        print("attention_mask", attention_mask.shape)
         # input_ids[:, -1] = self.pad_token_id
         input_ids[input_ids == self.image_token_index] = self.pad_token_id
         input_ids[:, : self.image_seq_length] = self.image_token_index
@@ -366,7 +365,6 @@ def test_small_model_integration_forward(self):
             output = model(**inputs)
 
         actual_logits = output.logits[0, -1, :5].cpu()
-        print("actual_logits", actual_logits)
         expected_logits = torch.tensor([0.4109, 0.1532, 0.8018, 2.1328, 0.5483], dtype=torch.float16)
         self.assertTrue(
             torch.allclose(actual_logits, expected_logits, atol=0.1),
@@ -400,7 +398,6 @@ def test_small_model_integration_generate_text_only(self):
             decoded_output = processor.decode(
                 generate_ids[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True
             )
-        print("decoded_output", decoded_output)
 
         expected_outputs = Expectations(
             {
@@ -437,7 +434,6 @@ def test_small_model_integration_generate_chat_template(self):
             decoded_output = processor.decode(
                 generate_ids[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True
             )
-        print("decoded_output", decoded_output)
         expected_output = "The image depicts a cozy scene of two cats resting on a bright pink blanket. The cats,"  # fmt: skip
         self.assertEqual(decoded_output, expected_output)
 
@@ -477,7 +473,6 @@ def test_small_model_integration_batched_generate(self):
 
         # Check first output
         decoded_output = processor.decode(output[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True)
-        print("decoded_output", decoded_output)
         expected_outputs = Expectations(
             {
                 ("xpu", 3): "Wooden path to water,\nMountains echo in stillness,\nPeaceful forest lake.",
@@ -494,7 +489,6 @@ def test_small_model_integration_batched_generate(self):
 
         # Check second output
         decoded_output = processor.decode(output[1, inputs["input_ids"].shape[1] :], skip_special_tokens=True)
-        print("decoded_output", decoded_output)
         expected_output = 'This image captures a vibrant street scene in a bustling urban area, likely in an Asian city. The focal point is a'  # fmt: skip
 
         self.assertEqual(
@@ -558,7 +552,6 @@ def test_small_model_integration_batched_generate_multi_image(self):
         )  # fmt: skip
         expected_output = expected_outputs.get_expectation()
 
-        print("decoded_output", decoded_output)
         self.assertEqual(
             decoded_output,
             expected_output,
@@ -567,7 +560,6 @@ def test_small_model_integration_batched_generate_multi_image(self):
 
         # Check second output
         decoded_output = processor.decode(output[1, inputs["input_ids"].shape[1] :], skip_special_tokens=True)
-        print("decoded_output", decoded_output)
         expected_outputs = Expectations(
             {
                 ("xpu", 3): "The first image showcases the Statue of Liberty, a colossal neoclassical sculpture on Liberty Island in New York Harbor. Standing at ",