Skip to content

Commit ede7976

Browse files
authored
Fixed incorrect model_type for qwen2vl and qwen2.5vl when config is saved and loaded again (#41758)
* fixed incorrect model_type for qwen2vl and qwen2.5vl * added tests
1 parent ee3a100 commit ede7976

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/transformers/models/qwen2_5_vl/configuration_qwen2_5_vl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ def __setattr__(self, key, value):
313313

314314
def __getattribute__(self, key):
315315
if "text_config" in super().__getattribute__("__dict__") and key not in [
316+
"_name_or_path",
317+
"model_type",
316318
"dtype",
317319
"_attn_implementation_internal",
318320
]:

src/transformers/models/qwen2_vl/configuration_qwen2_vl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ def __setattr__(self, key, value):
301301

302302
def __getattribute__(self, key):
303303
if "text_config" in super().__getattribute__("__dict__") and key not in [
304+
"_name_or_path",
305+
"model_type",
304306
"dtype",
305307
"_attn_implementation_internal",
306308
]:

tests/models/qwen2_5_vl/test_modeling_qwen2_5_vl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ def test_text_config(self):
235235
self.assertEqual(base_config.patch_size, 8)
236236
self.assertNotEqual(base_config.vision_config.patch_size, 8)
237237

238+
# Test for making sure config save and load preserves correct model type
239+
config, _ = self.model_tester.prepare_config_and_inputs_for_common()
240+
241+
self.assertEqual(config.model_type, "qwen2_5_vl")
242+
243+
with tempfile.TemporaryDirectory() as tmp_dir:
244+
config.save_pretrained(tmp_dir)
245+
246+
loaded_config = Qwen2_5_VLConfig.from_pretrained(tmp_dir)
247+
self.assertEqual(loaded_config.model_type, "qwen2_5_vl")
248+
238249
def test_mismatching_num_image_tokens(self):
239250
"""
240251
Tests that VLMs through an error with explicit message saying what is wrong

tests/models/qwen2_vl/test_modeling_qwen2_vl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ def test_text_config(self):
215215
self.assertEqual(base_config.patch_size, 8)
216216
self.assertNotEqual(base_config.vision_config.patch_size, 8)
217217

218+
# Test for making sure config save and load preserves correct model type
219+
config, _ = self.model_tester.prepare_config_and_inputs_for_common()
220+
221+
self.assertEqual(config.model_type, "qwen2_vl")
222+
223+
with tempfile.TemporaryDirectory() as tmp_dir:
224+
config.save_pretrained(tmp_dir)
225+
226+
loaded_config = Qwen2VLConfig.from_pretrained(tmp_dir)
227+
self.assertEqual(loaded_config.model_type, "qwen2_vl")
228+
218229
def test_mismatching_num_image_tokens(self):
219230
"""
220231
Tests that VLMs through an error with explicit message saying what is wrong

0 commit comments

Comments
 (0)