Skip to content

Commit 8532e79

Browse files
cymbalrushfacebook-github-bot
authored andcommitted
Update coreml runner to only profile model when prof… (#2574)
Summary: The CoreML executor would profile the model by default, this causes an issue when the installed sdk < 14.4. Model execution fails as profiling is only available for >= 14.4 and on older sdk it returns an error. This addresses the issue by fixing the default option and only profiling when `profiling_model` option is set. Pull Request resolved: #2574 Reviewed By: kirklandsign Differential Revision: D55260924 Pulled By: shoumikhin fbshipit-source-id: b8d3713b16f7dd8eb9dfcefce313c590b65e366a
1 parent 911e9a3 commit 8532e79

File tree

2 files changed

+121
-88
lines changed

2 files changed

+121
-88
lines changed

backends/apple/coreml/runtime/sdk/ETCoreMLModelAnalyzer.mm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
9191
configuration:(MLModelConfiguration *)configuration
9292
assetManager:(ETCoreMLAssetManager *)assetManager
9393
error:(NSError * __autoreleasing *)error {
94-
if (![modelAsset keepAliveAndReturnError:error]) {
94+
if (modelAsset && ![modelAsset keepAliveAndReturnError:error]) {
9595
return nil;
9696
}
9797

@@ -123,11 +123,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
123123
modelAsset.contentURL.path);
124124
}
125125

126-
ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc] initWithCompiledModelAsset:model.asset
127-
outputNames:model.orderedOutputNames
128-
configuration:configuration
129-
error:error];
130-
131126
self = [super init];
132127
if (self) {
133128
_model = model;
@@ -136,7 +131,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
136131
_configuration = configuration;
137132
_pathToSymbolNameMap = pathToSymbolNameMap;
138133
_executor = [[ETCoreMLDefaultModelExecutor alloc] initWithModel:model];
139-
_profiler = profiler;
140134
}
141135

142136
return self;
@@ -147,12 +141,22 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
147141
eventLogger:(const executorchcoreml::ModelEventLogger *)eventLogger
148142
error:(NSError * __autoreleasing *)error {
149143
if (self.profiler == nil) {
144+
ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc] initWithCompiledModelAsset:self.model.asset
145+
outputNames:self.model.orderedOutputNames
146+
configuration:self.configuration
147+
error:error];
148+
self.profiler = profiler;
149+
}
150+
151+
152+
if (!self.profiler) {
150153
ETCoreMLLogErrorAndSetNSError(error,
151154
ETCoreMLErrorModelProfilingNotSupported,
152155
"%@: Model profiling is only available for macOS >= 14.4, iOS >= 17.4, tvOS >= 17.4 and watchOS >= 10.4.",
153156
NSStringFromClass(ETCoreMLModelAnalyzer.class));
154157
return nil;
155158
}
159+
156160
NSArray<MLMultiArray *> *modelOutputs = nil;
157161
NSArray<ETCoreMLModelStructurePath *> *operationPaths = self.profiler.operationPaths;
158162
ETCoreMLModelProfilingResult *profilingInfos = [self.profiler profilingInfoForOperationsAtPaths:operationPaths

0 commit comments

Comments
 (0)