Skip to content

Commit

Permalink
Add CI test for the AudioSet recipe. (#1585)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Apr 9, 2024
1 parent f5d7818 commit fa5d861
Show file tree
Hide file tree
Showing 21 changed files with 367 additions and 121 deletions.
94 changes: 94 additions & 0 deletions .github/scripts/audioset/AT/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env bash

set -ex

python3 -m pip install onnxoptimizer onnxsim

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]}) $*"
}

cd egs/audioset/AT

function test_pretrained() {
repo_url=https://huggingface.co/marcoyang/icefall-audio-tagging-audioset-zipformer-2024-03-12
repo=$(basename $repo_url)
GIT_LFS_SKIP_SMUDGE=1 git clone $repo_url
pushd $repo/exp
git lfs pull --include pretrained.pt
ln -s pretrained.pt epoch-99.pt
ls -lh
popd

log "test pretrained.pt"

python3 zipformer/pretrained.py \
--checkpoint $repo/exp/pretrained.pt \
--label-dict $repo/data/class_labels_indices.csv \
$repo/test_wavs/1.wav \
$repo/test_wavs/2.wav \
$repo/test_wavs/3.wav \
$repo/test_wavs/4.wav

log "test jit export"
ls -lh $repo/exp/
python3 zipformer/export.py \
--exp-dir $repo/exp \
--epoch 99 \
--avg 1 \
--use-averaged-model 0 \
--jit 1
ls -lh $repo/exp/

log "test jit models"
python3 zipformer/jit_pretrained.py \
--nn-model-filename $repo/exp/jit_script.pt \
--label-dict $repo/data/class_labels_indices.csv \
$repo/test_wavs/1.wav \
$repo/test_wavs/2.wav \
$repo/test_wavs/3.wav \
$repo/test_wavs/4.wav

log "test onnx export"
ls -lh $repo/exp/
python3 zipformer/export-onnx.py \
--exp-dir $repo/exp \
--epoch 99 \
--avg 1 \
--use-averaged-model 0

ls -lh $repo/exp/

pushd $repo/exp/
mv model-epoch-99-avg-1.onnx model.onnx
mv model-epoch-99-avg-1.int8.onnx model.int8.onnx
popd

ls -lh $repo/exp/

log "test onnx models"
for m in model.onnx model.int8.onnx; do
log "$m"
python3 zipformer/onnx_pretrained.py \
--model-filename $repo/exp/model.onnx \
--label-dict $repo/data/class_labels_indices.csv \
$repo/test_wavs/1.wav \
$repo/test_wavs/2.wav \
$repo/test_wavs/3.wav \
$repo/test_wavs/4.wav
done

log "prepare data for uploading to huggingface"
dst=/icefall/model-onnx
mkdir -p $dst
cp -v $repo/exp/*.onnx $dst/
cp -v $repo/data/* $dst/
cp -av $repo/test_wavs $dst

ls -lh $dst
ls -lh $dst/test_wavs
}

test_pretrained
2 changes: 2 additions & 0 deletions .github/scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ RUN pip install --no-cache-dir \
multi_quantization \
numba \
numpy \
onnxoptimizer \
onnxsim \
onnx \
onnxmltools \
onnxruntime \
Expand Down
137 changes: 137 additions & 0 deletions .github/workflows/audioset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: audioset

on:
push:
branches:
- master

pull_request:
branches:
- master

workflow_dispatch:

concurrency:
group: audioset-${{ github.ref }}
cancel-in-progress: true

jobs:
generate_build_matrix:
if: github.repository_owner == 'csukuangfj' || github.repository_owner == 'k2-fsa'
# see https://github.com/pytorch/pytorch/pull/50633
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generating build matrix
id: set-matrix
run: |
# outputting for debugging purposes
python ./.github/scripts/docker/generate_build_matrix.py
MATRIX=$(python ./.github/scripts/docker/generate_build_matrix.py)
echo "::set-output name=matrix::${MATRIX}"
audioset:
needs: generate_build_matrix
name: py${{ matrix.python-version }} torch${{ matrix.torch-version }} v${{ matrix.version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
${{ fromJson(needs.generate_build_matrix.outputs.matrix) }}

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

- name: Free space
shell: bash
run: |
ls -lh
df -h
rm -rf /opt/hostedtoolcache
df -h
echo "pwd: $PWD"
echo "github.workspace ${{ github.workspace }}"
- name: Run tests
uses: addnab/docker-run-action@v3
with:
image: ghcr.io/${{ github.repository_owner }}/icefall:cpu-py${{ matrix.python-version }}-torch${{ matrix.torch-version }}-v${{ matrix.version }}
options: |
--volume ${{ github.workspace }}/:/icefall
shell: bash
run: |
export PYTHONPATH=/icefall:$PYTHONPATH
cd /icefall
git config --global --add safe.directory /icefall
.github/scripts/audioset/AT/run.sh
- name: Show model files
shell: bash
run: |
sudo chown -R runner ./model-onnx
ls -lh ./model-onnx
chmod -x ./model-onnx/class_labels_indices.csv
echo "----------"
ls -lh ./model-onnx/*
- name: Upload model to huggingface
if: matrix.python-version == '3.9' && matrix.torch-version == '2.2.0' && github.event_name == 'push'
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
uses: nick-fields/retry@v3
with:
max_attempts: 20
timeout_seconds: 200
shell: bash
command: |
git config --global user.email "[email protected]"
git config --global user.name "Fangjun Kuang"
rm -rf huggingface
export GIT_LFS_SKIP_SMUDGE=1
git clone https://huggingface.co/k2-fsa/sherpa-onnx-zipformer-audio-tagging-2024-04-09 huggingface
cd huggingface
git fetch
git pull
git merge -m "merge remote" --ff origin main
cp ../model-onnx/*.onnx ./
cp ../model-onnx/*.csv ./
cp -a ../model-onnx/test_wavs ./
ls -lh
git add .
git status
git commit -m "update models"
git status
git push https://csukuangfj:[email protected]/k2-fsa/sherpa-onnx-zipformer-audio-tagging-2024-04-09 main || true
rm -rf huggingface
- name: Prepare for release
if: matrix.python-version == '3.9' && matrix.torch-version == '2.2.0' && github.event_name == 'push'
shell: bash
run: |
d=sherpa-onnx-zipformer-audio-tagging-2024-04-09
mv ./model-onnx $d
tar cjvf ${d}.tar.bz2 $d
ls -lh
- name: Release exported onnx models
if: matrix.python-version == '3.9' && matrix.torch-version == '2.2.0' && github.event_name == 'push'
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: sherpa-onnx-*.tar.bz2
repo_name: k2-fsa/sherpa-onnx
repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }}
tag: audio-tagging-models

2 changes: 2 additions & 0 deletions docker/torch1.12.1-cuda11.3.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch1.13.0-cuda11.6.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch1.9.0-cuda10.2.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ RUN pip uninstall -y tqdm && \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.0.0-cuda11.7.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.1.0-cuda11.8.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.1.0-cuda12.1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.0-cuda11.8.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.0-cuda12.1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.1-cuda11.8.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.1-cuda12.1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.2-cuda11.8.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
2 changes: 2 additions & 0 deletions docker/torch2.2.2-cuda12.1.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ RUN pip install --no-cache-dir \
onnx \
onnxruntime \
onnxmltools \
onnxoptimizer \
onnxsim \
multi_quantization \
typeguard \
numpy \
Expand Down
Loading

0 comments on commit fa5d861

Please sign in to comment.