Skip to content

Commit a6d67c7

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Move LLaMA tests to a subdir.
Summary: . Reviewed By: kirklandsign Differential Revision: D63914432 fbshipit-source-id: 41a28e6c4fcfb20919193098a11a9585dd73e68a
1 parent a4fcdcd commit a6d67c7

File tree

3 files changed

+77
-75
lines changed

3 files changed

+77
-75
lines changed

extension/apple/Benchmark/Frameworks/download_frameworks.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ frameworks=(
1616
"kernels_quantized"
1717
)
1818

19+
cd "$(dirname "$0")" || exit
20+
1921
for framework in "${frameworks[@]}"; do
20-
rm -f "${f}-latest.zip"
21-
rm -rf "${f}.xcframework"
22+
rm -f "${framework}-latest.zip"
23+
rm -rf "${framework}.xcframework"
2224
curl -sSLO "https://ossci-ios.s3.amazonaws.com/executorch/${framework}-latest.zip" && \
2325
unzip -q "${framework}-latest.zip" && \
2426
rm "${framework}-latest.zip"

extension/apple/Benchmark/Tests/GenericTests.mm

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,62 +35,62 @@ @implementation GenericTests
3535
}
3636

3737
+ (NSDictionary<NSString *, BOOL (^)(NSString *)> *)predicates {
38-
return @{@"model" : ^BOOL(NSString *filename){
38+
return @{
39+
@"model" : ^BOOL(NSString *filename){
3940
return [filename hasSuffix:@".pte"];
40-
}
41-
}
42-
;
41+
},
42+
};
4343
}
4444

4545
+ (NSDictionary<NSString *, void (^)(XCTestCase *)> *)dynamicTestsForResources:
4646
(NSDictionary<NSString *, NSString *> *)resources {
4747
NSString *modelPath = resources[@"model"];
48-
return @{@"load" : ^(XCTestCase *testCase){
48+
return @{
49+
@"load" : ^(XCTestCase *testCase){
4950
[testCase
5051
measureWithMetrics:@[ [XCTClockMetric new], [XCTMemoryMetric new] ]
5152
block:^{
5253
XCTAssertEqual(
5354
Module(modelPath.UTF8String).load_forward(),
5455
Error::Ok);
5556
}];
56-
}
57-
, @"forward" : ^(XCTestCase *testCase) {
58-
auto __block module = std::make_unique<Module>(modelPath.UTF8String);
59-
60-
const auto method_meta = module->method_meta("forward");
61-
ASSERT_OK_OR_RETURN(method_meta);
62-
63-
const auto num_inputs = method_meta->num_inputs();
64-
XCTAssertGreaterThan(num_inputs, 0);
65-
66-
std::vector<TensorPtr> tensors;
67-
tensors.reserve(num_inputs);
68-
69-
for (auto index = 0; index < num_inputs; ++index) {
70-
const auto input_tag = method_meta->input_tag(index);
71-
ASSERT_OK_OR_RETURN(input_tag);
72-
73-
switch (*input_tag) {
74-
case Tag::Tensor: {
75-
const auto tensor_meta = method_meta->input_tensor_meta(index);
76-
ASSERT_OK_OR_RETURN(tensor_meta);
77-
78-
const auto sizes = tensor_meta->sizes();
79-
tensors.emplace_back(
80-
ones({sizes.begin(), sizes.end()}, tensor_meta->scalar_type()));
81-
XCTAssertEqual(module->set_input(tensors.back(), index), Error::Ok);
82-
} break;
83-
default:
84-
XCTFail("Unsupported tag %i at input %d", *input_tag, index);
85-
}
86-
}
87-
[testCase measureWithMetrics:@[ [XCTClockMetric new], [XCTMemoryMetric new] ]
88-
block:^{
89-
XCTAssertEqual(module->forward().error(), Error::Ok);
90-
}];
91-
}
92-
}
93-
;
57+
},
58+
@"forward" : ^(XCTestCase *testCase) {
59+
auto __block module = std::make_unique<Module>(modelPath.UTF8String);
60+
61+
const auto method_meta = module->method_meta("forward");
62+
ASSERT_OK_OR_RETURN(method_meta);
63+
64+
const auto num_inputs = method_meta->num_inputs();
65+
XCTAssertGreaterThan(num_inputs, 0);
66+
67+
std::vector<TensorPtr> tensors;
68+
tensors.reserve(num_inputs);
69+
70+
for (auto index = 0; index < num_inputs; ++index) {
71+
const auto input_tag = method_meta->input_tag(index);
72+
ASSERT_OK_OR_RETURN(input_tag);
73+
74+
switch (*input_tag) {
75+
case Tag::Tensor: {
76+
const auto tensor_meta = method_meta->input_tensor_meta(index);
77+
ASSERT_OK_OR_RETURN(tensor_meta);
78+
79+
const auto sizes = tensor_meta->sizes();
80+
tensors.emplace_back(
81+
ones({sizes.begin(), sizes.end()}, tensor_meta->scalar_type()));
82+
XCTAssertEqual(module->set_input(tensors.back(), index), Error::Ok);
83+
} break;
84+
default:
85+
XCTFail("Unsupported tag %i at input %d", *input_tag, index);
86+
}
87+
}
88+
[testCase measureWithMetrics:@[ [XCTClockMetric new], [XCTMemoryMetric new] ]
89+
block:^{
90+
XCTAssertEqual(module->forward().error(), Error::Ok);
91+
}];
92+
},
93+
};
9494
}
9595

9696
@end

extension/apple/Benchmark/Tests/LLaMATests.mm renamed to extension/apple/Benchmark/Tests/LLaMA/LLaMATests.mm

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,45 +58,45 @@ @implementation LLaMATests
5858
}
5959

6060
+ (NSDictionary<NSString *, BOOL (^)(NSString *)> *)predicates {
61-
return @{@"model" : ^BOOL(NSString *filename){
61+
return @{
62+
@"model" : ^BOOL(NSString *filename){
6263
return [filename hasSuffix:@".pte"] && [filename containsString:@"llama"];
63-
}
64-
, @"tokenizer" : ^BOOL(NSString *filename) {
65-
return [filename isEqual:@"tokenizer.model"];
66-
},
67-
}
68-
;
64+
},
65+
@"tokenizer" : ^BOOL(NSString *filename) {
66+
return [filename isEqual:@"tokenizer.model"];
67+
},
68+
};
6969
}
7070

7171
+ (NSDictionary<NSString *, void (^)(XCTestCase *)> *)dynamicTestsForResources:
7272
(NSDictionary<NSString *, NSString *> *)resources {
7373
NSString *modelPath = resources[@"model"];
7474
NSString *tokenizerPath = resources[@"tokenizer"];
75-
return @{@"generate" : ^(XCTestCase *testCase){
75+
return @{
76+
@"generate" : ^(XCTestCase *testCase){
7677
auto __block runner = std::make_unique<example::Runner>(
7778
modelPath.UTF8String, tokenizerPath.UTF8String);
78-
const auto status = runner->load();
79-
if (status != Error::Ok) {
80-
XCTFail("Load failed with error %i", status);
81-
return;
82-
}
83-
TokensPerSecondMetric *tokensPerSecondMetric = [TokensPerSecondMetric new];
84-
[testCase measureWithMetrics:@[ tokensPerSecondMetric, [XCTMemoryMetric new] ]
85-
block:^{
86-
tokensPerSecondMetric.tokenCount = 0;
87-
const auto status = runner->generate(
88-
"Once upon a time",
89-
128,
90-
[=](const std::string &token) {
91-
tokensPerSecondMetric.tokenCount++;
92-
},
93-
nullptr,
94-
false);
95-
XCTAssertEqual(status, Error::Ok);
96-
}];
97-
}
98-
}
99-
;
79+
const auto status = runner->load();
80+
if (status != Error::Ok) {
81+
XCTFail("Load failed with error %i", status);
82+
return;
83+
}
84+
TokensPerSecondMetric *tokensPerSecondMetric = [TokensPerSecondMetric new];
85+
[testCase measureWithMetrics:@[ tokensPerSecondMetric, [XCTMemoryMetric new] ]
86+
block:^{
87+
tokensPerSecondMetric.tokenCount = 0;
88+
const auto status = runner->generate(
89+
"Once upon a time",
90+
128,
91+
[=](const std::string &token) {
92+
tokensPerSecondMetric.tokenCount++;
93+
},
94+
nullptr,
95+
false);
96+
XCTAssertEqual(status, Error::Ok);
97+
}];
98+
},
99+
};
100100
}
101101

102102
@end

0 commit comments

Comments
 (0)