Skip to content

[CoreML Backend] Update coreml runner to only profile model when prof… #2574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions backends/apple/coreml/runtime/sdk/ETCoreMLModelAnalyzer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
configuration:(MLModelConfiguration *)configuration
assetManager:(ETCoreMLAssetManager *)assetManager
error:(NSError * __autoreleasing *)error {
if (![modelAsset keepAliveAndReturnError:error]) {
if (modelAsset && ![modelAsset keepAliveAndReturnError:error]) {
return nil;
}

Expand Down Expand Up @@ -123,11 +123,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
modelAsset.contentURL.path);
}

ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc] initWithCompiledModelAsset:model.asset
outputNames:model.orderedOutputNames
configuration:configuration
error:error];

self = [super init];
if (self) {
_model = model;
Expand All @@ -136,7 +131,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
_configuration = configuration;
_pathToSymbolNameMap = pathToSymbolNameMap;
_executor = [[ETCoreMLDefaultModelExecutor alloc] initWithModel:model];
_profiler = profiler;
}

return self;
Expand All @@ -147,12 +141,22 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
eventLogger:(const executorchcoreml::ModelEventLogger *)eventLogger
error:(NSError * __autoreleasing *)error {
if (self.profiler == nil) {
ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc] initWithCompiledModelAsset:self.model.asset
outputNames:self.model.orderedOutputNames
configuration:self.configuration
error:error];
self.profiler = profiler;
}


if (!self.profiler) {
ETCoreMLLogErrorAndSetNSError(error,
ETCoreMLErrorModelProfilingNotSupported,
"%@: Model profiling is only available for macOS >= 14.4, iOS >= 17.4, tvOS >= 17.4 and watchOS >= 10.4.",
NSStringFromClass(ETCoreMLModelAnalyzer.class));
return nil;
}

NSArray<MLMultiArray *> *modelOutputs = nil;
NSArray<ETCoreMLModelStructurePath *> *operationPaths = self.profiler.operationPaths;
ETCoreMLModelProfilingResult *profilingInfos = [self.profiler profilingInfoForOperationsAtPaths:operationPaths
Expand Down
Loading