Lower all submodules nodes given in the method_to_submodule_nodes map to backend_id.
(
backend_id: str,
method_to_submodules_nodes: Dict[str, List[torch.fx.Node]],
method_to_tagged_edge_program: Dict[str, ExportedProgram],
)
| 559 | |
| 560 | |
| 561 | def lower_all_submodules_to_backend( |
| 562 | backend_id: str, |
| 563 | method_to_submodules_nodes: Dict[str, List[torch.fx.Node]], |
| 564 | method_to_tagged_edge_program: Dict[str, ExportedProgram], |
| 565 | ) -> None: |
| 566 | """ |
| 567 | Lower all submodules nodes given in the method_to_submodule_nodes map to backend_id. |
| 568 | """ |
| 569 | # The created exported program for the submodules are in the call_module node's meta data |
| 570 | # We just map the method_to_submodule_nodes directly to the method_to_partitioned_exported_programs |
| 571 | method_to_partitioned_program = { |
| 572 | method_name: [ |
| 573 | # perform deep copy here in case backends change graph inside preprocess method |
| 574 | copy.deepcopy(node.meta["submodule_program"]) |
| 575 | for node in call_submodule_nodes |
| 576 | ] |
| 577 | for method_name, call_submodule_nodes in method_to_submodules_nodes.items() |
| 578 | } |
| 579 | method_to_compile_specs = { |
| 580 | method_name: [node.meta["compile_spec"] for node in call_submodule_nodes] |
| 581 | for method_name, call_submodule_nodes in method_to_submodules_nodes.items() |
| 582 | } |
| 583 | |
| 584 | backend_name_to_subclass = { |
| 585 | subclass.__name__: subclass for subclass in BackendDetails.__subclasses__() |
| 586 | } |
| 587 | if backend_id not in backend_name_to_subclass: |
| 588 | raise NotImplementedError(f"Backend {backend_id} was not found.") |
| 589 | |
| 590 | method_to_preprocess_result: dict[str, List[PreprocessResult]] = ( |
| 591 | backend_name_to_subclass[backend_id].preprocess_multimethod( |
| 592 | method_to_partitioned_program, method_to_compile_specs |
| 593 | ) |
| 594 | ) |
| 595 | |
| 596 | for method_name in method_to_preprocess_result.keys(): |
| 597 | owning_program = method_to_tagged_edge_program[method_name] |
| 598 | list_of_preprocess_results = method_to_preprocess_result[method_name] |
| 599 | list_of_call_submodule_nodes = method_to_submodules_nodes[method_name] |
| 600 | list_of_compile_specs = method_to_compile_specs[method_name] |
| 601 | for preprocess_result, call_submodule_node, compile_spec in zip( |
| 602 | list_of_preprocess_results, |
| 603 | list_of_call_submodule_nodes, |
| 604 | list_of_compile_specs, |
| 605 | ): |
| 606 | submodule_program = call_submodule_node.meta["submodule_program"] |
| 607 | lowered_module = LoweredBackendModule( |
| 608 | edge_program=submodule_program, |
| 609 | backend_id=backend_id, |
| 610 | processed_bytes=preprocess_result.processed_bytes, |
| 611 | compile_specs=compile_spec, |
| 612 | named_data_store_output=preprocess_result.data_store_output, |
| 613 | ) |
| 614 | lowered_module.meta = { |
| 615 | "debug_handle_map": preprocess_result.debug_handle_map, |
| 616 | } |
| 617 | if preprocess_result._delegate_info_meta is not None: |
| 618 | assert lowered_module.meta is not None |
no test coverage detected