xref: /aosp_15_r20/external/executorch/backends/apple/coreml/runtime/sdk/ETCoreMLModelDebugger.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 //
2 // ETCoreMLModelDebugger.h
3 //
4 // Copyright © 2024 Apple Inc. All rights reserved.
5 //
6 // Please refer to the license found in the LICENSE file in the root directory of the source tree.
7 
8 #import <CoreML/CoreML.h>
9 
10 @class ETCoreMLAsset;
11 @class ETCoreMLAssetManager;
12 @class ETCoreMLModelDebugInfo;
13 @class ETCoreMLModelStructurePath;
14 
15 typedef NSDictionary<ETCoreMLModelStructurePath*, MLMultiArray*> ETCoreMLModelOutputs;
16 
17 NS_ASSUME_NONNULL_BEGIN
18 /// A class responsible for debugging a model.
19 __attribute__((objc_subclassing_restricted))
20 @interface ETCoreMLModelDebugger : NSObject
21 
22 - (instancetype)init NS_UNAVAILABLE;
23 
24 + (instancetype)new NS_UNAVAILABLE;
25 
26 /// Constructs an `ETCoreMLModelDebugger` instance.
27 ///
28 /// @param modelAsset The model asset (mlpackage).
29 /// @param modelDebugInfo The model debug info.
30 /// @param outputNames The model output names.
31 /// @param configuration The model configuration.
32 /// @param assetManager The asset manager used to manage storage of compiled models.
33 /// @param error   On failure, error is filled with the failure information.
34 - (nullable instancetype)initWithModelAsset:(ETCoreMLAsset*)modelAsset
35                              modelDebugInfo:(nullable ETCoreMLModelDebugInfo*)modelDebugInfo
36                                 outputNames:(NSOrderedSet<NSString*>*)outputNames
37                               configuration:(MLModelConfiguration*)configuration
38                                assetManager:(ETCoreMLAssetManager*)assetManager
39                                       error:(NSError* __autoreleasing*)error NS_DESIGNATED_INITIALIZER;
40 
41 /// Returns outputs of operations at the specified paths.
42 ///
43 /// This is an expensive method, it creates models with intermediate outputs, compiles, and executes them.
44 ///
45 /// @param paths The operation paths.
46 /// @param options The prediction options.
47 /// @param inputs The model inputs..
48 /// @param modelOutputs  On success, modelOutputs is filled with the model outputs.
49 /// @param error   On failure, error is filled with the failure information.
50 /// @retval A dictionary with the operation path as the key and the operation output as the value.
51 - (nullable ETCoreMLModelOutputs*)
52     outputsOfOperationsAtPaths:(NSArray<ETCoreMLModelStructurePath*>*)paths
53                        options:(MLPredictionOptions*)options
54                         inputs:(id<MLFeatureProvider>)inputs
55                   modelOutputs:(NSArray<MLMultiArray*>* _Nullable __autoreleasing* _Nonnull)modelOutputs
56                          error:(NSError* __autoreleasing*)error;
57 
58 /// The paths to all the operations for which we can get the outputs.
59 @property (readonly, copy, nonatomic) NSArray<ETCoreMLModelStructurePath*>* operationPaths;
60 
61 /// Operation path to debug symbol map.
62 @property (readonly, copy, nonatomic)
63     NSDictionary<ETCoreMLModelStructurePath*, NSString*>* operationPathToDebugSymbolMap;
64 
65 @end
66 
67 NS_ASSUME_NONNULL_END
68