Files
pytorch/ios/TestApp/TestAppTests/TestAppTests.mm
Ailing Zhang 24c904951c Replace AutoNonVariableTypeMode with InferenceMode in fbcode. (#55114)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/55114

Test Plan: CI

Reviewed By: ezyang, bhosmer

Differential Revision: D27472768

fbshipit-source-id: 76f17ef7de40f6e04e2968f8958027b5f93e1c0c
2021-04-02 11:45:53 -07:00

37 lines
928 B
Plaintext

#import <XCTest/XCTest.h>
#include <torch/script.h>
@interface TestAppTests : XCTestCase
@end
@implementation TestAppTests {
torch::jit::Module _module;
}
+ (void)setUp {
[super setUp];
}
- (void)setUp {
[super setUp];
NSString* modelPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"model"
ofType:@"pt"];
XCTAssertTrue([NSFileManager.defaultManager fileExistsAtPath:modelPath],
@"model.pt doesn't exist!");
_module = torch::jit::load(modelPath.UTF8String);
}
- (void)testForward {
_module.eval();
c10::InferenceMode mode;
std::vector<c10::IValue> inputs;
inputs.push_back(torch::ones({1, 3, 224, 224}, at::ScalarType::Float));
auto outputTensor = _module.forward(inputs).toTensor();
float* outputBuffer = outputTensor.data_ptr<float>();
XCTAssertTrue(outputBuffer != nullptr, @"");
}
@end