Skip to content

Commit cd2d2b4

Browse files
zonglinpengfacebook-github-bot
authored andcommitted
fixed empty output from runtime executor in CPU flow (#6184)
Summary: Pull Request resolved: #6184 - add missing dependency dtype_util.cpp - it was missing etrecord. And dump-output is not toggled in executor. - Also enable runtime logging Reviewed By: Vysarat, mcremon-meta Differential Revision: D64272605 fbshipit-source-id: 9299fafeb6575b392d26b10caddef2192cae68e5
1 parent 1f2b9aa commit cd2d2b4

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

backends/cadence/aot/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ python_library(
4343
"//executorch/backends/transforms:decompose_sdpa",
4444
"//executorch/backends/transforms:remove_clone_ops",
4545
"//executorch/exir:lib",
46+
"//executorch/devtools:lib",
4647
],
4748
)
4849

backends/cadence/aot/compiler.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# pyre-strict
88

99
import logging
10+
from pathlib import Path
1011
from typing import Optional
1112

1213
import torch
@@ -29,7 +30,13 @@
2930
DecomposeScaledDotProductAttention,
3031
)
3132
from executorch.backends.transforms.remove_clone_ops import RemoveCloneOpsTransform
32-
from executorch.exir import EdgeCompileConfig, EdgeProgramManager, to_edge
33+
from executorch.devtools import generate_etrecord
34+
from executorch.exir import (
35+
EdgeCompileConfig,
36+
EdgeProgramManager,
37+
ExecutorchProgramManager,
38+
to_edge,
39+
)
3340
from torch.ao.quantization.pt2e.export_utils import model_is_exported
3441
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e
3542

@@ -197,11 +204,12 @@ def export_to_edge(
197204
# Export the model and lower it to an EdgeProgramManager (in edge IR), and
198205
# apply passes specific to Cadence DSP execution. Return both to print the
199206
# differences.
200-
def export_to_cadence(
207+
def export_to_cadence_edge_executorch(
201208
model: torch.nn.Module,
202209
inputs: tuple[object, ...],
203210
dump_graphs: bool = False,
204-
) -> EdgeProgramManager:
211+
output_dir: Optional[str] = None,
212+
) -> ExecutorchProgramManager:
205213
edge_prog_manager = export_to_edge(model, inputs)
206214

207215
# Run a couple required passes for quant/dequant ops
@@ -225,4 +233,29 @@ def export_to_cadence(
225233
cadence_prog_manager.exported_program().graph_module,
226234
)
227235

228-
return cadence_prog_manager
236+
# Get executorch program after Cadence specific passes
237+
exec_prog: ExecutorchProgramManager = cadence_prog_manager.to_executorch()
238+
if output_dir:
239+
_gen_etrecord(edge_prog_manager, exec_prog, Path(output_dir))
240+
else:
241+
logging.warning("No output directory provided, skipping ETRecord generation")
242+
243+
return exec_prog
244+
245+
246+
def _gen_etrecord(
247+
edge_program: EdgeProgramManager,
248+
et_program: ExecutorchProgramManager,
249+
output_dir: Path,
250+
) -> None:
251+
etrec_path = output_dir / "etrecord.bin"
252+
try:
253+
generate_etrecord(
254+
et_record=etrec_path,
255+
edge_dialect_program=edge_program,
256+
executorch_program=et_program,
257+
)
258+
logging.info(f"Generated ETRecord at {etrec_path}")
259+
except Exception:
260+
# Any errors here shouldn't block the rest of the flow
261+
logging.exception("Encountered exception while generating ETRecord")

backends/cadence/aot/export_example.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from executorch.backends.cadence.aot.compiler import (
1616
convert_pt2,
17-
export_to_cadence,
17+
export_to_cadence_edge_executorch,
1818
fuse_pt2,
1919
)
2020
from executorch.backends.cadence.aot.quantizer.quantizer import CadenceQuantizer
@@ -53,10 +53,9 @@ def export_model(
5353
quantized_model = fuse_pt2(converted_model, quantizer)
5454

5555
# Get edge program after Cadence specific passes
56-
cadence_prog_manager = export_to_cadence(quantized_model, example_inputs)
57-
58-
# Get executorch program after Cadence specific passes
59-
exec_prog: ExecutorchProgramManager = cadence_prog_manager.to_executorch()
56+
exec_prog: ExecutorchProgramManager = export_to_cadence_edge_executorch(
57+
quantized_model, example_inputs, working_dir
58+
)
6059

6160
logging.info("Final exported graph:\n")
6261
exec_prog.exported_program().graph_module.graph.print_tabular()

backends/cadence/build_cadence_runner.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ main() {
2525
-DCMAKE_BUILD_TYPE=Release \
2626
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
2727
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
28+
-DEXECUTORCH_ENABLE_LOGGING=ON \
2829
-Bcmake-out .
2930
cmake --build cmake-out --target install --config Release -j16
3031

@@ -35,6 +36,7 @@ main() {
3536
cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
3637
-DCMAKE_BUILD_TYPE=Release \
3738
-DEXECUTORCH_CADENCE_CPU_RUNNER=ON \
39+
-DEXECUTORCH_ENABLE_LOGGING=ON \
3840
-B"${build_dir}" \
3941
"${example_dir}"
4042
cmake --build "${build_dir}" --config Release -j16

backends/cadence/reference/operators/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set(_aten_ops__srcs
2727
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/activation_ops_util.cpp"
2828
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/copy_ops_util.cpp"
2929
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/broadcast_util.cpp"
30+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/dtype_util.cpp"
3031
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/index_util.cpp"
3132
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/kernel_ops_util.cpp"
3233
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"

backends/cadence/runtime/executor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __call__(self) -> None:
123123
),
124124
"etdump_path": os.path.join(self.working_dir, "etdump.etdp"),
125125
"debug_output_path": os.path.join(self.working_dir, "debug_output.bin"),
126+
"dump_outputs": "true",
126127
}
127128
args = self.get_bash_command(self.execute_runner, cmd_args)
128129
logging.info(f"\33[33m{' '.join(args)}\33[0m")

0 commit comments

Comments
 (0)