Skip to content

Commit 757afa4

Browse files
authored
Arm backend: Fix LeakyReLU to handle the inplace attribute (pytorch#16826)
1 parent 397cc55 commit 757afa4

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

‎backends/arm/_passes/decompose_leaky_relu_pass.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from executorch.exir.pass_base import ExportPass
1414

1515
edge_ops = (exir_ops.edge.aten.leaky_relu.default,)
16-
torch_ops = (torch.ops.aten.leaky_relu.default,)
16+
torch_ops = (torch.ops.aten.leaky_relu.default, torch.ops.aten.leaky_relu_.default)
1717

1818

1919
def _get_leaky_relu_ops(op) -> tuple:

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

Lines changed: 20 additions & 20 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.
@@ -21,27 +21,27 @@
2121

2222

2323
class LeakyReLU(torch.nn.Module):
24-
def __init__(self, slope: float = 0.01):
24+
def __init__(self, slope: float = 0.01, inplace: bool = True):
2525
super().__init__()
26-
self.activation = torch.nn.LeakyReLU(slope)
26+
self.activation = torch.nn.LeakyReLU(slope, inplace=inplace)
2727

2828
def forward(self, x: torch.Tensor):
2929
return self.activation(x)
3030

3131
test_data: dict[str, input_t1] = {
32-
"zeros": lambda: ((torch.zeros(1, 1, 5, 5),), 0.01),
33-
"ones": lambda: ((torch.ones(1, 16, 96, 96),), 0.01),
34-
"rand": lambda: ((torch.rand(1, 64, 56, 56),), 0.2),
35-
"3Dtensor": lambda: ((torch.rand(5, 5, 5),), 0.001),
36-
"negative_slope": lambda: ((torch.rand(1, 16, 96, 96),), -0.002),
32+
"zeros": lambda: ((torch.zeros(1, 1, 5, 5),), 0.01, True),
33+
"ones": lambda: ((torch.ones(1, 16, 96, 96),), 0.01, False),
34+
"rand": lambda: ((torch.rand(1, 64, 56, 56),), 0.2, False),
35+
"3Dtensor": lambda: ((torch.rand(5, 5, 5),), 0.001, True),
36+
"negative_slope": lambda: ((torch.rand(1, 16, 96, 96),), -0.002, True),
3737
}
3838

3939

4040
@common.parametrize("test_data", LeakyReLU.test_data)
4141
def test_leaky_relu_tosa_FP(test_data):
42-
data, slope = test_data()
42+
data, slope, inplace = test_data()
4343
pipeline = TosaPipelineFP[input_t1](
44-
LeakyReLU(slope),
44+
LeakyReLU(slope, inplace),
4545
data,
4646
[],
4747
use_to_edge_transform_and_lower=True,
@@ -54,9 +54,9 @@ def test_leaky_relu_tosa_FP(test_data):
5454

5555
@common.parametrize("test_data", LeakyReLU.test_data)
5656
def test_leaky_relu_tosa_INT(test_data):
57-
data, slope = test_data()
57+
data, slope, inplace = test_data()
5858
pipeline = TosaPipelineINT[input_t1](
59-
LeakyReLU(slope),
59+
LeakyReLU(slope, inplace),
6060
data,
6161
[],
6262
use_to_edge_transform_and_lower=True,
@@ -68,9 +68,9 @@ def test_leaky_relu_tosa_INT(test_data):
6868
@common.parametrize("test_data", LeakyReLU.test_data)
6969
@common.XfailIfNoCorstone300
7070
def test_leaky_relu_u55_INT(test_data):
71-
data, slope = test_data()
71+
data, slope, inplace = test_data()
7272
pipeline = EthosU55PipelineINT[input_t1](
73-
LeakyReLU(slope),
73+
LeakyReLU(slope, inplace),
7474
data,
7575
[],
7676
use_to_edge_transform_and_lower=True,
@@ -82,9 +82,9 @@ def test_leaky_relu_u55_INT(test_data):
8282
@common.parametrize("test_data", LeakyReLU.test_data)
8383
@common.XfailIfNoCorstone320
8484
def test_leaky_relu_u85_INT(test_data):
85-
data, slope = test_data()
85+
data, slope, inplace = test_data()
8686
pipeline = EthosU85PipelineINT[input_t1](
87-
LeakyReLU(slope),
87+
LeakyReLU(slope, inplace),
8888
data,
8989
[],
9090
use_to_edge_transform_and_lower=True,
@@ -96,9 +96,9 @@ def test_leaky_relu_u85_INT(test_data):
9696
@common.parametrize("test_data", LeakyReLU.test_data)
9797
@common.SkipIfNoModelConverter
9898
def test_leaky_relu_vgf_no_quant(test_data):
99-
data, slope = test_data()
99+
data, slope, inplace = test_data()
100100
pipeline = VgfPipeline[input_t1](
101-
LeakyReLU(slope),
101+
LeakyReLU(slope, inplace),
102102
data,
103103
[],
104104
use_to_edge_transform_and_lower=True,
@@ -113,9 +113,9 @@ def test_leaky_relu_vgf_no_quant(test_data):
113113
@common.parametrize("test_data", LeakyReLU.test_data)
114114
@common.SkipIfNoModelConverter
115115
def test_leaky_relu_vgf_quant(test_data):
116-
data, slope = test_data()
116+
data, slope, inplace = test_data()
117117
pipeline = VgfPipeline[input_t1](
118-
LeakyReLU(slope),
118+
LeakyReLU(slope, inplace),
119119
data,
120120
[],
121121
use_to_edge_transform_and_lower=True,

0 commit comments

Comments
 (0)