mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-16 21:00:14 +00:00
### Description Enable support for building iOS packages/CocoaPods with training API - Add `Training` Package variant and config files in current iOS packaging utilities to enable creation of training packages ### Motivation and Context This PR introduces new `Training` variant in `build_and_assemble_ios_pods.py` script which allows creating pods for iOS with training API enabled. The sample script to build training pods: ``` python3 tools/ci_build/github/apple/build_and_assemble_ios_pods.py --variant Training \ --build-settings-file tools/ci_build/github/apple/default_full_ios_training_framework_build_settings.json \ -b=-- path_to_protoc_exe=<path/to/protoc> ``` Note: build settings file should have `--enable_training` as a build parameter. Simply adding training packaging increases the duration of the Azure pipeline for packaging by 70 minutes. To address this issue, we need to parallelize pod creation. In order not to further strain the pipeline, the changes for training packaging will be added in another PR, which optimizes the packaging pipeline. --------- Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
117 lines
3.5 KiB
Text
117 lines
3.5 KiB
Text
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import "ort_checkpoint.h"
|
|
#import "ort_training_session.h"
|
|
#import "ort_env.h"
|
|
#import "ort_session.h"
|
|
|
|
#import "test/test_utils.h"
|
|
#import "test/assertion_utils.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@interface ORTCheckpointTest : XCTestCase
|
|
@property(readonly, nullable) ORTEnv* ortEnv;
|
|
@end
|
|
|
|
@implementation ORTCheckpointTest
|
|
|
|
- (void)setUp {
|
|
[super setUp];
|
|
|
|
self.continueAfterFailure = NO;
|
|
|
|
NSError* err = nil;
|
|
_ortEnv = [[ORTEnv alloc] initWithLoggingLevel:ORTLoggingLevelWarning
|
|
error:&err];
|
|
ORTAssertNullableResultSuccessful(_ortEnv, err);
|
|
}
|
|
|
|
+ (NSString*)getCheckpointPath {
|
|
NSBundle* bundle = [NSBundle bundleForClass:[ORTCheckpointTest class]];
|
|
NSString* path = [[bundle resourcePath] stringByAppendingPathComponent:@"checkpoint.ckpt"];
|
|
return path;
|
|
}
|
|
|
|
+ (NSString*)getTrainingModelPath {
|
|
NSBundle* bundle = [NSBundle bundleForClass:[ORTCheckpointTest class]];
|
|
NSString* path = [[bundle resourcePath] stringByAppendingPathComponent:@"training_model.onnx"];
|
|
return path;
|
|
}
|
|
|
|
- (void)testSaveCheckpoint {
|
|
NSError* error = nil;
|
|
ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error];
|
|
ORTAssertNullableResultSuccessful(checkpoint, error);
|
|
|
|
// save checkpoint
|
|
NSString* path = [test_utils::createTemporaryDirectory(self) stringByAppendingPathComponent:@"save_checkpoint.ckpt"];
|
|
XCTAssertNotNil(path);
|
|
BOOL result = [checkpoint saveCheckpointToPath:path withOptimizerState:NO error:&error];
|
|
|
|
ORTAssertBoolResultSuccessful(result, error);
|
|
}
|
|
|
|
- (void)testInitCheckpoint {
|
|
NSError* error = nil;
|
|
ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error];
|
|
ORTAssertNullableResultSuccessful(checkpoint, error);
|
|
}
|
|
|
|
- (void)testIntProperty {
|
|
NSError* error = nil;
|
|
// Load checkpoint
|
|
ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error];
|
|
ORTAssertNullableResultSuccessful(checkpoint, error);
|
|
|
|
// Add property
|
|
BOOL result = [checkpoint addIntPropertyWithName:@"test" value:314 error:&error];
|
|
ORTAssertBoolResultSuccessful(result, error);
|
|
|
|
// Get property
|
|
int64_t value = [checkpoint getIntPropertyWithName:@"test" error:&error];
|
|
XCTAssertEqual(value, 314);
|
|
}
|
|
|
|
- (void)testFloatProperty {
|
|
NSError* error = nil;
|
|
// Load checkpoint
|
|
ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error];
|
|
ORTAssertNullableResultSuccessful(checkpoint, error);
|
|
|
|
// Add property
|
|
BOOL result = [checkpoint addFloatPropertyWithName:@"test" value:3.14f error:&error];
|
|
ORTAssertBoolResultSuccessful(result, error);
|
|
|
|
// Get property
|
|
float value = [checkpoint getFloatPropertyWithName:@"test" error:&error];
|
|
XCTAssertEqual(value, 3.14f);
|
|
}
|
|
|
|
- (void)testStringProperty {
|
|
NSError* error = nil;
|
|
// Load checkpoint
|
|
ORTCheckpoint* checkpoint = [[ORTCheckpoint alloc] initWithPath:[ORTCheckpointTest getCheckpointPath] error:&error];
|
|
ORTAssertNullableResultSuccessful(checkpoint, error);
|
|
|
|
// Add property
|
|
BOOL result = [checkpoint addStringPropertyWithName:@"test" value:@"hello" error:&error];
|
|
ORTAssertBoolResultSuccessful(result, error);
|
|
|
|
// Get property
|
|
NSString* value = [checkpoint getStringPropertyWithName:@"test" error:&error];
|
|
XCTAssertEqualObjects(value, @"hello");
|
|
}
|
|
|
|
- (void)tearDown {
|
|
_ortEnv = nil;
|
|
|
|
[super tearDown];
|
|
}
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|