Package of one or more `ExportedPrograms` in Edge dialect. Designed to simplify lowering to ExecuTorch. See: https://pytorch.org/executorch/main/ir-exir Allows easy applications of transforms across a collection of exported programs including the delegation of subgraphs. Manag
| 1531 | |
| 1532 | |
| 1533 | class EdgeProgramManager: |
| 1534 | """ |
| 1535 | Package of one or more `ExportedPrograms` in Edge dialect. Designed to simplify |
| 1536 | lowering to ExecuTorch. See: https://pytorch.org/executorch/main/ir-exir |
| 1537 | |
| 1538 | Allows easy applications of transforms across a collection of exported programs |
| 1539 | including the delegation of subgraphs. |
| 1540 | |
| 1541 | Manages the second link in the lowering chain of ATen -> Edge -> ExecuTorch. |
| 1542 | """ |
| 1543 | |
| 1544 | def __init__( |
| 1545 | self, |
| 1546 | edge_programs: Union[ExportedProgram, Dict[str, ExportedProgram]], |
| 1547 | constant_methods: Optional[Dict[str, Any]] = None, |
| 1548 | compile_config: Optional[EdgeCompileConfig] = None, |
| 1549 | core_aten_ops_exception_list: Optional[List[torch._ops.OpOverload]] = None, |
| 1550 | preserve_ops: Optional[List[torch._ops.OpOverload]] = None, |
| 1551 | ): |
| 1552 | """ |
| 1553 | Should not be called directly by users. User should use :func:'to_edge' instead. |
| 1554 | |
| 1555 | Constructs an EdgeProgramManager from an existing set of exported programs in edge dialect. |
| 1556 | """ |
| 1557 | self.compile_config = compile_config or EdgeCompileConfig() |
| 1558 | if not isinstance(edge_programs, dict): |
| 1559 | edge_programs = {"forward": edge_programs} |
| 1560 | |
| 1561 | for name, program in edge_programs.items(): |
| 1562 | try: |
| 1563 | EXIREdgeDialectVerifier( |
| 1564 | edge_compile_config=self.compile_config, |
| 1565 | core_aten_ops_exception_list=core_aten_ops_exception_list, |
| 1566 | preserve_ops=preserve_ops, |
| 1567 | )(program.graph_module) |
| 1568 | except ExportError as e: |
| 1569 | logging.info(f"Input program {name} is not in aten dialect.") |
| 1570 | raise e |
| 1571 | |
| 1572 | self._edge_programs: Dict[str, ExportedProgram] = edge_programs |
| 1573 | self._config_methods = constant_methods |
| 1574 | |
| 1575 | self._named_data_store = NamedDataStore() |
| 1576 | for _, program in self._edge_programs.items(): |
| 1577 | collect_named_data_store_from_exported_program( |
| 1578 | program, self._named_data_store |
| 1579 | ) |
| 1580 | |
| 1581 | self._etrecord = None |
| 1582 | |
| 1583 | @property |
| 1584 | def methods(self) -> Set[str]: |
| 1585 | """ |
| 1586 | Returns the set of methods in this EdgeProgramManager. |
| 1587 | """ |
| 1588 | return set(self._edge_programs.keys()) |
| 1589 | |
| 1590 | @property |
no outgoing calls