Skip to content

Commit 96f5eaa

Browse files
digantdesaifacebook-github-bot
authored andcommitted
Add remove clone along with to_copy when redundant (#14785)
Summary: As title Reviewed By: SS-JIA Differential Revision: D83864591
1 parent d8e07bd commit 96f5eaa

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

backends/transforms/test/test_remove_clone_ops.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,13 @@ def test_clone_identity_removed(self):
176176
exported,
177177
compile_config=EdgeCompileConfig(_skip_dim_order=skip_dim_order),
178178
)
179+
# Early exit if clone_op_str is not present in the graph
180+
# This is because some other pass may have removed the clone op.
181+
before_gm_code = before_epm.exported_program().graph_module.code
182+
if clone_op_str not in before_gm_code:
183+
continue
179184

180-
FileCheck().check_count(clone_op_str, 1, exactly=True).run(
181-
before_epm.exported_program().graph_module.code
182-
)
185+
FileCheck().check_count(clone_op_str, 1, exactly=True).run(before_gm_code)
183186

184187
updated_epm = before_epm.transform([RemoveCloneOpsTransform()])
185188

exir/passes/remove_noop_pass.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ def call(self, graph_module: GraphModule) -> PassResult:
104104
if node.op != "call_function":
105105
continue
106106

107-
if node.target not in (torch.ops.aten._to_copy.default,):
107+
if node.target not in (
108+
torch.ops.aten._to_copy.default,
109+
torch.ops.aten.clone.default,
110+
):
108111
continue
109112

110113
orig_tensor = node.args[0].meta["val"]

0 commit comments

Comments
 (0)