99#import " LLaMARunner.h"
1010
1111#import < ExecuTorch/ExecuTorchLog.h>
12- #import < executorch/examples/models/llama/runner/runner.h>
12+ #import < executorch/extension/llm/runner/text_llm_runner.h>
13+ #import < executorch/examples/models/llama/tokenizer/llama_tiktoken.h>
1314
14- using executorch::extension::llm::GenerationConfig;
15- using executorch::extension::llm::TextLLMRunner;
16- using executorch::runtime::Error;
15+ using namespace executorch ::extension;
16+ using namespace executorch ::runtime;
1717
1818NSErrorDomain const LLaMARunnerErrorDomain = @" LLaMARunnerErrorDomain" ;
1919
2020@interface LLaMARunner ()<ExecuTorchLogSink>
2121@end
2222
2323@implementation LLaMARunner {
24- std::unique_ptr<TextLLMRunner> _runner;
24+ std::unique_ptr<llm:: TextLLMRunner> _runner;
2525}
2626
2727- (instancetype )initWithModelPath : (NSString *)modelPath
2828 tokenizerPath : (NSString *)tokenizerPath {
2929 self = [super init ];
3030 if (self) {
3131 [ExecuTorchLog.sharedLog addSink: self ];
32- _runner = example::create_llama_runner (
33- modelPath.UTF8String , tokenizerPath.UTF8String );
32+ _runner = llm::create_text_llm_runner (
33+ modelPath.UTF8String ,
34+ llm::load_tokenizer (
35+ tokenizerPath.UTF8String ,
36+ example::get_special_tokens (example::Version::Default)
37+ )
38+ );
3439 }
3540 return self;
3641}
@@ -60,20 +65,19 @@ - (BOOL)generate:(NSString*)prompt
6065 sequenceLength : (NSInteger )seq_len
6166 withTokenCallback : (nullable void (^)(NSString *))callback
6267 error:(NSError **)error {
63- const GenerationConfig config{
64- .seq_len = static_cast <int32_t >(seq_len)
65- };
6668 const auto status = _runner->generate (
67- prompt.UTF8String , config, [callback](const std::string& token) {
69+ prompt.UTF8String ,
70+ llm::GenerationConfig{.seq_len = static_cast <int32_t >(seq_len)},
71+ [callback](const std::string& token) {
6872 callback (@(token.c_str ()));
6973 });
7074 if (status != Error::Ok) {
7175 if (error) {
7276 *error = [NSError errorWithDomain: LLaMARunnerErrorDomain
7377 code: (NSInteger )status
7478 userInfo: nil ];
75- return NO ;
7679 }
80+ return NO ;
7781 }
7882 return YES ;
7983}
@@ -95,15 +99,16 @@ - (void)logWithLevel:(ExecuTorchLogLevel)level
9599 NSUInteger seconds = totalSeconds % 60 ;
96100 NSUInteger microseconds = (timestamp - totalSeconds) * 1000000 ;
97101 NSLog (
98- @" %c %02lu :%02lu :%02lu .%06lu executorch:%s :%zu ] %s " ,
99- (char )level,
100- hours,
101- minutes,
102- seconds,
103- microseconds,
104- filename.UTF8String,
105- line,
106- message.UTF8String);
102+ @" %c %02lu :%02lu :%02lu .%06lu executorch:%s :%zu ] %s " ,
103+ (char )level,
104+ hours,
105+ minutes,
106+ seconds,
107+ microseconds,
108+ filename.UTF8String,
109+ line,
110+ message.UTF8String
111+ );
107112}
108113
109114@end
0 commit comments