MCPcopy Create free account
hub / github.com/pytorch/executorch / to_backend

Method to_backend

exir/program/_program.py:1680–1728  ·  view source on GitHub ↗

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. Args: partitioner: The partitioner can either be a Partitioner subc

(
        self,
        partitioner: Union[Partitioner, Dict[str, Partitioner]],
    )

Source from the content-addressed store, hash-verified

1678
1679 @et_logger("to_backend")
1680 def to_backend(
1681 self,
1682 partitioner: Union[Partitioner, Dict[str, Partitioner]],
1683 ) -> "EdgeProgramManager":
1684 """
1685 Returns a semantically-equivalent program to the one given as input,
1686 but with portions of each program in the EdgeProgramManager targeted
1687 for delegation as determined by the partitioner.
1688
1689 Args:
1690 partitioner: The partitioner can either be a Partitioner subclass instance, or a
1691 dictionary mapping method names to Partitioner subclass instance. If it is a
1692 Partitioner subclass, all programs in the given EdgeProgramManager
1693 will be lowered using the given partitioner. If it is a
1694 dictionary, only method names specified in the dictionary will be
1695 lowered with the given partitioner.
1696
1697 The Partitioner subclass instance is in charge with tagging portions of the
1698 input program for delegation. A valid partitioner must return PartitionerResult including valid
1699 partition_tags: Dict[str, DelegationSpec], where each key is a tag
1700 name and the nodes with same tag will be fused a one subgraph and
1701 delegated to backend specififed in delegation spec.
1702
1703 Returns:
1704 EdgeProgramManager: A copy of the calling EdgeProgramManager with the
1705 specified subgraphs lowered.
1706 """
1707 new_edge_programs: Dict[str, ExportedProgram] = {}
1708 method_to_partitioner: Dict[str, Partitioner] = {}
1709 if not isinstance(partitioner, dict):
1710 method_to_partitioner = {name: partitioner for name in self._edge_programs}
1711 else:
1712 method_to_partitioner = partitioner
1713
1714 method_to_programs_and_partitioners = MethodProgramsPartitionerSpec(
1715 self._edge_programs,
1716 method_to_partitioner,
1717 )
1718
1719 new_edge_programs = to_backend(method_to_programs_and_partitioners)
1720 config = EdgeCompileConfig(_check_ir_validity=False)
1721 epm = EdgeProgramManager(
1722 new_edge_programs,
1723 copy.deepcopy(self._config_methods),
1724 config,
1725 )
1726
1727 epm._etrecord = self._etrecord
1728 return epm
1729
1730 @et_logger("to_executorch")
1731 def to_executorch( # noqa (FLAKE8) C901

Calls 4

to_backendFunction · 0.90
EdgeCompileConfigClass · 0.90
EdgeProgramManagerClass · 0.85