Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -35,7 +35,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
032A73C82CAFBA8600932D36 /* LLaMATests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LLaMATests.mm; sourceTree = "<group>"; };
032A73C82CAFBA8600932D36 /* LLMTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LLMTests.mm; sourceTree = "<group>"; };
037C96A02C8A570B00B3DF38 /* Tests.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tests.xctestplan; sourceTree = "<group>"; };
03B0118B2CAC567900054791 /* DynamicTestCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DynamicTestCase.h; sourceTree = "<group>"; };
03B0118C2CAC567900054791 /* DynamicTestCase.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DynamicTestCase.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
};
03B0118D2CAC567900054791 /* TestUtils */ = {
Expand Down Expand Up @@ -127,7 +127,7 @@
03B2D3782C8A515C0046936E /* Tests */ = {
isa = PBXGroup;
children = (
032A73C92CAFBA8600932D36 /* LLaMA */,
032A73C92CAFBA8600932D36 /* LLM */,
03E7E6782CBDC1C900205E71 /* CoreMLTests.mm */,
03B2D3792C8A515C0046936E /* GenericTests.mm */,
037C96A02C8A570B00B3DF38 /* Tests.xctestplan */,
Expand Down Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ - (id)copyWithZone:(NSZone *)zone {

@end

@interface LLaMATests : ResourceTestCase
@interface LLMTests : ResourceTestCase
@end

@implementation LLaMATests
@implementation LLMTests

+ (NSArray<NSString *> *)directories {
return @[
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExecuTorchLLMMultimodalInput *> *)inputs
config:(ExecuTorchLLMConfig *)config
withTokenCallback:(nullable void (^)(NSString *))callback
error:(NSError **)error
- (BOOL)generateWithInputs:(NSArray<ExecuTorchLLMMultimodalInput *> *)inputs
config:(ExecuTorchLLMConfig *)config
tokenCallback:(nullable void (^)(NSString *))callback
error:(NSError **)error
NS_SWIFT_NAME(generate(_:_:tokenCallback:));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ - (BOOL)loadWithError:(NSError**)error {
return YES;
}

- (BOOL)generate:(NSArray<ExecuTorchLLMMultimodalInput *> *)inputs
config:(ExecuTorchLLMConfig *)config
withTokenCallback:(nullable void (^)(NSString *))callback
error:(NSError **)error {
- (BOOL)generateWithInputs:(NSArray<ExecuTorchLLMMultimodalInput *> *)inputs
config:(ExecuTorchLLMConfig *)config
tokenCallback:(nullable void (^)(NSString *))callback
error:(NSError **)error {
if (![self loadWithError:error]) {
return NO;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:));

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading