Repository navigation
fix(fun-asr-nano): restore repetitive-garbage trimming in streaming vLLM - #3766
Open
MincongZhou wants to merge 2 commits into
Open
MincongZhou wants to merge 2 commits into
MincongZhou wants to merge 2 commits into
Conversation
inference_vllm_streaming.py carried a raw 0x01 control byte where its sibling
inference_vllm_pipeline.py has the two characters \1:
streaming: re.sub(r'(>.{2,8}?).{3,}', '', text) <- literal U+0001 in the raw string
pipeline : re.sub(r"(>.{2,8}?)\1{3,}", "", text) <- backreference
The streaming pattern therefore requires three or more U+0001 characters, which
no model output contains, so the rule never fires. It is the only control
character in funasr/. The intent is not in doubt: the commit that introduced
the feature (3817ca3) had \1, and the streaming rewrite (4bb5b54) shows
the 0x01 in its own diff, where git renders it as ^A:
+ text = re.sub(r'(>.{2,8}?)^A{3,}', '', text)
Effect: streaming_generate calls _clean_text for the returned text, for the
fixed_text = text[:-rollback_chars] window and for prev_text, so the streaming
engine kept repetition runs ("你好。>这个表面>这个表面>...") that the pipeline
engine strips from the same audio -- the post-processing remedy the pipeline
path already relies on.
Restore the backreference so both runtimes trim the same garbage.
Import both production _clean_text implementations and require them to produce the same output: on repetitive garbage (which the pipeline engine trims, the streaming engine did not) and on text without repetition (which neither should touch). The cases enumerate the rule's real boundaries rather than just the happy path: four repeats trim, three do not; the repeated group needs at least two characters; a genuine 0x01 byte in the text must survive. No weights, GPU or model artifact are needed - the modules only import torch, numpy and re at import time, which is what the neighbouring fun_asr_nano tests rely on too.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
funasr/models/fun_asr_nano/inference_vllm_streaming.pycarried a raw0x01control byte where its siblinginference_vllm_pipeline.pyhas the two characters\1:xxdon the two source lines:So the streaming pattern is
(>.{2,8}?)\x01{3,}— it requires three or more literalU+0001characters, which no model output contains, and therefore never fires. This is the only control character anywhere underfunasr/(grep -rlP '\x01' funasr --include=*.py→ this one file).The intent is unambiguous from the history:
3817ca31b3(feature introduction) hadr"(>.{2,8}?)\1{3,}".4bb5b543fe("fix: improve streaming vLLM with two-stage approach for long audio") rewrote this function, and its own diff shows the corruption — git renders0x01as^A:\1.streaming_generatecalls_clean_textfor the returnedtext, for thefixed_text = text[:-rollback_chars]fixed/unfixed window and forprev_textof later chunks. The streaming engine therefore keeps repetition runs of exactly the shape this rule exists to remove — the same model on the same audio gets cleaned by the pipeline path and not by the streaming path. This rule is the "后处理截断" remedy already relied on by the pipeline path (cf. #2930, #2950).Type of change
Validation
python -m compileall funasr examples tests→ exit 0 on the patched tree.The two
_clean_textimplementations were loaded verbatim from the real files (the function AST extracted and executed with onlyrein its namespace; the modules' torch/vLLM imports are unused by this function and were not needed) and compared on strings of exactly the shape the rule targets:Concretely, unchanged at
main:I could not run the real streaming engine end to end (no GPU, no vLLM, no checkpoint here), so I cannot show a real transcript that the pipeline cleans and streaming does not. The claim is limited to the function's behaviour, which is where the divergence is, and both copies are now identical on every case tried.
black --line-length=100 --checkoutput is byte-identical before and after — this file is already not black-formatted at HEAD, so it is deliberately not reformatted here (a one-byte fix, 1 insertion / 1 deletion).User impact
Anyone serving Fun-ASR-nano through the streaming vLLM engine gets cleaner transcripts, matching what the VAD+vLLM pipeline engine already produces for the same audio — repetition runs like
你好。>这个表面>这个表面>…no longer leak into the returned text, the fixed/unfixed window or the next chunk'sprev_text.Notes for reviewers
inference_vllm.py:665-670) has no repetition clause at all. That is a separate question and deliberately out of scope for this minimal fix.Competition
No competing item.
gh api search/issuesfor_clean_text→ 0, forinference_vllm_streaming→ 0, and for a control character in this context → 1 unrelated issue. The repo currently has only two open PRs (#3726, #3686), neither of which touches this file. The neighbouring issues that discuss this remedy (#2930, #2950, #3595, #3597) are all closed and address it by other means.