Skip to content

Commit 2d93b82

Browse files
digantdesaifacebook-github-bot
authored andcommitted
Arm backend: run on tosa_ref_model only when requested (pytorch#13165)
Summary: Pull Request resolved: pytorch#13165 This is needed to support running the tests on setups where we may not have tosa reference model installed. The downside is, it may pass without doing e2e validaiton, which shouldn't happen on the CI where this is installed. Differential Revision: D79741689
1 parent 96e82f5 commit 2d93b82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+416
-68
lines changed

backends/arm/test/misc/test_bn_relu_folding_qat.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ def forward(self, x: torch.Tensor):
4747

4848
@common.parametrize("model", models)
4949
def test_qat_tosa_INT(model: torch.nn.Module):
50-
pipeline = TosaPipelineINT[input_t1](model, model.test_data, [], [], qtol=1)
50+
pipeline = TosaPipelineINT[input_t1](
51+
model,
52+
model.test_data,
53+
[],
54+
[],
55+
qtol=1,
56+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
57+
)
5158
tosa_version = conftest.get_option("tosa_version")
5259
tosa_profiles = {
5360
"1.0": common.TosaSpecification.create_from_string("TOSA-1.0+INT"),

backends/arm/test/misc/test_custom_partition.py

Lines changed: 57 additions & 8 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 conftest
67
import logging
78
from typing import Tuple
89

@@ -50,7 +51,13 @@ def test_single_reject(caplog, test_data: input_t1):
5051
caplog.set_level(logging.INFO)
5152

5253
module = CustomPartitioning()
53-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
54+
pipeline = TosaPipelineFP[input_t1](
55+
module,
56+
test_data,
57+
[],
58+
exir_op=[],
59+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
60+
)
5461
check = DontPartition(exir_ops.edge.aten.sigmoid.default)
5562
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
5663
pipeline.change_args(
@@ -68,7 +75,13 @@ def test_single_reject(caplog, test_data: input_t1):
6875
@common.parametrize("test_data", CustomPartitioning.inputs)
6976
def test_multiple_reject(test_data: input_t1):
7077
module = CustomPartitioning()
71-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
78+
pipeline = TosaPipelineFP[input_t1](
79+
module,
80+
test_data,
81+
[],
82+
exir_op=[],
83+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
84+
)
7285
check = DontPartition(
7386
exir_ops.edge.aten.sigmoid.default, exir_ops.edge.aten.mul.Tensor
7487
)
@@ -90,7 +103,13 @@ def test_torch_op_reject(caplog, test_data: input_t1):
90103

91104
module = CustomPartitioning()
92105
check = DontPartition(torch.ops.aten.sigmoid.default)
93-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
106+
pipeline = TosaPipelineFP[input_t1](
107+
module,
108+
test_data,
109+
[],
110+
exir_op=[],
111+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
112+
)
94113
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
95114
pipeline.change_args(
96115
"check_count.exir", {"torch.ops.higher_order.executorch_call_delegate": 2}
@@ -108,7 +127,13 @@ def test_torch_op_reject(caplog, test_data: input_t1):
108127
def test_string_op_reject(test_data: input_t1):
109128
module = CustomPartitioning()
110129
check = DontPartition("aten.sigmoid.default")
111-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
130+
pipeline = TosaPipelineFP[input_t1](
131+
module,
132+
test_data,
133+
[],
134+
exir_op=[],
135+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
136+
)
112137
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
113138
pipeline.change_args(
114139
"check_count.exir", {"torch.ops.higher_order.executorch_call_delegate": 2}
@@ -127,7 +152,13 @@ def test_name_reject(caplog, test_data: input_t1):
127152

128153
module = CustomPartitioning()
129154
check = DontPartitionName("mul", "sigmoid", exact=False)
130-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
155+
pipeline = TosaPipelineFP[input_t1](
156+
module,
157+
test_data,
158+
[],
159+
exir_op=[],
160+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
161+
)
131162
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
132163
pipeline.change_args(
133164
"check_count.exir",
@@ -142,7 +173,13 @@ def test_name_reject(caplog, test_data: input_t1):
142173
def test_module_reject(test_data: input_t1):
143174
module = NestedModule()
144175
check = DontPartitionModule(module_name="CustomPartitioning")
145-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
176+
pipeline = TosaPipelineFP[input_t1](
177+
module,
178+
test_data,
179+
[],
180+
exir_op=[],
181+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
182+
)
146183
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
147184
pipeline.change_args(
148185
"check_count.exir",
@@ -158,7 +195,13 @@ def test_inexact_module_reject(caplog, test_data: input_t1):
158195

159196
module = NestedModule()
160197
check = DontPartitionModule(module_name="Custom", exact=False)
161-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
198+
pipeline = TosaPipelineFP[input_t1](
199+
module,
200+
test_data,
201+
[],
202+
exir_op=[],
203+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
204+
)
162205
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
163206
pipeline.change_args(
164207
"check_count.exir",
@@ -173,7 +216,13 @@ def test_inexact_module_reject(caplog, test_data: input_t1):
173216
def test_module_instance_reject(test_data: input_t1):
174217
module = NestedModule()
175218
check = DontPartitionModule(instance_name="nested")
176-
pipeline = TosaPipelineFP[input_t1](module, test_data, [], exir_op=[])
219+
pipeline = TosaPipelineFP[input_t1](
220+
module,
221+
test_data,
222+
[],
223+
exir_op=[],
224+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
225+
)
177226
pipeline.change_args("to_edge_transform_and_lower", additional_checks=[check])
178227
pipeline.change_args(
179228
"check_count.exir",

backends/arm/test/models/test_conformer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from typing import Tuple
77

8+
import conftest
89
import pytest
910

1011
import torch
@@ -56,6 +57,7 @@ def test_conformer_tosa_FP():
5657
TestConformer.model_example_inputs,
5758
aten_op=TestConformer.aten_ops,
5859
exir_op=[],
60+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
5961
use_to_edge_transform_and_lower=True,
6062
)
6163
pipeline.run()
@@ -67,6 +69,7 @@ def test_conformer_tosa_INT():
6769
TestConformer.model_example_inputs,
6870
aten_op=TestConformer.aten_ops,
6971
exir_op=[],
72+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
7073
use_to_edge_transform_and_lower=True,
7174
)
7275
pipeline.pop_stage("check_count.exir")

backends/arm/test/models/test_deit_tiny_arm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from typing import Tuple
99

10+
import conftest
1011
import timm
1112

1213
import torch
@@ -43,6 +44,7 @@ def test_deit_tiny_tosa_FP():
4344
model_inputs,
4445
aten_op=[],
4546
exir_op=[],
47+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
4648
use_to_edge_transform_and_lower=True,
4749
)
4850
pipeline.run()
@@ -54,6 +56,7 @@ def test_deit_tiny_tosa_INT():
5456
model_inputs,
5557
aten_op=[],
5658
exir_op=[],
59+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
5760
use_to_edge_transform_and_lower=True,
5861
atol=1.5,
5962
qtol=1,

backends/arm/test/models/test_llama.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def test_llama_tosa_FP():
111111
llama_inputs,
112112
aten_op=[],
113113
exir_op=[],
114+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
114115
use_to_edge_transform_and_lower=True,
115116
transform_passes=[InsertCastForOpsWithInt64InputPass()],
116117
)
@@ -129,6 +130,7 @@ def test_llama_tosa_INT():
129130
llama_inputs,
130131
aten_op=[],
131132
exir_op=[],
133+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
132134
use_to_edge_transform_and_lower=True,
133135
)
134136
pipeline.run()

backends/arm/test/models/test_lstm_arm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from typing import Tuple
77

8+
import conftest
89
import torch
910

1011
from executorch.backends.arm.test import common
@@ -49,6 +50,7 @@ def test_lstm_tosa_FP():
4950
TestLSTM.model_example_inputs,
5051
aten_op=[],
5152
exir_op=[],
53+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
5254
use_to_edge_transform_and_lower=True,
5355
)
5456
pipeline.change_args("run_method_and_compare_outputs", get_test_inputs(), atol=3e-1)
@@ -61,6 +63,7 @@ def test_lstm_tosa_INT():
6163
TestLSTM.model_example_inputs,
6264
aten_op=[],
6365
exir_op=[],
66+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
6467
use_to_edge_transform_and_lower=True,
6568
)
6669
pipeline.change_args(

backends/arm/test/models/test_w2l_arm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import unittest
99
from typing import Tuple
1010

11+
import conftest
1112
import pytest
1213

1314
import torch
@@ -53,6 +54,7 @@ def test_w2l_tosa_FP():
5354
TestW2L.model_example_inputs,
5455
aten_op=[],
5556
exir_op=TestW2L.all_operators,
57+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
5658
use_to_edge_transform_and_lower=True,
5759
)
5860
pipeline.run()
@@ -66,6 +68,7 @@ def test_w2l_tosa_INT():
6668
TestW2L.model_example_inputs,
6769
aten_op=[],
6870
exir_op=TestW2L.all_operators,
71+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
6972
use_to_edge_transform_and_lower=True,
7073
)
7174
pipeline.run()

backends/arm/test/ops/test_abs.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from typing import Tuple
1010

11+
import conftest
1112
import torch
1213
from executorch.backends.arm.test import common
1314
from executorch.backends.arm.test.tester.test_pipeline import (
@@ -41,13 +42,25 @@ def forward(self, x):
4142

4243
@common.parametrize("test_data", Abs.test_parameters)
4344
def test_abs_tosa_FP(test_data: torch.Tensor):
44-
pipeline = TosaPipelineFP[input_t1](Abs(), test_data(), aten_op, exir_op)
45+
pipeline = TosaPipelineFP[input_t1](
46+
Abs(),
47+
test_data(),
48+
aten_op,
49+
exir_op,
50+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
51+
)
4552
pipeline.run()
4653

4754

4855
@common.parametrize("test_data", Abs.test_parameters)
4956
def test_abs_tosa_INT(test_data: torch.Tensor):
50-
pipeline = TosaPipelineINT[input_t1](Abs(), test_data(), aten_op, exir_op)
57+
pipeline = TosaPipelineINT[input_t1](
58+
Abs(),
59+
test_data(),
60+
aten_op,
61+
exir_op,
62+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
63+
)
5164
pipeline.run()
5265

5366

backends/arm/test/ops/test_acosh.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# LICENSE file in the root directory of this source tree.
55
from typing import Tuple
66

7+
import conftest
78
import pytest
89

910
import torch
@@ -55,6 +56,7 @@ def test_acosh_tosa_FP(test_data: Tuple):
5556
(test_data(),),
5657
aten_op,
5758
exir_op=[],
59+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
5860
)
5961
pipeline.run()
6062

@@ -65,6 +67,7 @@ def test_acosh_tosa_INT(test_data: Tuple):
6567
Acosh(),
6668
(test_data(),),
6769
aten_op=[],
70+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
6871
)
6972
pipeline.run()
7073

backends/arm/test/ops/test_add.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,25 @@ def forward(self, x: torch.Tensor, y: torch.Tensor):
8181

8282
@common.parametrize("test_data", Add.test_data)
8383
def test_add_tensor_tosa_FP(test_data: input_t1):
84-
pipeline = TosaPipelineFP[input_t1](Add(), test_data(), aten_op, exir_op)
84+
pipeline = TosaPipelineFP[input_t1](
85+
Add(),
86+
test_data(),
87+
aten_op,
88+
exir_op,
89+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
90+
)
8591
pipeline.run()
8692

8793

8894
@common.parametrize("test_data", Add.test_data)
8995
def test_add_tensor_tosa_INT(test_data: input_t1):
90-
pipeline = TosaPipelineINT[input_t1](Add(), test_data(), aten_op, exir_op)
96+
pipeline = TosaPipelineINT[input_t1](
97+
Add(),
98+
test_data(),
99+
aten_op,
100+
exir_op,
101+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
102+
)
91103
pipeline.run()
92104

93105

@@ -146,25 +158,49 @@ def test_add_tensor_u85_INT(test_data: input_t1):
146158

147159
@common.parametrize("test_data", Add2.test_data)
148160
def test_add_tensor_tosa_FP_2(test_data: input_t2):
149-
pipeline = TosaPipelineFP[input_t2](Add2(), test_data(), aten_op, exir_op)
161+
pipeline = TosaPipelineFP[input_t2](
162+
Add2(),
163+
test_data(),
164+
aten_op,
165+
exir_op,
166+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
167+
)
150168
pipeline.run()
151169

152170

153171
@common.parametrize("test_data", Add3.test_data)
154172
def test_add_tensor_tosa_FP_3(test_data: input_t2):
155-
pipeline = TosaPipelineFP[input_t2](Add3(), test_data(), aten_op, exir_op)
173+
pipeline = TosaPipelineFP[input_t2](
174+
Add3(),
175+
test_data(),
176+
aten_op,
177+
exir_op,
178+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
179+
)
156180
pipeline.run()
157181

158182

159183
@common.parametrize("test_data", Add3.test_data)
160184
def test_add_tensor_tosa_INT_3(test_data: input_t2):
161-
pipeline = TosaPipelineINT[input_t2](Add3(), test_data(), aten_op, exir_op)
185+
pipeline = TosaPipelineINT[input_t2](
186+
Add3(),
187+
test_data(),
188+
aten_op,
189+
exir_op,
190+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
191+
)
162192
pipeline.run()
163193

164194

165195
@common.parametrize("test_data", Add2.test_data)
166196
def test_add_tensor_tosa_INT_2(test_data: input_t2):
167-
pipeline = TosaPipelineINT[input_t2](Add2(), test_data(), aten_op, exir_op)
197+
pipeline = TosaPipelineINT[input_t2](
198+
Add2(),
199+
test_data(),
200+
aten_op,
201+
exir_op,
202+
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
203+
)
168204
pipeline.run()
169205

170206

0 commit comments

Comments
 (0)