committed by
GitHub
parent
84ed5d4288
commit
01110cc22b
@@ -79,6 +79,31 @@ jobs:
|
||||
|
||||
tar cjvf ${d}.tar.bz2 $d
|
||||
|
||||
- name: Run CTC v2
|
||||
shell: bash
|
||||
run: |
|
||||
pushd scripts/nemo/GigaAM
|
||||
./run-ctc-v2.sh
|
||||
popd
|
||||
|
||||
d=sherpa-onnx-nemo-ctc-giga-am-v2-russian-2025-04-19
|
||||
mkdir $d
|
||||
mkdir $d/test_wavs
|
||||
rm scripts/nemo/GigaAM/v2_ctc.onnx
|
||||
mv -v scripts/nemo/GigaAM/*.int8.onnx $d/
|
||||
cp -v scripts/nemo/GigaAM/LICENCE $d/
|
||||
mv -v scripts/nemo/GigaAM/tokens.txt $d/
|
||||
mv -v scripts/nemo/GigaAM/*.wav $d/test_wavs/
|
||||
mv -v scripts/nemo/GigaAM/run-ctc.sh $d/
|
||||
mv -v scripts/nemo/GigaAM/*-ctc-v2.py $d/
|
||||
|
||||
ls -lh scripts/nemo/GigaAM/
|
||||
|
||||
ls -lh $d
|
||||
|
||||
tar cjvf ${d}.tar.bz2 $d
|
||||
|
||||
|
||||
- name: Release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
@@ -114,3 +139,29 @@ jobs:
|
||||
git status
|
||||
git commit -m "add models"
|
||||
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d main
|
||||
|
||||
- name: Publish v2 to huggingface (Transducer)
|
||||
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 "csukuangfj@gmail.com"
|
||||
git config --global user.name "Fangjun Kuang"
|
||||
|
||||
d=sherpa-onnx-nemo-transducer-giga-am-v2-russian-2025-04-19/
|
||||
export GIT_LFS_SKIP_SMUDGE=1
|
||||
export GIT_CLONE_PROTECTION_ACTIVE=false
|
||||
git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d huggingface
|
||||
mv -v $d/* ./huggingface
|
||||
cd huggingface
|
||||
git lfs track "*.onnx"
|
||||
git lfs track "*.wav"
|
||||
git status
|
||||
git add .
|
||||
git status
|
||||
git commit -m "add models"
|
||||
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$d main
|
||||
|
||||
57
scripts/nemo/GigaAM/export-onnx-ctc-v2.py
Normal file
57
scripts/nemo/GigaAM/export-onnx-ctc-v2.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import gigaam
|
||||
import onnx
|
||||
import torch
|
||||
from onnxruntime.quantization import QuantType, quantize_dynamic
|
||||
|
||||
|
||||
def add_meta_data(filename: str, meta_data: dict[str, str]):
|
||||
"""Add meta data to an ONNX model. It is changed in-place.
|
||||
|
||||
Args:
|
||||
filename:
|
||||
Filename of the ONNX model to be changed.
|
||||
meta_data:
|
||||
Key-value pairs.
|
||||
"""
|
||||
model = onnx.load(filename)
|
||||
while len(model.metadata_props):
|
||||
model.metadata_props.pop()
|
||||
|
||||
for key, value in meta_data.items():
|
||||
meta = model.metadata_props.add()
|
||||
meta.key = key
|
||||
meta.value = str(value)
|
||||
|
||||
onnx.save(model, filename)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
model_name = "v2_ctc"
|
||||
model = gigaam.load_model(model_name, fp16_encoder=False, use_flash=False, download_root=".")
|
||||
with open("./tokens.txt", "w", encoding="utf-8") as f:
|
||||
for i, s in enumerate(model.cfg["labels"]):
|
||||
f.write(f"{s} {i}\n")
|
||||
f.write(f"<blk> {i+1}\n")
|
||||
print("Saved to tokens.txt")
|
||||
model.to_onnx(".")
|
||||
meta_data = {
|
||||
"vocab_size": len(model.cfg["labels"]) + 1,
|
||||
"normalize_type": "",
|
||||
"subsampling_factor": 4,
|
||||
"model_type": "EncDecCTCModel",
|
||||
"version": "1",
|
||||
"model_author": "https://github.com/salute-developers/GigaAM",
|
||||
"license": "https://github.com/salute-developers/GigaAM/blob/main/LICENSE",
|
||||
"language": "Russian",
|
||||
"is_giga_am": 1,
|
||||
}
|
||||
add_meta_data(f"./{model_name}.onnx", meta_data)
|
||||
quantize_dynamic(
|
||||
model_input=f"./{model_name}.onnx",
|
||||
model_output="./model.int8.onnx",
|
||||
weight_type=QuantType.QUInt8,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
25
scripts/nemo/GigaAM/run-ctc-v2.sh
Executable file
25
scripts/nemo/GigaAM/run-ctc-v2.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
function install_gigaam() {
|
||||
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
||||
python3 get-pip.py
|
||||
|
||||
BRANCH='main'
|
||||
python3 -m pip install git+https://github.com/salute-developers/GigaAM.git@$BRANCH#egg=gigaam
|
||||
|
||||
python3 -m pip install -qq kaldi-native-fbank
|
||||
}
|
||||
|
||||
function download_files() {
|
||||
curl -SL -O https://huggingface.co/csukuangfj/tmp-files/resolve/main/GigaAM/example.wav
|
||||
curl -SL -O https://github.com/salute-developers/GigaAM/blob/main/LICENSE
|
||||
}
|
||||
|
||||
install_gigaam
|
||||
download_files
|
||||
|
||||
python3 ./export-onnx-ctc-v2.py
|
||||
ls -lh
|
||||
python3 ./test-onnx-ctc.py
|
||||
Reference in New Issue
Block a user