Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Dec 4, 2024
1 parent 973f155 commit 612475c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
6 changes: 3 additions & 3 deletions optimum/exporters/openvino/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def init_model_configs():
"transformers",
"Qwen2VLForConditionalGeneration",
)
TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS[
"image-text-to-text"
] = TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS["text-generation"]
TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS["image-text-to-text"] = (
TasksManager._TRANSFORMERS_TASKS_TO_MODEL_LOADERS["text-generation"]
)

supported_model_types = [
"_SUPPORTED_MODEL_TYPE",
Expand Down
12 changes: 6 additions & 6 deletions optimum/exporters/openvino/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ def _llama_gemma_update_causal_mask_legacy(self, attention_mask, input_tensor, c
offset = 0
mask_shape = attention_mask.shape
mask_slice = (attention_mask.eq(0.0)).to(dtype=dtype) * min_dtype
causal_mask[
: mask_shape[0], : mask_shape[1], offset : mask_shape[2] + offset, : mask_shape[3]
] = mask_slice
causal_mask[: mask_shape[0], : mask_shape[1], offset : mask_shape[2] + offset, : mask_shape[3]] = (
mask_slice
)

if (
self.config._attn_implementation == "sdpa"
Expand Down Expand Up @@ -2060,9 +2060,9 @@ def _dbrx_update_causal_mask_legacy(
offset = 0
mask_shape = attention_mask.shape
mask_slice = (attention_mask.eq(0.0)).to(dtype=dtype) * min_dtype
causal_mask[
: mask_shape[0], : mask_shape[1], offset : mask_shape[2] + offset, : mask_shape[3]
] = mask_slice
causal_mask[: mask_shape[0], : mask_shape[1], offset : mask_shape[2] + offset, : mask_shape[3]] = (
mask_slice
)

if (
self.config._attn_implementation == "sdpa"
Expand Down
12 changes: 6 additions & 6 deletions optimum/intel/openvino/modeling_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def __init__(
for idx, key in enumerate(model.inputs):
names = tuple(key.get_names())
input_names[next((name for name in names if "/" not in name), names[0])] = idx
input_dtypes[
next((name for name in names if "/" not in name), names[0])
] = key.get_element_type().get_type_name()
input_dtypes[next((name for name in names if "/" not in name), names[0])] = (
key.get_element_type().get_type_name()
)
self.input_names = input_names
self.input_dtypes = input_dtypes

Expand All @@ -122,9 +122,9 @@ def __init__(
for idx, key in enumerate(model.outputs):
names = tuple(key.get_names())
output_names[next((name for name in names if "/" not in name), names[0])] = idx
output_dtypes[
next((name for name in names if "/" not in name), names[0])
] = key.get_element_type().get_type_name()
output_dtypes[next((name for name in names if "/" not in name), names[0])] = (
key.get_element_type().get_type_name()
)

self.output_names = output_names
self.output_dtypes = output_dtypes
Expand Down
4 changes: 4 additions & 0 deletions optimum/intel/openvino/modeling_visual_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def prepare_inputs(
if past_len:
position_ids = position_ids[:, -inputs_embeds.shape[1] :]

if self.config.model_type == "qwen2_vl" and position_ids.ndim != 3:
position_ids = np.expand_dims(position_ids, 0)
position_ids = np.concatenate([position_ids, position_ids, position_ids], axis=0)

inputs["position_ids"] = position_ids

if "beam_idx" in self.input_names:
Expand Down
6 changes: 5 additions & 1 deletion tests/openvino/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ class OVModelForVisualCausalLMIntegrationTest(unittest.TestCase):
if is_transformers_version(">=", "4.40.0"):
SUPPORTED_ARCHITECTURES += ["llava_next", "nanollava"]
if is_transformers_version(">=", "4.45.0"):
SUPPORTED_ARCHITECTURES += ["minicpmv", "internvl2", "phi3_v"]
SUPPORTED_ARCHITECTURES += ["minicpmv", "internvl2", "phi3_v", "qwen2_vl"]
TASK = "image-text-to-text"
REMOTE_CODE_MODELS = ["internvl2", "minicpmv", "nanollava", "phi3_v"]

Expand All @@ -1996,6 +1996,10 @@ def get_transformer_model_class(self, model_arch):
from transformers import LlavaNextForConditionalGeneration

return LlavaNextForConditionalGeneration
if model_arch == "qwen2_vl":
from transformers import Qwen2VLForConditionalGeneration

return Qwen2VLForConditionalGeneration
return AutoModelForCausalLM

def _check_device_and_request(self, ov_model, expected_device, has_request):
Expand Down
1 change: 1 addition & 0 deletions tests/openvino/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"qwen": "katuni4ka/tiny-random-qwen",
"qwen2": "fxmarty/tiny-dummy-qwen2",
"qwen2-moe": "katuni4ka/tiny-random-qwen1.5-moe",
"qwen2_vl": "katuni4ka/tiny-random-qwen2vl",
"resnet": "hf-internal-testing/tiny-random-resnet",
"roberta": "hf-internal-testing/tiny-random-roberta",
"roformer": "hf-internal-testing/tiny-random-roformer",
Expand Down

0 comments on commit 612475c

Please sign in to comment.