• 文档 >
  • 导出到 ExecuTorch API 参考
快捷方式

导出到 ExecuTorch API 参考

executorch.exir.to_edge(programs, constant_methods=None, compile_config=None)[source]

to_edge() 根据 ATen 方言中的一组导出程序构建一个 EdgeProgramManager。构建时,这些程序将转换为 edge 方言。

参数
  • programs – 可以是单个 ExportedProgram 或将函数名映射到其对应的 ExportedPrograms 的字典。如果仅提供单个 ExportedProgram,则将为其分配名称“forward”。

  • constant_methods – 一个可选的字典,其中方法名对应于 eager 模式下该方法返回的常量值。通常用于存储 Edge 模型的配置信息。

  • compile_config – 一个可选参数,用于更好地控制转换为 edge 方言的过程。

返回

EdgeProgramManager

class executorch.exir.EdgeProgramManager(edge_programs, constant_methods=None, compile_config=None)[source]

Edge 方言中一个或多个 ExportedPrograms 的包。旨在简化降低到 ExecuTorch。请参阅:https://pytorch.ac.cn/executorch/stable/ir-exir.html

允许轻松地对一组导出程序应用转换,包括子图的委派。

管理 ATen -> Edge -> ExecuTorch 降低链中的第二个链接。

property config_methods

返回此 EdgeProgramManager 中的配置方法集。

exported_program(method_name='forward')[源代码]

返回“method_name”指定的 ExportedProgram。

property methods

返回此 EdgeProgramManager 中的方法集。

to_backend(partitioner)[源代码]

返回与输入给定的程序语义等价的程序,但 EdgeProgramManager 中的每个程序的部分被指定为由分区程序确定的委派目标。

参数

分区程序

分区程序可以是 Partitioner 子类实例,也可以是将方法名称映射到 Partitioner 子类实例的字典。如果它是 Partitioner 子类,则使用给定的分区程序降低给定 EdgeProgramManager 中的所有程序。如果它是字典,则仅使用给定的分区程序降低字典中指定的方法名称。

Partitioner 子类实例负责标记输入程序的部分以进行委派。有效的分区程序必须返回 PartitionerResult,其中包括有效的 partition_tags:Dict[str, DelegationSpec],其中每个键都是一个标记名称,具有相同标记的节点将融合为一个子图,并委派给委派规范中指定的后台。

返回

调用 EdgeProgramManager 的副本,其中指定子图已降低。

返回类型

EdgeProgramManager

to_executorch(config=None)[source]

将程序转换为 ExecuTorch 后端。

参数

config – 一个可选参数,用于对转换为 ExecuTorch 后端的过程进行更大程度的控制。

返回

在转换为 ExecuTorch 后端后,表示 EdgeProgramManager 状态的管理器。

返回类型

ExecutorchProgramManager

transform(passes, check_ir_validity=True)[source]

根据提供的 pass 转换程序。

参数

passes – pass 可以是 pass 列表,也可以是将方法名称映射到 pass 列表的字典。如果它只是一个 pass 列表,则给定 EdgeProgramManager 中的所有方法都将使用提供的 pass 进行转换。如果它是一个字典,则只有字典中指定的方法名称才会使用其对应的 pass 进行转换。

返回

应用转换后调用 EdgeProgramManager 的副本。

返回类型

EdgeProgramManager

class executorch.exir.ExecutorchProgramManager(execution_programs, config_methods=None, backend_config=None)[source]

执行方言中一个或多个 ExportedPrograms 的包。旨在简化降低到 ExecuTorch 的过程。请参阅:https://pytorch.ac.cn/executorch/stable/ir-exir.html

当构造 ExecutorchProgramManager 时,执行方言中的 ExportedPrograms 用于形成 executorch 二进制文件(在称为发射的过程),然后序列化到缓冲区。

管理 ATen -> Edge -> ExecuTorch 降低链中的最后一个环节。

property buffer

将序列化的 ExecuTorch 二进制文件作为字节字符串返回。

请注意,对 buffer 的调用可能会分配大量连续内存,具体取决于模型大小。如果写入文件,请使用 write_to_file,它不会产生额外的副本。

property config_methods

返回此 ExecutorchProgramManager 中的配置方法集。

dump_executorch_program(verbose=False)[source]

以人类可读的格式打印 ExecuTorch 二进制文件。

参数

verbose (bool) – 如果为 False,则以简明格式打印二进制文件。如果为 True,则按架构中的规范 1-1 打印二进制文件。

exported_program(method_name='forward')[source]

返回“method_name”指定的 ExportedProgram。

property methods

返回此 ExecutorchProgramManager 中的方法集。

executorch.exir.backend.backend_api.to_backend(args)[source]
executorch.exir.backend.backend_api.to_backend(backend_id, edge_program, compile_specs)
executorch.exir.backend.backend_api.to_backend(edge_program, partitioner_instance)

通用函数,分派发生在第一个参数的类型上。目前有两个重载的 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
class executorch.exir.backend.backend_api.LoweredBackendModule(edge_program, backend_id, processed_bytes, compile_specs)[source]

nn.Module 的子类,为包含委托函数的模块生成。这可以通过调用 to_backend 创建。

property backend_id

返回后端的名称。

buffer(extract_delegate_segments=False, segment_alignment=4096, constant_tensor_alignment=None, delegate_alignment=None)[source]

返回包含序列化 ExecuTorch 二进制文件的缓冲区。

property compile_specs

返回包含用于配置“编译”过程的静态元数据的特定于后端的对象列表。

property original_module

返回原始 EXIR 模块

property processed_bytes

返回由 backend.preprocess 创建的委托 blob

文档

访问 PyTorch 的综合开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源