@@ -52,6 +52,7 @@ class ETRecordReservedFileNames(StrEnum):
52
52
ET_DIALECT_GRAPH_MODULE = "et_dialect_graph_module"
53
53
DEBUG_HANDLE_MAP_NAME = "debug_handle_map"
54
54
DELEGATE_MAP_NAME = "delegate_map"
55
+ INSTRUCTION_ID_TO_NUM_OUTS_MAP_NAME = "instruction_id_to_num_outs_map"
55
56
REFERENCE_OUTPUTS = "reference_outputs"
56
57
REPRESENTATIVE_INPUTS = "representative_inputs"
57
58
@@ -67,6 +68,9 @@ def __init__(
67
68
_delegate_map : Optional [
68
69
Dict [str , Dict [int , Dict [str , Union [str , _DelegateDebugIdentifierMap ]]]]
69
70
] = None ,
71
+ _instruction_id_to_num_outs_map : Optional [
72
+ Dict [str , Dict [int , Union [int , List [int ]]]]
73
+ ] = None ,
70
74
_reference_outputs : Optional [Dict [str , List [ProgramOutput ]]] = None ,
71
75
_representative_inputs : Optional [List [ProgramInput ]] = None ,
72
76
):
@@ -92,6 +96,7 @@ def __init__(
92
96
self .graph_map = graph_map
93
97
self ._debug_handle_map = _debug_handle_map
94
98
self ._delegate_map = _delegate_map
99
+ self ._instruction_id_to_num_outs_map = _instruction_id_to_num_outs_map
95
100
self ._reference_outputs = _reference_outputs
96
101
self ._representative_inputs = _representative_inputs
97
102
@@ -172,6 +177,12 @@ def _save_metadata(self, etrecord_zip: ZipFile) -> None:
172
177
json .dumps (self ._delegate_map ),
173
178
)
174
179
180
+ if self ._instruction_id_to_num_outs_map is not None :
181
+ etrecord_zip .writestr (
182
+ ETRecordReservedFileNames .INSTRUCTION_ID_TO_NUM_OUTS_MAP_NAME ,
183
+ json .dumps (self ._instruction_id_to_num_outs_map ),
184
+ )
185
+
175
186
if self ._reference_outputs is not None :
176
187
etrecord_zip .writestr (
177
188
ETRecordReservedFileNames .REFERENCE_OUTPUTS ,
@@ -284,6 +295,7 @@ def add_executorch_program(
284
295
if (
285
296
self ._debug_handle_map is not None
286
297
or self ._delegate_map is not None
298
+ or self ._instruction_id_to_num_outs_map is not None
287
299
or self ._reference_outputs is not None
288
300
or self ._representative_inputs is not None
289
301
):
@@ -293,13 +305,18 @@ def add_executorch_program(
293
305
)
294
306
295
307
# Process executorch program and extract data
296
- debug_handle_map , delegate_map , reference_outputs , representative_inputs = (
297
- _process_executorch_program (executorch_program )
298
- )
308
+ (
309
+ debug_handle_map ,
310
+ delegate_map ,
311
+ instruction_id_to_num_outs_map ,
312
+ reference_outputs ,
313
+ representative_inputs ,
314
+ ) = _process_executorch_program (executorch_program )
299
315
300
316
# Set the extracted data
301
317
self ._debug_handle_map = debug_handle_map
302
318
self ._delegate_map = delegate_map
319
+ self ._instruction_id_to_num_outs_map = instruction_id_to_num_outs_map
303
320
self ._reference_outputs = reference_outputs
304
321
self ._representative_inputs = representative_inputs
305
322
@@ -593,7 +610,9 @@ def _process_executorch_program(
593
610
executorch_program : Union [
594
611
ExecutorchProgram , ExecutorchProgramManager , BundledProgram
595
612
]
596
- ) -> tuple [Optional [Dict ], Optional [Dict ], Optional [Dict ], Optional [List ]]:
613
+ ) -> tuple [
614
+ Optional [Dict ], Optional [Dict ], Optional [Dict ], Optional [Dict ], Optional [List ]
615
+ ]:
597
616
"""Process executorch program and return debug maps and bundled program data."""
598
617
if isinstance (executorch_program , BundledProgram ):
599
618
reference_outputs = _get_reference_outputs (executorch_program )
@@ -602,11 +621,30 @@ def _process_executorch_program(
602
621
debug_handle_map = executorch_program .executorch_program .debug_handle_map
603
622
# pyre-ignore[16]: Item `None` of `typing.Union[None, exir.program._program.ExecutorchProgram, exir.program._program.ExecutorchProgramManager]` has no attribute `debug_handle_map`
604
623
delegate_map = executorch_program .executorch_program .delegate_map
605
- return debug_handle_map , delegate_map , reference_outputs , representative_inputs
624
+ # pyre-ignore[16]: Item `None` of `typing.Union[None, exir.program._program.ExecutorchProgram, exir.program._program.ExecutorchProgramManager]` has no attribute `instruction_id_to_num_outs_map`
625
+ instruction_id_to_num_outs_map = (
626
+ executorch_program .executorch_program .instruction_id_to_num_outs_map
627
+ )
628
+ return (
629
+ debug_handle_map ,
630
+ delegate_map ,
631
+ instruction_id_to_num_outs_map ,
632
+ reference_outputs ,
633
+ representative_inputs ,
634
+ )
606
635
else :
607
636
debug_handle_map = executorch_program .debug_handle_map
608
637
delegate_map = executorch_program .delegate_map
609
- return debug_handle_map , delegate_map , None , None
638
+ instruction_id_to_num_outs_map = (
639
+ executorch_program .instruction_id_to_num_outs_map
640
+ )
641
+ return (
642
+ debug_handle_map ,
643
+ delegate_map ,
644
+ instruction_id_to_num_outs_map ,
645
+ None ,
646
+ None ,
647
+ )
610
648
611
649
612
650
def parse_etrecord (etrecord_path : str ) -> ETRecord : # noqa: C901
@@ -640,6 +678,7 @@ def parse_etrecord(etrecord_path: str) -> ETRecord: # noqa: C901
640
678
graph_map : Dict [str , ExportedProgram ] = {}
641
679
debug_handle_map = None
642
680
delegate_map = None
681
+ instruction_id_to_num_outs_map = None
643
682
exported_program = None
644
683
edge_dialect_program = None
645
684
reference_outputs = None
@@ -659,6 +698,12 @@ def parse_etrecord(etrecord_path: str) -> ETRecord: # noqa: C901
659
698
delegate_map = json .loads (
660
699
etrecord_zip .read (ETRecordReservedFileNames .DELEGATE_MAP_NAME )
661
700
)
701
+ elif entry == ETRecordReservedFileNames .INSTRUCTION_ID_TO_NUM_OUTS_MAP_NAME :
702
+ instruction_id_to_num_outs_map = json .loads (
703
+ etrecord_zip .read (
704
+ ETRecordReservedFileNames .INSTRUCTION_ID_TO_NUM_OUTS_MAP_NAME
705
+ )
706
+ )
662
707
elif entry == ETRecordReservedFileNames .ETRECORD_IDENTIFIER :
663
708
continue
664
709
elif entry == ETRecordReservedFileNames .EDGE_DIALECT_EXPORTED_PROGRAM :
@@ -724,6 +769,7 @@ def parse_etrecord(etrecord_path: str) -> ETRecord: # noqa: C901
724
769
graph_map = graph_map ,
725
770
_debug_handle_map = debug_handle_map ,
726
771
_delegate_map = delegate_map ,
772
+ _instruction_id_to_num_outs_map = instruction_id_to_num_outs_map ,
727
773
_reference_outputs = reference_outputs ,
728
774
_representative_inputs = representative_inputs ,
729
775
export_graph_id = export_graph_id ,
0 commit comments