Skip to content

Commit 6c0167e

Browse files
committed
code cleanup
1 parent 938bc11 commit 6c0167e

11 files changed

Lines changed: 21 additions & 47 deletions

File tree

-4.93 MB
Binary file not shown.

‎apps/llm/app/llm/index.tsx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ function LLMScreen() {
4242
const { bottom } = useSafeAreaInsets();
4343
const [isTextInputFocused, setIsTextInputFocused] = useState(false);
4444
const [userInput, setUserInput] = useState('');
45+
const [selectedModel, setSelectedModel] = useState<LLMModelSources>(
46+
models.llm.lfm2_5_1_2b_instruct()
47+
);
4548
const textInputRef = useRef<TextInput>(null);
4649
const { setGlobalGenerating } = useContext(GeneratingContext);
4750

48-
let llm = Object();
49-
51+
const llm = useLLM({ model: selectedModel });
5052
const tokenCount = llm.isReady ? llm.getGeneratedTokenCount() : 0;
5153
const { stats, onMessageSend } = useLLMStats(
5254
llm.response,
@@ -110,6 +112,13 @@ function LLMScreen() {
110112
/>
111113
</View>
112114
)}
115+
116+
<ModelPicker
117+
models={LLM_MODELS}
118+
selectedModel={selectedModel}
119+
onSelect={(m) => setSelectedModel(m)}
120+
disabled={llm.isGenerating}
121+
/>
113122
<StatsBar stats={stats} />
114123
<View
115124
style={[

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ BaseLLMRunner::BaseLLMRunner(std::unique_ptr<Module> module,
1818
tokenizer_(std::make_unique<tokenizers::HFTokenizer>()),
1919
metadata_({
2020
{kEnableDynamicShape, false},
21-
{kMaxSeqLen, 2048},
22-
{kMaxContextLen, 2048},
21+
{kMaxSeqLen, 128},
22+
{kMaxContextLen, 128},
2323
{kUseKVCache, true},
2424
}) {}
2525

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class MultimodalPrefiller {
2828

2929
// Prefill one input segment. Updates start_pos in-place.
3030
// Returns the first predicted token after this segment.
31-
::executorch::runtime::Result<uint64_t> prefill(const MultimodalInput &input,
32-
int64_t &start_pos);
31+
::executorch::runtime::Result<uint64_t>
32+
prefill(const std::vector<MultimodalInput> &inputs, int64_t &start_pos);
3333

3434
::executorch::runtime::Error load();
3535
bool is_method_loaded();

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "constants.h"
44
#include "util.h"
55
#include <rnexecutorch/Error.h>
6-
#include <rnexecutorch/Log.h>
76

87
namespace executorch::extension::llm {
98

@@ -83,15 +82,10 @@ Error MultimodalRunner::generate_internal(
8382
}
8483

8584
stats_.inference_start_ms = time_in_ms();
86-
const long t_gen_begin = stats_.inference_start_ms;
87-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info, "inputs count", inputs.size());
8885
auto prefill_result = mm_prefiller_->prefill(inputs, pos_);
8986
if (!prefill_result.ok())
9087
return prefill_result.error();
9188
uint64_t prefill_next_token = prefill_result.get();
92-
const long t_prefill_done = time_in_ms();
93-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info, "prefill result",
94-
prefill_next_token);
9589

9690
stats_.first_token_ms = time_in_ms();
9791
stats_.prompt_eval_end_ms = time_in_ms();

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ TextDecoderRunner::step(TensorPtr &tokens, int64_t start_pos) {
3535
// dynamic "forward"; single-token decode steps go through the static
3636
// "forward_decode" method when present (avoids dynamic-shape re-encode
3737
// overhead — measured 8× faster on gemma4 Vulkan).
38-
const char* method_name = "forward";
39-
// if (tokens->numel() == 1) {
40-
// auto decode_meta = module_->method_meta("forward_decode");
41-
// if (decode_meta.ok()) {
42-
// method_name = "forward_decode";
43-
// }
44-
// }
38+
const char *method_name = "forward";
4539
auto method_meta_result = module_->method_meta(method_name);
4640
if (!method_meta_result.ok()) {
4741
return method_meta_result.error();

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,10 @@ TextPrefiller::TextPrefiller(TextDecoderRunner *text_decoder_runner,
2222
int64_t max_seq_len)
2323
: text_decoder_runner_(text_decoder_runner), use_kv_cache_(use_kv_cache),
2424
enable_parallel_prefill_(enable_parallel_prefill),
25-
max_seq_len_(max_seq_len > 0 ? max_seq_len : 2048) {
25+
max_seq_len_(max_seq_len > 0 ? max_seq_len : 128) {
2626
// Auto-detect static-shape prefill: when `forward` declares input 0 as
2727
// [1, N] with N>1, we must pad every prefill call to exactly N tokens.
2828
prefill_static_len_ = text_decoder_runner_->prefill_static_len();
29-
if (prefill_static_len_ > 0) {
30-
rnexecutorch::log(
31-
rnexecutorch::LOG_LEVEL::Info,
32-
"TextPrefiller: static prefill len detected =", prefill_static_len_);
33-
}
3429
}
3530

3631
::executorch::runtime::Result<uint64_t>
@@ -108,9 +103,6 @@ TextPrefiller::prefill_chunk(std::vector<uint64_t> &prompt_tokens,
108103
auto tokens = from_blob(tokens_ptr, {1, tensor_len},
109104
executorch::aten::ScalarType::Long);
110105

111-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info, "prefill effective_len",
112-
num_prompt_tokens, "tensor_len", tensor_len, "start_pos",
113-
start_pos);
114106
auto outputs_res = text_decoder_runner_->step(tokens, start_pos);
115107

116108
ET_CHECK_OK_OR_RETURN_ERROR(outputs_res.error());

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class TextTokenGenerator {
9090
timestamp_ = std::chrono::high_resolution_clock::now();
9191

9292
// Generate our tokens
93-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info, "kappa generator", pos, start_pos, max_new_tokens);
9493
while (pos < start_pos + max_new_tokens) {
9594
// Run the model
9695
auto logits_res = text_decoder_runner_->step(tokens_managed, pos);
@@ -101,8 +100,8 @@ class TextTokenGenerator {
101100
prev_token = cur_token;
102101

103102
stats_->on_sampling_begin();
104-
cur_token =
105-
text_decoder_runner_->logits_to_token(logits_tensor, generated_tokens);
103+
cur_token = text_decoder_runner_->logits_to_token(logits_tensor,
104+
generated_tokens);
106105
stats_->on_sampling_end();
107106

108107
pos++;
@@ -126,10 +125,6 @@ class TextTokenGenerator {
126125
// history and corrupt the next turn's chat-template rendering
127126
// (e.g. duplicated <end_of_turn>).
128127
if (eos_reached_now) {
129-
printf("\n");
130-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info,
131-
"Reached end of generation");
132-
#ifndef RNEX_BYPASS_TOKENIZER
133128
if (!token_cache.empty()) {
134129
auto flush = tokenizer_->decode(token_cache, false);
135130
if (flush.ok() && !flush.get().empty() &&
@@ -138,19 +133,11 @@ class TextTokenGenerator {
138133
}
139134
token_cache.clear();
140135
}
141-
#else
142-
token_cache.clear();
143-
#endif
144136
break;
145137
}
146138

147139
token_cache.push_back(static_cast<uint64_t>(cur_token));
148140

149-
#ifdef RNEX_BYPASS_TOKENIZER
150-
rnexecutorch::log(rnexecutorch::LOG_LEVEL::Info,
151-
"gen_token=" + std::to_string(cur_token));
152-
std::string cache_decoded = std::to_string(cur_token) + " ";
153-
#else
154141
// print the token as string, decode it with the Tokenizer object
155142
// We pass false, as we want don't want to skip special tokens e.g.
156143
// <think>
@@ -164,7 +151,6 @@ class TextTokenGenerator {
164151
std::to_string(static_cast<int32_t>(decodeResult.error())));
165152
}
166153
std::string cache_decoded = decodeResult.get();
167-
#endif
168154
const auto timeIntervalElapsed =
169155
std::chrono::duration_cast<std::chrono::milliseconds>(
170156
std::chrono::high_resolution_clock::now() - timestamp_)

‎packages/react-native-executorch/src/constants/modelRegistry.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,12 @@ export const models = {
496496
M.LFM2_5_1_2B_INSTRUCT_QUANTIZED
497497
),
498498
bielik_v3_0_1_5b: pair(M.BIELIK_V3_0_1_5B, M.BIELIK_V3_0_1_5B_QUANTIZED),
499+
gemma4_e2b: base(M.GEMMA4_E2B),
499500
// Multimodal LLMs — same hook/module as plain LLMs, listed here so users
500501
// pick a model by capability ("LLM") rather than by modality.
501502
lfm2_5_vl_1_6b: base(M.LFM2_5_VL_1_6B_QUANTIZED),
502503
lfm2_5_vl_450m: base(M.LFM2_5_VL_450M_QUANTIZED),
503-
gemma4_e2b: base(M.GEMMA4_E2B),
504+
gemma4_e2b_multimodal: base(M.GEMMA4_E2B_MM),
504505
},
505506
classification: {
506507
efficientnet_v2_s: variant(EFFICIENTNET_V2_S_VARIANTS),

‎packages/react-native-executorch/src/controllers/LLMController.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ export class LLMController {
310310
this.isGeneratingCallback(true);
311311
this.nativeModule.reset();
312312
let response: string;
313-
console.log(input);
314313
if (hasImages || hasAudio) {
315314
response = await this.nativeModule.generateMultimodal(
316315
input,

0 commit comments

Comments
 (0)