Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
fix(paraformer): guard CIF against IndexError when no boundaries fire (#3028)
zhifu gao1da63a40b7a3
diff --git a/funasr/models/paraformer/cif_predictor.py b/funasr/models/paraformer/cif_predictor.pyindex d72bd0f7b..32f73a4fa 100644--- a/funasr/models/paraformer/cif_predictor.py+++ b/funasr/models/paraformer/cif_predictor.py@@ -616,6 +616,15 @@ def cif_v1_export(hidden, alphas, threshold: float):device = hidden.devicedtype = hidden.dtypebatch_size, len_time, hidden_size = hidden.size()+ if fire_idxs.sum() == 0:+ # No integration boundaries fired (e.g. a very short / silent+ # segment): return zero frames instead of indexing into the+ # resulting empty tensors, which raised an IndexError.+ max_label_len = torch.round(alphas.sum(-1)).int().max()+ return (+ torch.zeros(batch_size, max_label_len, hidden_size, dtype=dtype, device=device),+ fires,+ )threshold = torch.tensor([threshold], dtype=alphas.dtype).to(alphas.device)frames = torch.zeros(batch_size, len_time, hidden_size, dtype=dtype, device=device)@@ -853,6 +862,15 @@ def cif_v1(hidden, alphas, threshold):device = hidden.devicedtype = hidden.dtypebatch_size, len_time, hidden_size = hidden.size()+ if fire_idxs.sum() == 0:+ # No integration boundaries fired (e.g. a very short / silent+ # segment): return zero frames instead of indexing into the+ # resulting empty tensors, which raised an IndexError.+ max_label_len = torch.round(alphas.sum(-1)).int().max()+ return (+ torch.zeros(batch_size, max_label_len, hidden_size, dtype=dtype, device=device),+ fires,+ )# frames = torch.zeros(batch_size, len_time, hidden_size, dtype=dtype, device=device)# prefix_sum_hidden = torch.cumsum(alphas.unsqueeze(-1).tile((1, 1, hidden_size)) * hidden, dim=1)frames = torch.zeros(batch_size, len_time, hidden_size, dtype=dtype, device=device)