Skip to content

Commit b367540

Browse files
Arm backend: Align MobileNetV2 with MobileNetV3 unittest (#9900)
- Port MV2 to use new test pipelines - Use rand instead of randn data - Adjust atol Signed-off-by: Oscar Andersson <[email protected]>
1 parent 1231aeb commit b367540

File tree

1 file changed

+59
-83
lines changed

1 file changed

+59
-83
lines changed

backends/arm/test/models/test_mobilenet_v2_arm.py

Lines changed: 59 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -5,106 +5,82 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
import logging
9-
import unittest
8+
from typing import Tuple
109

1110
import pytest
1211

1312
import torch
14-
from executorch.backends.arm.test import common, conftest
13+
from executorch.backends.arm.test import common
14+
from executorch.backends.arm.test.tester.test_pipeline import (
15+
EthosU55PipelineBI,
16+
EthosU85PipelineBI,
17+
TosaPipelineBI,
18+
TosaPipelineMI,
19+
)
1520

16-
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1721
from torchvision import models, transforms # type: ignore[import-untyped]
1822
from torchvision.models.mobilenetv2 import ( # type: ignore[import-untyped]
1923
MobileNet_V2_Weights,
2024
)
2125

2226

23-
logger = logging.getLogger(__name__)
24-
logger.setLevel(logging.INFO)
27+
mv2 = models.mobilenetv2.mobilenet_v2(weights=MobileNet_V2_Weights.DEFAULT)
28+
mv2 = mv2.eval()
29+
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
2530

31+
model_inputs = (normalize(torch.rand((1, 3, 224, 224))),)
32+
input_t = Tuple[torch.Tensor]
2633

27-
class TestMobileNetV2(unittest.TestCase):
28-
"""Tests MobileNetV2."""
2934

30-
mv2 = models.mobilenetv2.mobilenet_v2(weights=MobileNet_V2_Weights.DEFAULT)
31-
mv2 = mv2.eval()
32-
normalize = transforms.Normalize(
33-
mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
35+
def test_mv2_tosa_MI():
36+
pipeline = TosaPipelineMI[input_t](
37+
mv2, model_inputs, aten_op=[], exir_op=[], use_to_edge_transform_and_lower=True
3438
)
39+
pipeline.run()
3540

36-
# Used e.g. for quantization calibration and shape extraction in the tester
37-
model_example_inputs = (normalize(torch.randn((1, 3, 224, 224))),)
3841

39-
def test_mv2_tosa_MI(self):
40-
(
41-
ArmTester(
42-
self.mv2,
43-
example_inputs=self.model_example_inputs,
44-
compile_spec=common.get_tosa_compile_spec("TOSA-0.80+MI"),
45-
)
46-
.export()
47-
.to_edge_transform_and_lower()
48-
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
49-
.to_executorch()
50-
.run_method_and_compare_outputs()
51-
)
42+
def test_mv2_tosa_BI():
43+
pipeline = TosaPipelineBI[input_t](
44+
mv2,
45+
model_inputs,
46+
aten_op=[],
47+
exir_op=[],
48+
use_to_edge_transform_and_lower=True,
49+
atol=0.25,
50+
qtol=1,
51+
)
52+
pipeline.run()
5253

53-
def test_mv2_tosa_BI(self):
54-
(
55-
ArmTester(
56-
self.mv2,
57-
example_inputs=self.model_example_inputs,
58-
compile_spec=common.get_tosa_compile_spec("TOSA-0.80+BI"),
59-
)
60-
.quantize()
61-
.export()
62-
.to_edge_transform_and_lower()
63-
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
64-
.to_executorch()
65-
.run_method_and_compare_outputs(rtol=0.001, atol=0.2, qtol=1)
66-
)
6754

68-
@pytest.mark.slow
69-
@pytest.mark.corstone_fvp
70-
def test_mv2_u55_BI(self):
71-
tester = (
72-
ArmTester(
73-
self.mv2,
74-
example_inputs=self.model_example_inputs,
75-
compile_spec=common.get_u55_compile_spec(),
76-
)
77-
.quantize()
78-
.export()
79-
.to_edge_transform_and_lower()
80-
.to_executorch()
81-
.serialize()
82-
)
83-
if conftest.is_option_enabled("corstone_fvp"):
84-
tester.run_method_and_compare_outputs(
85-
rtol=0.001,
86-
atol=0.2,
87-
qtol=1,
88-
)
55+
@pytest.mark.slow
56+
@pytest.mark.corstone_fvp
57+
@common.XfailIfNoCorstone300
58+
def test_mv2_u55_BI():
59+
pipeline = EthosU55PipelineBI[input_t](
60+
mv2,
61+
model_inputs,
62+
aten_ops=[],
63+
exir_ops=[],
64+
run_on_fvp=True,
65+
use_to_edge_transform_and_lower=True,
66+
atol=0.25,
67+
qtol=1,
68+
)
69+
pipeline.run()
8970

90-
@pytest.mark.slow
91-
@pytest.mark.corstone_fvp
92-
def test_mv2_u85_BI(self):
93-
tester = (
94-
ArmTester(
95-
self.mv2,
96-
example_inputs=self.model_example_inputs,
97-
compile_spec=common.get_u85_compile_spec(),
98-
)
99-
.quantize()
100-
.export()
101-
.to_edge_transform_and_lower()
102-
.to_executorch()
103-
.serialize()
104-
)
105-
if conftest.is_option_enabled("corstone_fvp"):
106-
tester.run_method_and_compare_outputs(
107-
rtol=0.001,
108-
atol=0.2,
109-
qtol=1,
110-
)
71+
72+
@pytest.mark.slow
73+
@pytest.mark.corstone_fvp
74+
@common.XfailIfNoCorstone320
75+
def test_mv2_u85_BI():
76+
pipeline = EthosU85PipelineBI[input_t](
77+
mv2,
78+
model_inputs,
79+
aten_ops=[],
80+
exir_ops=[],
81+
run_on_fvp=True,
82+
use_to_edge_transform_and_lower=True,
83+
atol=0.25,
84+
qtol=1,
85+
)
86+
pipeline.run()

0 commit comments

Comments
 (0)