From 123e1c4173166b429dbdd82fe14c3dcb373fe829 Mon Sep 17 00:00:00 2001 From: Ekaterina Shiryaeva Date: Wed, 15 Jan 2025 21:37:47 +0000 Subject: [PATCH] Correct path with stateless models --- .../test_whisper_pipeline_static.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/python_tests/test_whisper_pipeline_static.py b/tests/python_tests/test_whisper_pipeline_static.py index 511b178b8a..75bd5e1d86 100644 --- a/tests/python_tests/test_whisper_pipeline_static.py +++ b/tests/python_tests/test_whisper_pipeline_static.py @@ -8,6 +8,7 @@ import openvino_tokenizers import openvino import pytest +import pathlib # This test suite is designed specifically to validate the functionality # and robustness of the WhisperStaticPipeline on NPUW:CPU. @@ -15,10 +16,12 @@ "NPUW_DEVICES" : "CPU", "NPUW_ONLINE_PIPELINE" : "NONE"} -def load_and_save_whisper_model(params, **tokenizer_kwargs): +def load_and_save_whisper_model(params, stateful=False, **tokenizer_kwargs): model_id, path = params processor = WhisperProcessor.from_pretrained(model_id, trust_remote_code=True) + if not stateful: + path = pathlib.Path(f"{path}_with_past") if not (path / "openvino_encoder_model.xml").exists(): tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) @@ -39,15 +42,17 @@ def load_and_save_whisper_model(params, **tokenizer_kwargs): model_id, export=True, trust_remote_code=True, + stateful=stateful, compile=False, device="CPU", load_in_8bit=False, - stateful=False, ) opt_model.generation_config.save_pretrained(path) opt_model.config.save_pretrained(path) opt_model.save_pretrained(path) processor.save_pretrained(path) + + return model_id, path def get_results_cpu_npu(model_path, audio_sample, **config_kwargs): cpu_pipe = ov_genai.WhisperPipeline(model_path, "CPU") @@ -72,8 +77,7 @@ def compare_results_with_assert(expected, actual_out): @pytest.mark.parametrize("test_sample", get_samples_from_dataset(language="en", length=1)) @pytest.mark.precommit def test_static_whisper_generation_compare_with_cpu(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample) @@ -89,8 +93,7 @@ def test_static_whisper_generation_compare_with_cpu(model_descr, test_sample): ],) @pytest.mark.precommit def test_static_whisper_autodetect(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample) @@ -103,8 +106,7 @@ def test_static_whisper_autodetect(model_descr, test_sample): ) @pytest.mark.precommit def test_static_whisper_language_de(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample, max_new_tokens=30, language="<|de|>") @@ -117,8 +119,7 @@ def test_static_whisper_language_de(model_descr, test_sample): ) @pytest.mark.precommit def test_static_whisper_language_fr(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample, max_new_tokens=30, language="<|fr|>") @@ -131,8 +132,7 @@ def test_static_whisper_language_fr(model_descr, test_sample): ) @pytest.mark.precommit def test_static_whisper_language_ru(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample, max_new_tokens=30, language="<|ru|>") @@ -143,8 +143,7 @@ def test_static_whisper_language_ru(model_descr, test_sample): @pytest.mark.parametrize("test_sample", get_samples_from_dataset(language="en", length=1, long_form=True)) @pytest.mark.precommit def test_static_whisper_generation_long(model_descr, test_sample): - model_id, model_path = model_descr - load_and_save_whisper_model(model_descr) + model_id, model_path = load_and_save_whisper_model(model_descr) expected, actual_out = get_results_cpu_npu(model_path, test_sample)