Skip to content

Commit c415633

Browse files
eigen-kfacebook-github-bot
authored andcommitted
Replace duplicated RemoveCloneOpPass with RemoveCloneOpsTransformImported (pytorch#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. Differential Revision: D88109862
1 parent 2721a7f commit c415633

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

backends/cadence/aot/remove_ops.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
class RemoveCloneOpsTransformImported(ExportPass):
3939
def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
4040
finalize_passes: List[PassType] = [
41-
RemoveCloneOpsTransform(),
41+
RemoveCloneOpsTransform(
42+
eliminate_quant_dequant_pairs = False
43+
),
4244
]
4345
result = PassManager(passes=finalize_passes)(graph_module)
4446
dead_code_elimination_pass(result.graph_module)
@@ -356,19 +358,6 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
356358
return result
357359

358360

359-
@register_cadence_pass(CadencePassAttribute(opt_level=1))
360-
class RemoveCloneOpPass(RemoveOrReplacePassInterface):
361-
# If the op is a clone op, return the input and eliminate the op
362-
@property
363-
def targets(self) -> list[EdgeOpOverload]:
364-
return [exir_ops.edge.aten.clone.default]
365-
366-
def maybe_remove_or_replace(self, node: Node) -> bool:
367-
input_node = node.args[0]
368-
assert isinstance(input_node, Node)
369-
node.replace_all_uses_with(input_node)
370-
return True
371-
372361

373362
@register_cadence_pass(CadencePassAttribute(opt_level=1))
374363
class RemoveContiguousOpPass(RemoveOrReplacePassInterface):
@@ -926,7 +915,6 @@ def maybe_remove_or_replace(self, node: Node) -> bool:
926915

927916
class CommonRemovePasses:
928917
passes: List[Type[ExportPass]] = [
929-
RemoveCloneOpPass,
930918
RemoveAliasCopyOpPass,
931919
RemoveNopExpandOpPass,
932920
RemoveNopSliceOrViewOpPass,
@@ -935,13 +923,13 @@ class CommonRemovePasses:
935923
RemovePermutesAroundElementwiseOps,
936924
RemoveSqueezeViewBeforeElementwiseOps,
937925
RemoveCatFromSliceCopyPass,
926+
RemoveCloneOpsTransformImported,
938927
]
939928

940929

941930
class CadenceRemoveNops:
942931
passes: List[Type[ExportPass]] = CommonRemovePasses.passes + [
943932
SimplifySliceOpPass,
944-
RemoveCloneOpsTransformImported,
945933
RemoveNopRequantizeOpPass,
946934
RemoveZeroSizedConstantPadNd,
947935
RemoveContiguousOpPass,

0 commit comments

Comments
 (0)