Skip to content

Commit d17ff74

Browse files
Arm backend: Do not partition view_copy (pytorch#16005)
aten::view_copy is now considered no-compute by the partitioner. This prevents the case where a partition is left empty if two view_copy ops cancels each other out, leaving the partition empty. This was the case when running torch_audio_hdemucs_high_musdb(_plus), which made Vela output an error. Additionaly, some incorrectly named tests in test_sum have been renamed from view to sum Signed-off-by: Christoffer J.L. <christoffer.johanssonlundqvist@arm.com>
1 parent 7956941 commit d17ff74

7 files changed

Lines changed: 32 additions & 20 deletions

File tree

‎backends/arm/test/models/stable_diffusion/test_CLIPTextModelWithProjection.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ class TestCLIPTextModelWithProjection:
3939
ops_after_partitioner_FP = {
4040
"executorch_exir_dialects_edge__ops_aten_argmax_default": 1,
4141
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 2,
42-
"torch.ops.higher_order.executorch_call_delegate": 2,
42+
"torch.ops.higher_order.executorch_call_delegate": 1,
4343
}
4444

4545
ops_after_partitioner_INT = {
4646
"executorch_exir_dialects_edge__ops_aten_argmax_default": 1,
4747
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 2,
48-
"torch.ops.higher_order.executorch_call_delegate": 2,
4948
}
5049

5150
ops_after_partitioner_vgf_quantize = ops_after_partitioner_FP
52-
ops_after_partitioner_vgf_no_quantize = ops_after_partitioner_FP
51+
ops_after_partitioner_vgf_no_quantize = {
52+
"executorch_exir_dialects_edge__ops_aten_argmax_default": 1,
53+
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 2,
54+
"torch.ops.higher_order.executorch_call_delegate": 2,
55+
}
5356

5457
def _prepare_inputs(
5558
self,

‎backends/arm/test/models/stable_diffusion/test_SD3Transformer2DModel.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TestSD3Transformer2DModel:
3939

4040
ops_after_partitioner_INT = {
4141
"executorch_exir_dialects_edge__ops_dim_order_ops__to_dim_order_copy_default": 2,
42-
"torch.ops.higher_order.executorch_call_delegate": 3,
42+
"torch.ops.higher_order.executorch_call_delegate": 2,
4343
"executorch_exir_dialects_edge__ops_aten_permute_copy_default": 1,
4444
}
4545

‎backends/arm/test/ops/test_mean_dim.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,12 @@ def forward(self, tensor: torch.Tensor, keepdim: bool):
365365
return tensor.mean()
366366

367367
test_data_suite: dict[str, Callable[[], mean_input_t]] = {
368-
"rank1": lambda: (
369-
torch.rand(
370-
1,
371-
),
368+
"rank_2": lambda: (
369+
torch.rand(1, 2),
372370
False,
373371
),
374-
"rank2": lambda: (torch.rand(5, 5), True),
375-
"rank4": lambda: (torch.rand(5, 1, 10, 1), False),
372+
"rank_2_keepdim": lambda: (torch.rand(5, 5), True),
373+
"rank_4": lambda: (torch.rand(5, 1, 10, 1), False),
376374
}
377375

378376

‎backends/arm/test/ops/test_sum.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_sum_dim_intlist_tosa_INT(test_data: input_t1):
9898

9999
@common.parametrize("test_data", Sum.test_parameters)
100100
@common.XfailIfNoCorstone300
101-
def test_view_u55_INT_1_0(test_data: Tuple):
101+
def test_sum_u55_INT_1_0(test_data: Tuple):
102102
pipeline = EthosU55PipelineINT[input_t1](
103103
Sum(),
104104
test_data(),
@@ -110,7 +110,7 @@ def test_view_u55_INT_1_0(test_data: Tuple):
110110

111111
@common.parametrize("test_data", Sum.test_parameters)
112112
@common.XfailIfNoCorstone320
113-
def test_view_u85_INT_1_0(test_data: Tuple):
113+
def test_sum_u85_INT_1_0(test_data: Tuple):
114114
pipeline = EthosU85PipelineINT[input_t1](
115115
Sum(),
116116
test_data(),
@@ -154,7 +154,7 @@ def test_sum_dim_intlist_vgf_quant(test_data: input_t1):
154154

155155

156156
@common.parametrize("test_data", reject_inputs)
157-
def test_view_u55_INT_failure_set(test_data: Tuple):
157+
def test_sum_u55_INT_failure_set(test_data: Tuple):
158158
pipeline = EthosU55PipelineINT[input_t1](
159159
Sum(),
160160
test_data(),

‎backends/arm/test/ops/test_unflatten.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Arm Limited and/or its affiliates.
1+
# Copyright 2025-2026 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -29,7 +29,10 @@ def __init__(self, dim: int, sizes: Tuple[int, ...]):
2929
self.sizes = sizes
3030

3131
def forward(self, x: torch.Tensor) -> torch.Tensor:
32-
return torch.unflatten(x, self.dim, self.sizes)
32+
unflatten_op = torch.unflatten(x, self.dim, self.sizes)
33+
# Because we treat a single view as a no compute operation and therefore do not partition it,
34+
# we want to provide a mul op to verify that it does indeed get partitioned when bundled with another op.
35+
return unflatten_op * unflatten_op
3336

3437
test_data: dict[str, test_data_t] = {
3538
"rand_3d_batch3": (lambda: (Unflatten(1, (-1, 2)), (torch.rand(3, 4, 4),))),

‎backends/arm/test/ops/test_view.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ def __init__(self, new_shape):
7474
self.new_shape = new_shape
7575

7676
def forward(self, x: torch.Tensor):
77-
return x.view(self.new_shape)
77+
view_op = x.view(self.new_shape)
78+
# Because we treat a single view as a no compute operation and therefore do not partition it,
79+
# we want to provide a mul op to verify that it does indeed get partitioned when bundled with another op.
80+
return view_op * view_op
7881

7982

8083
@common.parametrize(
@@ -152,7 +155,7 @@ def test_view_u55_INT_not_delegated(test_data: Tuple):
152155
View(new_shape),
153156
(test_tensor,),
154157
{"executorch_exir_dialects_edge__ops_aten_view_copy": 1},
155-
n_expected_delegates=0,
158+
n_expected_delegates=1,
156159
quantize=True,
157160
u55_subset=True,
158161
)

‎backends/arm/tosa/partitioner.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def _is_noop_expand(node: torch.fx.node.Node) -> bool:
7474
return all(m == 1 for m in multiples) and not changes_rank
7575

7676

77+
def _is_view_copy(node: torch.fx.node.Node) -> bool:
78+
return node.target == exir_ops.edge.aten.view_copy.default
79+
80+
7781
def is_partitioned(
7882
node: torch.fx.Node,
7983
tag: str,
@@ -249,17 +253,18 @@ def _tag_module( # noqa
249253
reporter,
250254
)
251255

252-
is_noop_partition = all(
256+
# Check whether the partition contains only no-op or non-computational ops. Such partitions don't make sense to delegate, and in the worst case may be optimized away during lowering, which can break compilation."
257+
is_nocompute_partition = all(
253258
_is_noop_clone(node)
254259
or _is_noop_alias_copy(node)
255-
or _is_noop_detach_copy(node)
256260
or _is_noop_expand(node)
257261
or _is_noop_to_dim_order_copy(node)
262+
or _is_view_copy(node)
258263
or node.target in Q_OPS
259264
or node.target in DQ_OPS
260265
for node in partition.nodes
261266
)
262-
if is_noop_partition:
267+
if is_nocompute_partition:
263268
reject_partition(
264269
"Partition contained only ops which are removed in the TOSA lowering, leading to an empty partition.",
265270
partition,

0 commit comments

Comments
 (0)