Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
19 changes: 11 additions & 8 deletions extension/benchmark/apple/Benchmark/Tests/LLaMA/LLaMATests.mm
Original file line number Diff line number Diff line change
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:[[ExecuTorchLLMGenerationConfig alloc] initWithBlock:^(ExecuTorchLLMGenerationConfig *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