Skip to content

Commit 95d99fa

Browse files
authored
[iOS][SDK] Updated Executorch with upstream main branch (NimbleEdge#169)
* updated executorch_llm_executor * updated setup.sh --------- Signed-off-by: Suryansh Bisen <suryansh.bisen@nimbleedgehq.ai>
1 parent bec658a commit 95d99fa

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android:
1111
cmake_args: "-DANDROID_STL=c++_shared -DEXECUTORCH_EXECUTOR=0 -DONNXBuild=1_21_0_full -DONNXgenai=0_7_0_onnx_genai -DONNXext=0_13_0_ort_extensions -DMINIMAL_BUILD=0 -DExecutorchgenai=d4906e21_executorch -DGEMINI=1"
1212

1313
ios:
14-
cmake_args: "-DIOS=1 -DEXECUTORCH_EXECUTOR=0 -DONNXBuild=1_21_0_ios_full -DONNXgenai=0_7_0_ios_onnx-genai -DONNXext=0_13_0_ort_extension -DMINIMAL_BUILD=0 -DExecutorchgenai=d4906e21_executorch"
14+
cmake_args: "-DIOS=1 -DONNXGENAI_EXECUTOR=0 -DEXECUTORCH_EXECUTOR=1 -DONNXBuild=1_21_0_ios_full -DONNXgenai=0_7_0_ios_onnx-genai -DONNXext=0_13_0_ort_extension -DMINIMAL_BUILD=0 -DExecutorchgenai=e9c11a40_executorch"
1515

1616
react:
1717
ndk: "21.4.7075529"

coreruntime/nimblenet/llm_executors/include/executorch_llm_executor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "base_llm_executor.hpp"
1010
#include "task.hpp"
1111
#ifdef EXECUTORCH_EXECUTOR
12-
#include "executorch/extension/llm/runner/runner.h"
12+
#include "executorch/extension/llm/runner/text_llm_runner.h"
1313
#endif // EXECUTORCH_EXECUTOR
1414
#include "ne_fwd.hpp"
1515
#include "rigtorp/SPSCQueue.h"

coreruntime/nimblenet/llm_executors/src/executorch_llm_executor.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ ExecutorchLLMExecutor::ExecutorchLLMExecutor(
2323
_temperature = temperature;
2424

2525
try {
26-
_runner = example::Runner::create(modelDirectoryPath + "/" + pteFileName + ".pte",
27-
modelDirectoryPath + "/" + tokenizerFileName, std::nullopt,
26+
_runner = executorch::extension::llm::create_text_llm_runner(modelDirectoryPath + "/" + pteFileName + ".pte",
27+
executorch::extension::llm::load_tokenizer(modelDirectoryPath + "/" + tokenizerFileName), std::nullopt,
2828
temperature);
2929
_runner->load();
3030
if (!_runner->is_loaded()) {
@@ -42,6 +42,11 @@ std::shared_ptr<CharStream> ExecutorchLLMExecutor::run_prompt(const std::string&
4242
std::lock_guard<std::mutex> lock{_mutex};
4343

4444
stop_inference_thread();
45+
if (!_runner->is_loaded()) {
46+
LOG_TO_CLIENT_ERROR("LLM Runner is not loaded");
47+
_runner->load();
48+
}
49+
4550
// Creating these variables again to drop ones used by previous inference
4651
_charStream = CharStream::construct();
4752
_internalQueue = std::make_shared<Queue>(_executorConfig.internalQueueSize);
@@ -82,31 +87,31 @@ void ExecutorchLLMExecutor::run_inference(const std::string& prompt) {
8287
try {
8388
executorch::extension::llm::GenerationConfig config{
8489
.echo = false,
85-
.seq_len = _executorConfig.maxInputNumTokens,
8690
.temperature = _temperature,
8791
};
88-
auto status = _runner->generate_from_pos(prompt, config, _start_pos, token_callback, {});
92+
if (!_runner->is_loaded()) {
93+
_runner->load();
94+
}
95+
auto status = _runner->generate(prompt, config, token_callback, {});
8996
if (status != ::executorch::runtime::Error::Ok) {
9097
mark_end_of_stream();
91-
LOG_TO_CLIENT_ERROR("Error while running inference on LLM using executorch.");
9298
}
9399
} catch (const std::exception& e) {
94100
mark_end_of_stream();
95-
LOG_TO_CLIENT_ERROR("Error: %s while running inference on LLM using executorch.", e.what());
96101
}
97102
}
98103

99104
void ExecutorchLLMExecutor::add_prompt(const std::string& prompt) {
100105
std::lock_guard<std::mutex> lock{_mutex};
101106
stop_inference_thread();
102-
try {
103-
auto status = _runner->prefill_prompt(prompt, _start_pos, 0, 0);
104-
if (!status.ok()) {
105-
LOG_TO_CLIENT_ERROR("Error while setting context in LLM using executorch.");
106-
}
107-
} catch (const std::exception& e) {
108-
LOG_TO_CLIENT_ERROR("Error: %s while setting context in LLM using executorch.", e.what());
109-
}
107+
// try {
108+
// auto status = _runner->prefill_prompt(prompt, _start_pos, 0, 0);
109+
// if (!status.ok()) {
110+
// LOG_TO_CLIENT_ERROR("Error while setting context in LLM using executorch.");
111+
// }
112+
// } catch (const std::exception& e) {
113+
// LOG_TO_CLIENT_ERROR("Error: %s while setting context in LLM using executorch.", e.what());
114+
// }
110115
}
111116

112117
void ExecutorchLLMExecutor::cancel() {
@@ -133,4 +138,4 @@ void ExecutorchLLMExecutor::stop_inference_thread() {
133138
_internalQueue = nullptr;
134139
}
135140

136-
void ExecutorchLLMExecutor::mark_end_of_stream() { _internalQueue->push('\0'); }
141+
void ExecutorchLLMExecutor::mark_end_of_stream() { _internalQueue->push('\0'); }

setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ elif [[ "$sdk" == "ios" ]]; then
192192
fi
193193

194194
if [[ $download_executorch -eq 1 ]]; then
195-
mkdir -p third_party/runtime/executorch/ios/d4906e21_executorch
196-
aws s3 cp s3://deliteai/build-dependencies/executorch-d4906e21/ios third_party/runtime/executorch/ios/d4906e21_executorch --recursive --no-sign-request
195+
mkdir -p third_party/runtime/executorch/ios/e9c11a40_executorch
196+
aws s3 cp s3://deliteai/build-dependencies/executorch-e9c11a40/ios third_party/runtime/executorch/ios/e9c11a40_executorch --recursive --no-sign-request
197197
fi
198198
fi
199199

0 commit comments

Comments
 (0)