| 15 | |
| 16 | |
| 17 | class FusePatternsPass(ExportPass): |
| 18 | def __init__(self) -> None: |
| 19 | super().__init__() |
| 20 | self._exported_program: Optional[ExportedProgram] = None |
| 21 | |
| 22 | def call(self, graph_module: torch.fx.GraphModule): |
| 23 | assert self._exported_program is not None |
| 24 | |
| 25 | total_replaced = vk_patterns.replace_all_fusable_subgraphs( |
| 26 | self._exported_program, graph_module |
| 27 | ) |
| 28 | |
| 29 | if total_replaced > 0: |
| 30 | graph_module.recompile() |
| 31 | # Re-trace the graph |
| 32 | graph_module = super().call(graph_module).graph_module |
| 33 | |
| 34 | return PassResult(graph_module, total_replaced > 0) |
no outgoing calls