|
25 | 25 | from executorch.exir.backend.utils import format_delegated_graph |
26 | 26 | from executorch.exir.capture._config import EdgeCompileConfig, ExecutorchBackendConfig |
27 | 27 |
|
| 28 | +from executorch.exir.pass_manager import PassType |
28 | 29 | from executorch.exir.passes import MemoryPlanningPass |
29 | 30 | from executorch.exir.passes.quant_fusion_pass import QuantFusionPass |
30 | 31 | from executorch.exir.passes.sym_shape_eval_pass import ConstraintBasedSymShapeEvalPass |
@@ -395,26 +396,29 @@ def to_backend(self, partitioners: Optional[List[Partitioner]]) -> "LLMEdgeManag |
395 | 396 |
|
396 | 397 | return self |
397 | 398 |
|
398 | | - def to_executorch(self) -> "LLMEdgeManager": |
| 399 | + def to_executorch(self, passes: Optional[List[PassType]]) -> "LLMEdgeManager": |
399 | 400 | """ |
400 | 401 | Lower the model to executorch and get an ExecutorchProgram. |
401 | 402 | """ |
402 | 403 | assert self.edge_manager, "Need to run export_to_edge() first" |
| 404 | + to_executorch_passes = [ |
| 405 | + # If there are Linear operations left in the graph, let's execute |
| 406 | + # them with the optimized op_linear rather than materializing a |
| 407 | + # transpose followed by a regular op_mm. |
| 408 | + ConvertToLinearPass(), |
| 409 | + QuantFusionPass(), |
| 410 | + ] |
| 411 | + if passes: |
| 412 | + to_executorch_passes.extend(passes) |
| 413 | + |
403 | 414 | self.export_program = self.edge_manager.to_executorch( |
404 | 415 | ExecutorchBackendConfig( |
405 | 416 | extract_delegate_segments=True, |
406 | | - passes=[ |
407 | | - # If there are Linear operations left in the graph, let's execute |
408 | | - # them with the optimized op_linear rather than materializing a |
409 | | - # transpose followed by a regular op_mm. |
410 | | - ConvertToLinearPass(), |
411 | | - QuantFusionPass(), |
412 | | - ], |
| 417 | + passes=to_executorch_passes, |
413 | 418 | memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False), |
414 | 419 | sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(), |
415 | 420 | ) |
416 | 421 | ) |
417 | | - print(self.export_program.dump_executorch_program(verbose=True)) |
418 | 422 | logging.info( |
419 | 423 | "Required memory for activation in bytes: {}".format( |
420 | 424 | self.export_program._emitter_output.program.execution_plan[ |
|
0 commit comments