Skip to content

Commit bb6b99a

Browse files
authored
Replace legacy MovePermuteAfterConcat with the ExecuTorch pass (#21593)
Differential Revision: D114631054 Pull Request resolved: #21593
1 parent bfeeb05 commit bb6b99a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

backends/cadence/aot/reorder_ops.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ def _match_inputs(
738738
# pyre-ignore[6]
739739
list[torch.fx.Node] | tuple[torch.fx.Node, ...],
740740
)
741+
# Moving one reused permute after cat makes it process the larger output.
742+
if inputs and all(inp is inputs[0] for inp in inputs):
743+
return None
741744

742745
unpermuted_inputs: List[torch.fx.Node] = []
743746
common_permutation: Optional[Tuple[int, ...]] = None

backends/cadence/aot/tests/test_reorder_ops_passes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,32 @@ def test_matching_single_user_permutes_moved_after_cat(self) -> None:
682682
placeholder_nodes = converted.graph.find_nodes(op="placeholder")
683683
self.assertEqual(cat_nodes[0].args[0], placeholder_nodes)
684684

685+
def test_repeated_permute_input_not_moved(self) -> None:
686+
x_data = torch.randn(1, 16, 32)
687+
builder = GraphBuilder()
688+
x = builder.placeholder("x", x_data)
689+
permuted_x = builder.call_operator(
690+
exir_ops.edge.aten.permute_copy.default,
691+
args=(x, [1, 2, 0]),
692+
)
693+
cat = builder.call_operator(
694+
exir_ops.edge.aten.cat.default,
695+
args=([permuted_x, permuted_x], 2),
696+
)
697+
builder.output([cat])
698+
699+
result = transform_and_check_numerics(
700+
builder.get_graph_module(),
701+
(x_data,),
702+
MovePermuteAfterConcat(),
703+
)
704+
705+
self.assertFalse(result.modified)
706+
self.assertEqual(
707+
get_compute_nodes_in_gm(result.graph_module),
708+
[exir_ops.edge.aten.permute_copy, exir_ops.edge.aten.cat],
709+
)
710+
685711
def test_different_permutations_not_moved(self) -> None:
686712
builder = GraphBuilder()
687713
x = builder.placeholder("x", torch.randn(2, 3, 4))

0 commit comments

Comments
 (0)