From 63a70a00f7c9f162e8d7b3e330516438fb8cd87b Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期五, 19 四月 2024 16:08:05 +0800
Subject: [PATCH] add dynamic batch for fetch

---
 funasr/models/paraformer_streaming/model.py |   21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/funasr/models/paraformer_streaming/model.py b/funasr/models/paraformer_streaming/model.py
index cebbfc1..33ec976 100644
--- a/funasr/models/paraformer_streaming/model.py
+++ b/funasr/models/paraformer_streaming/model.py
@@ -566,7 +566,7 @@
         max_seq_len=512,
         **kwargs,
     ):
-    
+        self.device = kwargs.get("device")
         is_onnx = kwargs.get("type", "onnx") == "onnx"
         encoder_class = tables.encoder_classes.get(kwargs["encoder"] + "Export")
         self.encoder = encoder_class(self.encoder, onnx=is_onnx)
@@ -579,15 +579,10 @@
         decoder_class = tables.decoder_classes.get(kwargs["decoder"] + "Export")
         self.decoder = decoder_class(self.decoder, onnx=is_onnx)
     
-        from funasr.utils.torch_function import MakePadMask
         from funasr.utils.torch_function import sequence_mask
-    
-        if is_onnx:
-            self.make_pad_mask = MakePadMask(max_seq_len, flip=False)
-        else:
-            self.make_pad_mask = sequence_mask(max_seq_len, flip=False)
-    
-        self.forward = self._export_forward
+
+
+        self.make_pad_mask = sequence_mask(max_seq_len, flip=False)
 
         import copy
         import types
@@ -595,7 +590,7 @@
         decoder_model = copy.copy(self)
 
         # encoder
-        encoder_model.forward = types.MethodType(ParaformerStreaming._export_encoder_forward, encoder_model)
+        encoder_model.forward = types.MethodType(ParaformerStreaming.export_encoder_forward, encoder_model)
         encoder_model.export_dummy_inputs = types.MethodType(ParaformerStreaming.export_encoder_dummy_inputs, encoder_model)
         encoder_model.export_input_names = types.MethodType(ParaformerStreaming.export_encoder_input_names, encoder_model)
         encoder_model.export_output_names = types.MethodType(ParaformerStreaming.export_encoder_output_names, encoder_model)
@@ -603,7 +598,7 @@
         encoder_model.export_name = types.MethodType(ParaformerStreaming.export_encoder_name, encoder_model)
         
         # decoder
-        decoder_model.forward = types.MethodType(ParaformerStreaming._export_decoder_forward, decoder_model)
+        decoder_model.forward = types.MethodType(ParaformerStreaming.export_decoder_forward, decoder_model)
         decoder_model.export_dummy_inputs = types.MethodType(ParaformerStreaming.export_decoder_dummy_inputs, decoder_model)
         decoder_model.export_input_names = types.MethodType(ParaformerStreaming.export_decoder_input_names, decoder_model)
         decoder_model.export_output_names = types.MethodType(ParaformerStreaming.export_decoder_output_names, decoder_model)
@@ -612,7 +607,7 @@
     
         return encoder_model, decoder_model
 
-    def _export_encoder_forward(
+    def export_encoder_forward(
         self,
         speech: torch.Tensor,
         speech_lengths: torch.Tensor,
@@ -663,7 +658,7 @@
     def export_encoder_name(self):
         return "model.onnx"
     
-    def _export_decoder_forward(
+    def export_decoder_forward(
         self,
         enc: torch.Tensor,
         enc_len: torch.Tensor,

--
Gitblit v1.9.1