Skip to content

fix(onnx): keep no left-context frames when chunk_size[0] is 0 in streaming Paraformer - #3790

Open
ychy7001 wants to merge 1 commit into
modelscope:mainfrom
ychy7001:fix/funasr-onnx-online-zero-left-chunk
Open

ychy7001 wants to merge 1 commit into
modelscope:mainfrom
ychy7001:fix/funasr-onnx-online-zero-left-chunk

Conversation

@ychy7001

@ychy7001 ychy7001 commented Oct 24, 2026 •

Copy link
Copy Markdown

Summary

Fixes #3789.

add_overlap_chunk stored the left context with overlap_feats[:, -n:, :]. With n == 0 this returns every frame, so with chunk_size=[0, 10, 5] (the streaming example in README and docs) the final chunk re-decodes the previous chunk's features and repeats the last characters, e.g. 火爆 → 火爆爆爆.

The start index is now computed explicitly in a small _tail_frames helper, used for both the final and non-final cache updates. Behaviour for non-zero context sizes is unchanged.

Type of change

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

Validation

  • python -m compileall funasr examples tests

  • Docs or links checked

  • Runtime/deployment command tested

  • python tests/test_funasr_onnx_paraformer_online_overlap.py against the installed package: 3 passed. Against the unfixed package, the two zero-context tests fail and the non-zero test passes.

  • The test is added to test-funasr-onnx-package.yml (path filters and a step after the installed-wrapper check), so CI runs it against the built wheel.

  • AISHELL-1 test (7176 utterances), iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online v2.0.5, chunk_size=[0, 10, 5], onnxruntime 1.20.1 CPU, dither 0:

export CER before CER after changed outputs
FP32 17.23% 15.18% 2170
quantized 17.15% 15.08% 2179

PyTorch AutoModel with the same settings: 14.81%.

  • With chunk_size=[5, 10, 5], outputs for the sampled utterances are identical before and after (the fix does not change slicing for non-zero sizes).

User impact

Removes the extra tail decoding caused by retaining all overlap frames when the requested context size is zero. This affects users running the streaming ONNX model with the documented chunk_size=[0, 10, 5]. Other trailing repeats that also appear in the PyTorch reference are out of scope.

Notes for reviewers

Only paraformer_online_bin.py is affected; the C++ runtime does not use this code. Running black on the file also reformats unrelated pre-existing lines, so those are left untouched.

…eaming Paraformer

overlap_feats[:, -0:, :] returns every frame instead of none, so with
chunk_size=[0, 10, 5] (the streaming example in README and docs) the
final chunk re-decodes the previous chunk's features and repeats the
last characters. Compute the tail start index explicitly; the same
applies to the non-final cache when chunk_size[0] + chunk_size[2] is 0.

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 repeats the last characters when chunk_size[0] is 0

1 participant