Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion funasr/models/fsmn_vad_streaming/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def ComputeDecibel(self, cache: dict = {}) -> None:


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.

assert (
scores.shape[1] == feats.shape[1]
), "The shape between feats and scores does not match"
Expand Down