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

Function create_program

extension/pybindings/test/make_test.py:151–186  ·  view source on GitHub ↗

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

(
    eager_module: torch.nn.Module,
    et_config: Optional[ExecutorchBackendConfig] = None,
)

Source from the content-addressed store, hash-verified

149
150
151def create_program(
152 eager_module: torch.nn.Module,
153 et_config: Optional[ExecutorchBackendConfig] = None,
154) -> Tuple[ExecutorchProgramManager, Tuple[Any, ...]]:
155 """Returns an executorch program based on ModuleAdd, along with inputs."""
156
157 # Trace the test module and create a serialized ExecuTorch program.
158 # pyre-fixme[29]: `Union[torch._tensor.Tensor, torch.nn.modules.module.Module]`
159 # is not a function.
160 inputs = eager_module.get_inputs()
161 input_map = {}
162 # pyre-fixme[29]: `Union[torch._tensor.Tensor, torch.nn.modules.module.Module]`
163 # is not a function.
164 for method in eager_module.get_methods_to_export():
165 input_map[method] = inputs
166
167 class WrapperModule(torch.nn.Module):
168 def __init__(self, fn):
169 super().__init__()
170 self.fn = fn
171
172 def forward(self, *args, **kwargs):
173 return self.fn(*args, **kwargs)
174
175 exported_methods = {}
176 # These cleanup passes are required to convert the `add` op to its out
177 # variant, along with some other transformations.
178 for method_name, method_input in input_map.items():
179 wrapped_mod = WrapperModule(getattr(eager_module, method_name))
180 exported_methods[method_name] = export(wrapped_mod, method_input, strict=True)
181
182 exec_prog = to_edge(exported_methods).to_executorch(config=et_config)
183
184 # Create the ExecuTorch program from the graph.
185 exec_prog.dump_executorch_program(verbose=True)
186 return (exec_prog, inputs)

Calls 8

exportFunction · 0.90
to_edgeFunction · 0.90
itemsMethod · 0.80
WrapperModuleClass · 0.70
get_inputsMethod · 0.45
get_methods_to_exportMethod · 0.45
to_executorchMethod · 0.45

Tested by

no test coverage detected