From 70645e48072bf193fbf069949f1d2b10fddac8a3 Mon Sep 17 00:00:00 2001
From: pointerhacker <145901472+pointerhacker@users.noreply.github.com>
Date: 星期二, 15 十月 2024 17:50:51 +0800
Subject: [PATCH] 数据并行可能导致的模型训练报错 (#2139)
---
runtime/onnxruntime/src/funasrruntime.cpp | 25 +++++++++++++++----------
1 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/runtime/onnxruntime/src/funasrruntime.cpp b/runtime/onnxruntime/src/funasrruntime.cpp
index 31f8a95..88a3970 100644
--- a/runtime/onnxruntime/src/funasrruntime.cpp
+++ b/runtime/onnxruntime/src/funasrruntime.cpp
@@ -207,7 +207,8 @@
// APIs for Offline-stream Infer
_FUNASRAPI FUNASR_RESULT FunOfflineInferBuffer(FUNASR_HANDLE handle, const char* sz_buf, int n_len,
FUNASR_MODE mode, QM_CALLBACK fn_callback, const std::vector<std::vector<float>> &hw_emb,
- int sampling_rate, std::string wav_format, bool itn, FUNASR_DEC_HANDLE dec_handle)
+ int sampling_rate, std::string wav_format, bool itn, FUNASR_DEC_HANDLE dec_handle,
+ std::string svs_lang, bool svs_itn)
{
funasr::OfflineStream* offline_stream = (funasr::OfflineStream*)handle;
if (!offline_stream)
@@ -250,13 +251,18 @@
std::string cur_stamp = "[";
std::string lang = (offline_stream->asr_handle)->GetLang();
- while (audio.Fetch(buff, len, flag, start_time, batch_size, batch_in) > 0) {
+ while (audio.FetchDynamic(buff, len, flag, start_time, batch_size, batch_in) > 0) {
// dec reset
funasr::WfstDecoder* wfst_decoder = (funasr::WfstDecoder*)dec_handle;
if (wfst_decoder){
wfst_decoder->StartUtterance();
}
- vector<string> msg_batch = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb, dec_handle, batch_in);
+ vector<string> msg_batch;
+ if(offline_stream->GetModelType() == MODEL_SVS){
+ msg_batch = (offline_stream->asr_handle)->Forward(buff, len, true, svs_lang, svs_itn, batch_in);
+ }else{
+ msg_batch = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb, dec_handle, batch_in);
+ }
for(int idx=0; idx<batch_in; idx++){
string msg = msg_batch[idx];
if(msg_idx < index_vector.size()){
@@ -280,7 +286,7 @@
}
for(int idx=0; idx<msgs.size(); idx++){
string msg = msgs[idx];
- std::vector<std::string> msg_vec = funasr::split(msg, '|');
+ std::vector<std::string> msg_vec = funasr::SplitStr(msg, " | ");
if(msg_vec.size()==0){
continue;
}
@@ -372,13 +378,12 @@
std::string cur_stamp = "[";
std::string lang = (offline_stream->asr_handle)->GetLang();
- while (audio.Fetch(buff, len, flag, start_time, batch_size, batch_in) > 0) {
+ while (audio.FetchDynamic(buff, len, flag, start_time, batch_size, batch_in) > 0) {
// dec reset
funasr::WfstDecoder* wfst_decoder = (funasr::WfstDecoder*)dec_handle;
if (wfst_decoder){
wfst_decoder->StartUtterance();
}
- vector<string> msgs = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb, dec_handle, batch_in);
vector<string> msg_batch = (offline_stream->asr_handle)->Forward(buff, len, true, hw_emb, dec_handle, batch_in);
for(int idx=0; idx<batch_in; idx++){
string msg = msg_batch[idx];
@@ -403,7 +408,7 @@
}
for(int idx=0; idx<msgs.size(); idx++){
string msg = msgs[idx];
- std::vector<std::string> msg_vec = funasr::split(msg, '|');
+ std::vector<std::string> msg_vec = funasr::SplitStr(msg, " | ");
if(msg_vec.size()==0){
continue;
}
@@ -447,7 +452,7 @@
return p_result;
}
-#if !defined(__APPLE__)
+//#if !defined(__APPLE__)
_FUNASRAPI const std::vector<std::vector<float>> CompileHotwordEmbedding(FUNASR_HANDLE handle, std::string &hotwords, ASR_TYPE mode)
{
if (mode == ASR_OFFLINE){
@@ -471,7 +476,7 @@
}
}
-#endif
+//#endif
// APIs for 2pass-stream Infer
_FUNASRAPI FUNASR_RESULT FunTpassInferBuffer(FUNASR_HANDLE handle, FUNASR_HANDLE online_handle, const char* sz_buf,
@@ -564,7 +569,7 @@
len[0] = frame->len;
vector<string> msgs = ((funasr::Paraformer*)asr_handle)->Forward(buff, len, frame->is_final, hw_emb, dec_handle);
string msg = msgs.size()>0?msgs[0]:"";
- std::vector<std::string> msg_vec = funasr::split(msg, '|'); // split with timestamp
+ std::vector<std::string> msg_vec = funasr::SplitStr(msg, " | "); // split with timestamp
if(msg_vec.size()==0){
continue;
}
--
Gitblit v1.9.1