Skip to content

Commit 12783ee

Browse files
Raise exception when some compression parameter is given, but weight format is not. (#996)
1 parent 790244d commit 12783ee

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

optimum/commands/export/openvino.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ def run(self):
262262
if self.args.weight_format is None:
263263
ov_config = None
264264
if not no_compression_parameter_provided(self.args):
265-
logger.warning(
266-
"The provided compression parameters will not affect conversion because of the missing --weight-format argument."
265+
raise ValueError(
266+
"Some compression parameters are provided, but the weight format is not specified. "
267+
"Please provide it with --weight-format argument."
267268
)
268269
elif self.args.weight_format in {"fp16", "fp32"}:
269270
ov_config = OVConfig(dtype=self.args.weight_format)

tests/openvino/test_exporters_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,20 @@ def test_exporters_cli_open_clip(self):
384384
model = eval(_HEAD_TO_AUTOMODELS["open_clip"]).from_pretrained(tmpdir, compile=False)
385385
self.assertTrue("text_features" in model.text_model.output_names)
386386
self.assertTrue("image_features" in model.visual_model.output_names)
387+
388+
def test_export_openvino_with_missed_weight_format(self):
389+
# Test that exception is raised when some compression parameter is given, but weight format is not.
390+
with TemporaryDirectory() as tmpdir:
391+
with self.assertRaises(subprocess.CalledProcessError) as exc_info:
392+
subprocess.run(
393+
f"optimum-cli export openvino --model {MODEL_NAMES['gpt2']} --task text-generation --sym {tmpdir}",
394+
shell=True,
395+
check=True,
396+
stdout=subprocess.PIPE,
397+
stderr=subprocess.PIPE,
398+
text=True,
399+
)
400+
self.assertIn(
401+
"Some compression parameters are provided, but the weight format is not specified.",
402+
str(exc_info.exception.stderr),
403+
)

0 commit comments

Comments
 (0)