25
25
import torch
26
26
from executorch .exir import ExportedProgram
27
27
28
- from executorch .sdk .edir .et_schema import OperatorGraphWithStats , OperatorNode
28
+ from executorch .sdk .edir .et_schema import OperatorNode
29
29
from executorch .sdk .etdump .schema_flatcc import ETDumpFlatCC , ProfileEvent
30
+ from executorch .sdk .etrecord import parse_etrecord
30
31
from executorch .sdk .inspector ._inspector_utils import (
31
32
create_debug_handle_to_op_node_mapping ,
32
33
EDGE_DIALECT_GRAPH_KEY ,
33
34
gen_etdump_object ,
34
- gen_etrecord_object ,
35
35
gen_graphs_from_etrecord ,
36
36
)
37
37
@@ -368,7 +368,6 @@ class Inspector:
368
368
369
369
Private Attributes:
370
370
_etrecord: Optional[ETRecord]. File under etrecord_path deserialized into an object.
371
- _op_graph_dict: Mapping[str, OperatorGraphWithStats]. Graph objects parsed from etrecord matched with user defined graph names.
372
371
"""
373
372
374
373
def __init__ (
@@ -387,14 +386,18 @@ def __init__(
387
386
defaults to milli (1000ms = 1s).
388
387
"""
389
388
390
- # TODO: etrecord_path can be optional, so need to support the case when it is not present
391
- self ._etrecord = gen_etrecord_object (etrecord_path = etrecord_path )
389
+ self ._etrecord = (
390
+ parse_etrecord (etrecord_path = etrecord_path )
391
+ if etrecord_path is not None
392
+ else None
393
+ )
394
+
392
395
etdump = gen_etdump_object (etdump_path = etdump_path )
393
396
self .event_blocks = EventBlock ._gen_from_etdump (etdump , etdump_scale )
394
397
395
- self . _op_graph_dict : Mapping [
396
- str , OperatorGraphWithStats
397
- ] = gen_graphs_from_etrecord ( etrecord = self . _etrecord )
398
+ # No additional data association can be done without ETRecord, so return early
399
+ if self . _etrecord is None :
400
+ return
398
401
399
402
# Use the delegate map from etrecord, associate debug handles with each event
400
403
for event_block in self .event_blocks :
@@ -406,9 +409,10 @@ def __init__(
406
409
)
407
410
408
411
# Traverse the edge dialect op graph to create mapping from debug_handle to op node
412
+ op_graph_dict = gen_graphs_from_etrecord (etrecord = self ._etrecord )
409
413
debug_handle_to_op_node_map = {}
410
414
create_debug_handle_to_op_node_mapping (
411
- self . _op_graph_dict [EDGE_DIALECT_GRAPH_KEY ],
415
+ op_graph_dict [EDGE_DIALECT_GRAPH_KEY ],
412
416
debug_handle_to_op_node_map ,
413
417
)
414
418
@@ -479,13 +483,22 @@ def write_tensorboard_artifact(self, path: str) -> None:
479
483
# TODO: implement
480
484
pass
481
485
482
- def get_exported_program (self , graph : Optional [str ] = None ) -> ExportedProgram :
486
+ def get_exported_program (
487
+ self , graph : Optional [str ] = None
488
+ ) -> Optional [ExportedProgram ]:
483
489
"""
484
490
Access helper for ETRecord, defaults to returning Edge Dialect Program
485
491
486
492
Args:
487
493
graph: Name of the graph to access. If None, returns the Edge Dialect Program.
488
494
"""
489
- if graph is None :
490
- return self ._etrecord .edge_dialect_program
491
- return self ._etrecord .graph_map .get (graph )
495
+ if self ._etrecord is None :
496
+ log .warning (
497
+ "Exported program is only available when a valid etrecord_path was provided at the time of Inspector construction"
498
+ )
499
+ return None
500
+ return (
501
+ self ._etrecord .edge_dialect_program
502
+ if graph is None
503
+ else self ._etrecord .graph_map .get (graph )
504
+ )
0 commit comments