@@ -91,7 +91,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
91
91
configuration : (MLModelConfiguration *)configuration
92
92
assetManager : (ETCoreMLAssetManager *)assetManager
93
93
error : (NSError * __autoreleasing *)error {
94
- if (![modelAsset keepAliveAndReturnError: error]) {
94
+ if (modelAsset && ![modelAsset keepAliveAndReturnError: error]) {
95
95
return nil ;
96
96
}
97
97
@@ -123,11 +123,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
123
123
modelAsset.contentURL.path);
124
124
}
125
125
126
- ETCoreMLModelProfiler *profiler = [[ETCoreMLModelProfiler alloc ] initWithCompiledModelAsset: model.asset
127
- outputNames: model.orderedOutputNames
128
- configuration: configuration
129
- error: error];
130
-
131
126
self = [super init ];
132
127
if (self) {
133
128
_model = model;
@@ -136,7 +131,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
136
131
_configuration = configuration;
137
132
_pathToSymbolNameMap = pathToSymbolNameMap;
138
133
_executor = [[ETCoreMLDefaultModelExecutor alloc ] initWithModel: model];
139
- _profiler = profiler;
140
134
}
141
135
142
136
return self;
@@ -147,12 +141,22 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
147
141
eventLogger : (const executorchcoreml::ModelEventLogger *)eventLogger
148
142
error : (NSError * __autoreleasing *)error {
149
143
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 ) {
150
153
ETCoreMLLogErrorAndSetNSError (error,
151
154
ETCoreMLErrorModelProfilingNotSupported,
152
155
" %@: Model profiling is only available for macOS >= 14.4, iOS >= 17.4, tvOS >= 17.4 and watchOS >= 10.4." ,
153
156
NSStringFromClass (ETCoreMLModelAnalyzer.class ));
154
157
return nil ;
155
158
}
159
+
156
160
NSArray <MLMultiArray *> *modelOutputs = nil ;
157
161
NSArray <ETCoreMLModelStructurePath *> *operationPaths = self.profiler .operationPaths ;
158
162
ETCoreMLModelProfilingResult *profilingInfos = [self .profiler profilingInfoForOperationsAtPaths: operationPaths
0 commit comments