Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exporting streaming zipformer models to onnx #1755

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

csukuangfj
Copy link
Collaborator

It is to fix the following warning messages when fixing the batch size of the kws model to 1:

2024-09-11 14:57:33.363528468 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.
2024-09-11 14:57:33.363944876 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample_1/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.
2024-09-11 14:57:33.364352529 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample_2/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.
2024-09-11 14:57:33.364754380 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample_3/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.
2024-09-11 14:57:33.365155584 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample_4/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.
2024-09-11 14:57:33.365553111 [W:onnxruntime:, graph.cc:108 MergeShapeInfo] Error merging shape info for output. '/downsample_output/Concat_1_output_0' source:{17,1,128} target:{16,1,128}. Falling back to lenient merge.

With this fix, you can re-export the kws model to onnx as follows:

cd egs/wenetspeech/KWS
wget https://github.com/pkufool/keyword-spotting-models/releases/download/v0.11/icefall-kws-zipformer-wenetspeech-20240219.tar.gz
tar xvf icefall-kws-zipformer-wenetspeech-20240219.tar.gz

pushed icefall-kws-zipformer-wenetspeech-20240219/exp
ln -s pretrained.pt epoch-99.pt
popd

./zipformer/export-onnx-streaming.py \
  --tokens ./icefall-kws-zipformer-wenetspeech-20240219/data/lang_partial_tone/tokens.txt \
  --exp-dir ./icefall-kws-zipformer-wenetspeech-20240219/exp \
  --epoch 99 \
  --avg 1 \
  --use-averaged-model 0 \
  \
  --num-encoder-layers "1,1,1,1,1,1" \
  --downsampling-factor "1,2,4,8,4,2" \
  --feedforward-dim "192,192,192,192,192,192" \
  --num-heads "4,4,4,8,4,4" \
  --encoder-dim "128,128,128,128,128,128" \
  --query-head-dim 32 \
  --value-head-dim 12 \
  --pos-head-dim 4 \
  --pos-dim 48 \
  --encoder-unmasked-dim "128,128,128,128,128,128" \
  --cnn-module-kernel "31,31,15,15,15,31" \
  --decoder-dim 320 \
  --joiner-dim 320 \
  --causal True \
  --chunk-size 16 \
  --left-context-frames 64

cd icefall-kws-zipformer-wenetspeech-20240219/exp

python3 -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param N --dim_value 1 ./encoder-epoch-99-avg-1-chunk-16-left-64.onnx tmp.fixed.onnx

python3 -m onnxruntime.quantization.preprocess --input ./tmp.fixed.onnx --output tmp.fixed.pre.onnx

# The original warning messages should disappear

@csukuangfj csukuangfj merged commit 6f1abd8 into k2-fsa:master Sep 11, 2024
76 of 108 checks passed
@csukuangfj csukuangfj deleted the fix-exporting-onnx branch September 11, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant