Skip to content

Commit 043c7a0

Browse files
authored
Arm backend: Fix flaky sigmoid 16/32 bit tests (#9537)
- Change constant test data to random generators. - Tests on Ethos-U55 are meant to xfail as int 16 tables are currently not supported. - For other tests, add flaky marker. Remove increased qtol, since the inaccuracies only show up sporadically. Signed-off-by: Erik Lundell <erik.lundell@arm.com>
1 parent 7d37bbc commit 043c7a0

File tree

3 files changed

+66
-40
lines changed

3 files changed

+66
-40
lines changed

backends/arm/test/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def parametrize(
231231
arg_name: str,
232232
test_data: dict[str, Any],
233233
xfails: dict[str, xfail_type] | None = None,
234+
strict: bool = True,
234235
):
235236
"""
236237
Custom version of pytest.mark.parametrize with some syntatic sugar and added xfail functionality
@@ -261,7 +262,9 @@ def decorator_func(func):
261262
pytest_param = pytest.param(
262263
test_parameters,
263264
id=id,
264-
marks=pytest.mark.xfail(reason=reason, raises=raises, strict=True),
265+
marks=pytest.mark.xfail(
266+
reason=reason, raises=raises, strict=strict
267+
),
265268
)
266269
else:
267270
pytest_param = pytest.param(test_parameters, id=id)

backends/arm/test/ops/test_sigmoid_16bit.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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.
55

6+
import pytest
7+
68
import torch
79
from executorch.backends.arm.quantizer.arm_quantizer import (
810
get_symmetric_quantization_config,
@@ -48,12 +50,12 @@ def get_16bit_sigmoid_quantizer(tosa_str: str):
4850

4951
input_t = tuple[torch.Tensor]
5052
test_data_suite = {
51-
"ones": (torch.ones(10, 10, 10),),
52-
"rand": (torch.rand(10, 10) - 0.5,),
53-
"rand_4d": (torch.rand(1, 1, 5, 10),),
54-
"randn_pos": (torch.randn(10) + 10,),
55-
"randn_neg": (torch.randn(10) - 10,),
56-
"ramp": (torch.arange(-16, 16, 0.02),),
53+
"ones": lambda: torch.ones(10, 10, 10),
54+
"rand": lambda: torch.rand(10, 10) - 0.5,
55+
"rand_4d": lambda: torch.rand(1, 1, 5, 10),
56+
"randn_pos": lambda: torch.randn(10) + 10,
57+
"randn_neg": lambda: torch.randn(10) - 10,
58+
"ramp": lambda: torch.arange(-16, 16, 0.02),
5759
}
5860

5961

@@ -79,8 +81,11 @@ def forward(self, x):
7981

8082

8183
@common.parametrize("test_data", test_data_suite)
84+
@pytest.mark.flaky(reruns=5)
8285
def test_sigmoid_tosa_BI(test_data):
83-
pipeline = TosaPipelineBI(Sigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op)
86+
pipeline = TosaPipelineBI(
87+
Sigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op
88+
)
8489
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
8590
pipeline.run()
8691

@@ -89,12 +94,13 @@ def test_sigmoid_tosa_BI(test_data):
8994
"test_data",
9095
test_data_suite,
9196
xfails={
92-
"ramp": "AssertionError: Output 0 does not match reference output. Passes with qtol=2. MLETORCH-787"
97+
"ramp": "AssertionError: Output 0 does not match reference output. MLETORCH-787"
9398
},
9499
)
100+
@pytest.mark.flaky(reruns=5)
95101
def test_sigmoid_add_sigmoid_tosa_BI(test_data):
96102
pipeline = TosaPipelineBI(
97-
SigmoidAddSigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op
103+
SigmoidAddSigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op
98104
)
99105
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
100106
pipeline.run()
@@ -107,13 +113,18 @@ def test_sigmoid_add_sigmoid_tosa_BI(test_data):
107113
"ones": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
108114
"rand": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
109115
"rand_4d": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
116+
"randn_pos": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
117+
"randn_neg": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
110118
"ramp": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
111119
},
120+
# int16 tables are not supported, but some tests happen to pass regardless.
121+
# Set them to xfail but strict=False -> ok if they pass.
122+
strict=False,
112123
)
113124
@common.XfailIfNoCorstone300
114125
def test_sigmoid_tosa_u55(test_data):
115126
pipeline = EthosU55PipelineBI(
116-
Sigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
127+
Sigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
117128
)
118129
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI+u55"))
119130
pipeline.run()
@@ -127,14 +138,18 @@ def test_sigmoid_tosa_u55(test_data):
127138
"rand": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
128139
"rand_4d": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
129140
"randn_neg": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
130-
"ramp": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
141+
"randn_pos": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
142+
"ramp": "AsssertionError: Output 0 does not match reference output. MLBEDSW-9770",
131143
},
144+
# int16 tables are not supported, but some tests happen to pass regardless.
145+
# Set them to xfail but strict=False -> ok if they pass.
146+
strict=False,
132147
)
133148
@common.XfailIfNoCorstone300
134149
def test_sigmoid_add_sigmoid_tosa_u55(test_data):
135150
pipeline = EthosU55PipelineBI(
136151
SigmoidAddSigmoid(),
137-
test_data,
152+
(test_data(),),
138153
Sigmoid.aten_op,
139154
Sigmoid.exir_op,
140155
run_on_fvp=True,
@@ -144,10 +159,11 @@ def test_sigmoid_add_sigmoid_tosa_u55(test_data):
144159

145160

146161
@common.parametrize("test_data", test_data_suite)
162+
@pytest.mark.flaky(reruns=5)
147163
@common.XfailIfNoCorstone320
148164
def test_sigmoid_tosa_u85(test_data):
149165
pipeline = EthosU85PipelineBI(
150-
Sigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
166+
Sigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
151167
)
152168
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
153169
pipeline.run()
@@ -160,11 +176,12 @@ def test_sigmoid_tosa_u85(test_data):
160176
"ramp": "AssertionError: Output 0 does not match reference output.",
161177
},
162178
)
179+
@pytest.mark.flaky(reruns=5)
163180
@common.XfailIfNoCorstone320
164181
def test_sigmoid_add_sigmoid_tosa_u85(test_data):
165182
pipeline = EthosU85PipelineBI(
166183
SigmoidAddSigmoid(),
167-
test_data,
184+
(test_data(),),
168185
Sigmoid.aten_op,
169186
Sigmoid.exir_op,
170187
run_on_fvp=True,

backends/arm/test/ops/test_sigmoid_32bit.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
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.
55

6+
import pytest
67
import torch
78
from executorch.backends.arm.quantizer.arm_quantizer import TOSAQuantizer
89
from executorch.backends.arm.quantizer.quantization_config import QuantizationConfig
@@ -52,7 +53,7 @@ def _get_32_bit_quant_config():
5253
return qconfig
5354

5455

55-
def get_16bit_sigmoid_quantizer(tosa_str: str):
56+
def get_32bit_sigmoid_quantizer(tosa_str: str):
5657
tosa_spec = common.TosaSpecification.create_from_string(tosa_str)
5758
quantizer = TOSAQuantizer(tosa_spec)
5859
quantizer.set_global(_get_32_bit_quant_config())
@@ -65,12 +66,12 @@ def get_16bit_sigmoid_quantizer(tosa_str: str):
6566

6667
input_t = tuple[torch.Tensor]
6768
test_data_suite = {
68-
"ones": (torch.ones(10, 10, 10),),
69-
"rand": (torch.rand(10, 10) - 0.5,),
70-
"rand_4d": (torch.rand(1, 10, 10, 10),),
71-
"randn_pos": (torch.randn(10) + 10,),
72-
"randn_neg": (torch.randn(10) - 10,),
73-
"ramp": (torch.arange(-16, 16, 0.2),),
69+
"ones": lambda: torch.ones(10, 10, 10),
70+
"rand": lambda: torch.rand(10, 10) - 0.5,
71+
"rand_4d": lambda: torch.rand(1, 10, 10, 10),
72+
"randn_pos": lambda: torch.randn(10) + 10,
73+
"randn_neg": lambda: torch.randn(10) - 10,
74+
"ramp": lambda: torch.arange(-16, 16, 0.2),
7475
}
7576

7677

@@ -96,28 +97,28 @@ def forward(self, x):
9697

9798

9899
@common.parametrize("test_data", test_data_suite)
100+
@pytest.mark.flaky(reruns=5)
99101
def test_sigmoid_tosa_BI(test_data):
100102
pipeline = TosaPipelineBI(
101103
Sigmoid(),
102-
test_data,
104+
(test_data(),),
103105
Sigmoid.aten_op,
104106
Sigmoid.exir_op,
105107
)
106-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
108+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI"))
107109
pipeline.run()
108110

109111

110112
@common.parametrize("test_data", test_data_suite)
113+
@pytest.mark.flaky(reruns=5)
111114
def test_sigmoid_add_sigmoid_tosa_BI(test_data):
112115
pipeline = TosaPipelineBI(
113116
SigmoidAddSigmoid(),
114-
test_data,
117+
(test_data(),),
115118
Sigmoid.aten_op,
116119
Sigmoid.exir_op,
117120
)
118-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
119-
pipeline.change_args("run_method_and_compare_outputs", test_data, qtol=1)
120-
121+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI"))
121122
pipeline.run()
122123

123124

@@ -129,16 +130,19 @@ def test_sigmoid_add_sigmoid_tosa_BI(test_data):
129130
"rand": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
130131
"rand_4d": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
131132
"randn_pos": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
133+
"randn_neg": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
132134
"ramp": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
133135
},
136+
# int16 tables are not supported, but some tests happen to pass regardless.
137+
# Set them to xfail but strict=False -> ok if they pass.
138+
strict=False,
134139
)
135140
@common.XfailIfNoCorstone300
136141
def test_sigmoid_tosa_u55(test_data):
137142
pipeline = EthosU55PipelineBI(
138-
Sigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
143+
Sigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
139144
)
140-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI+u55"))
141-
pipeline.change_args("run_method_and_compare_outputs", test_data, qtol=1)
145+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI+u55"))
142146
pipeline.run()
143147

144148

@@ -153,29 +157,31 @@ def test_sigmoid_tosa_u55(test_data):
153157
"randn_neg": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
154158
"ramp": "AssertionError: Output 0 does not match reference output. MLBEDSW-9770",
155159
},
160+
# int16 tables are not supported, but some tests happen to pass regardless.
161+
# Set them to xfail but strict=False -> ok if they pass.
162+
strict=False,
156163
)
157164
@common.XfailIfNoCorstone300
158165
def test_sigmoid_add_sigmoid_tosa_u55(test_data):
159166
pipeline = EthosU55PipelineBI(
160167
SigmoidAddSigmoid(),
161-
test_data,
168+
(test_data(),),
162169
Sigmoid.aten_op,
163170
Sigmoid.exir_op,
164171
run_on_fvp=True,
165172
)
166-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI+u55"))
167-
pipeline.change_args("run_method_and_compare_outputs", test_data, qtol=1)
173+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI+u55"))
168174
pipeline.run()
169175

170176

171177
@common.parametrize("test_data", test_data_suite)
178+
@pytest.mark.flaky(reruns=5)
172179
@common.XfailIfNoCorstone320
173180
def test_sigmoid_tosa_u85(test_data):
174181
pipeline = EthosU85PipelineBI(
175-
Sigmoid(), test_data, Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
182+
Sigmoid(), (test_data(),), Sigmoid.aten_op, Sigmoid.exir_op, run_on_fvp=True
176183
)
177-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
178-
pipeline.change_args("run_method_and_compare_outputs", test_data, qtol=1)
184+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI"))
179185
pipeline.run()
180186

181187

@@ -186,15 +192,15 @@ def test_sigmoid_tosa_u85(test_data):
186192
"ramp": "AssertionError: Output 0 does not match reference output.",
187193
},
188194
)
195+
@pytest.mark.flaky(reruns=5)
189196
@common.XfailIfNoCorstone320
190197
def test_sigmoid_add_sigmoid_tosa_u85(test_data):
191198
pipeline = EthosU85PipelineBI(
192199
SigmoidAddSigmoid(),
193-
test_data,
200+
(test_data(),),
194201
Sigmoid.aten_op,
195202
Sigmoid.exir_op,
196203
run_on_fvp=True,
197204
)
198-
pipeline.change_args("quantize", get_16bit_sigmoid_quantizer("TOSA-0.80+BI"))
199-
pipeline.change_args("run_method_and_compare_outputs", test_data, qtol=1)
205+
pipeline.change_args("quantize", get_32bit_sigmoid_quantizer("TOSA-0.80+BI"))
200206
pipeline.run()

0 commit comments

Comments
 (0)