|
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 | #
|
|
131 | 134 | # Note: An ``ETRecord`` is not required. If an ``ETRecord`` is not provided,
|
132 | 135 | # the Inspector will show runtime results without operator correlation.
|
133 | 136 | #
|
134 |
| -# To visualize all runtime events, call ``print_data_tabular``:: |
| 137 | +# To visualize all runtime events, call Inspector's ``print_data_tabular``:: |
135 | 138 | #
|
136 | 139 | # from executorch.sdk import Inspector
|
137 | 140 | #
|
|
140 | 143 | # inspector.print_data_tabular()
|
141 | 144 | #
|
142 | 145 |
|
143 |
| - |
144 | 146 | ######################################################################
|
145 | 147 | # Analyzing with an Inspector
|
146 | 148 | # ---------------------------
|
147 | 149 | #
|
148 |
| -# ``Inspector`` provides 2 ways of accessing ingested information: `EventBlocks <../sdk-inspector.rst>`__ |
| 150 | +# ``Inspector`` provides 2 ways of accessing ingested information: `EventBlocks <../sdk-inspector.html>`__ |
149 | 151 | # and ``DataFrames``. These mediums give users the ability to perform custom
|
150 | 152 | # analysis about their model performance.
|
151 | 153 | #
|
|
154 | 156 | # # Set Up
|
155 | 157 | #
|
156 | 158 | # import pprint as pp
|
157 |
| -# import pandas as pd |
158 | 159 | #
|
159 |
| -# pd.set_option('display.max_colwidth', None) |
160 |
| -# pd.set_option('display.max_columns', None) |
| 160 | +# import pandas as pd |
161 | 161 | #
|
| 162 | +# pd.set_option("display.max_colwidth", None) |
| 163 | +# pd.set_option("display.max_columns", None) |
| 164 | + |
| 165 | +###################################################################### |
162 | 166 | # If a user wants the raw profiling results, they would do something similar to
|
163 | 167 | # finding the raw runtime data of an ``addmm.out`` event::
|
164 | 168 | #
|
165 | 169 | # for event_block in inspector.event_blocks:
|
166 | 170 | # # Via EventBlocks
|
167 | 171 | # for event in event_block.events:
|
168 |
| -# if event.name == 'native_call_addmm.out': |
| 172 | +# if event.name == "native_call_addmm.out": |
169 | 173 | # print(event.name, event.perf_data.raw)
|
170 | 174 | #
|
171 | 175 | # # Via Dataframe
|
172 | 176 | # df = event_block.to_dataframe()
|
173 |
| -# df = df[df.event_name == 'native_call_addmm.out'] |
174 |
| -# print(df[['event_name', 'raw']]) |
| 177 | +# df = df[df.event_name == "native_call_addmm.out"] |
| 178 | +# print(df[["event_name', 'raw"]]) |
175 | 179 | # print()
|
176 | 180 | #
|
| 181 | + |
| 182 | +###################################################################### |
177 | 183 | # If a user wants to trace an operator back to their model code, they would do
|
178 | 184 | # something similar to finding the module hierarchy and stack trace of the
|
179 | 185 | # slowest ``convolution.out`` call::
|
|
182 | 188 | # # Via EventBlocks
|
183 | 189 | # slowest = None
|
184 | 190 | # for event in event_block.events:
|
185 |
| -# if event.name == 'native_call_convolution.out': |
| 191 | +# if event.name == "native_call_convolution.out": |
186 | 192 | # if slowest is None or event.perf_data.p50 > slowest.perf_data.p50:
|
187 | 193 | # slowest = event
|
188 | 194 | # if slowest is not None:
|
189 | 195 | # print(slowest.name)
|
190 | 196 | # print()
|
191 | 197 | # pp.pprint(slowest.stack_traces)
|
192 | 198 | # print()
|
193 |
| -# pp.pprint(slowest.module_hierarchy |
| 199 | +# pp.pprint(slowest.module_hierarchy) |
194 | 200 | #
|
195 | 201 | # # Via Dataframe
|
196 | 202 | # df = event_block.to_dataframe()
|
197 |
| -# df = df[df.event_name == 'native_call_convolution.out'] |
| 203 | +# df = df[df.event_name == "native_call_convolution.out"] |
198 | 204 | # if len(df) > 0:
|
199 |
| -# slowest = df.loc[df['p50'].idxmax()] |
| 205 | +# slowest = df.loc[df["p50"].idxmax()] |
200 | 206 | # print(slowest.event_name)
|
201 | 207 | # print()
|
202 | 208 | # pp.pprint(slowest.stack_traces)
|
203 | 209 | # print()
|
204 | 210 | # pp.pprint(slowest.module_hierarchy)
|
205 | 211 | #
|
206 |
| -# If a user wants the total runtime of a module:: |
| 212 | + |
| 213 | +###################################################################### |
| 214 | +# If a user wants the total runtime of a module, they can use |
| 215 | +# ``find_total_for_module``:: |
207 | 216 | #
|
208 | 217 | # print(inspector.find_total_for_module("L__self___features"))
|
209 | 218 | # print(inspector.find_total_for_module("L__self___features_14"))
|
210 |
| -# |
| 219 | + |
| 220 | +###################################################################### |
211 | 221 | # Note: ``find_total_for_module`` is a special first class method of
|
212 | 222 | # `Inspector <../sdk-inspector.html>`__
|
213 |
| -# |
214 | 223 |
|
215 | 224 | ######################################################################
|
216 | 225 | # Conclusion
|
|
0 commit comments