Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OV] Raise exception when some compression parameter is given, but weight format is not #996

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions optimum/commands/export/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/openvino/test_exporters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Loading