• Docs >
  • Export to ExecuTorch API Reference
Shortcuts

Export to ExecuTorch API Reference

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

to_edge() constructs an EdgeProgramManager from a set of exported programs in ATen dialect. Upon construction those programs are transformed into edge dialect.

Parameters
  • programs – Can be a single ExportedProgram or a dictionary mapping function names to their corresponding ExportedPrograms. If only a single ExportedProgram is provided it will be assigned the name “forward”.

  • constant_methods – An optional dictionary of method name to the constant value returned by that method in eager mode. Often used to store config information on Edge models.

  • compile_config – An optional argument used to provide greater control over the transformation to edge dialect process.

Returns

EdgeProgramManager

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

Package of one or more ExportedPrograms in Edge dialect. Designed to simplify lowering to ExecuTorch. See: https://pytorch.org/executorch/stable/ir-exir.html

Allows easy applications of transforms across a collection of exported programs including the delegation of subgraphs.

Manages the second link in the lowering chain of ATen -> Edge -> ExecuTorch.

property config_methods

Returns the set of config methods in this EdgeProgramManager.

exported_program(method_name='forward')[source]

Returns the ExportedProgram specified by ‘method_name’.

property methods

Returns the set of methods in this EdgeProgramManager.

to_backend(partitioner)[source]

Returns a semantically-equivalent program to the one given as input, but with portions of each program in the EdgeProgramManager targeted for delegation as determined by the partitioner.

Parameters

partitioner

The partitioner can either be a Partitioner subclass instance, or a dictionary mapping method names to Partitioner subclass instance. If it is a Partitioner subclass, all programs in the given EdgeProgramManager will be lowered using the given partitioner. If it is a dictionary, only method names specified in the dictionary will be lowered with the given partitioner.

The Partitioner subclass instance is in charge with tagging portions of the input program for delegation. A valid partitioner must return PartitionerResult including valid partition_tags: Dict[str, DelegationSpec], where each key is a tag name and the nodes with same tag will be fused a one subgraph and delegated to backend specififed in delegation spec.

Returns

A copy of the calling EdgeProgramManager with the specified subgraphs lowered.

Return type

EdgeProgramManager

to_executorch(config=None)[source]

Transforms the program to the ExecuTorch backend.

Parameters

config – An optional argument used to provide greater control over the transformation to the ExecuTorch backend.

Returns

A manager representing the state of the EdgeProgramManager after it has been transformed to the ExecuTorch backend.

Return type

ExecutorchProgramManager

transform(passes, check_ir_validity=True)[source]

Transforms the program according to the provided passes.

Parameters

passes – The passes can either be a list of passes, or a dictionary mapping method names to lists of passes. If it is just a list of passes, all methods in the given EdgeProgramManager will be transformed with the provided passes. If it is a dictionary, only method names specified in the dictionary will be transformed with their corresponding passes.

Returns

A copy of the calling EdgeProgramManager with the transformations applied.

Return type

EdgeProgramManager

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

Package of one or more ExportedPrograms in Execution dialect. Designed to simplify lowering to ExecuTorch. See: https://pytorch.org/executorch/stable/ir-exir.html

When the ExecutorchProgramManager is constructed the ExportedPrograms in execution dialect are used to form the executorch binary (in a process called emission) and then serialized to a buffer.

Manages the final link in the lowering chain of ATen -> Edge -> ExecuTorch.

property buffer

Returns the serialized ExecuTorch binary as a byte string.

Note that the call to buffer may allocate a very large amount of contiguous memory, depending on the model size. If writing to a file, use write_to_file which won’t incur additional copies.

property config_methods

Returns the set of config methods in this ExecutorchProgramManager.

dump_executorch_program(verbose=False)[source]

Prints the ExecuTorch binary in a human readable format.

Parameters

verbose (bool) – If False prints the binary in a condensed format. If True prints the binary 1-1 with the specification in the schema.

exported_program(method_name='forward')[source]

Returns the ExportedProgram specified by ‘method_name’.

property methods

Returns the set of methods in this 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)

A generic function the dispatch happens on the type of the first argument. There are currently to overloaded to_backend function:

Note: Python is dynamically-typed language and therefore cannot have proper method overloading as that requires the language to be able to discriminate between types at compile-time. @to_backend.register will attach the function to to_backend() base on the type of the first argument (type annotation is required). However, it can’t take multiple types as arguments.

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]

A subclass of nn.Module that is generated for modules containing delegated functions. This is can be created by calling to_backend.

property backend_id

Returns the backends name.

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

Returns a buffer containing the serialized ExecuTorch binary.

property compile_specs

Returns a list of backend-specific objects with static metadata to configure the “compilation” process.

property original_module

Returns the original EXIR module

property processed_bytes

Returns the delegate blob created from backend.preprocess

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources