File tree Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Expand file tree Collapse file tree 4 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,19 @@ runtime.python_library(
73
73
],
74
74
)
75
75
76
+ runtime.python_library(
77
+ name = "remove_clone_ops",
78
+ srcs = ["remove_clone_ops.py"],
79
+ visibility = [
80
+ "//executorch/backends/...",
81
+ ],
82
+ deps = [
83
+ "//caffe2:torch",
84
+ "//executorch/exir:pass_base",
85
+ "//executorch/exir/dialects:lib",
86
+ ],
87
+ )
88
+
76
89
runtime.python_library(
77
90
name = "mean_to_sum_div",
78
91
srcs = ["mean_to_sum_div.py"],
Original file line number Diff line number Diff line change
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # pyre-strict
8
+
9
+ import torch
10
+ from executorch .exir .dialects ._ops import ops as exir_ops
11
+ from executorch .exir .pass_base import ExportPass , PassResult
12
+
13
+
14
+ def remove_clone_ops (graph : torch .fx .Graph ) -> torch .fx .Graph :
15
+ """
16
+ Remove clone op nodes and replace uses with parent node.
17
+ """
18
+ clone_op = exir_ops .edge .aten .clone .default
19
+ for node in graph .nodes :
20
+ if node .op == "call_function" and node .target == clone_op :
21
+ with graph .inserting_after (node ):
22
+ node .replace_all_uses_with (node .args [0 ])
23
+
24
+ graph .eliminate_dead_code ()
25
+ return graph
26
+
27
+
28
+ class RemoveCloneOpsTransform (ExportPass ):
29
+ def call (self , graph_module : torch .fx .GraphModule ) -> PassResult :
30
+ graph_module .graph = remove_clone_ops (graph_module .graph )
31
+ return PassResult (graph_module , True )
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ runtime.python_library(
26
26
"//executorch/backends/transforms:fuse_batch_norm_with_conv",
27
27
"//executorch/backends/transforms:fuse_conv_with_clamp",
28
28
"//executorch/backends/transforms:fuse_view_copy",
29
+ "//executorch/backends/transforms:remove_clone_ops",
29
30
"//executorch/exir:graph_module",
30
31
"//executorch/exir/_serialize:_bindings",
31
32
"//executorch/exir/_serialize:lib",
Original file line number Diff line number Diff line change 14
14
)
15
15
from executorch .backends .transforms .fuse_conv_with_clamp import FuseClampPass
16
16
from executorch .backends .transforms .fuse_view_copy import FuseViewCopyTransform
17
+ from executorch .backends .transforms .remove_clone_ops import RemoveCloneOpsTransform
17
18
18
19
from executorch .backends .vulkan .serialization .vulkan_graph_builder import VkGraphBuilder
19
20
from executorch .backends .vulkan .serialization .vulkan_graph_serialize import (
@@ -47,6 +48,7 @@ def preprocess( # noqa: C901
47
48
module_compile_spec : List [CompileSpec ],
48
49
) -> PreprocessResult :
49
50
passes = [
51
+ RemoveCloneOpsTransform (),
50
52
AddmmToLinearTransform (),
51
53
FuseViewCopyTransform (),
52
54
FuseBatchNormWithConvPass (program ),
You can’t perform that action at this time.
0 commit comments