@@ -187,24 +187,22 @@ def forward(self, x):
187
187
188
188
from executorch .devtools import Inspector
189
189
190
+
190
191
# sphinx_gallery_start_ignore
191
- inspector_patch = patch .object (Inspector , "__init__" , return_value = None )
192
- inspector_patch_print = patch .object (Inspector , "print_data_tabular" , return_value = "" )
193
- inspector_patch .start ()
192
+ # inspector_patch = patch.object(Inspector, "__init__", return_value=None)
193
+ inspector_patch_print = patch .object (Inspector , "print_data_tabular" , return_value = None )
194
194
inspector_patch_print .start ()
195
195
# sphinx_gallery_end_ignore
196
196
etrecord_path = "etrecord.bin"
197
197
etdump_path = "etdump.etdp"
198
198
inspector = Inspector (etdump_path = etdump_path , etrecord = etrecord_path )
199
- # sphinx_gallery_start_ignore
200
- inspector .event_blocks = []
201
- # sphinx_gallery_end_ignore
202
199
inspector .print_data_tabular ()
203
200
204
- # sphinx_gallery_start_ignore
205
- inspector_patch .stop ()
206
- inspector_patch_print .stop ()
207
- # sphinx_gallery_end_ignore
201
+ ####################################
202
+ #
203
+ # Here is an example output:
204
+ #
205
+ # .. image:: ../_static/img/inspector_tabular_output.png
208
206
209
207
######################################################################
210
208
# Analyzing with an Inspector
@@ -234,11 +232,13 @@ def forward(self, x):
234
232
if event .name == "native_call_addmm.out" :
235
233
print (event .name , event .perf_data .raw if event .perf_data else "" )
236
234
235
+ print ()
237
236
# Via Dataframe
238
237
df = event_block .to_dataframe ()
239
238
df = df [df .event_name == "native_call_addmm.out" ]
240
- print (df [["event_name" , "raw" ]])
241
- print ()
239
+ if len (df ) > 0 :
240
+ print (df [["event_name" , "raw" ]])
241
+ print ()
242
242
243
243
######################################################################
244
244
# If a user wants to trace an operator back to their model code, they would do
@@ -255,6 +255,20 @@ def forward(self, x):
255
255
if slowest is not None :
256
256
print (slowest .name )
257
257
print ()
258
+ # sphinx_gallery_start_ignore
259
+ slowest_print = patch .object (
260
+ slowest ,
261
+ "stack_traces" ,
262
+ new = {
263
+ "aten_convolution_default_1_" : " File "
264
+ '"devtools-integration-tutorial.py", '
265
+ "line 82, in forward\n "
266
+ " x = F.max_pool2d(F.relu(self.conv2(x)), "
267
+ "2)\n "
268
+ },
269
+ )
270
+ slowest_print .start ()
271
+ # sphinx_gallery_end_ignore
258
272
pp .pprint (slowest .stack_traces )
259
273
print ()
260
274
pp .pprint (slowest .module_hierarchy )
@@ -264,7 +278,7 @@ def forward(self, x):
264
278
df = df [df .event_name == "native_call_convolution.out" ]
265
279
if len (df ) > 0 :
266
280
slowest = df .loc [df ["p50" ].idxmax ()]
267
- assert slowest
281
+ assert slowest is not None
268
282
print (slowest .name )
269
283
print ()
270
284
pp .pprint (slowest .stack_traces if slowest .stack_traces else "" )
@@ -281,6 +295,7 @@ def forward(self, x):
281
295
######################################################################
282
296
# Note: ``find_total_for_module`` is a special first class method of
283
297
# `Inspector <../model-inspector.html>`__
298
+ #
284
299
285
300
######################################################################
286
301
# Conclusion
0 commit comments