Skip to content

Commit

Permalink
Add C++ runtime support for Whisper models (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jan 14, 2025
1 parent cf0b558 commit 0387685
Show file tree
Hide file tree
Showing 51 changed files with 1,815 additions and 219 deletions.
84 changes: 84 additions & 0 deletions .github/scripts/run-offline-whisper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

set -ex

log() {
# This function is from espnet
local fname=${BASH_SOURCE[1]##*/}
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*"
}

log "=========================================================================="
model_list=(
base
base.en
distil-large-v2
distil-medium.en
distil-small.en
medium
medium.en
small
small.en
tiny
tiny.en
turbo
)

curl -SL -O https://hf-mirror.com/csukuangfj/sherpa-onnx-zh-wenet-aishell2/resolve/main/test_wavs/0.wav
mv 0.wav zh.wav

for m in ${model_list[@]}; do
d=sherpa-whisper-$m
log "----------testing $d----------"
curl -SL -O https://github.com/k2-fsa/sherpa/releases/download/asr-models/$d.tar.bz2
tar xvf $d.tar.bz2
rm $d.tar.bz2
ls -lh $d

if [[ $d == *en ]]; then
log "decode a single file"

./build/bin/sherpa-offline \
--debug=1 \
--whisper-model=./$d/model.pt \
--tokens=./$d/tokens.txt \
./$d/test_wavs/0.wav

log "decode two files"
./build/bin/sherpa-offline \
--debug=1 \
--whisper-model=./$d/model.pt \
--tokens=./$d/tokens.txt \
./$d/test_wavs/0.wav \
./$d/test_wavs/1.wav
fi

if [[ $d != *en ]]; then

log "decode a single file"

./build/bin/sherpa-offline \
--debug=1 \
--whisper-model=./$d/model.pt \
--tokens=./$d/tokens.txt \
./$d/test_wavs/0.wav

log "decode two files"
./build/bin/sherpa-offline \
--debug=1 \
--whisper-model=./$d/model.pt \
--tokens=./$d/tokens.txt \
./$d/test_wavs/0.wav \
./$d/test_wavs/1.wav

log "decode three files"
./build/bin/sherpa-offline \
--debug=1 \
--whisper-model=./$d/model.pt \
--tokens=./$d/tokens.txt \
./$d/test_wavs/0.wav \
./$d/test_wavs/1.wav \
./zh.wav
fi
rm -rf $d
done
2 changes: 1 addition & 1 deletion .github/workflows/build-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: ["3.10"]
steps:
# refer to https://github.com/actions/checkout
- uses: actions/checkout@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/macos-cpu-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generating build matrix
Expand All @@ -38,12 +38,12 @@ jobs:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
ls -lh ./wheelhouse/
- name: Upload Wheel
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-macos-latest-cpu
path: wheelhouse/*.whl
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"

- name: Install Python dependencies
shell: bash
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python_style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: ["3.10"]
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/run-cpp-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ concurrency:

jobs:
run_cpp_tests:
if: github.event.label.name == 'ready' || github.event.label.name == 'cpp' || github.event_name == 'push'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
torch: ["2.1.2"]
python-version: ["3.8"]
python-version: ["3.10"]
build_type: ["Release", "Debug"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -70,7 +69,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.torch }}-${{ matrix.python-version }}-${{ matrix.build_type }}

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -174,6 +173,11 @@ jobs:
./bin/sherpa-offline --help
- name: Run offline whisper
shell: bash
run: |
.github/scripts/run-offline-whisper.sh
- name: Run offline sense-voice
shell: bash
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-cpp-websocket-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
matrix:
os: [ubuntu-latest]
torch: ["1.13.1"]
python-version: ["3.8"]
python-version: ["3.10"]
build_type: ["Release", "Debug"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -47,7 +47,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.torch }}-${{ matrix.python-version }}-${{ matrix.build_type }}

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-python-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:
os: [ubuntu-latest]
torch: ["1.13.1"]
torchaudio: ["0.13.1"]
python-version: ["3.8"]
python-version: ["3.10"]
build_type: ["Release"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -52,7 +52,7 @@ jobs:
key: ${{ matrix.os }}-${{ matrix.torch }}-${{ matrix.python-version }}-${{ matrix.build_type }}

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/style_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: ["3.10"]
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test-offline-websocket-rtf-wer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
os: [ubuntu-latest]
torch: ["1.13.1"]
torchaudio: ["0.13.1"]
python-version: ["3.8"]
python-version: ["3.10"]
decoding_method: ["greedy_search", "modified_beam_search"]
num_connections: [50, 100, 200]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -55,7 +55,7 @@ jobs:
echo "Number of CPU cores: ${{ steps.cpu-cores.outputs.count }}"
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
cat ./log.txt
- name: Upload decoding results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: os-${{ matrix.os }}-decoding-method-${{ matrix.decoding_method }}
path: ./*.txt
8 changes: 4 additions & 4 deletions .github/workflows/test-online-websocket-rtf-wer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
os: [ubuntu-latest]
torch: ["1.13.1"]
torchaudio: ["0.13.1"]
python-version: ["3.8"]
python-version: ["3.10"]
decoding_method: ["greedy_search", "modified_beam_search"]
num_connections: [50, 100, 200]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -55,7 +55,7 @@ jobs:
echo "Number of CPU cores: ${{ steps.cpu-cores.outputs.count }}"
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
cat ./log.txt
- name: Upload decoding results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: os-${{ matrix.os }}-decoding-method-${{ matrix.decoding_method }}
path: ./*.txt
8 changes: 4 additions & 4 deletions .github/workflows/ubuntu-cpu-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generating build matrix
Expand All @@ -38,12 +38,12 @@ jobs:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
ls -lh ./wheelhouse/
- name: Upload Wheel
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-ubuntu-latest-cpu
path: wheelhouse/*.whl
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu-cuda-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generating build matrix
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
echo "github.workspace ${{ github.workspace }}"
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
ls -lh ./wheelhouse/
- name: Upload Wheel
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: torch-${{ matrix.torch }}-python-${{ matrix.python-version }}-ubuntu-latest-cuda
path: wheelhouse/*.whl
Expand Down
Loading

0 comments on commit 0387685

Please sign in to comment.