Repository navigation
fix(runtime): honor use_itn in funasr_onnx and funasr_torch SenseVoiceSmall - #3860
tanishqbaweja wants to merge 1 commit into
Conversation
…eSmall SenseVoiceSmall.__call__ in funasr_onnx and funasr_torch read only the textnorm keyword and defaulted it to "woitn", so use_itn was ignored. model(wavs, language="auto", use_itn=True), the call in the ONNX and Libtorch demos and in the SenseVoice READMEs, sent the woitn query (15) like use_itn=False, so the model was asked for text without punctuation and inverse text normalization. Both wrappers read use_itn until 925910c replaced it with the textnorm list/file reader. Fall back to use_itn when textnorm is not given, as SenseVoiceSmall.inference does for text_norm. An explicit textnorm still wins, and the default stays woitn. Add tests/test_runtime_sensevoice_use_itn.py, which runs both wrappers on a tiny graph that returns its language and textnorm queries as CTC tokens, exported to ONNX and traced to TorchScript, and run it in the runtime evaluation workflow.
Preserve the original PR #3860 commit and use_itn fallback. Retain singleton query tags independently while slicing per-utterance language and textnorm inputs. Add real ONNX/TorchScript regressions for lists, files and partial batches. Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
LauraGPT
left a comment
There was a problem hiding this comment.
I reproduced the ignored use_itn=True behavior and validated this fallback. While testing the real wrappers, I also found an existing adjacent batching defect: singleton language resets per-utterance textnorm values in later batches, while singleton textnorm can become an empty tensor when languages vary. The empty tensor triggered an actual ONNX CUDA illegal memory access in the analytic regression fixture.
Companion #3861 preserves your original commit and authorship and adds independent scalar/list slicing plus mixed-tag and short-tail regressions. Its fixed tree passed 112 related CPU cases and 96 actual L20Z ONNX/TorchScript CUDA contract cases; all 6 exact-head CI checks and their downloaded evidence passed. These are runtime-routing tests with generated fixtures, not pretrained ASR accuracy claims.
The full repository suite remains unresolved at an unchanged online Conformer test that needs an uncached model (79 passed, 1 skipped, 1 failed before stopping). No new pretrained weights were downloaded, and neither this change nor its companion has been merged or released.
|
Thanks for reproducing it on the real wrappers, and for #3861. Slicing |
Summary
Fixes #3859
SenseVoiceSmall.__call__infunasr_onnxandfunasr_torchreads onlytextnorm(default"woitn") and neveruse_itn. Somodel(wav_or_scp, language="auto", use_itn=True)sends thewoitnquery (15), the same asuse_itn=False. That is the call in the ONNX and Libtorch demos and in the ONNX and Libtorch sections of the SenseVoice README (alsoREADME_zh.mdandREADME_ja.md), which describesuse_itnas "Whether the output result includes punctuation and inverse text normalization".SenseVoiceSmall.inference(AutoModel) sendswithitn(14) foruse_itn=True, as the C++ runtime does forsvs_itn(default true).The
use_itn=Truecall came with aa3fe1a and c5f7f11, which made both wrappers readuse_itnlikeSenseVoiceSmall.inference; the next day, 925910c ("update onnx batch inference") replaced that with thetextnormlist/file reader and droppeduse_itn.This PR falls back to
use_itnwhen notextnormis given, in both wrappers:An explicit
textnorm(string, list or file) still wins, and the default stayswoitn.tests/test_runtime_sensevoice_use_itn.pyruns both wrappers through the real frontend, ONNX Runtime and TorchScript on a tiny graph that returns itslanguageandtextnorminputs as CTC tokens. A SentencePiece fixture names those ids (<|en|>,<|withitn|>,<|woitn|>), so each result shows the queries the wrapper sent. Cases: no options,use_itn=False,use_itn=True,textnorm="withitn",textnorm="woitn"withuse_itn=True, andlanguage="en"withuse_itn=True, each for both backends withbatch_size1 and 2 on two files. I added the file totest-runtime-eval.yml(both path filters and the pytest command); that job already installs what it needs.Type of change
Validation
python -m compileall funasr examples testsWindows 11, CPU, in two environments: Python 3.11.17 with torch 2.10.0+cpu and numpy 2.4.6, and Python 3.10.22 with the workflow's pins (torch 2.8.0+cpu, numpy 1.26.4); both with onnx 1.19.0 and onnxruntime 1.23.2.
python -m pytest -q tests/test_runtime_sensevoice_use_itn.pywith the wrappers ofmain(20f26b7): 8 failed, 16 passed in both environments. The failures are the cases that passuse_itn=Truewithouttextnorm, which return['<|woitn|>', '<|woitn|>'](<|en|><|woitn|>withlanguage="en"). On this branch: 24 passed.python -m pytest -q tests/test_runtime_eval_cli.py tests/test_runtime_eval_native.py tests/test_runtime_sensevoice_use_itn.py, on this branch: 76 passed in both environments.black --line-length=100(24.4.0, the pre-commit pin) leaves the new test unchanged and reports nothing in the changed lines of the wrappers.git diff --checkis clean.User impact
funasr_onnxandfunasr_torchusers who passuse_itn=True, as the demos and READMEs do, get thewithitnquery, as withAutoModel, instead of a silentwoitn. Calls withoutuse_itnor withtextnormare unchanged.Notes for reviewers
map_location. Not changed here.demo_onnx.py(use_itn=Truebecametextnorm="withitn"). With this fix, the ten ONNX and Libtorchuse_itn=Truecalls in this repo's demos and READMEs work as written.