diff --git a/extension/benchmark/apple/Benchmark/Benchmark.xcodeproj/project.pbxproj b/extension/benchmark/apple/Benchmark/Benchmark.xcodeproj/project.pbxproj index 3c8173d5bff..8a75010af6f 100644 --- a/extension/benchmark/apple/Benchmark/Benchmark.xcodeproj/project.pbxproj +++ b/extension/benchmark/apple/Benchmark/Benchmark.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 0314AE3A2E2AAEE700DDE821 /* executorch_llm in Frameworks */ = {isa = PBXBuildFile; productRef = 0314AE392E2AAEE700DDE821 /* executorch_llm */; }; - 032A73CA2CAFBA8600932D36 /* LLaMATests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 032A73C82CAFBA8600932D36 /* LLaMATests.mm */; }; + 032A73CA2CAFBA8600932D36 /* LLMTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 032A73C82CAFBA8600932D36 /* LLMTests.mm */; }; 0351D9D72CAFC9A200607121 /* Resources in Resources */ = {isa = PBXBuildFile; fileRef = 03C7FA322C8AA24200E6E9AE /* Resources */; }; 03B0118E2CAC567900054791 /* DynamicTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B0118C2CAC567900054791 /* DynamicTestCase.m */; }; 03B011912CAD114E00054791 /* ResourceTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 03B011902CAD114E00054791 /* ResourceTestCase.m */; }; @@ -35,7 +35,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 032A73C82CAFBA8600932D36 /* LLaMATests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LLaMATests.mm; sourceTree = ""; }; + 032A73C82CAFBA8600932D36 /* LLMTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LLMTests.mm; sourceTree = ""; }; 037C96A02C8A570B00B3DF38 /* Tests.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tests.xctestplan; sourceTree = ""; }; 03B0118B2CAC567900054791 /* DynamicTestCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DynamicTestCase.h; sourceTree = ""; }; 03B0118C2CAC567900054791 /* DynamicTestCase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DynamicTestCase.m; sourceTree = ""; }; @@ -76,12 +76,12 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 032A73C92CAFBA8600932D36 /* LLaMA */ = { + 032A73C92CAFBA8600932D36 /* LLM */ = { isa = PBXGroup; children = ( - 032A73C82CAFBA8600932D36 /* LLaMATests.mm */, + 032A73C82CAFBA8600932D36 /* LLMTests.mm */, ); - path = LLaMA; + path = LLM; sourceTree = ""; }; 03B0118D2CAC567900054791 /* TestUtils */ = { @@ -127,7 +127,7 @@ 03B2D3782C8A515C0046936E /* Tests */ = { isa = PBXGroup; children = ( - 032A73C92CAFBA8600932D36 /* LLaMA */, + 032A73C92CAFBA8600932D36 /* LLM */, 03E7E6782CBDC1C900205E71 /* CoreMLTests.mm */, 03B2D3792C8A515C0046936E /* GenericTests.mm */, 037C96A02C8A570B00B3DF38 /* Tests.xctestplan */, @@ -241,7 +241,7 @@ 03B011912CAD114E00054791 /* ResourceTestCase.m in Sources */, 03E7E6792CBDCAE900205E71 /* CoreMLTests.mm in Sources */, 03B2D37A2C8A515C0046936E /* GenericTests.mm in Sources */, - 032A73CA2CAFBA8600932D36 /* LLaMATests.mm in Sources */, + 032A73CA2CAFBA8600932D36 /* LLMTests.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/extension/benchmark/apple/Benchmark/Tests/LLaMA/LLaMATests.mm b/extension/benchmark/apple/Benchmark/Tests/LLM/LLMTests.mm similarity index 81% rename from extension/benchmark/apple/Benchmark/Tests/LLaMA/LLaMATests.mm rename to extension/benchmark/apple/Benchmark/Tests/LLM/LLMTests.mm index 0f509f2809c..eac95073d95 100644 --- a/extension/benchmark/apple/Benchmark/Tests/LLaMA/LLaMATests.mm +++ b/extension/benchmark/apple/Benchmark/Tests/LLM/LLMTests.mm @@ -42,10 +42,10 @@ - (id)copyWithZone:(NSZone *)zone { @end -@interface LLaMATests : ResourceTestCase +@interface LLMTests : ResourceTestCase @end -@implementation LLaMATests +@implementation LLMTests + (NSArray *)directories { return @[ @@ -87,9 +87,10 @@ @implementation LLaMATests for (NSUInteger index = 2; specialTokens.count < 256; ++index) { [specialTokens addObject:[NSString stringWithFormat:@"<|reserved_special_token_%zu|>", index]]; } - auto __block runner = [[ExecuTorchLLMTextRunner alloc] initWithModelPath:modelPath - tokenizerPath:tokenizerPath - specialTokens:specialTokens]; + ExecuTorchLLMTextRunner *__block runner = + [[ExecuTorchLLMTextRunner alloc] initWithModelPath:modelPath + tokenizerPath:tokenizerPath + specialTokens:specialTokens]; NSError *error; BOOL status = [runner loadWithError:&error]; if (!status) { @@ -100,12 +101,14 @@ @implementation LLaMATests [testCase measureWithMetrics:@[ tokensPerSecondMetric, [XCTClockMetric new], [XCTMemoryMetric new] ] block:^{ tokensPerSecondMetric.tokenCount = 0; - BOOL status = [runner generate:@"Once upon a time" - sequenceLength:50 - withTokenCallback:^(NSString *token) { - tokensPerSecondMetric.tokenCount++; + BOOL status = [runner generateWithPrompt:@"Once upon a time" + config:[[ExecuTorchLLMConfig alloc] initWithBlock:^(ExecuTorchLLMConfig *config) { + config.sequenceLength = 50; + }] + tokenCallback:^(NSString *token) { + ++tokensPerSecondMetric.tokenCount; } - error:NULL]; + error:NULL]; XCTAssertTrue(status); }]; }, diff --git a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.h b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.h index 3eb7226ba76..8523581da8a 100644 --- a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.h +++ b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.h @@ -193,10 +193,10 @@ __attribute__((objc_subclassing_restricted)) @param error On failure, populated with an NSError explaining the issue. @return YES if generation completes successfully, NO if an error occurred. */ -- (BOOL)generate:(NSArray *)inputs - config:(ExecuTorchLLMConfig *)config -withTokenCallback:(nullable void (^)(NSString *))callback - error:(NSError **)error +- (BOOL)generateWithInputs:(NSArray *)inputs + config:(ExecuTorchLLMConfig *)config + tokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error NS_SWIFT_NAME(generate(_:_:tokenCallback:)); /** diff --git a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.mm b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.mm index dd9b2065a26..a3dc3e6afd1 100644 --- a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.mm +++ b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMMultimodalRunner.mm @@ -162,10 +162,10 @@ - (BOOL)loadWithError:(NSError**)error { return YES; } -- (BOOL)generate:(NSArray *)inputs - config:(ExecuTorchLLMConfig *)config -withTokenCallback:(nullable void (^)(NSString *))callback - error:(NSError **)error { +- (BOOL)generateWithInputs:(NSArray *)inputs + config:(ExecuTorchLLMConfig *)config + tokenCallback:(nullable void (^)(NSString *))callback + error:(NSError **)error { if (![self loadWithError:error]) { return NO; } diff --git a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.h b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.h index 3d42c4853f1..550a20ea633 100644 --- a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.h +++ b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.h @@ -60,10 +60,10 @@ __attribute__((deprecated("This API is experimental."))) @param error On failure, populated with an NSError explaining the issue. @return YES if generation completes successfully, NO if an error occurred. */ -- (BOOL)generate:(NSString *)prompt - config:(ExecuTorchLLMConfig *)config -withTokenCallback:(nullable void (^)(NSString *token))callback - error:(NSError **)error +- (BOOL)generateWithPrompt:(NSString *)prompt + config:(ExecuTorchLLMConfig *)config + tokenCallback:(nullable void (^)(NSString *token))callback + error:(NSError **)error NS_SWIFT_NAME(generate(_:_:tokenCallback:)); /** diff --git a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.mm b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.mm index 6ce854a52f8..4ea1bd921f7 100644 --- a/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.mm +++ b/extension/llm/apple/ExecuTorchLLM/Exported/ExecuTorchLLMTextRunner.mm @@ -74,10 +74,10 @@ - (BOOL)loadWithError:(NSError**)error { return YES; } -- (BOOL)generate:(NSString*)prompt - config:(ExecuTorchLLMConfig *)config -withTokenCallback:(nullable void (^)(NSString*))callback - error:(NSError**)error { +- (BOOL)generateWithPrompt:(NSString*)prompt + config:(ExecuTorchLLMConfig *)config + tokenCallback:(nullable void (^)(NSString*))callback + error:(NSError**)error { if (![self loadWithError:error]) { return NO; }