MCPcopy Create free account
hub / github.com/pytorch/executorch / _to_edge

Function _to_edge

exir/program/_program.py:727–801  ·  view source on GitHub ↗
(ep, config: EdgeCompileConfig)

Source from the content-addressed store, hash-verified

725
726
727def _to_edge(ep, config: EdgeCompileConfig) -> "ExirExportedProgram":
728 if config._check_ir_validity:
729 try:
730 EXIRATenDialectVerifier()(ep.exported_program.graph_module)
731 except ExportError:
732 logging.info(
733 "If a particular operator failed core ATen IR check, please consider adding it to the exception list. "
734 "Add the operator to _core_aten_ops_exception_list in EdgeCompileConfig. This is the recommended way "
735 "to resolve this type of failure, so that the rest of the IR validation check can still be performed.\n"
736 "If you'd like to disable IR validation checking, please set _check_ir_validity in EdgeCompileConfig, "
737 "like *.to_edge(exir.EdgeCompileConfig(_check_ir_validity=False))."
738 )
739 raise
740
741 dialect = ep.exported_program.dialect
742 if dialect == "ATEN":
743 ep = ExirExportedProgram(
744 ExportedProgram(
745 root=ep.exported_program.graph_module,
746 graph=ep.exported_program.graph_module.graph,
747 graph_signature=ep.exported_program.graph_signature,
748 state_dict=ep.exported_program.state_dict,
749 range_constraints=ep.exported_program.range_constraints,
750 module_call_graph=ep.exported_program.module_call_graph,
751 example_inputs=ep.exported_program.example_inputs,
752 constants=ep.exported_program.constants,
753 verifiers=[
754 get_aten_verifier(
755 config=config,
756 )
757 ],
758 ),
759 False,
760 )
761 pre_op_replace_passes, post_op_replace_passes = _get_aten_to_edge_passes(config)
762
763 new_ep = copy.deepcopy(ep).transform(*pre_op_replace_passes)
764 if dialect == "ATEN":
765 new_ep.exported_program = lift_constant_tensor_pass(new_ep.exported_program)
766
767 new_gm = new_ep.exported_program.graph_module
768 if config._use_edge_ops:
769 new_gm_res = OpReplacePass()(new_gm)
770 assert new_gm_res is not None
771 new_gm = new_gm_res.graph_module
772 if not config._skip_dim_order:
773 new_gm_res = MemoryFormatOpsPass()(new_gm)
774 assert new_gm_res is not None
775 new_gm = new_gm_res.graph_module
776
777 for p in post_op_replace_passes:
778 new_gm_res = p(new_gm)
779 assert new_gm_res is not None
780 new_gm = new_gm_res.graph_module
781
782 new_ep.exported_program = ExportedProgram(
783 root=new_gm,
784 graph=new_gm.graph,

Callers 1

to_edgeMethod · 0.85

Calls 12

EXIRATenDialectVerifierFunction · 0.90
get_aten_verifierFunction · 0.90
OpReplacePassClass · 0.90
MemoryFormatOpsPassClass · 0.90
EXIREdgeDialectVerifierFunction · 0.90
ExirExportedProgramClass · 0.85
ExportedProgramClass · 0.85
_get_aten_to_edge_passesFunction · 0.85
infoMethod · 0.80
transformMethod · 0.45

Tested by

no test coverage detected