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

Method to_executorch

exir/program/_program.py:1731–1844  ·  view source on GitHub ↗

Transforms the program to the ExecuTorch backend. Args: config: An optional argument used to provide greater control over the transformation to the ExecuTorch backend. Returns: ExecutorchProgramManager: A manager representing the sta

(  # noqa (FLAKE8) C901
        self,
        config: Optional[ExecutorchBackendConfig] = None,
    )

Source from the content-addressed store, hash-verified

1729
1730 @et_logger("to_executorch")
1731 def to_executorch( # noqa (FLAKE8) C901
1732 self,
1733 config: Optional[ExecutorchBackendConfig] = None,
1734 ) -> "ExecutorchProgramManager":
1735 """
1736 Transforms the program to the ExecuTorch backend.
1737
1738 Args:
1739 config: An optional argument used to provide greater control over
1740 the transformation to the ExecuTorch backend.
1741
1742 Returns:
1743 ExecutorchProgramManager: A manager representing the state of the EdgeProgramManager
1744 after it has been transformed to the ExecuTorch backend.
1745 """
1746 config = config if config else ExecutorchBackendConfig()
1747 execution_programs: Dict[str, ExportedProgram] = {}
1748 for name, program in self._edge_programs.items():
1749 if config.do_quant_fusion_and_const_prop:
1750 if program.graph_signature.backward_signature is not None:
1751 raise Exception(
1752 "Cannot run do_quant_fusion_and_const_prop on a graph with a backward signature intended for on-device training."
1753 " Please set do_quant_fusion_and_const_prop to False in the ExecutorchBackendConfig."
1754 )
1755 program = quant_fusion_and_const_prop_pass(program)
1756 if config.run_reinplace_pass:
1757 program = reinplace_pass(program)
1758 program = weights_to_outputs_pass(program)
1759 program = unsafe_remove_auto_functionalized_pass(program)
1760 gm, new_signature = insert_write_back_for_buffers_pass(program)
1761 new_gm = program.graph_module
1762 for p in edge_to_executorch_passes(config, name):
1763 new_gm_res = p(new_gm)
1764 assert new_gm_res is not None
1765 new_gm = new_gm_res.graph_module
1766 if isinstance(p, SpecPropPass):
1767 # Note that this is a hacky way to get around the fact that
1768 # placeholder nodes corresponding to the parameters of the graph module
1769 # shall not participate in memory planning. It increases runtime memory
1770 # footprint.
1771 # Proper way would be to have ExportPass work with ExportedProgram
1772 # instead of GraphModule. This is because ExportPass should work
1773 # on top of the export artifact of torch.export whichi s ExportedProgram.
1774 # Working with GraphModule does not provide all the information contained
1775 # in the ExportedProgram
1776 # TODO(who?)
1777 p.update_placeholder_tensor_specs(program, new_gm)
1778
1779 # Tag constant weights.
1780 if (
1781 isinstance(config.external_constants, bool)
1782 and config.external_constants
1783 ):
1784 new_gm_res = external_constants_pass(new_gm)
1785 new_gm = new_gm_res.graph_module
1786 elif callable(config.external_constants):
1787 new_gm_res = external_constants_pass(new_gm, config.external_constants)
1788 new_gm = new_gm_res.graph_module

Callers 15

test_delegate_xnnpackMethod · 0.95
export_to_et_irFunction · 0.95
export_to_et_irFunction · 0.95
export_to_et_irFunction · 0.95
export_to_et_irFunction · 0.95
setUpMethod · 0.45
test_lowered_add_mulMethod · 0.45

Calls 15

reinplace_passFunction · 0.90
weights_to_outputs_passFunction · 0.90
external_constants_passFunction · 0.90
_copy_moduleFunction · 0.85
itemsMethod · 0.80