Skip to content

Commit 39aeff9

Browse files
authored
Back out "Implement intermediate tensor logging"
Differential Revision: D61345037 Pull Request resolved: #4735
1 parent bf29bd6 commit 39aeff9

33 files changed

+218
-1281
lines changed

backends/apple/coreml/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ if(NOT EXECUTORCH_ROOT)
1313
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
1414
endif()
1515

16-
if(EXECUTORCH_BUILD_SDK)
17-
# protobuf requires frtti
18-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -frtti" )
19-
endif()
20-
2116
option(COREML_BUILD_EXECUTOR_RUNNER "Build CoreML executor runner." OFF)
2217

2318
# inmemoryfs sources
@@ -64,7 +59,6 @@ set(SDK_SOURCES
6459
runtime/sdk/ETCoreMLModelAnalyzer.mm
6560
runtime/sdk/ETCoreMLModelStructurePath.mm
6661
runtime/sdk/ETCoreMLOperationProfilingInfo.mm
67-
runtime/sdk/ETCoreMLModelDebugInfo.mm
6862
runtime/sdk/ETCoreMLModelDebugger.mm
6963
runtime/sdk/ETCoreMLModelProfiler.mm
7064
runtime/sdk/ETCoreMLPair.mm
@@ -147,8 +141,6 @@ if(EXECUTORCH_BUILD_SDK)
147141
add_subdirectory(
148142
${CMAKE_CURRENT_SOURCE_DIR}/third-party/coremltools/deps/protobuf/cmake
149143
)
150-
151-
target_link_options_shared_lib(libprotobuf-lite)
152144
target_link_libraries(coremldelegate PRIVATE libprotobuf-lite)
153145
endif()
154146

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

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,36 @@
55
//
66
// Please refer to the license found in the LICENSE file in the root directory of the source tree.
77

8-
#import "ETCoreMLAsset.h"
9-
#import "ETCoreMLAssetManager.h"
10-
#import "ETCoreMLDefaultModelExecutor.h"
11-
#import "ETCoreMLLogging.h"
12-
#import "ETCoreMLModel.h"
13-
#import "ETCoreMLModelCompiler.h"
14-
#import "ETCoreMLModelExecutor.h"
15-
#import "ETCoreMLModelLoader.h"
16-
#import "ETCoreMLModelManager.h"
17-
#import "ETCoreMLStrings.h"
18-
#import "MLModel_Prewarm.h"
19-
#import "MLMultiArray_Copy.h"
8+
#import <ETCoreMLAsset.h>
9+
#import <ETCoreMLAssetManager.h>
10+
#import <ETCoreMLDefaultModelExecutor.h>
11+
#import <ETCoreMLLogging.h>
12+
#import <ETCoreMLModel.h>
13+
#import <ETCoreMLModelCompiler.h>
14+
#import <ETCoreMLModelExecutor.h>
15+
#import <ETCoreMLModelLoader.h>
16+
#import <ETCoreMLModelManager.h>
17+
#import <ETCoreMLStrings.h>
18+
#import <MLModel_Prewarm.h>
19+
#import <MLMultiArray_Copy.h>
2020
#import <filesystem>
21-
#import "inmemory_filesystem_utils.hpp"
21+
#import <inmemory_filesystem_utils.hpp>
2222
#import <iostream>
2323
#import <memory>
24-
#import "model_metadata.h"
25-
#import "multiarray.h"
26-
#import "objc_array_util.h"
24+
#import <model_metadata.h>
25+
#import <multiarray.h>
26+
#import <objc_array_util.h>
2727
#import <optional>
2828
#import <os/lock.h>
29-
#import "serde_json.h"
29+
#import <serde_json.h>
3030
#import <string>
3131
#import <system_error>
3232
#import <vector>
3333

3434
#if ET_EVENT_TRACER_ENABLED
35-
#import "ETCoreMLModelAnalyzer.h"
36-
#import "ETCoreMLModelDebugInfo.h"
37-
#import "ETCoreMLModelStructurePath.h"
38-
#import "objc_safe_cast.h"
35+
#import <ETCoreMLModelAnalyzer.h>
36+
#import <ETCoreMLModelStructurePath.h>
37+
#import <objc_safe_cast.h>
3938
#endif
4039

4140
namespace {
@@ -318,14 +317,31 @@ void add_compute_unit(std::string& identifier, MLComputeUnits compute_units) {
318317
return [[ETCoreMLAsset alloc] initWithBackingAsset:std::move(backingAsset.value())];
319318
}
320319

321-
ETCoreMLModelDebugInfo * _Nullable get_model_debug_info(const inmemoryfs::InMemoryFileSystem *inMemoryFS,
322-
NSError * __autoreleasing *error) {
320+
NSDictionary<ETCoreMLModelStructurePath *, NSString *> * _Nullable get_operation_path_to_symbol_name_map(const inmemoryfs::InMemoryFileSystem *inMemoryFS,
321+
NSError * __autoreleasing *error) {
323322
NSData *file_data = get_file_data(inMemoryFS, ETCoreMLStrings.debugInfoFileRelativePath);
324323
if (!file_data) {
325324
return nil;
326325
}
327-
328-
return [ETCoreMLModelDebugInfo modelDebugInfoFromData:file_data error:error];
326+
327+
id object = [NSJSONSerialization JSONObjectWithData:file_data options:(NSJSONReadingOptions)0 error:error];
328+
if (!object) {
329+
return nil;
330+
}
331+
332+
NSDictionary<NSString *, id> *json_dict = SAFE_CAST(object, NSDictionary);
333+
NSMutableDictionary<ETCoreMLModelStructurePath *, NSString *> *result = [NSMutableDictionary dictionaryWithCapacity:json_dict.count];
334+
NSDictionary<NSString *, NSArray<id> *> *debug_symbol_to_operation_path_map = SAFE_CAST(json_dict[ETCoreMLStrings.debugSymbolToOperationPathKeyName], NSDictionary);
335+
for (NSString *symbol_name in debug_symbol_to_operation_path_map) {
336+
NSArray<NSDictionary<NSString *, id> *> *components = SAFE_CAST(debug_symbol_to_operation_path_map[symbol_name], NSArray);
337+
if (components.count == 0) {
338+
continue;
339+
}
340+
ETCoreMLModelStructurePath *path = [[ETCoreMLModelStructurePath alloc] initWithComponents:components];
341+
result[path] = symbol_name;
342+
}
343+
344+
return result;
329345
}
330346

331347
#endif
@@ -474,16 +490,16 @@ - (nullable NSURL *)compiledModelURLWithIdentifier:(NSString *)identifier
474490
}
475491

476492
NSError *localError = nil;
477-
ETCoreMLModelDebugInfo *debug_info = get_model_debug_info(inMemoryFS, &localError);
493+
NSDictionary<ETCoreMLModelStructurePath *, NSString *> *operation_path_to_symbol_name_map = get_operation_path_to_symbol_name_map(inMemoryFS,
494+
&localError);
478495
if (localError) {
479496
ETCoreMLLogError(localError, "Failed to parse debug info file");
480497
}
481498

482-
483499
return [[ETCoreMLModelAnalyzer alloc] initWithCompiledModelAsset:compiledModelAsset
484500
modelAsset:modelAsset
485-
modelDebugInfo:debug_info
486501
metadata:metadata
502+
operationPathToDebugSymbolMap:operation_path_to_symbol_name_map
487503
configuration:configuration
488504
assetManager:self.assetManager
489505
error:error];

backends/apple/coreml/runtime/delegate/ETCoreMLStrings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ NS_ASSUME_NONNULL_BEGIN
6666
@property (class, copy, readonly, nonatomic, nullable) NSString* debugInfoFileRelativePath;
6767
/// The debug symbol to operation path key name.
6868
@property (class, copy, readonly, nonatomic, nullable) NSString* debugSymbolToOperationPathKeyName;
69-
/// The debug symbol to handles key name.
70-
@property (class, copy, readonly, nonatomic, nullable) NSString* debugSymbolToHandlesKeyName;
7169

7270
@end
7371

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ + (NSString *)debugSymbolToOperationPathKeyName {
9595
return ETCoreMLDebugSymbolToOperationPathKeyName;
9696
}
9797

98-
+ (NSString *)debugSymbolToHandlesKeyName {
99-
static NSString * const ETCoreMLDebugSymbolToHandlesKeyName = @"debugSymbolToHandles";
100-
return ETCoreMLDebugSymbolToHandlesKeyName;
101-
}
102-
10398
+ (nullable NSString *)assetsDirectoryPath {
10499
static dispatch_once_t onceToken;
105100
static NSString *result = nil;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ ModelLoggingOptions get_logging_options(BackendExecutionContext& context) {
124124
auto event_tracer = context.event_tracer();
125125
if (event_tracer) {
126126
options.log_profiling_info = true;
127-
auto debug_level = event_tracer->event_tracer_debug_level();
128-
options.log_intermediate_tensors = (debug_level >= EventTracerDebugLogLevel::kIntermediateOutputs);
127+
options.log_intermediate_tensors = event_tracer->intermediate_outputs_logging_status();
129128
}
130129

131130
return options;

backends/apple/coreml/runtime/delegate/model_event_logger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class ModelEventLogger {
3434
///
3535
/// @param op_path_to_value_map A dictionary with the operation path as the key and the operation's value as the
3636
/// value.
37-
/// @param op_path_to_debug_symbol_name_map A dictionary with the operation path as the key and the debug symbol
38-
/// name as the value.
37+
/// @param op_path_to_debug_symbol_name_map A dictionary with the operation path as the key and the symbol name as
38+
/// the value. The symbol name is the delegate handle.
3939
virtual void log_intermediate_tensors(
4040
NSDictionary<ETCoreMLModelStructurePath*, MLMultiArray*>* op_path_to_value_map,
4141
NSDictionary<ETCoreMLModelStructurePath*, NSString*>* op_path_to_debug_symbol_name_map) const noexcept = 0;

backends/apple/coreml/runtime/sdk/ETCoreMLModelAnalyzer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
#import <CoreML/CoreML.h>
99

10-
#import "ETCoreMLModelExecutor.h"
10+
#import <ETCoreMLModelExecutor.h>
1111

1212
namespace executorchcoreml {
1313
struct ModelMetadata;
1414
}
1515

1616
@class ETCoreMLAsset;
1717
@class ETCoreMLAssetManager;
18-
@class ETCoreMLModelDebugInfo;
1918
@class ETCoreMLModelStructurePath;
2019
@protocol ETCoreMLModelEventLogger;
2120

@@ -33,15 +32,16 @@ __attribute__((objc_subclassing_restricted))
3332
///
3433
/// @param compiledModelAsset The compiled model asset (mlmodelc).
3534
/// @param modelAsset The model asset (mlpackage).
36-
/// @param modelDebugInfo The model debug info.
3735
/// @param metadata The model metadata.
36+
/// @param operationPathToDebugSymbolMap The operation path to debug symbol map.
3837
/// @param configuration The model configuration.
3938
/// @param assetManager The asset manager used to manage storage of compiled models.
4039
/// @param error On failure, error is filled with the failure information.
4140
- (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset*)compiledModelAsset
4241
modelAsset:(nullable ETCoreMLAsset*)modelAsset
43-
modelDebugInfo:(nullable ETCoreMLModelDebugInfo*)modelDebugInfo
4442
metadata:(const executorchcoreml::ModelMetadata&)metadata
43+
operationPathToDebugSymbolMap:
44+
(nullable NSDictionary<ETCoreMLModelStructurePath*, NSString*>*)operationPathToDebugSymbolMap
4545
configuration:(MLModelConfiguration*)configuration
4646
assetManager:(ETCoreMLAssetManager*)assetManager
4747
error:(NSError* __autoreleasing*)error NS_DESIGNATED_INITIALIZER;

backends/apple/coreml/runtime/sdk/ETCoreMLModelAnalyzer.mm

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@
55
//
66
// Please refer to the license found in the LICENSE file in the root directory of the source tree.
77

8-
#import "ETCoreMLModelAnalyzer.h"
9-
10-
#import "ETCoreMLAsset.h"
11-
#import "ETCoreMLAssetManager.h"
12-
#import "ETCoreMLDefaultModelExecutor.h"
13-
#import "ETCoreMLLogging.h"
14-
#import "ETCoreMLModel.h"
15-
#import "ETCoreMLModelLoader.h"
16-
#import "ETCoreMLModelStructurePath.h"
17-
#import "ETCoreMLModelDebugInfo.h"
18-
#import "ETCoreMLModelDebugger.h"
19-
#import "ETCoreMLModelProfiler.h"
20-
#import "ETCoreMLStrings.h"
21-
#import "model_logging_options.h"
22-
#import "model_event_logger.h"
23-
#import "model_metadata.h"
24-
#import "model_package_info.h"
25-
#import "objc_safe_cast.h"
8+
#import <ETCoreMLAsset.h>
9+
#import <ETCoreMLAssetManager.h>
10+
#import <ETCoreMLDefaultModelExecutor.h>
11+
#import <ETCoreMLLogging.h>
12+
#import <ETCoreMLModel.h>
13+
#import <ETCoreMLModelAnalyzer.h>
14+
#import <ETCoreMLModelLoader.h>
15+
#import <ETCoreMLModelStructurePath.h>
16+
#import <ETCoreMLModelDebugger.h>
17+
#import <ETCoreMLModelProfiler.h>
18+
#import <ETCoreMLStrings.h>
19+
#import <model_logging_options.h>
20+
#import <model_event_logger.h>
21+
#import <model_metadata.h>
22+
#import <model_package_info.h>
23+
#import <objc_safe_cast.h>
2624

2725
namespace {
2826
using namespace executorchcoreml;
@@ -36,7 +34,7 @@ @interface ETCoreMLModelAnalyzer ()
3634
@property (strong, nonatomic, nullable) ETCoreMLModelProfiler *profiler;
3735
@property (strong, nonatomic, nullable) ETCoreMLModelDebugger *debugger;
3836
@property (strong, nonatomic, nullable) id<ETCoreMLModelExecutor> executor;
39-
@property (readonly, copy, nonatomic, nullable) ETCoreMLModelDebugInfo *modelDebugInfo;
37+
@property (readonly, copy, nonatomic, nullable) NSDictionary<ETCoreMLModelStructurePath *, NSString *> *operationPathToDebugSymbolMap;
4038
@property (readonly, strong, nonatomic) MLModelConfiguration *configuration;
4139

4240
@end
@@ -45,8 +43,8 @@ @implementation ETCoreMLModelAnalyzer
4543

4644
- (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledModelAsset
4745
modelAsset:(nullable ETCoreMLAsset *)modelAsset
48-
modelDebugInfo:(nullable ETCoreMLModelDebugInfo *)modelDebugInfo
4946
metadata:(const executorchcoreml::ModelMetadata&)metadata
47+
operationPathToDebugSymbolMap:(nullable NSDictionary<ETCoreMLModelStructurePath *, NSString *> *)operationPathToDebugSymbolMap
5048
configuration:(MLModelConfiguration *)configuration
5149
assetManager:(ETCoreMLAssetManager *)assetManager
5250
error:(NSError * __autoreleasing *)error {
@@ -74,9 +72,9 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
7472
if (self) {
7573
_model = model;
7674
_modelAsset = modelAsset;
77-
_modelDebugInfo = modelDebugInfo;
7875
_assetManager = assetManager;
7976
_configuration = configuration;
77+
_operationPathToDebugSymbolMap = operationPathToDebugSymbolMap;
8078
_executor = [[ETCoreMLDefaultModelExecutor alloc] initWithModel:model];
8179
}
8280

@@ -115,7 +113,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
115113
return nil;
116114
}
117115

118-
eventLogger->log_profiling_infos(profilingInfos, self.modelDebugInfo.pathToDebugSymbolMap);
116+
eventLogger->log_profiling_infos(profilingInfos, self.operationPathToDebugSymbolMap);
119117
return modelOutputs;
120118
}
121119

@@ -133,7 +131,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
133131

134132
if (!self.debugger) {
135133
self.debugger = [[ETCoreMLModelDebugger alloc] initWithModelAsset:self.modelAsset
136-
modelDebugInfo:self.modelDebugInfo
137134
outputNames:self.model.orderedOutputNames
138135
configuration:self.configuration
139136
assetManager:self.assetManager
@@ -146,7 +143,6 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
146143

147144
NSArray<MLMultiArray *> *modelOutputs = nil;
148145
NSArray<ETCoreMLModelStructurePath *> *operationPaths = self.debugger.operationPaths;
149-
NSDictionary<ETCoreMLModelStructurePath *, NSString *> *operationPathToDebugSymbolMap = self.debugger.operationPathToDebugSymbolMap;
150146
NSInteger n = operationPaths.count/MAX_MODEL_OUTPUTS_COUNT + (operationPaths.count % MAX_MODEL_OUTPUTS_COUNT == 0 ? 0 : 1);
151147
for (NSInteger i = 0; i < n; i++) {
152148
@autoreleasepool {
@@ -161,7 +157,7 @@ - (nullable instancetype)initWithCompiledModelAsset:(ETCoreMLAsset *)compiledMod
161157
}
162158

163159
if (outputs.count > 0) {
164-
eventLogger->log_intermediate_tensors(outputs, operationPathToDebugSymbolMap);
160+
eventLogger->log_intermediate_tensors(outputs, self.operationPathToDebugSymbolMap);
165161
}
166162
}
167163
}

backends/apple/coreml/runtime/sdk/ETCoreMLModelDebugInfo.h

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)