Skip to content

Commit 4aaec4f

Browse files
committed
backport [MLModel predictionFromFeatures:completionHandler] methods as those are exclusive to macos 14
1 parent 705db0f commit 4aaec4f

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if (WHISPER_COREML)
5858
set(TARGET whisper.coreml)
5959

6060
add_library(${TARGET}
61+
coreml/MLModel+Compat.m
6162
coreml/whisper-encoder.h
6263
coreml/whisper-encoder.mm
6364
coreml/whisper-encoder-impl.h
@@ -76,6 +77,7 @@ if (WHISPER_COREML)
7677
COMPILE_FLAGS "-fobjc-arc"
7778
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
7879
)
80+
7981
set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
8082
endif()
8183

src/coreml/MLModel+Compat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#import <CoreML/CoreML.h>
2+
3+
@interface MLModel (Compat)
4+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
5+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
6+
7+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
8+
options:(MLPredictionOptions *) options
9+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler;
10+
@end

src/coreml/MLModel+Compat.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#import "MLModel+Compat.h"
2+
3+
@implementation MLModel (Compat)
4+
5+
#if !defined(MAC_OS_X_VERSION_14_00) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_14_00
6+
7+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
8+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
9+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
10+
NSError *error = nil;
11+
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];
12+
completionHandler(prediction, error);
13+
}];
14+
}
15+
16+
- (void) predictionFromFeatures:(id<MLFeatureProvider>) input
17+
options:(MLPredictionOptions *) options
18+
completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
19+
[NSOperationQueue.mainQueue addOperationWithBlock:^{
20+
NSError *error = nil;
21+
id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];
22+
completionHandler(prediction, error);
23+
}];
24+
}
25+
26+
#endif
27+
28+
@end

src/coreml/whisper-decoder-impl.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
99
#endif
1010

11+
#import "MLModel+Compat.h"
1112
#import "whisper-decoder-impl.h"
1213

1314
@implementation whisper_decoder_implInput

src/coreml/whisper-encoder-impl.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
99
#endif
1010

11+
#import "MLModel+Compat.h"
1112
#import "whisper-encoder-impl.h"
1213

1314
@implementation whisper_encoder_implInput

0 commit comments

Comments
 (0)