glaszig commited on
Commit
dc0917f
·
unverified ·
1 Parent(s): a45c78b

coreml : backport CoreML features to macos < 14 (#3255)

Browse files
src/CMakeLists.txt CHANGED
@@ -58,6 +58,7 @@ if (WHISPER_COREML)
58
  set(TARGET whisper.coreml)
59
 
60
  add_library(${TARGET}
 
61
  coreml/whisper-encoder.h
62
  coreml/whisper-encoder.mm
63
  coreml/whisper-encoder-impl.h
@@ -76,6 +77,7 @@ if (WHISPER_COREML)
76
  COMPILE_FLAGS "-fobjc-arc"
77
  XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
78
  )
 
79
  set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
80
  endif()
81
 
 
58
  set(TARGET whisper.coreml)
59
 
60
  add_library(${TARGET}
61
+ coreml/whisper-compat.m
62
  coreml/whisper-encoder.h
63
  coreml/whisper-encoder.mm
64
  coreml/whisper-encoder-impl.h
 
77
  COMPILE_FLAGS "-fobjc-arc"
78
  XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
79
  )
80
+
81
  set_target_properties(${TARGET} PROPERTIES FOLDER "libs")
82
  endif()
83
 
src/coreml/whisper-compat.h ADDED
@@ -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/whisper-compat.m ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import "whisper-compat.h"
2
+ #import <Foundation/Foundation.h>
3
+
4
+ @implementation MLModel (Compat)
5
+
6
+ #if !defined(MAC_OS_X_VERSION_14_00) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_14_00
7
+
8
+ - (void) predictionFromFeatures:(id<MLFeatureProvider>) input
9
+ completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
10
+ [NSOperationQueue.new addOperationWithBlock:^{
11
+ NSError *error = nil;
12
+ id<MLFeatureProvider> prediction = [self predictionFromFeatures:input error:&error];
13
+
14
+ [NSOperationQueue.mainQueue addOperationWithBlock:^{
15
+ completionHandler(prediction, error);
16
+ }];
17
+ }];
18
+ }
19
+
20
+ - (void) predictionFromFeatures:(id<MLFeatureProvider>) input
21
+ options:(MLPredictionOptions *) options
22
+ completionHandler:(void (^)(id<MLFeatureProvider> output, NSError * error)) completionHandler {
23
+ [NSOperationQueue.new addOperationWithBlock:^{
24
+ NSError *error = nil;
25
+ id<MLFeatureProvider> prediction = [self predictionFromFeatures:input options:options error:&error];
26
+
27
+ [NSOperationQueue.mainQueue addOperationWithBlock:^{
28
+ completionHandler(prediction, error);
29
+ }];
30
+ }];
31
+ }
32
+
33
+ #endif
34
+
35
+ @end
src/coreml/whisper-decoder-impl.m CHANGED
@@ -8,6 +8,7 @@
8
  #error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
9
  #endif
10
 
 
11
  #import "whisper-decoder-impl.h"
12
 
13
  @implementation whisper_decoder_implInput
 
8
  #error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
9
  #endif
10
 
11
+ #import "whisper-compat.h"
12
  #import "whisper-decoder-impl.h"
13
 
14
  @implementation whisper_decoder_implInput
src/coreml/whisper-encoder-impl.m CHANGED
@@ -8,6 +8,7 @@
8
  #error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
9
  #endif
10
 
 
11
  #import "whisper-encoder-impl.h"
12
 
13
  @implementation whisper_encoder_implInput
 
8
  #error This file must be compiled with automatic reference counting enabled (-fobjc-arc)
9
  #endif
10
 
11
+ #import "whisper-compat.h"
12
  #import "whisper-encoder-impl.h"
13
 
14
  @implementation whisper_encoder_implInput