Skip to content

Commit be9e995

Browse files
committed
add tests
1 parent 0f6e903 commit be9e995

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

docs/source/openvino/models.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Here is the list of the supported architectures :
6262
- GPT-NeoX-Japanese
6363
- Gemma
6464
- Gemma2
65+
- GOT-OCR 2.0
6566
- Granite
6667
- GraniteMoE
6768
- Hubert

optimum/exporters/openvino/model_configs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3004,7 +3004,7 @@ def patch_model_for_export(
30043004
return DeepseekPatcher(self, model, model_kwargs=model_kwargs)
30053005

30063006

3007-
@register_in_tasks_manager("got-ocr2", *["image-text-to-text"], library_name="transformers")
3007+
@register_in_tasks_manager("got-ocr2", *["image-to-text", "image-text-to-text"], library_name="transformers")
30083008
class GotOCR2OpenVINOConfig(LlavaOpenVINOConfig):
30093009
MIN_TRANSFORMERS_VERSION = "4.49.0"
30103010

tests/openvino/test_modeling.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ class OVModelForVisualCausalLMIntegrationTest(unittest.TestCase):
21412141
SUPPORTED_ARCHITECTURES += ["maira2"]
21422142

21432143
if is_transformers_version(">=", "4.49.0"):
2144-
SUPPORTED_ARCHITECTURES += ["qwen2_5_vl"]
2144+
SUPPORTED_ARCHITECTURES += ["qwen2_5_vl", "got_ocr2"]
21452145
SUPPORT_VIDEO.append("qwen2_5_vl")
21462146
TASK = "image-text-to-text"
21472147
REMOTE_CODE_MODELS = ["internvl2", "minicpmv", "nanollava", "phi3_v", "maira2"]
@@ -2154,7 +2154,13 @@ class OVModelForVisualCausalLMIntegrationTest(unittest.TestCase):
21542154
)
21552155

21562156
def get_transformer_model_class(self, model_arch):
2157-
if is_transformers_version(">=", "4.46") and model_arch in ["llava", "llava_next", "qwen2_vl", "qwen2_5_vl"]:
2157+
if is_transformers_version(">=", "4.46") and model_arch in [
2158+
"llava",
2159+
"llava_next",
2160+
"qwen2_vl",
2161+
"qwen2_5_vl",
2162+
"got_ocr2",
2163+
]:
21582164
from transformers import AutoModelForImageTextToText
21592165

21602166
return AutoModelForImageTextToText
@@ -2339,14 +2345,16 @@ def test_generate_utils(self, model_arch):
23392345
outputs = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1] :], skip_special_tokens=True)
23402346
self.assertIsInstance(outputs[0], str)
23412347

2342-
# No input image case
2343-
question = "Hi, how are you?"
2344-
inputs = model.preprocess_inputs(**preprocessors, text=question, image=None)
2345-
outputs = model.generate(**inputs, max_new_tokens=10)
2346-
# filter out original prompt becuase it may contains out of tokenizer tokens e.g. in nanollva text separator = -200
2347-
outputs = outputs[:, inputs["input_ids"].shape[1] :]
2348-
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)
2349-
self.assertIsInstance(outputs[0], str)
2348+
# GOT-OCR2 does not support text-only input
2349+
if model_arch != "got_ocr2":
2350+
# No input image case
2351+
question = "Hi, how are you?"
2352+
inputs = model.preprocess_inputs(**preprocessors, text=question, image=None)
2353+
outputs = model.generate(**inputs, max_new_tokens=10)
2354+
# filter out original prompt becuase it may contains out of tokenizer tokens e.g. in nanollva text separator = -200
2355+
outputs = outputs[:, inputs["input_ids"].shape[1] :]
2356+
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)
2357+
self.assertIsInstance(outputs[0], str)
23502358

23512359
# video loader helper only available for transformers >= 4.49
23522360
if model_arch in self.SUPPORT_VIDEO and is_transformers_version(">=", "4.49"):

tests/openvino/utils_tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"exaone": "katuni4ka/tiny-random-exaone",
6464
"gemma": "fxmarty/tiny-random-GemmaForCausalLM",
6565
"gemma2": "katuni4ka/tiny-random-gemma2",
66+
"got_ocr2": "katuni4ka/tiny-random-got-ocr2-hf",
6667
"falcon": "fxmarty/really-tiny-falcon-testing",
6768
"falcon-40b": "katuni4ka/tiny-random-falcon-40b",
6869
"flaubert": "hf-internal-testing/tiny-random-flaubert",

0 commit comments

Comments
 (0)