19
19
from executorch .backends .apple .coreml .partition .coreml_partitioner import (
20
20
CoreMLPartitioner ,
21
21
)
22
+ from executorch .exir import to_edge
22
23
23
24
from executorch .exir .backend .backend_api import to_backend
24
25
from executorch .sdk .etrecord import generate_etrecord
26
+ from torch .export import export
25
27
26
28
REPO_ROOT = pathlib .Path (__file__ ).resolve ().parent .parent .parent .parent .parent
27
29
EXAMPLES_DIR = REPO_ROOT / "examples"
32
34
33
35
# Script to export a model with coreml delegation.
34
36
35
- _CAPTURE_CONFIG = exir .CaptureConfig (enable_aot = True , _unlift = False )
36
37
_EDGE_COMPILE_CONFIG = exir .EdgeCompileConfig (
37
38
_check_ir_validity = False ,
38
39
)
@@ -84,9 +85,7 @@ def partition_module_to_coreml(module):
84
85
85
86
def lower_module_to_coreml (module , compile_specs ):
86
87
module = module .eval ()
87
- edge = exir .capture (module , example_inputs , _CAPTURE_CONFIG ).to_edge (
88
- _EDGE_COMPILE_CONFIG
89
- )
88
+ edge = to_edge (export (module , example_inputs ), compile_config = _EDGE_COMPILE_CONFIG )
90
89
# All of the subsequent calls on the edge_dialect_graph generated above (such as delegation or
91
90
# to_executorch()) are done in place and the graph is also modified in place. For debugging purposes
92
91
# we would like to keep a copy of the original edge dialect graph and hence we create a deepcopy of
@@ -95,7 +94,7 @@ def lower_module_to_coreml(module, compile_specs):
95
94
96
95
lowered_module = to_backend (
97
96
CoreMLBackend .__name__ ,
98
- edge .exported_program ,
97
+ edge .exported_program () ,
99
98
compile_specs ,
100
99
)
101
100
@@ -104,13 +103,11 @@ def lower_module_to_coreml(module, compile_specs):
104
103
105
104
def export_lowered_module_to_executorch_program (lowered_module , example_inputs ):
106
105
lowered_module (* example_inputs )
107
- exec_prog = (
108
- exir .capture (lowered_module , example_inputs , _CAPTURE_CONFIG )
109
- .to_edge (_EDGE_COMPILE_CONFIG )
110
- .to_executorch (
111
- config = exir .ExecutorchBackendConfig (
112
- extract_constant_segment = False , extract_delegate_segments = True
113
- )
106
+ exec_prog = to_edge (
107
+ export (lowered_module , example_inputs ), compile_config = _EDGE_COMPILE_CONFIG
108
+ ).to_executorch (
109
+ config = exir .ExecutorchBackendConfig (
110
+ extract_constant_segment = False , extract_delegate_segments = True
114
111
)
115
112
)
116
113
0 commit comments