Skip to content

Commit

Permalink
add some instructions for ios test (pytorch#79097)
Browse files Browse the repository at this point in the history
as title

Pull Request resolved: pytorch#79097
Approved by: https://github.com/kit1980
  • Loading branch information
linbinyu authored and pytorchmergebot committed Jun 8, 2022
1 parent 530ee1c commit e1534e3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ios/TestApp/TestAppTests/TestLiteInterpreter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ @implementation TestAppTests {
- (void)testCoreML {
NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"model_coreml"
ofType:@"ptl"];
XCTAssertNotNil(modelPath, @"model_coreml.ptl not found. Run coreml_backend.py in ios/TestApp/benchmark to generate it.");
auto module = torch::jit::_load_for_mobile(modelPath.UTF8String);
c10::InferenceMode mode;
auto input = torch::ones({1, 3, 224, 224}, at::kFloat);
auto outputTensor = module.forward({input}).toTensor();
XCTAssertTrue(outputTensor.numel() == 1000);
}

- (void)testModel:(NSString*)filename {
// model generated using the current pytorch revision
[self runModel:[NSString stringWithFormat:@"%@_temp", filename]];
// model generated using older pyotrch revision
[self runModel:filename];
}
- (void)testModel:(NSString*)modelName {
NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:modelName
ofType:@"ptl"];
XCTAssertNotNil(modelPath, @"Model not found. See https://github.com/pytorch/pytorch/tree/master/test/mobile/model_test#diagnose-failed-test.");
[self runModel:modelPath];

- (void)runModel:(NSString*)filename {
NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:filename
// model generated on the fly
NSString* onTheFlyModelName = [NSString stringWithFormat:@"%@_temp", modelName]];
NSString* onTheFlyModelPath = [[NSBundle bundleForClass:[self class]] pathForResource:onTheFlyModelName
ofType:@"ptl"];
XCTAssertNotNil(modelPath);
XCTAssertNotNil(onTheFlyModelPath, @"On-the-fly model not found. Follow https://github.com/pytorch/pytorch/tree/master/test/mobile/model_test#diagnose-failed-test to generate them and run the setup script again.");
[self runModel:onTheFlyModelPath];
}

- (void)runModel:(NSString*)modelPath {
c10::InferenceMode mode;
auto module = torch::jit::_load_for_mobile(modelPath.UTF8String);
auto has_bundled_input = module.find_method("get_all_bundled_inputs");
Expand Down

0 comments on commit e1534e3

Please sign in to comment.