Skip to content

Commit 1fedffc

Browse files
cccclaifacebook-github-bot
authored andcommitted
Make export file compatible with buck (#5703)
Summary: Pull Request resolved: #5703 Part of the export.py isn't working well with buck, move the function from `__main__.py` to a standalone `main` function so it can be called ghstack-source-id: 244927520 exported-using-ghexport bypass-github-export-checks Reviewed By: shoumikhin Differential Revision: D63476613 fbshipit-source-id: 1defdde080f05b5c31557de54314f3423b7e3c4f
1 parent c3460e5 commit 1fedffc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/apple/coreml/scripts/export.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
from executorch.exir import to_edge
2222

2323
from executorch.exir.backend.backend_api import to_backend
24+
2425
from torch.export import export
2526

2627
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent.parent.parent
2728
EXAMPLES_DIR = REPO_ROOT / "examples"
2829
sys.path.append(str(EXAMPLES_DIR.absolute()))
2930

30-
from models import MODEL_NAME_TO_MODEL
31-
from models.model_factory import EagerModelFactory
31+
from executorch.examples.models import MODEL_NAME_TO_MODEL
32+
from executorch.examples.models.model_factory import EagerModelFactory
3233

3334
# Script to export a model with coreml delegation.
3435

@@ -82,7 +83,7 @@ def partition_module_to_coreml(module):
8283
module = module.eval()
8384

8485

85-
def lower_module_to_coreml(module, compile_specs):
86+
def lower_module_to_coreml(module, compile_specs, example_inputs):
8687
module = module.eval()
8788
edge = to_edge(export(module, example_inputs), compile_config=_EDGE_COMPILE_CONFIG)
8889
# All of the subsequent calls on the edge_dialect_graph generated above (such as delegation or
@@ -141,7 +142,7 @@ def generate_compile_specs_from_args(args):
141142
)
142143

143144

144-
if __name__ == "__main__":
145+
def main():
145146
args = parse_args()
146147

147148
if args.model_name not in MODEL_NAME_TO_MODEL:
@@ -167,6 +168,7 @@ def generate_compile_specs_from_args(args):
167168
if args.use_partitioner:
168169
model.eval()
169170
exir_program_aten = torch.export.export(model, example_inputs)
171+
170172
edge_program_manager = exir.to_edge(exir_program_aten)
171173
edge_copy = copy.deepcopy(edge_program_manager)
172174
partitioner = CoreMLPartitioner(
@@ -179,6 +181,7 @@ def generate_compile_specs_from_args(args):
179181
else:
180182
lowered_module, edge_copy = lower_module_to_coreml(
181183
module=model,
184+
example_inputs=example_inputs,
182185
compile_specs=compile_specs,
183186
)
184187
exec_program = export_lowered_module_to_executorch_program(
@@ -193,3 +196,7 @@ def generate_compile_specs_from_args(args):
193196
save_processed_bytes(
194197
lowered_module.processed_bytes, args.model_name, args.compute_unit
195198
)
199+
200+
201+
if __name__ == "__main__":
202+
main()

0 commit comments

Comments
 (0)