Skip to content

Commit 69f3f1c

Browse files
cymbalrushfacebook-github-bot
authored andcommitted
Fix prewarming (#4454)
Summary: Prewarms the model if `config.should_prewarm_model` is `true`. This improves the latency of first inference call as the necessary objects are created when the model is prewarmed. Testing: Existing tests Pull Request resolved: #4454 Reviewed By: kirklandsign Differential Revision: D60469148 Pulled By: cccclai fbshipit-source-id: d88883e721269d03298265dd420f08cbbe4787ce
1 parent 1ec3444 commit 69f3f1c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

backends/apple/coreml/runtime/delegate/ETCoreMLModelManager.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ - (void)prewarmRecentlyUsedAssetsWithMaxCount:(NSUInteger)maxCount {
655655

656656
NSError *prewarmError = nil;
657657
if (![asset prewarmAndReturnError:&prewarmError]) {
658-
ETCoreMLLogError(localError,
658+
ETCoreMLLogError(prewarmError,
659659
"%@: Failed to prewarm asset with identifier = %@",
660660
NSStringFromClass(strongSelf.assetManager.class),
661661
asset.identifier);

backends/apple/coreml/runtime/delegate/backend_delegate.mm

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ - (BOOL)_loadAndReturnError:(NSError * _Nullable __autoreleasing *)error {
157157
if (self.config.should_prewarm_asset) {
158158
[modelManager prewarmRecentlyUsedAssetsWithMaxCount:1];
159159
}
160-
160+
161161
return YES;
162162
}
163163

@@ -188,9 +188,14 @@ - (ModelHandle*)loadModelFromAOTData:(NSData*)data
188188
return nil;
189189
}
190190

191-
return [self.impl loadModelFromAOTData:data
192-
configuration:configuration
193-
error:error];
191+
auto handle = [self.impl loadModelFromAOTData:data
192+
configuration:configuration
193+
error:error];
194+
if ((handle != NULL) && self.config.should_prewarm_model) {
195+
[self.impl prewarmModelWithHandle:handle error:nil];
196+
}
197+
198+
return handle;
194199
}
195200

196201
- (BOOL)executeModelWithHandle:(ModelHandle*)handle

0 commit comments

Comments
 (0)