Skip to content

Commit f9f89e5

Browse files
Jack-Khuufacebook-github-bot
authored andcommitted
Move Inspector Tutorial Code into individual code cells (#814)
Summary: Run linter on the code portions and separate them into different notebook cells --- Note: The generated Cell types are being set to markdown and that is intentional. Normally code cells would be best, but due to usage of runtime and python sections in this notebook, code cells would result in the documentation triggering a suite of build errors Differential Revision: D50147708
1 parent 164aeab commit f9f89e5

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#
6262
# # Imports
6363
# import copy
64+
#
6465
# import torch
6566
#
6667
# from executorch.examples.models.mobilenet_v2 import MV2Model
@@ -81,7 +82,9 @@
8182
# model.get_example_inputs(),
8283
# )
8384
#
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+
# )
8588
# edge_program_manager_copy = copy.deepcopy(edge_program_manager)
8689
# et_program_manager: ExecutorchProgramManager = edge_program_manager_copy.to_executorch()
8790
#
@@ -121,7 +124,7 @@
121124
# Note: An ``ETRecord`` is not required. If an ``ETRecord`` is not provided,
122125
# the Inspector will show runtime results without operator correlation.
123126
#
124-
# To visualize all runtime events, call ``print_data_tabular``::
127+
# To visualize all runtime events, call Inspector's ``print_data_tabular``::
125128
#
126129
# from executorch.sdk import Inspector
127130
#
@@ -130,12 +133,11 @@
130133
# inspector.print_data_tabular()
131134
#
132135

133-
134136
######################################################################
135137
# Analyzing with an Inspector
136138
# ---------------------------
137139
#
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>`__
139141
# and ``DataFrames``. These mediums give users the ability to perform custom
140142
# analysis about their model performance.
141143
#
@@ -144,26 +146,30 @@
144146
# # Set Up
145147
#
146148
# import pprint as pp
147-
# import pandas as pd
148149
#
149-
# pd.set_option('display.max_colwidth', None)
150-
# pd.set_option('display.max_columns', None)
150+
# import pandas as pd
151151
#
152+
# pd.set_option("display.max_colwidth", None)
153+
# pd.set_option("display.max_columns", None)
154+
155+
######################################################################
152156
# If a user wants the raw profiling results, they would do something similar to
153157
# finding the raw runtime data of an ``addmm.out`` event::
154158
#
155159
# for event_block in inspector.event_blocks:
156160
# # Via EventBlocks
157161
# for event in event_block.events:
158-
# if event.name == 'native_call_addmm.out':
162+
# if event.name == "native_call_addmm.out":
159163
# print(event.name, event.perf_data.raw)
160164
#
161165
# # Via Dataframe
162166
# 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"]])
165169
# print()
166170
#
171+
172+
######################################################################
167173
# If a user wants to trace an operator back to their model code, they would do
168174
# something similar to finding the module hierarchy and stack trace of the
169175
# slowest ``convolution.out`` call::
@@ -172,35 +178,38 @@
172178
# # Via EventBlocks
173179
# slowest = None
174180
# for event in event_block.events:
175-
# if event.name == 'native_call_convolution.out':
181+
# if event.name == "native_call_convolution.out":
176182
# if slowest is None or event.perf_data.p50 > slowest.perf_data.p50:
177183
# slowest = event
178184
# if slowest is not None:
179185
# print(slowest.name)
180186
# print()
181187
# pp.pprint(slowest.stack_traces)
182188
# print()
183-
# pp.pprint(slowest.module_hierarchy
189+
# pp.pprint(slowest.module_hierarchy)
184190
#
185191
# # Via Dataframe
186192
# 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"]
188194
# if len(df) > 0:
189-
# slowest = df.loc[df['p50'].idxmax()]
195+
# slowest = df.loc[df["p50"].idxmax()]
190196
# print(slowest.event_name)
191197
# print()
192198
# pp.pprint(slowest.stack_traces)
193199
# print()
194200
# pp.pprint(slowest.module_hierarchy)
195201
#
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``::
197206
#
198207
# print(inspector.find_total_for_module("L__self___features"))
199208
# print(inspector.find_total_for_module("L__self___features_14"))
200-
#
209+
210+
######################################################################
201211
# Note: ``find_total_for_module`` is a special first class method of
202212
# `Inspector <../sdk-inspector.html>`__
203-
#
204213

205214
######################################################################
206215
# Conclusion

0 commit comments

Comments
 (0)