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

Function create_program

codegen/tools/test/test_tools_selective_build.py:52–87  ·  view source on GitHub ↗

Returns an executorch program based on ModuleAdd, along with inputs.

(
    eager_module: Optional[Union[ModuleAdd, ModuleMulti]] = None,
)

Source from the content-addressed store, hash-verified

50
51
52def create_program(
53 eager_module: Optional[Union[ModuleAdd, ModuleMulti]] = None,
54) -> Tuple[ExecutorchProgramManager, Tuple[Any, ...]]:
55 """Returns an executorch program based on ModuleAdd, along with inputs."""
56
57 if eager_module is None:
58 eager_module = ModuleAdd()
59
60 class WrapperModule(torch.nn.Module):
61 def __init__(self, fn):
62 super().__init__()
63 self.fn = fn
64
65 def forward(self, *args, **kwargs):
66 return self.fn(*args, **kwargs)
67
68 # Trace the test module and create a serialized ExecuTorch program.
69 inputs = (torch.ones(2, 2), torch.ones(2, 2))
70 input_map = {}
71 # pyre-fixme[29]: `Union[torch._tensor.Tensor, torch.nn.modules.module.Module]`
72 # is not a function.
73 for method in eager_module.get_methods_to_export():
74 input_map[method] = inputs
75
76 exported_methods = {}
77 # These cleanup passes are required to convert the `add` op to its out
78 # variant, along with some other transformations.
79 for method_name, method_input in input_map.items():
80 module = WrapperModule(getattr(eager_module, method_name))
81 exported_methods[method_name] = export(module, method_input, strict=True)
82
83 exec_prog = to_edge(exported_methods).to_executorch()
84
85 # Create the ExecuTorch program from the graph.
86 exec_prog.dump_executorch_program(verbose=True)
87 return (exec_prog, inputs)
88
89
90class PybindingsTest(unittest.TestCase):

Callers 2

test_dump_operatorsMethod · 0.70
test_get_op_io_metaMethod · 0.70

Calls 9

get_methods_to_exportMethod · 0.95
exportFunction · 0.90
to_edgeFunction · 0.90
onesMethod · 0.80
itemsMethod · 0.80
ModuleAddClass · 0.70
WrapperModuleClass · 0.70
to_executorchMethod · 0.45

Tested by

no test coverage detected