|
61 | 61 | #
|
62 | 62 | # # Imports
|
63 | 63 | # import copy
|
| 64 | +# |
64 | 65 | # import torch
|
65 | 66 | #
|
66 | 67 | # from executorch.examples.models.mobilenet_v2 import MV2Model
|
|
81 | 82 | # model.get_example_inputs(),
|
82 | 83 | # )
|
83 | 84 | #
|
84 |
| -# edge_program_manager: EdgeProgramManager = to_edge(aten_model, compile_config=EdgeCompileConfig(_check_ir_validity=True)) |
| 85 | +# edge_program_manager: EdgeProgramManager = to_edge( |
| 86 | +# aten_model, compile_config=EdgeCompileConfig(_check_ir_validity=True) |
| 87 | +# ) |
85 | 88 | # edge_program_manager_copy = copy.deepcopy(edge_program_manager)
|
86 | 89 | # et_program_manager: ExecutorchProgramManager = edge_program_manager_copy.to_executorch()
|
87 | 90 | #
|
|
121 | 124 | # Note: An ``ETRecord`` is not required. If an ``ETRecord`` is not provided,
|
122 | 125 | # the Inspector will show runtime results without operator correlation.
|
123 | 126 | #
|
124 |
| -# To visualize all runtime events, call ``print_data_tabular``:: |
| 127 | +# To visualize all runtime events, call Inspector's ``print_data_tabular``:: |
125 | 128 | #
|
126 | 129 | # from executorch.sdk import Inspector
|
127 | 130 | #
|
|
130 | 133 | # inspector.print_data_tabular()
|
131 | 134 | #
|
132 | 135 |
|
133 |
| - |
134 | 136 | ######################################################################
|
135 | 137 | # Analyzing with an Inspector
|
136 | 138 | # ---------------------------
|
137 | 139 | #
|
138 |
| -# ``Inspector`` provides 2 ways of accessing ingested information: `EventBlocks <../sdk-inspector.rst>`__ |
| 140 | +# ``Inspector`` provides 2 ways of accessing ingested information: `EventBlocks <../sdk-inspector.html>`__ |
139 | 141 | # and ``DataFrames``. These mediums give users the ability to perform custom
|
140 | 142 | # analysis about their model performance.
|
141 | 143 | #
|
|
144 | 146 | # # Set Up
|
145 | 147 | #
|
146 | 148 | # import pprint as pp
|
147 |
| -# import pandas as pd |
148 | 149 | #
|
149 |
| -# pd.set_option('display.max_colwidth', None) |
150 |
| -# pd.set_option('display.max_columns', None) |
| 150 | +# import pandas as pd |
151 | 151 | #
|
| 152 | +# pd.set_option("display.max_colwidth", None) |
| 153 | +# pd.set_option("display.max_columns", None) |
| 154 | + |
| 155 | +###################################################################### |
152 | 156 | # If a user wants the raw profiling results, they would do something similar to
|
153 | 157 | # finding the raw runtime data of an ``addmm.out`` event::
|
154 | 158 | #
|
155 | 159 | # for event_block in inspector.event_blocks:
|
156 | 160 | # # Via EventBlocks
|
157 | 161 | # for event in event_block.events:
|
158 |
| -# if event.name == 'native_call_addmm.out': |
| 162 | +# if event.name == "native_call_addmm.out": |
159 | 163 | # print(event.name, event.perf_data.raw)
|
160 | 164 | #
|
161 | 165 | # # Via Dataframe
|
162 | 166 | # df = event_block.to_dataframe()
|
163 |
| -# df = df[df.event_name == 'native_call_addmm.out'] |
164 |
| -# print(df[['event_name', 'raw']]) |
| 167 | +# df = df[df.event_name == "native_call_addmm.out"] |
| 168 | +# print(df[["event_name', 'raw"]]) |
165 | 169 | # print()
|
166 | 170 | #
|
| 171 | + |
| 172 | +###################################################################### |
167 | 173 | # If a user wants to trace an operator back to their model code, they would do
|
168 | 174 | # something similar to finding the module hierarchy and stack trace of the
|
169 | 175 | # slowest ``convolution.out`` call::
|
|
172 | 178 | # # Via EventBlocks
|
173 | 179 | # slowest = None
|
174 | 180 | # for event in event_block.events:
|
175 |
| -# if event.name == 'native_call_convolution.out': |
| 181 | +# if event.name == "native_call_convolution.out": |
176 | 182 | # if slowest is None or event.perf_data.p50 > slowest.perf_data.p50:
|
177 | 183 | # slowest = event
|
178 | 184 | # if slowest is not None:
|
179 | 185 | # print(slowest.name)
|
180 | 186 | # print()
|
181 | 187 | # pp.pprint(slowest.stack_traces)
|
182 | 188 | # print()
|
183 |
| -# pp.pprint(slowest.module_hierarchy |
| 189 | +# pp.pprint(slowest.module_hierarchy) |
184 | 190 | #
|
185 | 191 | # # Via Dataframe
|
186 | 192 | # df = event_block.to_dataframe()
|
187 |
| -# df = df[df.event_name == 'native_call_convolution.out'] |
| 193 | +# df = df[df.event_name == "native_call_convolution.out"] |
188 | 194 | # if len(df) > 0:
|
189 |
| -# slowest = df.loc[df['p50'].idxmax()] |
| 195 | +# slowest = df.loc[df["p50"].idxmax()] |
190 | 196 | # print(slowest.event_name)
|
191 | 197 | # print()
|
192 | 198 | # pp.pprint(slowest.stack_traces)
|
193 | 199 | # print()
|
194 | 200 | # pp.pprint(slowest.module_hierarchy)
|
195 | 201 | #
|
196 |
| -# If a user wants the total runtime of a module:: |
| 202 | + |
| 203 | +###################################################################### |
| 204 | +# If a user wants the total runtime of a module, they can use |
| 205 | +# ``find_total_for_module``:: |
197 | 206 | #
|
198 | 207 | # print(inspector.find_total_for_module("L__self___features"))
|
199 | 208 | # print(inspector.find_total_for_module("L__self___features_14"))
|
200 |
| -# |
| 209 | + |
| 210 | +###################################################################### |
201 | 211 | # Note: ``find_total_for_module`` is a special first class method of
|
202 | 212 | # `Inspector <../sdk-inspector.html>`__
|
203 |
| -# |
204 | 213 |
|
205 | 214 | ######################################################################
|
206 | 215 | # Conclusion
|
|
0 commit comments