diff --git a/optimum/commands/export/openvino.py b/optimum/commands/export/openvino.py index 2b031bad97..f092d5cb25 100644 --- a/optimum/commands/export/openvino.py +++ b/optimum/commands/export/openvino.py @@ -262,8 +262,9 @@ def run(self): if self.args.weight_format is None: ov_config = None if not no_compression_parameter_provided(self.args): - logger.warning( - "The provided compression parameters will not affect conversion because of the missing --weight-format argument." + raise ValueError( + "Some compression parameters are provided, but the weight format is not specified. " + "Please provide it with --weight-format argument." ) elif self.args.weight_format in {"fp16", "fp32"}: ov_config = OVConfig(dtype=self.args.weight_format) diff --git a/tests/openvino/test_exporters_cli.py b/tests/openvino/test_exporters_cli.py index 9952611e40..91e19ff7a3 100644 --- a/tests/openvino/test_exporters_cli.py +++ b/tests/openvino/test_exporters_cli.py @@ -384,3 +384,20 @@ def test_exporters_cli_open_clip(self): model = eval(_HEAD_TO_AUTOMODELS["open_clip"]).from_pretrained(tmpdir, compile=False) self.assertTrue("text_features" in model.text_model.output_names) self.assertTrue("image_features" in model.visual_model.output_names) + + def test_export_openvino_with_missed_weight_format(self): + # Test that exception is raised when some compression parameter is given, but weight format is not. + with TemporaryDirectory() as tmpdir: + with self.assertRaises(subprocess.CalledProcessError) as exc_info: + subprocess.run( + f"optimum-cli export openvino --model {MODEL_NAMES['gpt2']} --task text-generation --sym {tmpdir}", + shell=True, + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + self.assertIn( + "Some compression parameters are provided, but the weight format is not specified.", + str(exc_info.exception.stderr), + )