Skip to content

Comments

Fix #2809: [Performance Regression] funasr 1.3.1 offline(vad+asr) laten#2817

Open
danielalanbates wants to merge 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2809
Open

Fix #2809: [Performance Regression] funasr 1.3.1 offline(vad+asr) laten#2817
danielalanbates wants to merge 1 commit intomodelscope:mainfrom
danielalanbates:fix/issue-2809

Conversation

@danielalanbates
Copy link

Fixes #2809

Summary

This PR addresses: [Performance Regression] funasr 1.3.1 offline(vad+asr) latency is ~10x slower than 1.3.0 on RTX 4080/4090

Changes

funasr/models/fsmn_vad_streaming/model.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Testing

Please review the changes carefully. The fix was verified against the existing test suite.


This PR was created with the assistance of Claude Sonnet 4.6 by Anthropic | effort: low. Happy to make any adjustments!

…mputeScores

The .to('cpu') call after each encoder forward pass in ComputeScores()
forced a GPU->CPU synchronization point on every VAD chunk inference,
causing ~10x latency regression on GPU (RTX 4080/4090) in offline
VAD+ASR mode. The scores tensor stays on the same device as the encoder
output; downstream .item() calls handle the scalar extraction correctly
regardless of device.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danielalanbates, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a significant performance degradation in the funasr library's offline VAD+ASR functionality. The core issue stemmed from an inefficient tensor device management operation that forced data onto the CPU, hindering GPU acceleration. By eliminating this redundant transfer, the change restores the expected high performance on NVIDIA GPUs.

Highlights

  • Performance Regression Fix: Addressed a critical performance regression in the funasr 1.3.1 offline VAD+ASR pipeline, which was reported to be approximately 10x slower on RTX 4080/4090 GPUs compared to version 1.3.0.
  • Tensor Device Optimization: Removed an unnecessary .to("cpu") call in the ComputeScores method within the FSMN VAD streaming model, preventing explicit tensor transfer to the CPU during GPU-accelerated operations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • funasr/models/fsmn_vad_streaming/model.py
    • Removed an explicit .to("cpu") call from the scores tensor assignment in the ComputeScores method.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a performance regression in the FSMN VAD model by removing an explicit CPU transfer of the encoder scores. This change optimizes the concatenation of scores on the GPU, which is particularly beneficial for long audio sequences where CPU-based concatenation becomes a bottleneck. However, it may introduce a different performance overhead in the VAD logic due to synchronous scalar access from the GPU.


def ComputeScores(self, feats: torch.Tensor, cache: dict = {}) -> None:
scores = self.encoder(feats, cache=cache["encoder"]).to("cpu") # return B * T * D
scores = self.encoder(feats, cache=cache["encoder"]) # return B * T * D
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Removing .to("cpu") keeps the scores tensor on the GPU. This is an effective fix for the reported performance regression because it allows the torch.cat operation at line 360 to occur on the GPU. For long audio files, concatenating large tensors on the CPU involves significant memory copy overhead ($O(N^2)$ complexity over time), which explains the 10x slowdown on high-end hardware like the RTX 4090.

However, note that the VAD logic in GetFrameState (lines 516-518) still uses .item() to access individual scores. When the tensor resides on the GPU, each .item() call triggers a synchronous host-device transfer. While this is likely faster than the previous CPU concatenation bottleneck, it remains a performance anti-pattern. For maximum efficiency, consider keeping the global buffer on the GPU but moving only the current chunk of scores to the CPU once per ComputeScores call for the VAD state machine to process.

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.

[Performance Regression] funasr 1.3.1 offline(vad+asr) latency is ~10x slower than 1.3.0 on RTX 4080/4090

1 participant