Skip to content

Commit 7a4d15b

Browse files
author
Github Executorch
committed
Remove legacy transform_for_cortex_m_backend and --enable_qdq_fusion_pass flag
Summary: Remove the transform_for_cortex_m_backend() function and the --enable_qdq_fusion_pass CLI flag from aot_arm_compiler.py. The function applied Cortex-M passes as a post-hoc step to all non-VGF targets, which made the compilation flow hard to follow and coupled the delegation path to Cortex-M-specific logic. Instead, ReplaceQuantNodesPass is now applied directly inside to_edge_TOSA_delegate() to handle any boundary quantized_decomposed::* nodes that remain outside the delegated subgraph. This makes the delegation path self-contained and explicit about its runtime requirements. This change is in preparation for an upcoming PR (#17075) that introduces Cortex-M as a first-class compilation target with its own dedicated pipeline, including CortexMQuantizer and CortexMPassManager.
1 parent eef30fd commit 7a4d15b

1 file changed

Lines changed: 14 additions & 38 deletions

File tree

examples/arm/aot_arm_compiler.py

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@
3838
from executorch.backends.arm.vgf import VgfCompileSpec
3939

4040
# To use Cortex-M backend
41-
from executorch.backends.cortex_m.passes.convert_to_cortex_m_pass import (
42-
ConvertToCortexMPass,
43-
)
44-
45-
from executorch.backends.cortex_m.passes.quantized_op_fusion_pass import (
46-
QuantizedOpFusionPass,
47-
)
48-
4941
from executorch.backends.cortex_m.passes.replace_quant_nodes_pass import (
5042
ReplaceQuantNodesPass,
5143
)
@@ -206,6 +198,12 @@ def _load_serialized_model(
206198

207199
return model, example_inputs
208200

201+
def _apply_replace_quant_nodes(edge, args):
202+
""" Apply the replace_quant_nodes pass to the edge graph module. """
203+
204+
if args.target != "vgf" and not args.direct_drive:
205+
edge = edge.transform([ReplaceQuantNodesPass()])
206+
return edge
209207

210208
def get_model_and_inputs_from_name(
211209
model_name: str, model_input: str | None
@@ -603,11 +601,6 @@ def get_args():
603601
action="store_false",
604602
help="Disable strict checking while exporting models.",
605603
)
606-
parser.add_argument(
607-
"--enable_qdq_fusion_pass",
608-
action="store_true",
609-
help="Enable the Quantized qdq fusion Op passes",
610-
)
611604
parser.add_argument(
612605
"--enable_debug_mode",
613606
required=False,
@@ -787,6 +780,10 @@ def to_edge_TOSA_delegate(
787780
),
788781
)
789782

783+
# Replace quantized_decomposed::* nodes with cortex_m::* equivalents for
784+
# any QDQ ops that remain outside the delegated subgraph.
785+
edge = _apply_replace_quant_nodes(edge, args)
786+
790787
return model_quant, edge
791788

792789

@@ -822,27 +819,11 @@ def to_edge_no_delegate(
822819
),
823820
)
824821

825-
return model_quant, edge
826-
822+
# Replace quantized_decomposed::* nodes with cortex_m::* equivalents for
823+
# any QDQ ops that remain outside the delegated subgraph.
824+
edge = _apply_replace_quant_nodes(edge, args)
827825

828-
def transform_for_cortex_m_backend(edge_program_manager, args):
829-
# Let's make sure we are using optimized Cortex M backend
830-
# NB: If we can't find and replace ops those are expected to be replaced,
831-
# bad things will happen at runtime, like "missing operator" errors!
832-
833-
# Instantiate the mandatory ReplaceQuantNodesPass
834-
passes = [ReplaceQuantNodesPass]
835-
if args.enable_qdq_fusion_pass:
836-
passes += [ConvertToCortexMPass, QuantizedOpFusionPass]
837-
current_edge = edge_program_manager
838-
for pass_cls in passes:
839-
transform_pass = (
840-
pass_cls(current_edge.exported_program())
841-
if pass_cls.__name__ == "QuantizedLinearFusionPass"
842-
else pass_cls()
843-
)
844-
current_edge = current_edge.transform([transform_pass])
845-
return current_edge
826+
return model_quant, edge
846827

847828

848829
if __name__ == "__main__": # noqa: C901
@@ -885,11 +866,6 @@ def transform_for_cortex_m_backend(edge_program_manager, args):
885866
exported_program, args, model, example_inputs
886867
)
887868

888-
# Cortex-m ops are never included in vgf or direct-drive
889-
if args.target != "vgf" and not args.direct_drive:
890-
# Transform so we can use ops from the Cortex M backend
891-
edge = transform_for_cortex_m_backend(edge, args)
892-
893869
dump_delegation_info(edge, args.intermediates)
894870

895871
edge_program_manager_copy = copy.deepcopy(edge)

0 commit comments

Comments
 (0)