Skip to content

Commit

Permalink
support whisper onnx audio-classification
Browse files Browse the repository at this point in the history
  • Loading branch information
fxmarty committed Feb 27, 2024
1 parent c7cc312 commit 6e4f116
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions optimum/exporters/onnx/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,9 +1342,15 @@ class WhisperOnnxConfig(AudioToTextOnnxConfig):

@property
def inputs(self) -> Dict[str, Dict[int, str]]:
common_inputs = super().inputs
if self._behavior is ConfigBehavior.DECODER and self.use_past_in_inputs is False:
common_inputs["encoder_outputs"][1] = f"{common_inputs['encoder_outputs'][1]} / 2"
if self.task == "audio-classification":
common_inputs = {"input_features": {0: "batch_size"}}
else:
common_inputs = super().inputs
if self._behavior is not ConfigBehavior.DECODER:
common_inputs["input_features"] = {0: "batch_size"} # Remove unnecessary dynamic axis.

if self._behavior is ConfigBehavior.DECODER and self.use_past_in_inputs is False:
common_inputs["encoder_outputs"][1] = f"{common_inputs['encoder_outputs'][1]} / 2"
return common_inputs

@property
Expand Down
1 change: 1 addition & 0 deletions optimum/exporters/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ class TasksManager:
"whisper": supported_tasks_mapping(
"feature-extraction",
"feature-extraction-with-past",
"audio-classification",
"automatic-speech-recognition",
"automatic-speech-recognition-with-past",
onnx="WhisperOnnxConfig",
Expand Down
1 change: 1 addition & 0 deletions tests/onnxruntime/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,7 @@ class ORTModelForAudioClassificationIntegrationTest(ORTModelTestMixin):
"wavlm",
"wav2vec2",
"wav2vec2-conformer",
"whisper",
]

FULL_GRID = {"model_arch": SUPPORTED_ARCHITECTURES}
Expand Down

0 comments on commit 6e4f116

Please sign in to comment.