导出到 ExecuTorch API 参考¶
有关 API 如何发展和弃用过程的详细信息,请参阅 ExecuTorch API 生命周期和弃用策略。
- executorch.exir 中。to_edge(程序,constant_methods=无,compile_config=无)[来源]¶
从 ATen dialect.在构建时,这些程序将转换为 edge dialect。
- 参数
programs – 可以是单个 ExportedProgram 或将函数名称映射到其相应 ExportedPrograms 的字典。如果只提供了一个 ExportedProgram,则将为其分配名称 “forward”。
constant_methods – 一个可选的方法名称字典,其中包含该方法在 Eager 模式下返回的常量值。通常用于存储 Edge 模型的配置信息。
compile_config – 一个可选参数,用于更好地控制转换为 edge dialect 过程。
- 返回
EdgeProgramManager
- executorch.exir 中。to_edge_transform_and_lower(程序, transform_passes=无, partitioner=无, constant_methods=无, compile_config=无)[来源]¶
从一组 以 ATen 方言导出的程序。它与 to_edge 的根本区别在于 将 ATen 方言转换为 edge 方言程序,然后运行 转换通过,然后将程序降低到其 相应的后端都集成到一个 API 中。
这对于降低到已注册 ops 的后端非常有用 不想被分解,因此依赖于与这些未分解的 OPS 匹配。为 这些类型的后端,这是唯一应该用于降低到边缘的 API 方言。使用 to_edge(...) 和 to_backend(...) 的组合将导致不一致 或错误的行为。
此 API 是降低到基于 CPU 的 XNNPack 后端的主要推荐方法。
- 参数
programs— 可以是单个 ExportedProgram 或映射函数名称的字典 添加到相应的 ExportedPrograms 中。如果只有一个 ExportedProgram 是 前提是它将被分配名称 “forward”。
transform_passes – 通行证可以是通行证列表,也可以是字典 将方法名称映射到通道列表。如果它只是一个传递列表,则所有方法 在给定的 EdgeProgramManager 中,将使用提供的通道进行转换。如果它 是一个字典,则只会转换字典中指定的方法名称 及其相应的通行证。
partitioner – 分区器可以是 Partitioner 子类实例,也可以是 字典 Map 方法名称到 Partitioner 子类实例。如果它是一个 Partitioner 子类中,给定 EdgeProgramManager 中的所有程序都会被降低 使用给定的 partitioner。如果是字典,则仅在 字典将使用给定的 partitioner 降低。
constant_methods – 将方法名称转换为常量值的可选字典 由该方法在 EAGER 模式下返回。通常用于存储 上的配置信息 Edge 模型。
compile_config – 一个可选参数,用于更好地控制 转换为 Edge dialect 过程。
- 返回
EdgeProgramManager
- 类 executorch.exir 中。EdgeProgramManager(edge_programs, constant_methods=无, compile_config=无, ops_set_to_not_decompose=无)[来源]¶
Edge 方言中的一个或多个 ExportedPrograms 的包。旨在简化 降低到 ExecuTorch。另请: https://pytorch.org/executorch/stable/ir-exir.html
允许在导出的程序集合中轻松应用转换 包括子图的委派。
管理 ATen -> Edge -> ExecuTorch 的下降链中的第二个链接。
- 属性 config_methods¶
返回此 EdgeProgramManager 中的配置方法集。
- 属性方法¶
返回此 EdgeProgramManager 中的方法集。
- to_backend(分区程序)[来源]¶
返回一个语义上等价的程序,该程序与作为输入的程序相同, 但目标 EdgeProgramManager 中每个程序的部分 for delegation (由分区程序确定)。
- 参数
partitioner — 分区程序 –
分区器可以是 Partitioner 子类实例,也可以是 字典 Map 方法名称到 Partitioner 子类实例。如果它是一个 Partitioner 子类,则给定 EdgeProgramManager 中的所有程序 将使用给定的 partitioner 降低。如果它是一个 dictionary 中,只有字典中指定的方法名称才会是 使用给定的 partitioner 降低。
Partitioner 子类实例负责标记 委托的 input 程序。有效的分区程序必须返回 PartitionerResult,包括有效的 partition_tags:Dict[str, DelegationSpec],其中每个键都是一个标签 name 和具有相同 tag 的节点将被融合为 one 子图, delegated to backend 中指定的 delegate spec.
- 返回
调用 EdgeProgramManager 的副本,其中包含 指定的子图降低。
- 返回类型
- to_executorch(config=None)[来源]¶
将程序转换为 ExecuTorch 后端。
- 参数
config – 一个可选参数,用于更好地控制 到 ExecuTorch 后端的转换。
- 返回
表示 EdgeProgramManager 状态的管理器 在它被转换为 ExecuTorch 后端之后。
- 返回类型
- transform(passes, compile_config=None)[来源]¶
根据提供的通道转换程序。
- 参数
passes – 这些通行证可以是通行证列表,也可以是 字典 将方法名称映射到传递列表。如果是 只是一个传递列表,给定 EdgeProgramManager 中的所有方法 将使用提供的通道进行转换。如果它是一个 dictionary 中,只有字典中指定的方法名称才会是 transformed。
compile_config – 编译配置以验证模型的正确性 图表。如果未指定,则 调用 EdgeProgramManager。它将在 as compile 中使用 config 返回的 EdgeProgramManager 的 Edge ProgramManager 的 Edge ProgramManager 的 Edge Program Manager 中
- 返回
调用 EdgeProgramManager 的副本,其中包含 应用转换。
- 返回类型
- 类 executorch.exir 中。ExecutorchProgramManager(execution_programs, config_methods=无, backend_config=无)[来源]¶
执行方言中的一个或多个 ExportedPrograms 的包。旨在简化 降低到 ExecuTorch。另请: https://pytorch.org/executorch/stable/ir-exir.html
当 ExecutorchProgramManager 被构造时,ExportedPrograms in execution dialect 用于形成 executorch 二进制文件(在称为 emission的过程中),然后序列化 添加到缓冲区。
管理 ATen -> Edge -> ExecuTorch 的下降链中的最后一个环节。
- 属性缓冲区¶
将序列化的 ExecuTorch 二进制文件作为字节字符串返回。
请注意,对 buffer 的调用可能会分配非常大量的 连续内存,具体取决于模型大小。如果写入文件, 使用不会产生额外副本的 write_to_file。
- 属性 config_methods¶
返回此 ExecutorchProgramManager 中的配置方法集。
- dump_executorch_program(verbose=False, out=None)[来源]¶
以人类可读的格式打印 ExecuTorch 二进制文件。
- 参数
verbose (bool) – 如果为 False,则以压缩格式打印二进制文件。 如果为 True,则打印二进制 1-1 以及架构中的规范。
出 –
如果为 None,则打印到 stdout。 如果为非 None,则将字符串写入该 stream 对象。可以是
文件对象、StringIO 对象或任何其他 TextIO 子类。
- 属性方法¶
返回此 ExecutorchProgramManager 中的方法集。
- executorch.exir.backend.backend_api。to_backend(args)[来源]¶
- executorch.exir.backend.backend_api。to_backend(backend_id, edge_program, compile_specs)
- executorch.exir.backend.backend_api。to_backend(edge_program, partitioner_instance)
一个泛型函数,dispatch 发生在第一个参数的类型上。目前有 to 重载的 to_backend 函数:
注意: Python 是动态类型的语言,因此不能有适当的方法重载,因为这需要语言 能够在编译时区分类型。@to_backend.register to_backend将根据第一个 参数(需要类型注释)。但是,它不能将多个类型作为参数。
def to_backend( backend_id: str, edge_graph_module: ExportedProgram, compile_specs: List[CompileSpec], ) -> LoweredBackendModule: def to_backend( graph_module: torch.fx.GraphModule, partitioner: Type[TPartitioner], ) -> torch.fx.GraphModule
- executorch.exir.backend.backend_api 类。LoweredBackendModule(edge_program, backend_id, processed_bytes, compile_specs)[来源]¶
nn.为包含 委托函数。这可以通过调用 to_backend 来创建。
- 属性backend_id¶
返回后端名称。
- buffer(extract_delegate_segments=False, segment_alignment=128, constant_tensor_alignment=无, delegate_alignment=无, memory_planning=无)[来源]¶
返回包含序列化 ExecuTorch 二进制文件的缓冲区。
- 物业 compile_specs¶
返回具有静态元数据的后端特定对象列表,以配置 “compilation” 过程。
- 属性 original_module¶
返回原始 EXIR 模块
- 属性 processed_bytes¶
返回从 backend.preprocess 创建的委托 blob