Update to 1.18.0 resources (#17)
* update to 1.18.0 resources * Update Package.swift Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com> * update --------- Co-authored-by: rachguo <rachguo@rachguos-Mini.attlocal.net> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
This commit is contained in:
+6
-6
@@ -96,21 +96,21 @@ if let pod_archive_path = ProcessInfo.processInfo.environment["ORT_IOS_POD_LOCAL
|
||||
package.targets.append(Target.binaryTarget(name: "onnxruntime", path: pod_archive_path))
|
||||
|
||||
} else {
|
||||
// ORT 1.17.0 release
|
||||
// ORT 1.18.0 release
|
||||
package.targets.append(
|
||||
Target.binaryTarget(name: "onnxruntime",
|
||||
url: "https://onnxruntimepackages.z14.web.core.windows.net/pod-archive-onnxruntime-c-1.17.0.zip",
|
||||
checksum: "1623e1150507d9e50554e3d3e5cf9abf75e1bfd8324b74a602acfe45343db871")
|
||||
url: "https://download.onnxruntime.ai/pod-archive-onnxruntime-c-1.18.0.zip",
|
||||
checksum: "9f196b7d09129177f529be63a91e18731ab1ccc830828e29edcbe95bd652fa5c")
|
||||
)
|
||||
}
|
||||
|
||||
if let ext_pod_archive_path = ProcessInfo.processInfo.environment["ORT_EXTENSIONS_IOS_POD_LOCAL_PATH"] {
|
||||
package.targets.append(Target.binaryTarget(name: "onnxruntime_extensions", path: ext_pod_archive_path))
|
||||
} else {
|
||||
// ORT Extensions 0.10.0 release
|
||||
// ORT Extensions 0.11.0 release
|
||||
package.targets.append(
|
||||
Target.binaryTarget(name: "onnxruntime_extensions",
|
||||
url: "https://onnxruntimepackages.z14.web.core.windows.net/pod-archive-onnxruntime-extensions-c-0.10.0.zip",
|
||||
checksum: "c0fbe30bcf898b0f7428e913918803372ba986ed9c662c1b8300ceaff3f442e0")
|
||||
url: "https://download.onnxruntime.ai/pod-archive-onnxruntime-extensions-c-0.11.0.zip",
|
||||
checksum: "289e8b7847116744946003ed21e1ac9ee4897c3aca48e261238e329634c27c0a")
|
||||
)
|
||||
}
|
||||
@@ -41,6 +41,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
*/
|
||||
@property BOOL onlyEnableForDevicesWithANE;
|
||||
|
||||
/**
|
||||
* Only allow CoreML EP to take nodes with inputs with static shapes. By default it will also allow inputs with
|
||||
* dynamic shapes. However, the performance may be negatively impacted if inputs have dynamic shapes.
|
||||
*/
|
||||
@property BOOL onlyAllowStaticInputShapes;
|
||||
|
||||
/**
|
||||
* Create an MLProgram. By default it will create a NeuralNetwork model. Requires Core ML 5 or later.
|
||||
*/
|
||||
@property BOOL createMLProgram;
|
||||
|
||||
@end
|
||||
|
||||
@interface ORTSessionOptions (ORTSessionOptionsCoreMLEP)
|
||||
|
||||
@@ -24,6 +24,9 @@ NSString* _Nullable ORTVersion(void);
|
||||
|
||||
/**
|
||||
* The ORT environment.
|
||||
* It maintains shared state including the default logger.
|
||||
*
|
||||
* @note One ORTEnv should be created before and destroyed after other ORT API usage.
|
||||
*/
|
||||
@interface ORTEnv : NSObject
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* session which will be moved to the device specified in the session option if needed.
|
||||
*
|
||||
* @param env The `ORTEnv` instance to use for the training session.
|
||||
* @param sessionOptions The `ORTSessionOptions` to use for the training session.
|
||||
* @param sessionOptions The optional `ORTSessionOptions` to use for the training session.
|
||||
* @param checkpoint Training states that are used as a starting point for training.
|
||||
* @param trainModelPath The path to the training onnx model.
|
||||
* @param evalModelPath The path to the evaluation onnx model.
|
||||
@@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* keeps a strong (owning) pointer to the checkpoint state.
|
||||
*/
|
||||
- (nullable instancetype)initWithEnv:(ORTEnv*)env
|
||||
sessionOptions:(ORTSessionOptions*)sessionOptions
|
||||
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
|
||||
checkpoint:(ORTCheckpoint*)checkpoint
|
||||
trainModelPath:(NSString*)trainModelPath
|
||||
evalModelPath:(nullable NSString*)evalModelPath
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <variant>
|
||||
#import "cxx_api.h"
|
||||
|
||||
#import "cxx_utils.h"
|
||||
#import "error_utils.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@@ -73,7 +74,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
try {
|
||||
Ort::Property value = [self CXXAPIOrtCheckpoint].GetProperty(name.UTF8String);
|
||||
if (std::string* str = std::get_if<std::string>(&value)) {
|
||||
return [NSString stringWithUTF8String:str->c_str()];
|
||||
return utils::toNSString(str->c_str());
|
||||
}
|
||||
ORT_CXX_API_THROW("Property is not a string.", ORT_INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,10 @@ BOOL ORTIsCoreMLExecutionProviderAvailable() {
|
||||
const uint32_t flags =
|
||||
(options.useCPUOnly ? COREML_FLAG_USE_CPU_ONLY : 0) |
|
||||
(options.enableOnSubgraphs ? COREML_FLAG_ENABLE_ON_SUBGRAPH : 0) |
|
||||
(options.onlyEnableForDevicesWithANE ? COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE : 0);
|
||||
(options.onlyEnableForDevicesWithANE ? COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE : 0) |
|
||||
(options.onlyAllowStaticInputShapes ? COREML_FLAG_ONLY_ALLOW_STATIC_INPUT_SHAPES : 0) |
|
||||
(options.createMLProgram ? COREML_FLAG_CREATE_MLPROGRAM : 0);
|
||||
|
||||
Ort::ThrowOnError(OrtSessionOptionsAppendExecutionProvider_CoreML(
|
||||
[self CXXAPIOrtSessionOptions], flags));
|
||||
return YES;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#import "cxx_api.h"
|
||||
#import "cxx_utils.h"
|
||||
#import "error_utils.h"
|
||||
#import "ort_enums_internal.h"
|
||||
#import "ort_env_internal.h"
|
||||
@@ -23,6 +24,7 @@ enum class NamedValueType {
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation ORTSession {
|
||||
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
|
||||
std::optional<Ort::Session> _session;
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
}
|
||||
|
||||
_env = env;
|
||||
_session = Ort::Session{[env CXXAPIOrtEnv],
|
||||
path.UTF8String,
|
||||
[sessionOptions CXXAPIOrtSessionOptions]};
|
||||
@@ -196,8 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
for (size_t i = 0; i < nameCount; ++i) {
|
||||
auto name = getName(i, allocator);
|
||||
NSString* nameNsstr = [NSString stringWithUTF8String:name.get()];
|
||||
NSAssert(nameNsstr != nil, @"nameNsstr must not be nil");
|
||||
NSString* nameNsstr = utils::toNSString(name.get());
|
||||
[result addObject:nameNsstr];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation ORTTrainingSession {
|
||||
std::optional<Ort::TrainingSession> _session;
|
||||
ORTEnv* _env; // keep a strong reference so the ORTEnv doesn't get destroyed before this does
|
||||
ORTCheckpoint* _checkpoint;
|
||||
std::optional<Ort::TrainingSession> _session;
|
||||
}
|
||||
|
||||
- (Ort::TrainingSession&)CXXAPIOrtTrainingSession {
|
||||
@@ -28,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithEnv:(ORTEnv*)env
|
||||
sessionOptions:(ORTSessionOptions*)sessionOptions
|
||||
sessionOptions:(nullable ORTSessionOptions*)sessionOptions
|
||||
checkpoint:(ORTCheckpoint*)checkpoint
|
||||
trainModelPath:(NSString*)trainModelPath
|
||||
evalModelPath:(nullable NSString*)evalModelPath
|
||||
@@ -39,9 +40,17 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
try {
|
||||
if (!sessionOptions) {
|
||||
sessionOptions = [[ORTSessionOptions alloc] initWithError:error];
|
||||
if (!sessionOptions) {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> evalPath = utils::toStdOptionalString(evalModelPath);
|
||||
std::optional<std::string> optimizerPath = utils::toStdOptionalString(optimizerModelPath);
|
||||
|
||||
_env = env;
|
||||
_checkpoint = checkpoint;
|
||||
_session = Ort::TrainingSession{
|
||||
[env CXXAPIOrtEnv],
|
||||
@@ -50,6 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
trainModelPath.UTF8String,
|
||||
evalPath,
|
||||
optimizerPath};
|
||||
|
||||
return self;
|
||||
}
|
||||
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)
|
||||
|
||||
@@ -148,6 +148,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
|
||||
- (nullable ORTTensorTypeAndShapeInfo*)tensorTypeAndShapeInfoWithError:(NSError**)error {
|
||||
try {
|
||||
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
|
||||
if (!tensorTypeAndShapeInfo) {
|
||||
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
|
||||
}
|
||||
return CXXAPIToPublicTensorTypeAndShapeInfo(tensorTypeAndShapeInfo);
|
||||
}
|
||||
ORT_OBJC_API_IMPL_CATCH_RETURNING_NULLABLE(error)
|
||||
@@ -156,6 +159,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
|
||||
- (nullable NSMutableData*)tensorDataWithError:(NSError**)error {
|
||||
try {
|
||||
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
|
||||
if (!tensorTypeAndShapeInfo) {
|
||||
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
|
||||
}
|
||||
if (tensorTypeAndShapeInfo.GetElementType() == ONNX_TENSOR_ELEMENT_DATA_TYPE_STRING) {
|
||||
ORT_CXX_API_THROW(
|
||||
"This ORTValue holds string data. Please call tensorStringDataWithError: "
|
||||
@@ -182,6 +188,9 @@ bool SafeMultiply(size_t a, size_t b, size_t& out) {
|
||||
- (nullable NSArray<NSString*>*)tensorStringDataWithError:(NSError**)error {
|
||||
try {
|
||||
const auto tensorTypeAndShapeInfo = _typeInfo->GetTensorTypeAndShapeInfo();
|
||||
if (!tensorTypeAndShapeInfo) {
|
||||
ORT_CXX_API_THROW("ORTValue is not a tensor.", ORT_RUNTIME_EXCEPTION);
|
||||
}
|
||||
const size_t elementCount = tensorTypeAndShapeInfo.GetElementCount();
|
||||
const size_t tensorStringDataLength = _value->GetStringTensorDataLength();
|
||||
std::vector<char> tensorStringData(tensorStringDataLength, '\0');
|
||||
|
||||
Reference in New Issue
Block a user