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
7.02k stars 747 forks source link

paraformer in funasr_onnx is not thread safe in version 0.2.1! #911

Closed lixikun closed 1 year ago

lixikun commented 1 year ago

Hi:
when i use multithread to test the funasr_onnx , I get the following error: (_server:508) ERROR: Exception calling application: deque::_M_range_check: n (which is 27)>= this->size() (which is 14) Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/grpc/_server.py", line 494, in _call_behavior response_or_iterator = behavior(argument, context) File "/opt/asr/asr_server_zh.py", line 150, in recognizeOff res = self.run_infrence(self.speech2text,sid,float_data) File "/opt/asr/asr_server_zh.py", line 92, in run_infrence results = results = speech2text(audio) File "/usr/local/lib/python3.10/dist-packages/funasr_onnx/paraformer_bin.py", line 86, in call__ feats, feats_len = self.extract_feat(waveform_list[beg_idx:end_idx]) File "/usr/local/lib/python3.10/dist-packages/funasr_onnx/paraformer_bin.py", line 162, in extractfeat speech, = self.frontend.fbank(waveform) File "/usr/local/lib/python3.10/dist-packages/funasr_onnx/utils/frontend.py", line 62, in fbank mat[i, :] = self.fbank_fn.get_frame(i) after searching the code, I found that the var fbank_fn in frontend.py is global, and this can cause the above error and the paraformer is not thread safe . I just modify the code, remain that the variable fbank_fn is local , there is no error . I don't know the purpose of modify the variable fbank_fn to be global. and whether the solution is correct!

the version of funasr_onnx is 0.2.1

LauraGPT commented 1 year ago

The version of python onnxruntime does not support the multi-threads. Maybe you could use multiprocess, or the the version of c++ onnxruntime. docs

lixikun commented 1 year ago

thanks!