-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export whisper models to torchscript. (#693)
- Loading branch information
1 parent
e5b91cd
commit 2ffe462
Showing
10 changed files
with
1,254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
name: export-whisper | ||
|
||
on: | ||
push: | ||
branches: | ||
- export-whisper | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: export-whisper-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
export-whisper: | ||
if: github.repository_owner == 'k2-fsa' || github.repository_owner == 'csukuangfj' | ||
name: export whisper ${{ matrix.model }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos-latest] | ||
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"] | ||
python-version: ["3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
python3 -m pip install torch==1.13.0 torchaudio==0.13.0 -f https://download.pytorch.org/whl/cpu/torch_stable.html numpy==1.26.4 kaldi-native-fbank | ||
python3 -m pip install -U openai-whisper | ||
python3 -m pip install onnx soundfile librosa | ||
- name: Download model files for ${{ matrix.model }} | ||
shell: bash | ||
run: | | ||
pushd scripts/whisper | ||
model=${{ matrix.model }} | ||
echo "model: $model" | ||
if [[ $model == distil-medium.en ]]; then | ||
wget -q -O distil-medium-en-original-model.bin https://huggingface.co/distil-whisper/distil-medium.en/resolve/main/original-model.bin | ||
ls -lh | ||
elif [[ $model == distil-large-v2 ]]; then | ||
wget -q -O distil-large-v2-original-model.bin https://huggingface.co/distil-whisper/distil-large-v2/resolve/main/original-model.bin | ||
ls -lh | ||
elif [[ $model == distil-small.en ]]; then | ||
wget -q -O distil-small-en-original-model.bin https://huggingface.co/distil-whisper/distil-small.en/resolve/main/original-model.bin | ||
ls -lh | ||
elif [[ $model == medium-aishell ]]; then | ||
wget -q -O medium-aishell.pt https://huggingface.co/yuekai/icefall_asr_aishell_whisper/resolve/main/exp_medium/whisper-medium-aishell1-epoch-10-avg-4.pt | ||
ls -lh | ||
fi | ||
- name: Export ${{ matrix.model }} | ||
shell: bash | ||
run: | | ||
pushd scripts/whisper | ||
export name=${{ matrix.model }} | ||
./run.sh | ||
- name: Test ${{ matrix.model }} | ||
shell: bash | ||
run: | | ||
pushd scripts/whisper | ||
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/0.wav | ||
./test.py | ||
- name: Collect results | ||
shell: bash | ||
run: | | ||
d=sherpa-whisper-${{ matrix.model }} | ||
mkdir $d | ||
mv -v scripts/whisper/model.pt $d/ | ||
mv -v scripts/whisper/tokens.txt $d/ | ||
mv -v scripts/whisper/README.md $d/ | ||
pushd $d | ||
mkdir test_wavs | ||
cd test_wavs | ||
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/0.wav | ||
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/1.wav | ||
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/8k.wav | ||
curl -SL -O https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/trans.txt | ||
popd | ||
ls -lh $d | ||
tar cjvf $d.tar.bz2 $d | ||
echo "---" | ||
ls -lh | ||
- name: Release | ||
if: matrix.model != 'large' && matrix.model != 'large-v1' && matrix.model != 'large-v2' && matrix.model != 'large-v3' && matrix.model != 'medium-aishell' | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
file_glob: true | ||
file: ./*.tar.bz2 | ||
overwrite: true | ||
repo_name: k2-fsa/sherpa | ||
repo_token: ${{ secrets.UPLOAD_GH_SHERPA_TOKEN }} | ||
tag: asr-models | ||
|
||
- name: Publish ${{ matrix.model }} to huggingface | ||
shell: bash | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
run: | | ||
src=sherpa-whisper-${{ matrix.model }} | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
export GIT_CLONE_PROTECTION_ACTIVE=false | ||
export GIT_LFS_SKIP_SMUDGE=1 | ||
rm -rf huggingface | ||
git clone https://csukuangfj:[email protected]/csukuangfj/$src huggingface | ||
rm -rf huggingface/* | ||
cp -av $src/* ./huggingface/ | ||
cd huggingface | ||
git status | ||
ls -lh | ||
git lfs track "*.pt*" | ||
git add . | ||
git commit -m "upload $src" || true | ||
git push https://csukuangfj:[email protected]/csukuangfj/$src main || true | ||
- name: Publish ${{ matrix.model }} to huggingface | ||
shell: bash | ||
env: | ||
HF_TOKEN: ${{ secrets.HF_TOKEN }} | ||
run: | | ||
src=sherpa-whisper-${{ matrix.model }} | ||
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
export GIT_CLONE_PROTECTION_ACTIVE=false | ||
export GIT_LFS_SKIP_SMUDGE=1 | ||
rm -rf huggingface | ||
git clone https://csukuangfj:[email protected]/k2-fsa/sherpa-models huggingface | ||
cp -av $src.tar.bz2 ./huggingface/non-streaming-asr | ||
cd huggingface | ||
git status | ||
ls -lh | ||
git lfs track "*.tar.bz2*" | ||
git add . | ||
git commit -m "upload $src" || true | ||
git push https://csukuangfj:[email protected]/k2-fsa/sherpa-models main || true | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ sherpa-nemo-ctc* | |
/.cache | ||
/.idea | ||
/.vscode | ||
*.pt | ||
tokens.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Introduction | ||
|
||
Models in this file are converted from | ||
https://github.com/openai/whisper | ||
using the following script | ||
https://github.com/k2-fsa/sherpa/blob/master/scripts/whisper/run.sh | ||
|
Oops, something went wrong.