Skip to content

Commit 727b6ce

Browse files
[OV] Fix automatic-speech-recognition-with-past quantization from CLI (#1180)
* Fix automatic-speech-recognition-with-past quantization from CLI * Switch test to fp8 * Add explicit error on the wrong type of config
1 parent 4ef6494 commit 727b6ce

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

optimum/commands/export/openvino.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def run(self):
429429
maybe_convert_tokenizers(library_name, self.args.output, model, task=task)
430430
elif (
431431
quantize_with_dataset
432-
and (task.startswith("text-generation") or task == "automatic-speech-recognition")
432+
and (task.startswith("text-generation") or "automatic-speech-recognition" in task)
433433
or (task == "image-text-to-text" and quantization_config is not None)
434434
):
435435
if task.startswith("text-generation"):

optimum/intel/openvino/quantization.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,11 @@ def _weight_only_quantization(
10031003
if isinstance(config, dict):
10041004
config = OVWeightQuantizationConfig.from_dict(quantization_config)
10051005

1006+
if not isinstance(config, OVWeightQuantizationConfig):
1007+
raise ValueError(
1008+
f"Expected quantization config to be an instance of `OVWeightQuantizationConfig`, but got {type(config)}."
1009+
)
1010+
10061011
dataset = None
10071012
if calibration_dataset is not None:
10081013
if is_datasets_available() and isinstance(calibration_dataset, Dataset):
@@ -1036,6 +1041,11 @@ def _full_quantization(
10361041
verify_not_optimized: bool = True,
10371042
**kwargs,
10381043
):
1044+
if not isinstance(quantization_config, OVQuantizationConfig):
1045+
raise ValueError(
1046+
f"Expected quantization config to be an instance of `OVQuantizationConfig`, but got {type(quantization_config)}."
1047+
)
1048+
10391049
if verify_not_optimized:
10401050
_verify_not_optimized(model)
10411051
q_kwargs = copy.deepcopy(kwargs)

optimum/intel/openvino/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"open_clip_vision": "OVModelOpenCLIPVisual",
135135
"open_clip": "OVModelOpenCLIPForZeroShotImageClassification",
136136
"automatic-speech-recognition": "OVModelForSpeechSeq2Seq",
137+
"automatic-speech-recognition-with-past": "OVModelForSpeechSeq2Seq",
137138
}
138139

139140

tests/openvino/test_exporters_cli.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ class OVCLIExportTestCase(unittest.TestCase):
193193
if is_transformers_version("<=", "4.36.0")
194194
else [{"int8": 14}, {"int8": 22}, {"int8": 18}],
195195
),
196+
(
197+
"automatic-speech-recognition-with-past",
198+
"whisper",
199+
"f8e4m3",
200+
"--dataset librispeech --num-samples 1 --smooth-quant-alpha 0.9 --trust-remote-code",
201+
[14, 22, 21] if is_transformers_version("<=", "4.36.0") else [14, 22, 25],
202+
[{"f8e4m3": 14}, {"f8e4m3": 21}, {"f8e4m3": 17}]
203+
if is_transformers_version("<=", "4.36.0")
204+
else [{"f8e4m3": 14}, {"f8e4m3": 22}, {"f8e4m3": 18}],
205+
),
196206
(
197207
"text-generation",
198208
"llama",
@@ -670,13 +680,14 @@ def test_exporters_cli_full_quantization(
670680
):
671681
with TemporaryDirectory() as tmpdir:
672682
subprocess.run(
673-
f"optimum-cli export openvino --model {MODEL_NAMES[model_type]} --quant-mode {quant_mode} {option} {tmpdir}",
683+
f"optimum-cli export openvino --task {task} --model {MODEL_NAMES[model_type]} "
684+
f"--quant-mode {quant_mode} {option} {tmpdir}",
674685
shell=True,
675686
check=True,
676687
)
677688
model = eval(_HEAD_TO_AUTOMODELS[task]).from_pretrained(tmpdir)
678689

679-
if task == "automatic-speech-recognition":
690+
if "automatic-speech-recognition" in task:
680691
submodels = [model.encoder, model.decoder]
681692
if model.decoder_with_past is not None:
682693
submodels.append(model.decoder_with_past)

0 commit comments

Comments
 (0)