Skip to content

Commit c455ad2

Browse files
authored
Export whisper distil-large-v3 and distil-large-v3.5 to sherpa-onnx (k2-fsa#2506)
This PR adds support for exporting two new whisper distil models (distil-large-v3 and distil-large-v3.5) to ONNX format for use with sherpa-onnx. The changes enable these models to be processed through the existing export pipeline. - Added support for distil-large-v3 and distil-large-v3.5 models in the export script - Updated GitHub workflow to include the new models in the CI matrix - Configured proper n_mels parameter (128) for the new distil models
1 parent 896afa7 commit c455ad2

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

.github/workflows/export-whisper-to-onnx.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [macos-latest]
19-
model: ["turbo", "distil-medium.en", "distil-small.en", "tiny.en", "base.en", "small.en", "medium.en", "tiny", "base", "small", "medium", "medium-aishell", "large", "large-v1", "large-v2", "large-v3", "distil-large-v2"]
19+
model: ["turbo", "distil-medium.en", "distil-small.en", "tiny.en", "base.en", "small.en", "medium.en", "tiny", "base", "small", "medium", "medium-aishell", "large", "large-v1", "large-v2", "large-v3", "distil-large-v2", "distil-large-v3", "distil-large-v3.5"]
2020
# model: ["large", "large-v1", "large-v2", "large-v3", "distil-large-v2"]
21+
# model: ["distil-large-v3.5", "distil-large-v3"]
2122
python-version: ["3.8"]
2223

2324
steps:
@@ -47,6 +48,12 @@ jobs:
4748
elif [[ $model == distil-large-v2 ]]; then
4849
wget -q -O distil-large-v2-original-model.bin https://huggingface.co/distil-whisper/distil-large-v2/resolve/main/original-model.bin
4950
ls -lh
51+
elif [[ $model == distil-large-v3 ]]; then
52+
wget -q -O distil-large-v3-original-model.bin https://huggingface.co/distil-whisper/distil-large-v3-openai/resolve/main/model.bin
53+
ls -lh
54+
elif [[ $model == distil-large-v3.5 ]]; then
55+
wget -q -O distil-large-v3.5-original-model.bin https://huggingface.co/distil-whisper/distil-large-v3.5-openai/resolve/main/model.bin
56+
ls -lh
5057
elif [[ $model == distil-small.en ]]; then
5158
wget -q -O distil-small-en-original-model.bin https://huggingface.co/distil-whisper/distil-small.en/resolve/main/original-model.bin
5259
ls -lh
@@ -155,6 +162,7 @@ jobs:
155162
156163
git status
157164
ls -lh
165+
git lfs track "*.wav*"
158166
git lfs track "*onnx*"
159167
git lfs track "*weights*"
160168

scripts/whisper/export-onnx.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def get_args():
4949
"large-v1", "large-v2",
5050
"large", "large-v3", "turbo", # these three have feature dim 128
5151
"distil-medium.en", "distil-small.en", "distil-large-v2",
52-
# "distil-large-v3", # distil-large-v3 is not supported!
52+
"distil-large-v3",
53+
"distil-large-v3.5",
5354
# for fine-tuned models from icefall
5455
"medium-aishell",
5556
],
@@ -348,6 +349,32 @@ def main():
348349
"""
349350
)
350351
model = whisper.load_model(filename)
352+
elif name == "distil-large-v3":
353+
filename = "./distil-large-v3-original-model.bin"
354+
if not Path(filename).is_file():
355+
raise ValueError(
356+
"""
357+
Please go to https://huggingface.co/distil-whisper/distil-large-v3-openai
358+
to download model.bin
359+
You can use the following command to do that:
360+
361+
wget -O distil-large-v3-original-model.bin https://huggingface.co/distil-whisper/distil-large-v3-openai/resolve/main/model.bin
362+
"""
363+
)
364+
model = whisper.load_model(filename)
365+
elif name == "distil-large-v3.5":
366+
filename = "./distil-large-v3.5-original-model.bin"
367+
if not Path(filename).is_file():
368+
raise ValueError(
369+
"""
370+
Please go to https://huggingface.co/distil-whisper/distil-large-v3.5-openai/
371+
to download model.bin
372+
You can use the following command to do that:
373+
374+
wget -O distil-large-v3.5-original-model.bin https://huggingface.co/distil-whisper/distil-large-v3.5-openai/resolve/main/model.bin
375+
"""
376+
)
377+
model = whisper.load_model(filename)
351378
elif name == "distil-small.en":
352379
filename = "./distil-small-en-original-model.bin"
353380
if not Path(filename).is_file():
@@ -405,10 +432,17 @@ def main():
405432
audio = whisper.pad_or_trim(audio)
406433
assert audio.shape == (16000 * 30,), audio.shape
407434

408-
if args.model in ("large", "large-v3", "turbo"):
435+
if args.model in ("distil-large-v3", "distil-large-v3.5"):
436+
n_mels = 128
437+
elif args.model in (
438+
"large",
439+
"large-v3",
440+
"turbo",
441+
):
409442
n_mels = 128
410443
else:
411444
n_mels = 80
445+
412446
mel = (
413447
whisper.log_mel_spectrogram(audio, n_mels=n_mels).to(model.device).unsqueeze(0)
414448
)

0 commit comments

Comments
 (0)