Skip to content

Commit 88b6cd2

Browse files
JacobSzwejbkafacebook-github-bot
authored andcommitted
remove exir.capture from coreml script (#2830)
Summary: Pull Request resolved: #2830 capture is deprecated use, export directly Reviewed By: mergennachin Differential Revision: D55702166 fbshipit-source-id: 5ca9b10a2fc24c9543611a8b52a5fd3342514a4f
1 parent f1badd0 commit 88b6cd2

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

examples/apple/coreml/scripts/export.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
from executorch.backends.apple.coreml.partition.coreml_partitioner import (
2020
CoreMLPartitioner,
2121
)
22+
from executorch.exir import to_edge
2223

2324
from executorch.exir.backend.backend_api import to_backend
2425
from executorch.sdk.etrecord import generate_etrecord
26+
from torch.export import export
2527

2628
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent.parent
2729
EXAMPLES_DIR = REPO_ROOT / "examples"
@@ -32,7 +34,6 @@
3234

3335
# Script to export a model with coreml delegation.
3436

35-
_CAPTURE_CONFIG = exir.CaptureConfig(enable_aot=True, _unlift=False)
3637
_EDGE_COMPILE_CONFIG = exir.EdgeCompileConfig(
3738
_check_ir_validity=False,
3839
)
@@ -84,9 +85,7 @@ def partition_module_to_coreml(module):
8485

8586
def lower_module_to_coreml(module, compile_specs):
8687
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)
9089
# All of the subsequent calls on the edge_dialect_graph generated above (such as delegation or
9190
# to_executorch()) are done in place and the graph is also modified in place. For debugging purposes
9291
# 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):
9594

9695
lowered_module = to_backend(
9796
CoreMLBackend.__name__,
98-
edge.exported_program,
97+
edge.exported_program(),
9998
compile_specs,
10099
)
101100

@@ -104,13 +103,11 @@ def lower_module_to_coreml(module, compile_specs):
104103

105104
def export_lowered_module_to_executorch_program(lowered_module, example_inputs):
106105
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
114111
)
115112
)
116113

0 commit comments

Comments
 (0)