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
Update cif_predictor.py (#1811)
zhong zhuang145022c438c8
diff --git a/funasr/models/paraformer/cif_predictor.py b/funasr/models/paraformer/cif_predictor.pyindex 7490310c9..05e283a24 100644--- a/funasr/models/paraformer/cif_predictor.py+++ b/funasr/models/paraformer/cif_predictor.py@@ -504,7 +504,7 @@ def cif_v1_export(hidden, alphas, threshold: float):frames = torch.zeros(batch_size, len_time, hidden_size, dtype=dtype, device=device)fires = torch.zeros(batch_size, len_time, dtype=dtype, device=device)- prefix_sum = torch.cumsum(alphas, dim=1)+ prefix_sum = torch.cumsum(alphas, dim=1, dtype=torch.float64).to(torch.float32) # cumsum precision degradation cause wrong result in extremeprefix_sum_floor = torch.floor(prefix_sum)dislocation_prefix_sum = torch.roll(prefix_sum, 1, dims=1)dislocation_prefix_sum_floor = torch.floor(dislocation_prefix_sum)@@ -539,7 +539,8 @@ def cif_v1_export(hidden, alphas, threshold: float):frames = frames - shift_frames + shift_remain_frames - remain_frames- max_label_len = batch_len.max()+ max_label_len = alphas.sum(dim=-1)+ max_label_len = torch.floor(max_label_len).max().to(dtype=torch.int64)frame_fires = torch.zeros(batch_size, max_label_len, hidden_size, dtype=dtype, device=device@@ -670,7 +671,7 @@ def cif_wo_hidden_v1(alphas, threshold, return_fire_idxs=False):fires = torch.zeros(batch_size, len_time, dtype=dtype, device=device)- prefix_sum = torch.cumsum(alphas, dim=1)+ prefix_sum = torch.cumsum(alphas, dim=1, dtype=torch.float64).to(torch.float32) # cumsum precision degradation cause wrong result in extremeprefix_sum_floor = torch.floor(prefix_sum)dislocation_prefix_sum = torch.roll(prefix_sum, 1, dims=1)dislocation_prefix_sum_floor = torch.floor(dislocation_prefix_sum)@@ -718,7 +719,7 @@ def cif_v1(hidden, alphas, threshold):frames = frames - shift_frames + shift_remain_frames - remain_frames- max_label_len = batch_len.max()+ max_label_len = torch.round(alphas.sum(-1)).int().max() # torch.round to calculate the max lengthframe_fires = torch.zeros(batch_size, max_label_len, hidden_size, dtype=dtype, device=device