Skip to content

Commit d3a699f

Browse files
author
LittleMouse
committed
[fix] Fix the bug that token was truncated incorrectly
1 parent 8a3d162 commit d3a699f

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

  • projects/llm_framework

projects/llm_framework/main_llm/src/runner/LLM.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,16 @@ class LLM
579579
if (_attr.runing_callback)
580580
{
581581
cached_token.push_back(max_index);
582-
if (cached_token.size() >= 5)
582+
if (cached_token.size() >= 3)
583583
{
584584
float t_cost_ms = t_cost.cost();
585585
float token_per_sec = token_ids.size() / (t_cost_ms / 1000);
586586
auto tmp_out = tokenizer->Decode(cached_token);
587-
_attr.runing_callback(cached_token.data(), cached_token.size(), tmp_out.c_str(), token_per_sec, _attr.reserve);
588-
cached_token.clear();
587+
if (!tmp_out.empty() && tmp_out.back() != 0xBD)
588+
{
589+
_attr.runing_callback(cached_token.data(), cached_token.size(), tmp_out.c_str(), token_per_sec, _attr.reserve);
590+
cached_token.clear();
591+
}
589592
}
590593
}
591594
}

projects/llm_framework/main_vlm/src/runner/LLM.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,15 @@ class LLM {
619619

620620
if (_attr.runing_callback) {
621621
cached_token.push_back(max_index);
622-
if (cached_token.size() >= 5) {
622+
if (cached_token.size() >= 3) {
623623
float t_cost_ms = t_cost.cost();
624624
float token_per_sec = token_ids.size() / (t_cost_ms / 1000);
625625
auto tmp_out = tokenizer->Decode(cached_token);
626-
_attr.runing_callback(cached_token.data(), cached_token.size(), tmp_out.c_str(), token_per_sec,
627-
_attr.reserve);
628-
cached_token.clear();
626+
if (!tmp_out.empty() && tmp_out.back() != 0xBD) {
627+
_attr.runing_callback(cached_token.data(), cached_token.size(), tmp_out.c_str(),
628+
token_per_sec, _attr.reserve);
629+
cached_token.clear();
630+
}
629631
}
630632
}
631633
}

0 commit comments

Comments
 (0)