modelscope / FunASR

A Fundamental End-to-End Speech Recognition Toolkit and Open Source SOTA Pretrained Models, Supporting Speech Recognition, Voice Activity Detection, Text Post-processing etc.
https://www.funasr.com
Other
5.81k stars 629 forks source link

AutoModel inference函数有bug,Paramformer online并行处理多个音频时cache错乱 #1805

Closed Ignalxy closed 1 month ago

Ignalxy commented 2 months ago

🐛 Bug

AutoModel inference函数line 255 deep_update导致kwargs['cache']并不是传入的cache

To Reproduce

以下代码输出错乱

Code sample

import copy
import os
import logging
import soundfile
import torch
from funasr.auto.auto_model import AutoModel

chunk_size = [0, 10, 5] #[0, 10, 5] 600ms, [0, 8, 4] 480ms
encoder_chunk_look_back = 4 #number of chunks to lookback for encoder self-attention
decoder_chunk_look_back = 1 #number of encoder chunks to lookback for decoder cross-attention

model = AutoModel(model="paraformer-zh-streaming")

import soundfile
import os

wav_file = os.path.join(model.model_path, "example/asr_example.wav")
speech, sample_rate = soundfile.read(wav_file)
chunk_stride = chunk_size[1] * 960 # 600ms

cache = {}
cache1 = {}
print(id(cache), id(cache1))
result = ''
result1 = ''
total_chunk_num = int(len((speech)-1)/chunk_stride+1)
for i in range(total_chunk_num):
    speech_chunk = speech[i*chunk_stride:(i+1)*chunk_stride]
    is_final = i == total_chunk_num - 1
    res = model.generate(input=speech_chunk, cache=cache, is_final=is_final, chunk_size=chunk_size, encoder_chunk_look_back=encoder_chunk_look_back, decoder_chunk_look_back=decoder_chunk_look_back)
    res1= model.generate(input=speech_chunk, cache=cache1, is_final=is_final, chunk_size=chunk_size, encoder_chunk_look_back=encoder_chunk_look_back, decoder_chunk_look_back=decoder_chunk_look_back)

    if res:
        print(res[0]['text'])
        result += res[0]['text']
    if res1:
        print(res1[0]['text'])
        result1 += res1[0]['text']

print(result)
print(result1)

Expected behavior

改为kwargs.update(cfg)就正常了

LauraGPT commented 2 months ago

Ok, we would check it.

LauraGPT commented 1 month ago

Thank for you feedback. We had fixed the bug: https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L267

You could update funasr-1.1.4