@@ -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
99104void 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
112117void 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 ' ); }
0 commit comments