Skip to content

Commit ecaa78b

Browse files
committed
update tests and add comments to patcher
1 parent 2b0e599 commit ecaa78b

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

optimum/exporters/openvino/model_configs.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,10 @@ def init_model_configs():
132132
"transformers",
133133
"Qwen2VLForConditionalGeneration",
134134
)
135-
if is_transformers_version(">", "4.48.99"):
136-
TasksManager._CUSTOM_CLASSES[("pt", "qwen2-5-vl", "image-text-to-text")] = (
137-
"transformers",
138-
"Qwen2_5_VLForConditionalGeneration",
139-
)
135+
TasksManager._CUSTOM_CLASSES[("pt", "qwen2-5-vl", "image-text-to-text")] = (
136+
"transformers",
137+
"Qwen2_5_VLForConditionalGeneration",
138+
)
140139
TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS[
141140
"image-text-to-text"
142141
] = TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS["text-generation"]
@@ -2716,6 +2715,8 @@ def outputs(self) -> Dict[str, Dict[int, str]]:
27162715

27172716
@register_in_tasks_manager("qwen2-5-vl", *["image-text-to-text"], library_name="transformers")
27182717
class Qwen2_5_VLOpenVINOConfig(Qwen2VLOpenVINOConfig):
2718+
MIN_TRANSFORMERS_VERSION = version.parse("4.49.0")
2719+
27192720
@property
27202721
def inputs(self) -> Dict[str, Dict[int, str]]:
27212722
if self._behavior == Qwen2VLConfigBehavior.VISION_EMBEDDINGS_MERGER:

optimum/exporters/openvino/model_patcher.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3956,7 +3956,8 @@ def block_forward(self, hidden_states, attention_mask, rotary_pos_emb) -> torch.
39563956
return hidden_states
39573957

39583958
else:
3959-
3959+
# Modified from https://github.com/huggingface/transformers/blob/v4.49.0/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L391
3960+
# added attention_mask input instead of internal calculation (unsupported by tracing due to cycle with dynamic len)
39603961
def sdpa_attn_forward(
39613962
self,
39623963
hidden_states: torch.Tensor,
@@ -4001,6 +4002,8 @@ def apply_rotary_pos_emb_vision(
40014002
attn_output = self.proj(attn_output)
40024003
return attn_output
40034004

4005+
# Modified from https://github.com/huggingface/transformers/blob/v4.49.0/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L446
4006+
# added attention_mask input propagation to self.attn
40044007
def block_forward(
40054008
self,
40064009
hidden_states,
@@ -4069,8 +4072,9 @@ def __init__(
40694072

40704073
model.__orig_forward = model.forward
40714074

4072-
# Modified from https://github.com/huggingface/transformers/blob/v4.45.2/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L1118
4073-
# added attention_mask input instead cu_lens for its internal calculation model (unsupported by tracing due to cycle with dynamic len)
4075+
# Modified from https://github.com/huggingface/transformers/blob/v4.49.0/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py#L405
4076+
# added attention_mask and window_attention_mask inputs instead cu_lens and window_cu_lens processing for its internal calculation model
4077+
# (unsupported by tracing due to cycle with dynamic len)
40744078
# separated patch_embed and rot_pos_emb calls for performing as part of another model
40754079
def image_embed_forward(
40764080
self,

tests/openvino/test_modeling.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ class OVModelForVisualCausalLMIntegrationTest(unittest.TestCase):
21342134

21352135
if is_transformers_version(">=", "4.46.0"):
21362136
SUPPORTED_ARCHITECTURES += ["maira2"]
2137-
2137+
21382138
if is_transformers_version(">=", "4.49.0"):
21392139
SUPPORTED_ARCHITECTURES += ["qwen2_5_vl"]
21402140
TASK = "image-text-to-text"
@@ -2160,7 +2160,7 @@ def get_transformer_model_class(self, model_arch):
21602160
from transformers import Qwen2VLForConditionalGeneration
21612161

21622162
return Qwen2VLForConditionalGeneration
2163-
if model_arch == "qwen_25_vl":
2163+
if model_arch == "qwen2_5_vl":
21642164
from transformers import Qwen2_5_VLForConditionalGeneration
21652165

21662166
return Qwen2_5_VLForConditionalGeneration

0 commit comments

Comments
 (0)