@@ -70,6 +70,22 @@ def __init__(
70
70
_reference_outputs : Optional [Dict [str , List [ProgramOutput ]]] = None ,
71
71
_representative_inputs : Optional [List [ProgramInput ]] = None ,
72
72
):
73
+ """
74
+ Please do not construct an ETRecord object directly.
75
+
76
+ If you want to create an ETRecord for logging AOT information to further analysis, please mark `generate_etrecord`
77
+ as True in your export api, and get the ETRecord object from the `ExecutorchProgramManager`.
78
+ For exmaple:
79
+ ```python
80
+ exported_program = torch.export.export(model, inputs)
81
+ edge_program = to_edge_transform_and_lower(exported_program, generate_etrecord=True)
82
+ executorch_program = edge_program.to_executorch()
83
+ etrecord = executorch_program.get_etrecord()
84
+ ```
85
+
86
+ If user need to create an ETRecord manually, please use the `create_etrecord` function.
87
+ """
88
+
73
89
self .exported_program = exported_program
74
90
self .export_graph_id = export_graph_id
75
91
self .edge_dialect_program = edge_dialect_program
@@ -81,15 +97,25 @@ def __init__(
81
97
82
98
def save (self , path : Union [str , os .PathLike , BinaryIO , IO [bytes ]]) -> None :
83
99
"""
84
- Serialize and save the ETRecord to the specified path.
100
+ Serialize and save the ETRecord to the specified path for use in Inspector. The ETRecord
101
+ should contains at least edge dialect program and executorch program information for further
102
+ analysis, otherwise it will raise an exception.
85
103
86
104
Args:
87
105
path: Path where the ETRecord file will be saved to.
106
+
107
+ Raises:
108
+ RuntimeError: If the ETRecord does not contain essential information for Inpector.
88
109
"""
89
110
if isinstance (path , (str , os .PathLike )):
90
111
# pyre-ignore[6]: In call `os.fspath`, for 1st positional argument, expected `str` but got `Union[PathLike[typing.Any], str]`
91
112
path = os .fspath (path )
92
113
114
+ if not (self .edge_dialect_program and self ._debug_handle_map ):
115
+ raise RuntimeError (
116
+ "ETRecord must contain edge dialect program and executorch program to be saved"
117
+ )
118
+
93
119
etrecord_zip = ZipFile (path , "w" )
94
120
95
121
try :
0 commit comments