Skip to content

fixed empty output from runtime executor in CPU flow #6184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backends/cadence/aot/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ python_library(
"//executorch/backends/transforms:decompose_sdpa",
"//executorch/backends/transforms:remove_clone_ops",
"//executorch/exir:lib",
"//executorch/devtools:lib",
],
)

Expand Down
41 changes: 37 additions & 4 deletions backends/cadence/aot/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# pyre-strict

import logging
from pathlib import Path
from typing import Optional

import torch
Expand All @@ -29,7 +30,13 @@
DecomposeScaledDotProductAttention,
)
from executorch.backends.transforms.remove_clone_ops import RemoveCloneOpsTransform
from executorch.exir import EdgeCompileConfig, EdgeProgramManager, to_edge
from executorch.devtools import generate_etrecord
from executorch.exir import (
EdgeCompileConfig,
EdgeProgramManager,
ExecutorchProgramManager,
to_edge,
)
from torch.ao.quantization.pt2e.export_utils import model_is_exported
from torch.ao.quantization.quantize_pt2e import convert_pt2e, prepare_pt2e

Expand Down Expand Up @@ -197,11 +204,12 @@ def export_to_edge(
# Export the model and lower it to an EdgeProgramManager (in edge IR), and
# apply passes specific to Cadence DSP execution. Return both to print the
# differences.
def export_to_cadence(
def export_to_cadence_edge_executorch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need "edge"?

model: torch.nn.Module,
inputs: tuple[object, ...],
dump_graphs: bool = False,
) -> EdgeProgramManager:
output_dir: Optional[str] = None,
) -> ExecutorchProgramManager:
edge_prog_manager = export_to_edge(model, inputs)

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

return cadence_prog_manager
# Get executorch program after Cadence specific passes
exec_prog: ExecutorchProgramManager = cadence_prog_manager.to_executorch()
if output_dir:
_gen_etrecord(edge_prog_manager, exec_prog, Path(output_dir))
else:
logging.warning("No output directory provided, skipping ETRecord generation")

return exec_prog


def _gen_etrecord(
edge_program: EdgeProgramManager,
et_program: ExecutorchProgramManager,
output_dir: Path,
) -> None:
etrec_path = output_dir / "etrecord.bin"
try:
generate_etrecord(
et_record=etrec_path,
edge_dialect_program=edge_program,
executorch_program=et_program,
)
logging.info(f"Generated ETRecord at {etrec_path}")
except Exception:
# Any errors here shouldn't block the rest of the flow
logging.exception("Encountered exception while generating ETRecord")
9 changes: 4 additions & 5 deletions backends/cadence/aot/export_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from executorch.backends.cadence.aot.compiler import (
convert_pt2,
export_to_cadence,
export_to_cadence_edge_executorch,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that API new? I don't see it in the changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. now ported.

fuse_pt2,
)
from executorch.backends.cadence.aot.quantizer.quantizer import CadenceQuantizer
Expand Down Expand Up @@ -53,10 +53,9 @@ def export_model(
quantized_model = fuse_pt2(converted_model, quantizer)

# Get edge program after Cadence specific passes
cadence_prog_manager = export_to_cadence(quantized_model, example_inputs)

# Get executorch program after Cadence specific passes
exec_prog: ExecutorchProgramManager = cadence_prog_manager.to_executorch()
exec_prog: ExecutorchProgramManager = export_to_cadence_edge_executorch(
quantized_model, example_inputs, working_dir
)

logging.info("Final exported graph:\n")
exec_prog.exported_program().graph_module.graph.print_tabular()
Expand Down
2 changes: 2 additions & 0 deletions backends/cadence/build_cadence_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ main() {
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
-DEXECUTORCH_ENABLE_LOGGING=ON \
-Bcmake-out .
cmake --build cmake-out --target install --config Release -j16

Expand All @@ -35,6 +36,7 @@ main() {
cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_CADENCE_CPU_RUNNER=ON \
-DEXECUTORCH_ENABLE_LOGGING=ON \
-B"${build_dir}" \
"${example_dir}"
cmake --build "${build_dir}" --config Release -j16
Expand Down
1 change: 1 addition & 0 deletions backends/cadence/reference/operators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(_aten_ops__srcs
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/activation_ops_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/copy_ops_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/broadcast_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/dtype_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/index_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/kernel_ops_util.cpp"
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"
Expand Down
1 change: 1 addition & 0 deletions backends/cadence/runtime/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __call__(self) -> None:
),
"etdump_path": os.path.join(self.working_dir, "etdump.etdp"),
"debug_output_path": os.path.join(self.working_dir, "debug_output.bin"),
"dump_outputs": "true",
}
args = self.get_bash_command(self.execute_runner, cmd_args)
logging.info(f"\33[33m{' '.join(args)}\33[0m")
Expand Down
Loading