Skip to content

Commit d2fd7e6

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. Reviewed By: DrJessop Differential Revision: D88109862
1 parent 2551f30 commit d2fd7e6

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):
@@ -925,7 +914,6 @@ def maybe_remove_or_replace(self, node: Node) -> bool:
925914

926915
class CommonRemovePasses:
927916
passes: List[Type[ExportPass]] = [
928-
RemoveCloneOpPass,
929917
RemoveAliasCopyOpPass,
930918
RemoveNopExpandOpPass,
931919
RemoveNopSliceOrViewOpPass,
@@ -934,13 +922,13 @@ class CommonRemovePasses:
934922
RemovePermutesAroundElementwiseOps,
935923
RemoveSqueezeViewBeforeElementwiseOps,
936924
RemoveCatFromSliceCopyPass,
925+
RemoveCloneOpsTransformImported,
937926
]
938927

939928

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

0 commit comments

Comments
 (0)