Returns an executorch program based on ModuleAdd, along with inputs.
(
eager_module: Optional[Union[ModuleAdd, ModuleMulti]] = None,
)
| 50 | |
| 51 | |
| 52 | def 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 | |
| 90 | class PybindingsTest(unittest.TestCase): |
no test coverage detected