Skip to content

Commit 0b26a02

Browse files
authored
[Inference] Support qwen2_5_vl (#9924)
* support qwen2_5_vl * update support qwen2_vl & qwen2_5_vl & support multi models mapping
1 parent 0c65ce7 commit 0b26a02

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

paddlenlp/experimental/transformers/qwen2/modeling.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,4 +1554,17 @@ class Qwen2VLForConditionalGenerationBlockInferenceModel(Qwen2ForCausalLMBlockIn
15541554

15551555
# NOTE: (changwenbin) This function corresponds to QWen2-VL's second part, only used for QWen2-VL.
15561556
def __init__(self, config: Qwen2Config):
1557-
super().__init__(config, base_model_prefix="model")
1557+
super().__init__(config)
1558+
self.qwen2.base_model_prefix = "model"
1559+
1560+
1561+
class Qwen2_5_VLForConditionalGenerationBlockInferenceModel(Qwen2ForCausalLMBlockInferenceModel):
1562+
"""
1563+
NOTE: (changwenbin) This class inherits from Qwen2ForCausalLMBlockInferenceModel.
1564+
Used only for QWen2-5-VL's second part.
1565+
"""
1566+
1567+
# NOTE: (changwenbin) This function corresponds to QWen2-5-VL's second part, only used for QWen2-5-VL.
1568+
def __init__(self, config: Qwen2Config):
1569+
super().__init__(config)
1570+
self.qwen2.base_model_prefix = "model"

paddlenlp/transformers/auto/configuration.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@
213213
]
214214
)
215215

216+
MULTI_MODELS_MAPPING = OrderedDict(
217+
# multi models mapping
218+
[
219+
("qwen2_vl", "qwen2"),
220+
("qwen2_5_vl", "qwen2"),
221+
]
222+
)
223+
216224

217225
def config_class_to_model_type(config):
218226
"""Converts a config class name to the corresponding model type"""
@@ -238,8 +246,9 @@ def __init__(self, mapping):
238246

239247
def __getitem__(self, key):
240248
# NOTE: (changwenbin) This is to enable the qwen2_vl language model to use qwen2 reasoning optimization
241-
if key == "qwen2_vl":
242-
key = "qwen2"
249+
for model_type, model_key in MULTI_MODELS_MAPPING.items():
250+
if key == model_type:
251+
key = model_key
243252
if key in self._extra_content:
244253
return self._extra_content[key]
245254
if key not in self._mapping:

0 commit comments

Comments
 (0)