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): place cif_v1_export empty-fire guard after fire_idxs is defined
LauraGPT57f97776165c
diff --git a/funasr/models/paraformer/cif_predictor.py b/funasr/models/paraformer/cif_predictor.pyindex 32f73a4fa..93645a8ff 100644--- a/funasr/models/paraformer/cif_predictor.py+++ b/funasr/models/paraformer/cif_predictor.py@@ -616,15 +616,6 @@ 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)@@ -645,6 +636,16 @@ def cif_v1_export(hidden, alphas, threshold: float):fires[fire_idxs] = 1fires = fires + prefix_sum - prefix_sum_floor+ 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 at `shift_frames[shift_batch_idxs]`.+ # Placed after fire_idxs/fires are computed (TorchScript requires every+ # referenced name to be defined first).+ max_label_len = torch.floor(alphas.sum(dim=-1)).max().to(dtype=torch.int64)+ frame_fires = torch.zeros(batch_size, max_label_len, hidden_size, dtype=dtype, device=device)+ return frame_fires, fires+# prefix_sum_hidden = torch.cumsum(alphas.unsqueeze(-1).tile((1, 1, hidden_size)) * hidden, dim=1)prefix_sum_hidden = torch.cumsum(alphas.unsqueeze(-1).repeat((1, 1, hidden_size)) * hidden, dim=1)frames = prefix_sum_hidden[fire_idxs]