Skip to content

Commit 2a2a565

Browse files
Jack-Khuufacebook-github-bot
authored andcommitted
Move Inspector Tutorial Code into individual code cells (#814)
Summary: Pull Request resolved: #814 The generated Notebook Cell types were being set to markdown. This diff just makes them into code cells Differential Revision: D50147708 fbshipit-source-id: 4768ed781c9869e6a4776afa22733ab9bb14aff0
1 parent db752d4 commit 2a2a565

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

docs/source/tutorials_source/sdk-integration-tutorial.py

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757
# edge dialect model (``EdgeProgramManager``), the ExecuTorch dialect model
5858
# (``ExecutorchProgramManager``), and an optional dictionary of additional models
5959
#
60-
# In this tutorial, the mobilenet v2 example model is used to demonstrate::
61-
#
60+
# In this tutorial, the mobilenet v2 example model is used to demonstrate.
61+
62+
######################################################################
6263
# # Imports
6364
# import copy
65+
#
6466
# import torch
6567
#
6668
# from executorch.examples.models.mobilenet_v2 import MV2Model
@@ -81,15 +83,18 @@
8183
# model.get_example_inputs(),
8284
# )
8385
#
84-
# edge_program_manager: EdgeProgramManager = to_edge(aten_model, compile_config=EdgeCompileConfig(_check_ir_validity=True))
86+
# edge_program_manager: EdgeProgramManager = to_edge(
87+
# aten_model, compile_config=EdgeCompileConfig(_check_ir_validity=True)
88+
# )
8589
# edge_program_manager_copy = copy.deepcopy(edge_program_manager)
8690
# et_program_manager: ExecutorchProgramManager = edge_program_manager_copy.to_executorch()
8791
#
8892
#
8993
# # Generate ETRecord
9094
# etrecord_path = "etrecord.bin"
9195
# generate_etrecord(etrecord_path, edge_program_manager, et_program_manager)
92-
#
96+
97+
######################################################################
9398
# .. warning::
9499
# Users should do a deepcopy of the output of to_edge() and pass in the
95100
# deepcopy to the generate_etrecord API. This is needed because the
@@ -131,15 +136,15 @@
131136
# Note: An ``ETRecord`` is not required. If an ``ETRecord`` is not provided,
132137
# the Inspector will show runtime results without operator correlation.
133138
#
134-
# To visualize all runtime events, call ``print_data_tabular``::
135-
#
139+
# To visualize all runtime events, call Inspector's ``print_data_tabular``.
140+
141+
######################################################################
136142
# from executorch.sdk import Inspector
137143
#
144+
# etrecord_path = "etdump.etdp"
138145
# etdump_path = "etdump.etdp"
139146
# inspector = Inspector(etdump_path=etdump_path, etrecord_path=etrecord_path)
140147
# inspector.print_data_tabular()
141-
#
142-
143148

144149
######################################################################
145150
# Analyzing with an Inspector
@@ -149,68 +154,76 @@
149154
# and ``DataFrames``. These mediums give users the ability to perform custom
150155
# analysis about their model performance.
151156
#
152-
# Below are examples usages, with both ``EventBlock`` and ``DataFrame`` approaches::
153-
#
157+
# Below are examples usages, with both ``EventBlock`` and ``DataFrame`` approaches.
158+
159+
######################################################################
154160
# # Set Up
155-
#
156161
# import pprint as pp
157-
# import pandas as pd
158162
#
159-
# pd.set_option('display.max_colwidth', None)
160-
# pd.set_option('display.max_columns', None)
163+
# import pandas as pd
161164
#
165+
# pd.set_option("display.max_colwidth", None)
166+
# pd.set_option("display.max_columns", None)
167+
168+
######################################################################
162169
# If a user wants the raw profiling results, they would do something similar to
163-
# finding the raw runtime data of an ``addmm.out`` event::
164-
#
170+
# finding the raw runtime data of an ``addmm.out`` event.
171+
172+
######################################################################
165173
# for event_block in inspector.event_blocks:
166174
# # Via EventBlocks
167175
# for event in event_block.events:
168-
# if event.name == 'native_call_addmm.out':
176+
# if event.name == "native_call_addmm.out":
169177
# print(event.name, event.perf_data.raw)
170178
#
171179
# # Via Dataframe
172180
# df = event_block.to_dataframe()
173-
# df = df[df.event_name == 'native_call_addmm.out']
174-
# print(df[['event_name', 'raw']])
181+
# df = df[df.event_name == "native_call_addmm.out"]
182+
# print(df[["event_name', 'raw"]])
175183
# print()
176-
#
184+
185+
######################################################################
177186
# If a user wants to trace an operator back to their model code, they would do
178187
# something similar to finding the module hierarchy and stack trace of the
179-
# slowest ``convolution.out`` call::
180-
#
188+
# slowest ``convolution.out`` call.
189+
190+
######################################################################
181191
# for event_block in inspector.event_blocks:
182192
# # Via EventBlocks
183193
# slowest = None
184194
# for event in event_block.events:
185-
# if event.name == 'native_call_convolution.out':
195+
# if event.name == "native_call_convolution.out":
186196
# if slowest is None or event.perf_data.p50 > slowest.perf_data.p50:
187197
# slowest = event
188198
# if slowest is not None:
189199
# print(slowest.name)
190200
# print()
191201
# pp.pprint(slowest.stack_traces)
192202
# print()
193-
# pp.pprint(slowest.module_hierarchy
203+
# pp.pprint(slowest.module_hierarchy)
194204
#
195205
# # Via Dataframe
196206
# df = event_block.to_dataframe()
197-
# df = df[df.event_name == 'native_call_convolution.out']
207+
# df = df[df.event_name == "native_call_convolution.out"]
198208
# if len(df) > 0:
199-
# slowest = df.loc[df['p50'].idxmax()]
209+
# slowest = df.loc[df["p50"].idxmax()]
200210
# print(slowest.event_name)
201211
# print()
202212
# pp.pprint(slowest.stack_traces)
203213
# print()
204214
# pp.pprint(slowest.module_hierarchy)
205-
#
206-
# If a user wants the total runtime of a module::
207-
#
215+
216+
######################################################################
217+
# If a user wants the total runtime of a module, they can use
218+
# ``find_total_for_module``.
219+
220+
######################################################################
208221
# print(inspector.find_total_for_module("L__self___features"))
209222
# print(inspector.find_total_for_module("L__self___features_14"))
210-
#
223+
224+
######################################################################
211225
# Note: ``find_total_for_module`` is a special first class method of
212226
# `Inspector <../sdk-inspector.html>`__
213-
#
214227

215228
######################################################################
216229
# Conclusion

0 commit comments

Comments
 (0)