Args: config: The configuration for the edge program. program: The exported program to be converted to an edge program. core_aten_ops_exception_list: A list of aten ops that are missing decompositions to core aten. preserve_ops: A list of aten ops that should not
(
config: EdgeCompileConfig,
program: ExportedProgram,
core_aten_ops_exception_list: Optional[List[torch._ops.OpOverload]] = None,
preserve_ops: Optional[List[torch._ops.OpOverload]] = None,
)
| 858 | |
| 859 | |
| 860 | def _generate_edge_program( |
| 861 | config: EdgeCompileConfig, |
| 862 | program: ExportedProgram, |
| 863 | core_aten_ops_exception_list: Optional[List[torch._ops.OpOverload]] = None, |
| 864 | preserve_ops: Optional[List[torch._ops.OpOverload]] = None, |
| 865 | ) -> ExportedProgram: |
| 866 | """ |
| 867 | Args: |
| 868 | config: The configuration for the edge program. |
| 869 | program: The exported program to be converted to an edge program. |
| 870 | core_aten_ops_exception_list: A list of aten ops that are missing decompositions to core aten. |
| 871 | preserve_ops: A list of aten ops that should not be decomposed. |
| 872 | Returns: |
| 873 | An ExportedProgram in edge dialect. |
| 874 | """ |
| 875 | # Remove unused parameters |
| 876 | program = remove_unused_parameters_pass(program) |
| 877 | |
| 878 | pre_op_replace_passes, post_op_replace_passes = _get_aten_to_edge_passes(config) |
| 879 | |
| 880 | passes = [ |
| 881 | # Remove invalid assert ops, such as _assert_tensor_metadata |
| 882 | RemoveNonCoreAtenOpGraphAssertsPass(), |
| 883 | # TODO move inside aten_to_edge passes after all users are migrated off v1 capture |
| 884 | ReplaceViewOpsWithViewCopyOpsPass(), |
| 885 | ] |
| 886 | passes.extend(pre_op_replace_passes) |
| 887 | if config._use_edge_ops: |
| 888 | passes.append(OpReplacePass()) |
| 889 | if not config._skip_dim_order: |
| 890 | passes.append(MemoryFormatOpsPass()) |
| 891 | |
| 892 | gm = program.graph_module |
| 893 | for p in passes: |
| 894 | gm_res = p(gm) |
| 895 | assert gm_res is not None |
| 896 | gm = gm_res.graph_module |
| 897 | |
| 898 | edge_program = ExportedProgram( |
| 899 | root=gm, |
| 900 | graph=gm.graph, |
| 901 | graph_signature=_get_updated_graph_signature(program.graph_signature, gm), |
| 902 | state_dict=program.state_dict, |
| 903 | range_constraints=program.range_constraints, |
| 904 | module_call_graph=program.module_call_graph, |
| 905 | example_inputs=program.example_inputs, |
| 906 | constants=program.constants, |
| 907 | verifiers=[ |
| 908 | EXIREdgeDialectVerifier( |
| 909 | edge_compile_config=config, |
| 910 | class_only=True, |
| 911 | core_aten_ops_exception_list=core_aten_ops_exception_list, |
| 912 | preserve_ops=preserve_ops, |
| 913 | ) |
| 914 | ], |
| 915 | ) |
| 916 | |
| 917 | # Lift the tensor constants created in ScalarToTensorPass |
no test coverage detected