Skip to content

fix(onnx): return an empty list for empty split-final Paraformer results - #3792

Open
ychy7001 wants to merge 1 commit into
modelscope:mainfrom
ychy7001:fix/funasr-onnx-online-empty-final-result
Open

ychy7001 wants to merge 1 commit into
modelscope:mainfrom
ychy7001:fix/funasr-onnx-online-empty-final-result

Conversation

@ychy7001

Copy link
Copy Markdown

Summary

Fixes #3791.

When a final call is split into two chunks and both infer() calls return [], the merge loop leaves res = {} and __call__ returns [{}]. The official runtime/python/onnxruntime/demo_paraformer_online.py checks len(rec_result) > 0 before accessing rec_result[0]["preds"][0], so this result passes the check and raises KeyError: 'preds'.

Change one runtime line to return [res] if res else []. Normal recognition and merging are unchanged, including a result from only one of the two chunks. Single-chunk results, including [{"preds": ("", [])}], are unchanged. infer() and sentence_postprocess() are untouched.

Type of change

  • Bug fix
  • Documentation
  • Example or demo
  • Runtime or deployment
  • Benchmark or evaluation
  • Model/training change

Validation

  • PYTHONPATH=runtime/python/onnxruntime python tests/test_funasr_onnx_paraformer_online_empty_final.py -v: 5 passed. On fbbfe01, only the both-chunks-empty test fails ([{}] != []); the other 4 pass. Tests mock feature extraction and infer() while exercising the real __call__, cache preparation and overlap splitting. No model downloads are needed.
  • Official v2.0.5 FP32 ONNX export, Python 3.12.3, onnxruntime 1.20.1 CPU, numpy 1.26.4, default dither, chunk_size=[5, 10, 5]: a 9600-sample non-final silence call followed by a 16000-sample final silence call returns [{}] before the fix and triggers the demo's access error. After the fix it returns [] without an error. No overlap-slicing monkeypatch was used.
  • For AISHELL-1 BAC009S0764W0129, appending 0, 0.6, 1, 1.2, 2, 3 or 5 seconds of silence and using the demo's 9600-sample step did not trigger the error. Results were identical before and after. The reproduced 16000-sample final call is larger than the demo's usual step; this does not establish that trailing silence generally crashes the demo loop.
  • The new test is wired into .github/workflows/test-funasr-onnx-package.yml (path filters and a step after the wheel install).
  • git diff --check passed.

Notes for reviewers

A caller could theoretically treat [{}] as a status signal, so returning [] changes that observation. The tradeoff is to represent the absence of recognition results consistently with infer() and avoid the official demo's KeyError.

Other output consistency issues, including single-chunk tuple versus split-chunk list values under preds, are outside this change. This PR does not depend on #3790. The commit contains the one-line runtime fix, a regression test file, and the workflow entry that runs the test in Validate funasr-onnx package after the wheel is installed.

This branch has not been deployed

No deployments
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.

funasr_onnx streaming Paraformer returns inconsistent structures for empty results

1 participant