From 9c94e92f4316f8c0ca985914c92e74a5c89c529b Mon Sep 17 00:00:00 2001 From: eaidova Date: Wed, 15 May 2024 13:16:48 +0400 Subject: [PATCH 1/4] cover more models with openvino export --- optimum/exporters/openvino/model_configs.py | 47 +++++++++++++++++++++ tests/openvino/test_modeling.py | 4 ++ tests/openvino/utils_tests.py | 4 ++ 3 files changed, 55 insertions(+) diff --git a/optimum/exporters/openvino/model_configs.py b/optimum/exporters/openvino/model_configs.py index 575f1cc4db..2afc3848ad 100644 --- a/optimum/exporters/openvino/model_configs.py +++ b/optimum/exporters/openvino/model_configs.py @@ -592,3 +592,50 @@ def outputs(self) -> Dict[str, Dict[int, str]]: return { "sample": {0: "batch_size", 2: "height", 3: "width"}, } + + +@register_in_tasks_manager( + "persimmon", + *[ + "feature-extraction", + "feature-extraction-with-past", + "text-generation", + "text-generation-with-past", + "text-classification", + ], + library_name="transformers", +) +class PersimmonOpenVINOConfig(TextDecoderWithPositionIdsOnnxConfig): + DEFAULT_ONNX_OPSET = 14 + NORMALIZED_CONFIG_CLASS = NormalizedTextConfig + + +@register_in_tasks_manager("biogpt", *["text-generation", "text-generation-with-past"], library_name="transformers") +class BioGPTOpenVINOConfig(TextDecoderOnnxConfig): + # BioGPT does not require position_ids input. + DEFAULT_ONNX_OPSET = 13 + NORMALIZED_CONFIG_CLASS = NormalizedTextConfig + + +@register_in_tasks_manager( + "gpt-neox-japanese", *["text-generation", "text-generation-with-past"], library_name="transformers" +) +class GPTNeoxJapaneseOpenVINOConfig(TextDecoderOnnxConfig): + # GPTNeoxJapanese does not require position_ids input. + DEFAULT_ONNX_OPSET = 13 + NORMALIZED_CONFIG_CLASS = NormalizedTextConfig + + +@register_in_tasks_manager( + "cohere", + *[ + "feature-extraction", + "feature-extraction-with-past", + "text-generation", + "text-generation-with-past", + "text-classification", + ], + library_name="transformers", +) +class CohereOpenVINOConfig(LlamaOpenVINOConfig): + pass diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index d4f55c683b..e0dd917a26 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -552,6 +552,10 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): "orion", "falcon", "falcon-40b", + "persimmon", + "biogpt", + "gpt_neox_japanese", + "cohere", ) GENERATION_LENGTH = 100 REMOTE_CODE_MODELS = ( diff --git a/tests/openvino/utils_tests.py b/tests/openvino/utils_tests.py index 9f28e40a4b..b65b0c447e 100644 --- a/tests/openvino/utils_tests.py +++ b/tests/openvino/utils_tests.py @@ -26,11 +26,13 @@ "baichuan2": "katuni4ka/tiny-random-baichuan2", "baichuan2-13b": "katuni4ka/tiny-random-baichuan2-13b", "bigbird_pegasus": "hf-internal-testing/tiny-random-bigbird_pegasus", + "biogpt": "hf-tiny-model-private/tiny-random-BioGptForCausalLM", "blenderbot-small": "hf-internal-testing/tiny-random-BlenderbotModel", "blenderbot": "hf-internal-testing/tiny-random-BlenderbotModel", "bloom": "hf-internal-testing/tiny-random-BloomModel", "camembert": "hf-internal-testing/tiny-random-camembert", "convbert": "hf-internal-testing/tiny-random-ConvBertForSequenceClassification", + "cohere": "hf-internal-testing/tiny-random-CohereForCausalLM", "chatglm": "katuni4ka/tiny-random-chatglm2", "codegen": "hf-internal-testing/tiny-random-CodeGenForCausalLM", "data2vec_text": "hf-internal-testing/tiny-random-Data2VecTextModel", @@ -51,6 +53,7 @@ "gpt2": "hf-internal-testing/tiny-random-gpt2", "gpt_neo": "hf-internal-testing/tiny-random-GPTNeoModel", "gpt_neox": "hf-internal-testing/tiny-random-GPTNeoXForCausalLM", + "gpt_neox_japanese": "hf-internal-testing/tiny-random-GPTNeoXJapaneseForCausalLM", "gptj": "hf-internal-testing/tiny-random-GPTJModel", "hubert": "hf-internal-testing/tiny-random-HubertModel", "ibert": "hf-internal-testing/tiny-random-ibert", @@ -78,6 +81,7 @@ "olmo": "katuni4ka/tiny-random-olmo-hf", "orion": "katuni4ka/tiny-random-orion", "pegasus": "hf-internal-testing/tiny-random-pegasus", + "persimmon": "hf-internal-testing/tiny-random-PersimmonForCausalLM", "pix2struct": "fxmarty/pix2struct-tiny-random", "phi": "echarlaix/tiny-random-PhiForCausalLM", "phi3": "katuni4ka/tiny-random-phi3", From 8e4464683e798b72b35b00c342fcd315a18b8d12 Mon Sep 17 00:00:00 2001 From: eaidova Date: Wed, 15 May 2024 13:59:58 +0400 Subject: [PATCH 2/4] xglm --- optimum/exporters/openvino/model_configs.py | 10 ++++++++++ tests/openvino/test_modeling.py | 1 + tests/openvino/utils_tests.py | 1 + 3 files changed, 12 insertions(+) diff --git a/optimum/exporters/openvino/model_configs.py b/optimum/exporters/openvino/model_configs.py index 2afc3848ad..8f64641cde 100644 --- a/optimum/exporters/openvino/model_configs.py +++ b/optimum/exporters/openvino/model_configs.py @@ -639,3 +639,13 @@ class GPTNeoxJapaneseOpenVINOConfig(TextDecoderOnnxConfig): ) class CohereOpenVINOConfig(LlamaOpenVINOConfig): pass + + +@register_in_tasks_manager( + "xglm", + *["text-generation", "text-generation-with-past"], + library_name="transformers" +) +class XGLMConfig(TextDecoderWithPositionIdsOnnxConfig): + DEFAULT_ONNX_OPSET = 13 + NORMALIZED_CONFIG_CLASS = NormalizedTextConfig.with_args(num_attention_heads="attention_heads", hidden_size="d_model") \ No newline at end of file diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index e0dd917a26..4cff9b9f33 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -556,6 +556,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): "biogpt", "gpt_neox_japanese", "cohere", + "xglm" ) GENERATION_LENGTH = 100 REMOTE_CODE_MODELS = ( diff --git a/tests/openvino/utils_tests.py b/tests/openvino/utils_tests.py index b65b0c447e..9eec192b32 100644 --- a/tests/openvino/utils_tests.py +++ b/tests/openvino/utils_tests.py @@ -119,6 +119,7 @@ "whisper": "openai/whisper-tiny.en", "xlm": "hf-internal-testing/tiny-random-xlm", "xlm_roberta": "hf-internal-testing/tiny-xlm-roberta", + "xglm": "hf-internal-testing/tiny-random-XGLMForCausalLM" } From bf2e2d6c0dee636fcfb5f24dcc51c96246e03484 Mon Sep 17 00:00:00 2001 From: eaidova Date: Wed, 15 May 2024 17:18:53 +0400 Subject: [PATCH 3/4] fix tests --- optimum/exporters/openvino/model_configs.py | 10 ++++------ tests/openvino/test_modeling.py | 7 +++++-- tests/openvino/utils_tests.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/optimum/exporters/openvino/model_configs.py b/optimum/exporters/openvino/model_configs.py index 8f64641cde..47ca4ff241 100644 --- a/optimum/exporters/openvino/model_configs.py +++ b/optimum/exporters/openvino/model_configs.py @@ -641,11 +641,9 @@ class CohereOpenVINOConfig(LlamaOpenVINOConfig): pass -@register_in_tasks_manager( - "xglm", - *["text-generation", "text-generation-with-past"], - library_name="transformers" -) +@register_in_tasks_manager("xglm", *["text-generation", "text-generation-with-past"], library_name="transformers") class XGLMConfig(TextDecoderWithPositionIdsOnnxConfig): DEFAULT_ONNX_OPSET = 13 - NORMALIZED_CONFIG_CLASS = NormalizedTextConfig.with_args(num_attention_heads="attention_heads", hidden_size="d_model") \ No newline at end of file + NORMALIZED_CONFIG_CLASS = NormalizedTextConfig.with_args( + num_attention_heads="attention_heads", hidden_size="d_model" + ) diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index 4cff9b9f33..ac6b550351 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -556,7 +556,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase): "biogpt", "gpt_neox_japanese", "cohere", - "xglm" + "xglm", ) GENERATION_LENGTH = 100 REMOTE_CODE_MODELS = ( @@ -622,8 +622,11 @@ def test_compare_to_transformers(self, model_arch): if model_arch == "qwen": return - if model_arch != "chatglm": + if not model_arch in ["chatglm", "persimmon"]: tokenizer.pad_token_id = tokenizer.eos_token_id + + if model_arch == "persimmon": + tokenizer.pad_token_id = tokenizer.bos_token_id # Compare batched generation tokenizer.padding_side = "left" tokens = tokenizer(["Today is a nice day and I am longer", "This is me"], return_tensors="pt", padding=True) diff --git a/tests/openvino/utils_tests.py b/tests/openvino/utils_tests.py index 9eec192b32..aa3ea5f33a 100644 --- a/tests/openvino/utils_tests.py +++ b/tests/openvino/utils_tests.py @@ -119,7 +119,7 @@ "whisper": "openai/whisper-tiny.en", "xlm": "hf-internal-testing/tiny-random-xlm", "xlm_roberta": "hf-internal-testing/tiny-xlm-roberta", - "xglm": "hf-internal-testing/tiny-random-XGLMForCausalLM" + "xglm": "hf-internal-testing/tiny-random-XGLMForCausalLM", } From a661d4f3801e121505332436c8288ebea7d8caec Mon Sep 17 00:00:00 2001 From: Ella Charlaix <80481427+echarlaix@users.noreply.github.com> Date: Wed, 15 May 2024 16:18:51 +0200 Subject: [PATCH 4/4] Update tests/openvino/test_modeling.py --- tests/openvino/test_modeling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/openvino/test_modeling.py b/tests/openvino/test_modeling.py index ac6b550351..272914ee63 100644 --- a/tests/openvino/test_modeling.py +++ b/tests/openvino/test_modeling.py @@ -622,7 +622,7 @@ def test_compare_to_transformers(self, model_arch): if model_arch == "qwen": return - if not model_arch in ["chatglm", "persimmon"]: + if model_arch not in ["chatglm", "persimmon"]: tokenizer.pad_token_id = tokenizer.eos_token_id if model_arch == "persimmon":