Skip to content

Commit 12f147e

Browse files
committed
cleanup
1 parent 70f1e79 commit 12f147e

3 files changed

Lines changed: 8 additions & 26 deletions

File tree

‎packages/react-native-executorch/common/runner/text_decoder_runner.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ TextDecoderRunner::step(TensorPtr &tokens, int64_t start_pos) {
5353
auto inputs_res = io_manager_->prepare_decode(tokens, start_pos_tensor);
5454
ET_CHECK_OK_OR_RETURN_ERROR(inputs_res.error());
5555
inputs = inputs_res.get();
56-
auto outputs_res = module_->execute("forward", inputs);
56+
auto outputs_res = module_->forward(inputs);
5757
ET_CHECK_OK_OR_RETURN_ERROR(outputs_res.error());
5858

5959
auto update_err = io_manager_->update_decode(outputs_res.get());

‎packages/react-native-executorch/common/runner/text_runner.cpp‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ TextRunner::TextRunner(std::unique_ptr<Module> module,
1616
: BaseLLMRunner(std::move(module), tokenizer_path, config) {}
1717

1818
bool TextRunner::is_loaded() const {
19-
#ifdef RNEX_BYPASS_TOKENIZER
20-
return module_ && module_->is_loaded() && text_decoder_runner_ &&
21-
text_prefiller_ && text_token_generator_;
22-
#else
2319
return module_ && module_->is_loaded() && tokenizer_ &&
2420
tokenizer_->is_loaded() && text_decoder_runner_ && text_prefiller_ &&
2521
text_token_generator_;
26-
#endif
2722
}
2823

2924
Error TextRunner::load_subcomponents() {

‎packages/react-native-executorch/common/runner/text_token_generator.h‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <executorch/extension/tensor/tensor.h>
1717
#include <pytorch/tokenizers/hf_tokenizer.h>
1818
#include <rnexecutorch/Error.h>
19-
#include <rnexecutorch/Log.h>
2019

2120
namespace executorch {
2221
namespace extension {
@@ -108,8 +107,6 @@ class TextTokenGenerator {
108107
pos++;
109108
generated_tokens.push_back(cur_token);
110109

111-
const bool eos_reached_now = eos_ids_->find(cur_token) != eos_ids_->end();
112-
113110
if (use_kv_cache_) {
114111
// update the token tensor. token_data will not be empty.
115112
// NOLINTNEXTLINE(facebook-hte-LocalUncheckedArrayBounds)
@@ -121,22 +118,6 @@ class TextTokenGenerator {
121118
tokens_managed, {1, static_cast<int>(token_data.size())}));
122119
}
123120

124-
// Don't include the terminal EOS/EOT token in the streamed text — it
125-
// would otherwise be appended to the assistant message stored in chat
126-
// history and corrupt the next turn's chat-template rendering
127-
// (e.g. duplicated <end_of_turn>).
128-
if (eos_reached_now) {
129-
if (!token_cache.empty()) {
130-
auto flush = tokenizer_->decode(token_cache, false);
131-
if (flush.ok() && !flush.get().empty() &&
132-
!flush.get().ends_with("�") && token_callback) {
133-
token_callback(flush.get());
134-
}
135-
token_cache.clear();
136-
}
137-
break;
138-
}
139-
140121
token_cache.push_back(static_cast<uint64_t>(cur_token));
141122

142123
// print the token as string, decode it with the Tokenizer object
@@ -161,7 +142,7 @@ class TextTokenGenerator {
161142
const auto eos_reached = eos_ids_->contains(cur_token);
162143

163144
if (!cache_decoded.ends_with("�") &&
164-
(countIntervalElapsed || timeIntervalElapsed || should_stop_)) {
145+
(countIntervalElapsed || timeIntervalElapsed || should_stop_ || eos_reached)) {
165146
token_callback(cache_decoded);
166147
token_cache.clear();
167148
timestamp_ = std::chrono::high_resolution_clock::now();
@@ -170,6 +151,12 @@ class TextTokenGenerator {
170151
if (should_stop_) {
171152
break;
172153
}
154+
// data-dependent terminating condition: we have n_eos_ number of EOS
155+
if (eos_ids_->find(cur_token) != eos_ids_->end()) {
156+
printf("\n");
157+
ET_LOG(Info, "\nReached to the end of generation");
158+
break;
159+
}
173160
}
174161
return pos - start_pos;
175162
}

0 commit comments

Comments
 (0)