Skip to content

Commit 26d0df6

Browse files
Zonglin Pengfacebook-github-bot
authored andcommitted
split to_cadence_edge_executorch API to to_cadence and to_executorch_gen_etrecord
Summary: for pass tests Differential Revision: D65917897
1 parent c6b8555 commit 26d0df6

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

backends/cadence/aot/compiler.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,26 @@ def export_to_edge(
196196
# Export the model and lower it to an EdgeProgramManager (in edge IR), and
197197
# apply passes specific to Cadence DSP execution. Return both to print the
198198
# differences.
199-
def export_to_cadence_edge_executorch(
199+
def export_to_cadence(
200+
model: torch.nn.Module,
201+
inputs: tuple[object, ...],
202+
dump_graphs: bool = False,
203+
output_dir: Optional[str] = None,
204+
opt_level: int = 1,
205+
) -> EdgeProgramManager:
206+
edge_prog_manager = export_to_edge(model, inputs)
207+
cadence_passes = get_cadence_passes(opt_level)
208+
209+
# Run a couple required passes for quant/dequant ops
210+
cadence_prog_manager = edge_prog_manager.transform(
211+
cast(
212+
list[Callable[[torch.fx.GraphModule], Optional[PassResult]]], cadence_passes
213+
)
214+
)
215+
return cadence_prog_manager
216+
217+
218+
def export_to_executorch_gen_etrecord(
200219
model: torch.nn.Module,
201220
inputs: tuple[object, ...],
202221
dump_graphs: bool = False,

backends/cadence/aot/export_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from executorch.backends.cadence.aot.compiler import (
1818
convert_pt2,
19-
export_to_cadence_edge_executorch,
19+
export_to_executorch_gen_etrecord,
2020
fuse_pt2,
2121
)
2222

@@ -86,8 +86,8 @@ def export_model(
8686
quantized_model = fuse_pt2(converted_model, quantizer)
8787

8888
# Get edge program after Cadence specific passes
89-
exec_prog: ExecutorchProgramManager = export_to_cadence_edge_executorch(
90-
quantized_model, example_inputs, working_dir
89+
exec_prog: ExecutorchProgramManager = export_to_executorch_gen_etrecord(
90+
quantized_model, example_inputs, output_dir=working_dir
9191
)
9292

9393
logging.info("Final exported graph:\n")

backends/cadence/aot/tests/test_graph_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
22

33

4-
import torch
54
import executorch.backends.cadence.aot.ops_registrations # noqa
5+
import torch
66
from executorch.backends.cadence.aot.graph_builder import (
77
GraphBuilder,
88
single_op_builder,
99
)
10+
from executorch.backends.cadence.aot.pass_utils import count_node
1011
from executorch.exir.dialects._ops import ops as exir_ops
1112
from executorch.exir.pass_base import ExportPass
1213
from later.unittest import TestCase
13-
from executorch.backends.cadence.aot.pass_utils import count_node
14+
1415

1516
class TestGraphBuilder(TestCase):
1617
def test_graph_with_single_im2row(self) -> None:

0 commit comments

Comments
 (0)