From e42ea3c0c2d303aff3236c7ac43dd8254d60e396 Mon Sep 17 00:00:00 2001 From: Ekaterina Ignasheva Date: Wed, 10 Dec 2025 14:40:53 -0800 Subject: [PATCH 1/2] Replace duplicated RemoveCloneOpPass with RemoveCloneOpsTransformImported (#16048) Summary: This change eliminates code duplication by replacing the local `RemoveCloneOpPass` implementation with the imported `RemoveCloneOpsTransformImported` from the executorch transforms module. Previously, there were multiple implementations of the clone removal pass scattered across the codebase. This consolidation improves maintainability by ensuring a single source of truth for the clone removal optimization logic. Reviewed By: DrJessop Differential Revision: D88109862 --- backends/cadence/aot/remove_ops.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/backends/cadence/aot/remove_ops.py b/backends/cadence/aot/remove_ops.py index 98102a415e5..f7419ff25dc 100644 --- a/backends/cadence/aot/remove_ops.py +++ b/backends/cadence/aot/remove_ops.py @@ -38,7 +38,7 @@ class RemoveCloneOpsTransformImported(ExportPass): def call(self, graph_module: torch.fx.GraphModule) -> PassResult: finalize_passes: List[PassType] = [ - RemoveCloneOpsTransform(), + RemoveCloneOpsTransform(eliminate_quant_dequant_pairs=False), ] result = PassManager(passes=finalize_passes)(graph_module) dead_code_elimination_pass(result.graph_module) @@ -356,20 +356,6 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult: return result -@register_cadence_pass(CadencePassAttribute(opt_level=1)) -class RemoveCloneOpPass(RemoveOrReplacePassInterface): - # If the op is a clone op, return the input and eliminate the op - @property - def targets(self) -> list[EdgeOpOverload]: - return [exir_ops.edge.aten.clone.default] - - def maybe_remove_or_replace(self, node: Node) -> bool: - input_node = node.args[0] - assert isinstance(input_node, Node) - node.replace_all_uses_with(input_node) - return True - - @register_cadence_pass(CadencePassAttribute(opt_level=1)) class RemoveContiguousOpPass(RemoveOrReplacePassInterface): """ @@ -925,7 +911,6 @@ def maybe_remove_or_replace(self, node: Node) -> bool: class CommonRemovePasses: passes: List[Type[ExportPass]] = [ - RemoveCloneOpPass, RemoveAliasCopyOpPass, RemoveNopExpandOpPass, RemoveNopSliceOrViewOpPass, @@ -934,13 +919,13 @@ class CommonRemovePasses: RemovePermutesAroundElementwiseOps, RemoveSqueezeViewBeforeElementwiseOps, RemoveCatFromSliceCopyPass, + RemoveCloneOpsTransformImported, ] class CadenceRemoveNops: passes: List[Type[ExportPass]] = CommonRemovePasses.passes + [ SimplifySliceOpPass, - RemoveCloneOpsTransformImported, RemoveNopRequantizeOpPass, RemoveZeroSizedConstantPadNd, RemoveContiguousOpPass, From b762ac7a24b440432f4ab8941dea2099eba8b901 Mon Sep 17 00:00:00 2001 From: Ekaterina Ignasheva Date: Wed, 10 Dec 2025 14:40:53 -0800 Subject: [PATCH 2/2] Move remove passes to iterative section (#16049) Summary: This change reorganizes the pass execution order by moving the remove passes (clone removal, permute removal, etc.) into the iterative section of the pass manager. Previously, these passes were executed in a single-shot manner. By moving them to the iterative section, the pass manager can now run these optimization passes repeatedly until a fixed point is reached, where no further optimizations can be applied. This is important because removing one operation may enable additional removal opportunities that weren't visible before. Reviewed By: hsharma35 Differential Revision: D88109852 --- backends/cadence/aot/remove_ops.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/backends/cadence/aot/remove_ops.py b/backends/cadence/aot/remove_ops.py index f7419ff25dc..63e03bc5203 100644 --- a/backends/cadence/aot/remove_ops.py +++ b/backends/cadence/aot/remove_ops.py @@ -909,7 +909,7 @@ def maybe_remove_or_replace(self, node: Node) -> bool: return False -class CommonRemovePasses: +class CadenceRemoveNops: passes: List[Type[ExportPass]] = [ RemoveAliasCopyOpPass, RemoveNopExpandOpPass, @@ -920,12 +920,6 @@ class CommonRemovePasses: RemoveSqueezeViewBeforeElementwiseOps, RemoveCatFromSliceCopyPass, RemoveCloneOpsTransformImported, - ] - - -class CadenceRemoveNops: - passes: List[Type[ExportPass]] = CommonRemovePasses.passes + [ - SimplifySliceOpPass, RemoveNopRequantizeOpPass, RemoveZeroSizedConstantPadNd, RemoveContiguousOpPass,