Skip to content

Commit 738ac7e

Browse files
mcremon-metameta-codesync[bot]
authored andcommitted
Move permute optimization passes to shared transforms location (#19002)
Summary: Pull Request resolved: #19002 Move 6 permute optimization passes and their shared infrastructure from executorch/backends/cadence/aot/ to executorch/backends/transforms/ so they can be shared between the Cadence and Arm backends without a cross-backend dependency. New files: - permute_pass_utils.py: base classes (HierarchicalInplacePassInterface, RemoveOrReplacePassInterface, FuseOpPairsAcrossBranchesPass) and utilities (get_arg, set_arg, get_transposed_dims, get_permuted_dims, get_shape, get_edge_overload_packet) - fuse_cascaded_transpose_or_permute_ops.py - fuse_cascaded_view_ops.py - fuse_transpose_or_permute_op_pairs_pass.py - remove_permutes_around_elementwise_ops.py - postpone_permute_below_squeeze_view.py - replace_nop_transpose_or_permute_with_view.py The shared versions omit register_cadence_pass decorators and cadence-specific ops from default op sets. Cadence files will subclass these and re-add the decorators and ops. Added OSS tests (test_permute_optimization_passes.py) for the 4 passes that can be imported without quantized op registration: FuseCascadedTransposeOrPermuteOps, FuseCascadedViewOps, PostponePermuteOpBelowSqueezeOrUnsqueezeLikeView, and ReplaceNopTransposeOrPermuteWithViewPass. These run in GitHub CI via pytest and are discovered automatically through pytest.ini testpaths. Differential Revision: D101459577 Reviewed By: ethansfng
1 parent 799bf5a commit 738ac7e

16 files changed

Lines changed: 1696 additions & 971 deletions

backends/cadence/aot/BUCK

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ fbcode_target(_kind = runtime.python_library,
8181
"pass_utils.py",
8282
],
8383
deps = [
84-
"fbsource//third-party/pypi/beartype:beartype",
8584
":utils",
8685
"//caffe2:torch",
86+
"//executorch/backends/transforms:permute_pass_utils",
8787
"//executorch/exir:pass_base",
8888
"//executorch/exir/dialects:lib",
8989
"//executorch/exir/passes:lib",
@@ -188,7 +188,6 @@ fbcode_target(_kind = python_unittest,
188188
],
189189
typing = True,
190190
deps = [
191-
"fbsource//third-party/pypi/beartype:beartype",
192191
":pass_utils",
193192
"//caffe2:torch",
194193
],
@@ -267,6 +266,10 @@ fbcode_target(_kind = runtime.python_library,
267266
"//caffe2:torch",
268267
"//executorch/backends/cadence/aot:pass_utils",
269268
"//executorch/backends/cadence/aot:utils",
269+
"//executorch/backends/transforms:fuse_cascaded_transpose_or_permute_ops",
270+
"//executorch/backends/transforms:fuse_cascaded_view_ops",
271+
"//executorch/backends/transforms:fuse_transpose_or_permute_op_pairs_pass",
272+
"//executorch/backends/transforms:permute_pass_utils",
270273
"//executorch/exir:pass_base",
271274
"//executorch/exir/dialects:lib",
272275
"//executorch/exir/dialects/edge:lib",
@@ -304,6 +307,7 @@ fbcode_target(_kind = runtime.python_library,
304307
"//executorch/backends/cadence/aot:pass_utils",
305308
"//executorch/backends/cadence/aot:simplify_ops",
306309
"//executorch/backends/transforms:remove_clone_ops",
310+
"//executorch/backends/transforms:remove_permutes_around_elementwise_ops",
307311
"//executorch/exir:pass_base",
308312
"//executorch/exir/dialects:lib",
309313
"//executorch/exir/dialects/edge:lib",
@@ -322,6 +326,7 @@ fbcode_target(_kind = runtime.python_library,
322326
"//executorch/backends/cadence/aot:compiler_utils",
323327
"//executorch/backends/cadence/aot:pass_utils",
324328
"//executorch/backends/cadence/aot:utils",
329+
"//executorch/backends/transforms:postpone_permute_below_squeeze_view",
325330
"//executorch/exir:pass_base",
326331
"//executorch/exir:tensor",
327332
"//executorch/exir/dialects:lib",
@@ -343,6 +348,7 @@ fbcode_target(_kind = runtime.python_library,
343348
"//executorch/backends/cadence/aot:pass_utils",
344349
"//executorch/backends/cadence/aot:remove_ops",
345350
"//executorch/backends/cadence/aot:utils",
351+
"//executorch/backends/transforms:replace_nop_transpose_or_permute_with_view",
346352
"//executorch/backends/transforms:replace_scalar_with_tensor",
347353
"//executorch/exir:pass_base",
348354
"//executorch/exir/dialects:lib",

0 commit comments

Comments
 (0)