目录

检查器 API

概述

Inspector API 为分析 ETRecordETDump 的内容,帮助开发者了解模型 架构和性能统计数据。它构建在 EventBlock 类数据结构 它组织了一组 Events,以便轻松访问分析事件的详细信息。

用户可以通过多种方式与 Inspector 交互 蜜蜂属:

  • 通过使用类提供的公共方法Inspector

  • 通过访问 、 和 类的 public 属性InspectorEventBlockEvent

  • 通过使用 CLI 工具实现基本功能。

请参阅 e2e 用例文档,了解如何在实际示例中使用这些内容。

Inspector 方法

构造 函数

executorch.devtools.Inspector 的__init__selfetdump_path=Noneetrecord=Nonesource_time_scale=TimeScale.NStarget_time_scale=TimeScale.MSdebug_buffer_path=delegate_metadata_parser=delegate_time_scale_converter=enable_module_hierarchy=False)

使用基础 EventBlock初始化 Inspector 实例,其中填充了来自提供的 ETDump 路径的数据 和可选的 ETRecord 路径。

参数
  • etdump_path – ETDump 文件的路径。

  • etrecord – 可选的 ETRecord 对象或 ETRecord 文件的路径。

  • source_time_scale – 从运行时检索的性能数据的时间刻度。运行时中的默认时间钩子实现返回 NS。

  • target_time_scale – 用户希望将其性能数据转换为的目标时间刻度。默认为 MS。

  • debug_buffer_path – 调试缓冲区文件路径,其中包含 ETDump 为中间和程序输出引用的调试数据。

  • delegate_metadata_parser – 用于解析性能分析事件中的委托元数据的可选函数。该函数的预期签名为: (delegate_metadata_list: List[bytes]) -> Union[List[str], Dict[str, Any]]

  • delegate_time_scale_converter – 用于转换委托分析数据的时间刻度的可选函数。如果未给出,请使用 target_time_scale/source_time_scale。

  • enable_module_hierarchy – 在操作员图中启用子模块。默认为 False。

返回

没有

示例用法:

from executorch.devtools import Inspector

inspector = Inspector(etdump_path="/path/to/etdump.etdp", etrecord="/path/to/etrecord.bin")

to_dataframe

executorch.devtools.Inspector 的to_dataframeselfinclude_units=Trueinclude_delegate_debug_data=False)
参数
  • include_units – 标题是否应包含单位 (默认为 true)

  • include_delegate_debug_data – 是否包含委托调试元数据 (默认为 false)

返回

返回检查器中每个 EventBlock 中 Events 的 pandas DataFrame,每行表示一个 Event。

find_total_for_module

executorch.devtools.Inspector 的find_total_for_moduleselfmodule_name)

返回指定模块中所有运算符的总平均计算时间。

参数

module_name – 要聚合的模块的名称。

返回

模块中所有运算符的平均计算时间(以秒为单位)的总和,其中 “module_name”。

示例用法:

print(inspector.find_total_for_module("L__self___conv_layer"))
0.002

get_exported_program

executorch.devtools.Inspector 的get_exported_programselfgraph=无))

ETRecord 的访问帮助程序默认返回 Edge Dialect 程序。

参数

graph – 要访问的图形的可选名称。如果为 None,则返回 Edge Dialect 程序。

返回

“graph” 的 ExportedProgram 对象。

示例用法:

print(inspector.get_exported_program())
ExportedProgram:
    class GraphModule(torch.nn.Module):
        def forward(self, arg0_1: f32[4, 3, 64, 64]):
            # No stacktrace found for following nodes
            _param_constant0 = self._param_constant0
            _param_constant1 = self._param_constant1

            ### ... Omit part of the program for documentation readability ... ###

Graph signature: ExportGraphSignature(parameters=[], buffers=[], user_inputs=['arg0_1'], user_outputs=['aten_tan_default'], inputs_to_parameters={}, inputs_to_buffers={}, buffers_to_mutate={}, backward_signature=None, assertion_dep_token=None)
Range constraints: {}
Equality constraints: []

Inspector 属性

EventBlock

通过属性 实例中,例如:EventBlockevent_blocksInspector

inspector.event_blocks
executorch.devtools.inspector。EventBlock名称事件=<factory>source_time_scale=TimeScale.NStarget_time_scale=TimeScale.MSbundled_input_index=无run_output=无reference_output=无[来源]

EventBlock 包含与从运行时检索的特定性能分析/调试块关联的事件集合。 每个 EventBlock 表示一种执行模式。例如,模型启动和加载位于单个 EventBlock 中。 如果存在控制流,则每个分支将由单独的 EventBlock 表示。

参数
  • name – 性能分析/调试块的名称。

  • events – 与性能分析/调试块关联的 Event列表。

  • bundled_input_idx – 此 EventBlock 对应的捆绑输入的索引。

  • run_output – 运行从封装事件中提取的输出

Event

通过 instance 的属性访问实例。EventeventsEventBlock

executorch.devtools.inspector。Eventnameperf_data=无op_types=<factory>delegate_debug_identifier=无debug_handles=无stack_traces=<factory>module_hierarchy=<factory>is_delegated_op=无delegate_backend_name=无_delegate_debug_metadatas=<factory>debug_data=<factory>_instruction_id=无_delegate_metadata_parser=无_delegate_time_scale_converter=无[来源]

Event 对应于一个运算符实例,其中包含从运行时检索的 perf 数据以及 ETRecord 中的其他元数据。

参数
  • name – 分析事件的名称,如果没有分析事件,则为空。

  • perf_data – 与从运行时检索的事件关联的性能数据(可用属性:p10、p50、p90、avg、min 和 max)。

  • op_type – 与事件对应的操作类型列表。

  • delegate_debug_identifier – 与指令 ID 结合使用的补充标识符。

  • debug_handles – 与此事件相关的模型图中的 Debug 句柄。

  • stack_trace – 一个字典,用于将每个关联操作的名称映射到其堆栈跟踪。

  • module_hierarchy – 将每个关联运算的名称映射到其模块层次结构的字典。

  • is_delegated_op – 事件是否已委派。

  • delegate_backend_name – 此事件委托到的后端的名称。

  • _delegate_debug_metadatas – 以字符串形式显示的原始委托调试元数据列表,每个配置文件事件一个元数据。 可用解析(如果提供解析器)作为 Event.delegate_debug_metadatas 以 Event.raw_delegate_debug_metadatas 的形式提供

  • debug_data – 包含收集的中间数据的列表。

  • _instruction_id – 符号化的指令标识符

  • _delegate_metadata_parser – _delegate_debug_metadatas 的可选解析器

示例用法:

for event_block in inspector.event_blocks:
    for event in event_block.events:
        if event.name == "Method::execute":
            print(event.perf_data.raw)
[175.748, 78.678, 70.429, 122.006, 97.495, 67.603, 70.2, 90.139, 66.344, 64.575, 134.135, 93.85, 74.593, 83.929, 75.859, 73.909, 66.461, 72.102, 84.142, 77.774, 70.038, 80.246, 59.134, 68.496, 67.496, 100.491, 81.162, 74.53, 70.709, 77.112, 59.775, 79.674, 67.54, 79.52, 66.753, 70.425, 71.703, 81.373, 72.306, 72.404, 94.497, 77.588, 79.835, 68.597, 71.237, 88.528, 71.884, 74.047, 81.513, 76.116]

命令行界面

在终端中执行以下命令以显示数据 桌子。此命令生成的 table 输出与调用前面提到的 print_data_tabular 相同:

python3 -m devtools.inspector.inspector_cli --etdump_path <path_to_etdump> --etrecord_path <path_to_etrecord>

请注意,etrecord_path 参数是可选的。

我们计划在将来扩展 CLI 的功能。

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源