Skip to content

Commit 7ef721c

Browse files
Jack-Khuufacebook-github-bot
authored andcommitted
Move Inspector Tutorial Code into individual code cells (#814)
Summary: Pull Request resolved: #814 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 Reviewed By: tarun292 Differential Revision: D50147708 fbshipit-source-id: 80f31eaea6fe7473091b33364c266eaeef785ae4
1 parent c20df2a commit 7ef721c

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
#
@@ -131,7 +134,7 @@
131134
# Note: An ``ETRecord`` is not required. If an ``ETRecord`` is not provided,
132135
# the Inspector will show runtime results without operator correlation.
133136
#
134-
# To visualize all runtime events, call ``print_data_tabular``::
137+
# To visualize all runtime events, call Inspector's ``print_data_tabular``::
135138
#
136139
# from executorch.sdk import Inspector
137140
#
@@ -140,12 +143,11 @@
140143
# inspector.print_data_tabular()
141144
#
142145

143-
144146
######################################################################
145147
# Analyzing with an Inspector
146148
# ---------------------------
147149
#
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>`__
149151
# and ``DataFrames``. These mediums give users the ability to perform custom
150152
# analysis about their model performance.
151153
#
@@ -154,26 +156,30 @@
154156
# # Set Up
155157
#
156158
# import pprint as pp
157-
# import pandas as pd
158159
#
159-
# pd.set_option('display.max_colwidth', None)
160-
# pd.set_option('display.max_columns', None)
160+
# import pandas as pd
161161
#
162+
# pd.set_option("display.max_colwidth", None)
163+
# pd.set_option("display.max_columns", None)
164+
165+
######################################################################
162166
# If a user wants the raw profiling results, they would do something similar to
163167
# finding the raw runtime data of an ``addmm.out`` event::
164168
#
165169
# for event_block in inspector.event_blocks:
166170
# # Via EventBlocks
167171
# for event in event_block.events:
168-
# if event.name == 'native_call_addmm.out':
172+
# if event.name == "native_call_addmm.out":
169173
# print(event.name, event.perf_data.raw)
170174
#
171175
# # Via Dataframe
172176
# 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"]])
175179
# print()
176180
#
181+
182+
######################################################################
177183
# If a user wants to trace an operator back to their model code, they would do
178184
# something similar to finding the module hierarchy and stack trace of the
179185
# slowest ``convolution.out`` call::
@@ -182,35 +188,38 @@
182188
# # Via EventBlocks
183189
# slowest = None
184190
# for event in event_block.events:
185-
# if event.name == 'native_call_convolution.out':
191+
# if event.name == "native_call_convolution.out":
186192
# if slowest is None or event.perf_data.p50 > slowest.perf_data.p50:
187193
# slowest = event
188194
# if slowest is not None:
189195
# print(slowest.name)
190196
# print()
191197
# pp.pprint(slowest.stack_traces)
192198
# print()
193-
# pp.pprint(slowest.module_hierarchy
199+
# pp.pprint(slowest.module_hierarchy)
194200
#
195201
# # Via Dataframe
196202
# 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"]
198204
# if len(df) > 0:
199-
# slowest = df.loc[df['p50'].idxmax()]
205+
# slowest = df.loc[df["p50"].idxmax()]
200206
# print(slowest.event_name)
201207
# print()
202208
# pp.pprint(slowest.stack_traces)
203209
# print()
204210
# pp.pprint(slowest.module_hierarchy)
205211
#
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``::
207216
#
208217
# print(inspector.find_total_for_module("L__self___features"))
209218
# print(inspector.find_total_for_module("L__self___features_14"))
210-
#
219+
220+
######################################################################
211221
# Note: ``find_total_for_module`` is a special first class method of
212222
# `Inspector <../sdk-inspector.html>`__
213-
#
214223

215224
######################################################################
216225
# Conclusion

0 commit comments

Comments
 (0)