From 172a3152b42af36443ec6a0a39969471c35b893d Mon Sep 17 00:00:00 2001
From: maliubiao <maliubiao@gmail.com>
Date: 星期日, 29 十二月 2024 22:33:22 +0800
Subject: [PATCH] 允许 model.generate 使用bytes io, 以便不写入文件,节省io时间 (#2343)

---
 runtime/onnxruntime/src/ct-transformer-online.cpp |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/runtime/onnxruntime/src/ct-transformer-online.cpp b/runtime/onnxruntime/src/ct-transformer-online.cpp
index 769bb65..83c0327 100644
--- a/runtime/onnxruntime/src/ct-transformer-online.cpp
+++ b/runtime/onnxruntime/src/ct-transformer-online.cpp
@@ -42,6 +42,11 @@
     vector<int> InputData;
     string strText; //full_text
     strText = accumulate(arr_cache.begin(), arr_cache.end(), strText);
+
+    // 濡傛灉涓婁竴鍙ョ殑缁撳熬鏄嫳璇瓧姣嶏紝骞朵笖杩欎竴鍙ョ殑寮�濮嬩篃鏄嫳璇瓧姣嶏紝搴旇娣诲姞绌烘牸
+    if ((strText.size() > 0 and !(strText[strText.size()-1] & 0x80)) && (strlen(sz_input) > 0 && !(sz_input[0] & 0x80)))
+        strText += " ";
+
     strText += sz_input;  // full_text = precache + text  
     m_tokenizer.Tokenize(strText.c_str(), strOut, InputData);
 
@@ -107,7 +112,7 @@
     {
         if (!(sentence_words_list[i][0] & 0x80) && (i + 1) < sentence_words_list.size() && !(sentence_words_list[i + 1][0] & 0x80))
         {
-            sentence_words_list[i] = " " + sentence_words_list[i];
+            sentence_words_list[i] = sentence_words_list[i] + " ";
         }
         if (nSkipNum < arr_cache.size())  //    if skip_num < len(cache):
             nSkipNum++;

--
Gitblit v1.9.1