Skip to content

Commit 80e3989

Browse files
cymbalrushfacebook-github-bot
authored andcommitted
Fix debugger tests - sdk issue (#2503)
Summary: For sdk < 17.4 there is no profiling support and we were returning `nil` from `ETCoreMLModelAnalyzer` if the profiler was nil. We could still support model debugging even if we can't profile the model, the change addresses it by creating the `ETCoreMLModelAnalyzer` instance. Pull Request resolved: #2503 Reviewed By: shoumikhin Differential Revision: D55076647 Pulled By: tarun292 fbshipit-source-id: 28f96042e5f89aef7bd6ffc8ada52191594c69f2
1 parent 22cd0f8 commit 80e3989

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

backends/apple/coreml/runtime/delegate/ETCoreMLLogging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef NS_ERROR_ENUM(ETCoreMLErrorDomain, ETCoreMLError) {
2222
ETCoreMLErrorBrokenModel, // CoreML model doesn't match the input and output specification.
2323
ETCoreMLErrorCompilationFailed, // CoreML model failed to compile.
2424
ETCoreMLErrorModelCompilationNotSupported, // CoreML model compilation is not supported by the target.
25+
ETCoreMLErrorModelProfilingNotSupported, // Model profiling is not supported by the target.
2526
ETCoreMLErrorModelSaveFailed, // Failed to save CoreML model to disk.
2627
ETCoreMLErrorModelCacheCreationFailed, // Failed to create model cache.
2728
ETCoreMLErrorInternalError, // Internal error.

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,34 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
9999
return nil;
100100
}
101101

102+
NSError *localError = nil;
102103
ETCoreMLModel *model = [ETCoreMLModelLoader loadModelWithContentsOfURL:compiledModelAsset.contentURL
103104
configuration:configuration
104105
metadata:metadata
105106
assetManager:assetManager
106-
error:error];
107+
error:&localError];
107108
if (!model) {
108-
return nil;
109+
ETCoreMLLogError(localError,
110+
"%@: Failed to create model profiler.",
111+
NSStringFromClass(ETCoreMLAssetManager.class));
109112
}
110113

111-
NSError *localError = nil;
114+
localError = nil;
112115
NSDictionary<ETCoreMLModelStructurePath *, NSString *> *pathToSymbolNameMap = get_path_to_symbol_name_map(modelAsset,
113116
assetManager.fileManager,
114117
&localError);
115118

116119
if (localError) {
117-
os_log_error(ETCoreMLErrorUtils.loggingChannel , "%@: The model package at path=%@ has invalid or missing debug symbols file.",
118-
NSStringFromClass(ETCoreMLModelAnalyzer.class),
119-
modelAsset.contentURL.path);
120+
ETCoreMLLogError(localError,
121+
"%@: The model package at path=%@ has invalid or missing debug symbols file.",
122+
NSStringFromClass(ETCoreMLModelAnalyzer.class),
123+
modelAsset.contentURL.path);
120124
}
121125

122126
ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc] initWithCompiledModelAsset:model.asset
123127
outputNames:model.orderedOutputNames
124128
configuration:configuration
125129
error:error];
126-
if (!profiler) {
127-
return nil;
128-
}
129130

130131
self = [super init];
131132
if (self) {
@@ -145,6 +146,13 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
145146
predictionOptions:(MLPredictionOptions *)predictionOptions
146147
eventLogger:(const executorchcoreml::ModelEventLogger *)eventLogger
147148
error:(NSError * __autoreleasing *)error {
149+
if (self.profiler == nil) {
150+
ETCoreMLLogErrorAndSetNSError(error,
151+
ETCoreMLErrorModelProfilingNotSupported,
152+
"%@: Model profiling is only available for macOS >= 14.4, iOS >= 17.4, tvOS >= 17.4 and watchOS >= 10.4.",
153+
NSStringFromClass(ETCoreMLModelAnalyzer.class));
154+
return nil;
155+
}
148156
NSArray<MLMultiArray *> *modelOutputs = nil;
149157
NSArray<ETCoreMLModelStructurePath *> *operationPaths = self.profiler.operationPaths;
150158
ETCoreMLModelProfilingResult *profilingInfos = [self.profiler profilingInfoForOperationsAtPaths:operationPaths

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
292292
}
293293
#endif
294294
ETCoreMLLogErrorAndSetNSError(error,
295-
ETCoreMLErrorCorruptedModel,
295+
ETCoreMLErrorModelProfilingNotSupported,
296296
"%@: Model profiling is only available for macOS >= 14.4, iOS >= 17.4, tvOS >= 17.4 and watchOS >= 10.4.",
297297
NSStringFromClass(self.class));
298298
return nil;

0 commit comments

Comments
 (0)