Skip to content

Commit 20ea601

Browse files
angelayifacebook-github-bot
authored andcommitted
Remove export_[graph_module|exported_program]_to_executorch
Reviewed By: ydwu4 Differential Revision: D47391764 fbshipit-source-id: 5d4ee888b552b4c9f9dd6f8e9b00feab18b59983
1 parent 2dc56dd commit 20ea601

File tree

1 file changed

+20
-61
lines changed

1 file changed

+20
-61
lines changed

exir/__init__.py

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,26 @@ def to_executorch(
253253
self,
254254
config: Optional[ExecutorchBackendConfig] = None,
255255
) -> "ExecutorchProgram":
256-
return exir_exported_program_to_executorch(self, config)
256+
if not self.after_to_edge_passes:
257+
raise RuntimeError("Must run to_edge before to_executorch.")
258+
config = config or ExecutorchBackendConfig()
259+
new_prog = self.transform(*edge_to_executorch_passes(config))
260+
meta = get_exir_meta(new_prog.graph_module)
261+
executorch_prog = ExecutorchProgram(
262+
new_prog,
263+
emit_stacktrace=config.emit_stacktrace,
264+
extract_segments=config.extract_segments,
265+
segment_alignment=config.segment_alignment,
266+
constant_tensor_alignment=config.constant_tensor_alignment,
267+
delegate_alignment=config.delegate_alignment,
268+
)
269+
attach_export_graph_metadata(executorch_prog.graph_module, meta)
270+
# We only need to update the meta of the root graph module since it is
271+
# reconstructed in ExecutorchProgram. The submodules are exactly the
272+
# original submodules in new_prog.
273+
executorch_prog.graph_module.meta.update(new_prog.graph_module.meta)
274+
executorch_prog.graph_module.meta.update(self.graph_module.meta)
275+
return executorch_prog
257276

258277
def __reduce__(
259278
self,
@@ -901,66 +920,6 @@ def edge_to_executorch_passes(config: ExecutorchBackendConfig) -> List[PassType]
901920
return passes
902921

903922

904-
def exir_exported_program_to_executorch(
905-
edge_dialect_program: ExirExportedProgram,
906-
config: Optional[ExecutorchBackendConfig] = None,
907-
) -> ExecutorchProgram:
908-
if not edge_dialect_program.after_to_edge_passes:
909-
raise RuntimeError("Must run to_edge before to_executorch.")
910-
config = config or ExecutorchBackendConfig()
911-
new_prog = edge_dialect_program.transform(*edge_to_executorch_passes(config))
912-
meta = get_exir_meta(new_prog.graph_module)
913-
executorch_prog = ExecutorchProgram(
914-
new_prog,
915-
emit_stacktrace=config.emit_stacktrace,
916-
extract_segments=config.extract_segments,
917-
segment_alignment=config.segment_alignment,
918-
constant_tensor_alignment=config.constant_tensor_alignment,
919-
delegate_alignment=config.delegate_alignment,
920-
)
921-
attach_export_graph_metadata(executorch_prog.graph_module, meta)
922-
# We only need to update the meta of the root graph module since it is
923-
# reconstructed in ExecutorchProgram. The submodules are exactly the
924-
# original submodules in new_prog.
925-
executorch_prog.graph_module.meta.update(new_prog.graph_module.meta)
926-
executorch_prog.graph_module.meta.update(edge_dialect_program.graph_module.meta)
927-
return executorch_prog
928-
929-
930-
# TODO(ycao): Remove this once all single-method programs migrated to new API
931-
def export_graph_module_to_executorch(
932-
edge_dialect_graph_module: torch.fx.GraphModule,
933-
config: Optional[ExecutorchBackendConfig] = None,
934-
) -> ExecutorchProgram:
935-
config = config or ExecutorchBackendConfig()
936-
pm = PassManager(edge_to_executorch_passes(config))
937-
res = pm(edge_dialect_graph_module)
938-
meta = get_exir_meta(res.graph_module)
939-
assert res is not None
940-
ep = ExirExportedProgram(
941-
res.graph_module,
942-
res.graph_module.graph,
943-
ExportGraphSignature([], [], [], [], {}, {}, {}, None),
944-
CallSpec(meta.in_spec, meta.out_spec),
945-
{},
946-
{},
947-
[],
948-
True,
949-
)
950-
executorch_prog = ExecutorchProgram(
951-
ep,
952-
emit_stacktrace=config.emit_stacktrace,
953-
extract_segments=config.extract_segments,
954-
segment_alignment=config.segment_alignment,
955-
constant_tensor_alignment=config.constant_tensor_alignment,
956-
delegate_alignment=config.delegate_alignment,
957-
)
958-
attach_export_graph_metadata(executorch_prog.graph_module, meta)
959-
executorch_prog.graph_module.meta.update(edge_dialect_graph_module.meta)
960-
executorch_prog.graph_module.meta.update(res.graph_module.meta)
961-
return executorch_prog
962-
963-
964923
def multi_method_program_to_executorch(
965924
edge_dialect_program: MultiMethodExirExportedProgram,
966925
config: Optional[ExecutorchBackendConfig] = None,

0 commit comments

Comments
 (0)