Skip to content

Commit 603f679

Browse files
mcr229facebook-github-bot
authored andcommitted
MobileNetv2 FP32 + QS8 Test
Summary: Adding some CI for Mobilenetv2. The test tests for FP32 model and QS8 Model via long term quantization flow. Differential Revision: D48488928 fbshipit-source-id: 58c97896f01d0bd10938d025f08b3d2a069c01b6
1 parent eb9bfcf commit 603f679

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

backends/xnnpack/test/TARGETS

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,16 @@ python_unittest(
120120
"//executorch/backends/xnnpack/test/tester:tester",
121121
],
122122
)
123+
124+
python_unittest(
125+
name = "test_xnnpack_models",
126+
srcs = glob([
127+
"models/*.py",
128+
]),
129+
deps = [
130+
"//caffe2:torch",
131+
"//executorch/backends/xnnpack/partition:xnnpack_partitioner",
132+
"//executorch/backends/xnnpack/test/tester:tester",
133+
"//pytorch/vision:torchvision",
134+
],
135+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import unittest
8+
9+
import torch
10+
from executorch.backends.xnnpack.partition.xnnpack_partitioner import (
11+
XnnpackQuantizedPartitioner2,
12+
)
13+
from executorch.backends.xnnpack.test.tester import Partition, Tester
14+
from torchvision import models
15+
from torchvision.models.mobilenetv2 import MobileNet_V2_Weights
16+
17+
18+
class TestXNNPACKMobileNetV2(unittest.TestCase):
19+
20+
mv2 = models.mobilenet_v2(weights=MobileNet_V2_Weights)
21+
mv2 = mv2.eval()
22+
23+
all_operators = {
24+
"executorch_exir_dialects_edge__ops_aten__native_batch_norm_legit_no_training_default",
25+
"executorch_exir_dialects_edge__ops_aten_add_Tensor",
26+
"executorch_exir_dialects_edge__ops_aten_permute_copy_default",
27+
"executorch_exir_dialects_edge__ops_aten_addmm_default",
28+
"executorch_exir_dialects_edge__ops_aten_mean_dim",
29+
"executorch_exir_dialects_edge__ops_aten_hardtanh_default",
30+
"executorch_exir_dialects_edge__ops_aten_convolution_default",
31+
}
32+
33+
def test_fp32(self):
34+
model_inputs = (torch.ones(1, 3, 224, 244),)
35+
36+
(
37+
Tester(self.mv2, model_inputs)
38+
.export()
39+
.to_edge()
40+
.check(list(self.all_operators))
41+
.partition()
42+
.check(["torch.ops.executorch_call_delegate"])
43+
.check_not(list(self.all_operators))
44+
.to_executorch()
45+
.serialize()
46+
.run_method()
47+
.compare_outputs()
48+
)
49+
50+
def test_qs8_pt2e(self):
51+
model_inputs = (torch.ones(1, 3, 224, 244),)
52+
# Quantization fuses away batchnorm, so it is no longer in the graph
53+
ops_after_quantization = self.all_operators - {
54+
"executorch_exir_dialects_edge__ops_aten__native_batch_norm_legit_no_training_default",
55+
}
56+
57+
(
58+
Tester(self.mv2, model_inputs)
59+
.quantize2()
60+
.export()
61+
.to_edge()
62+
.check(list(ops_after_quantization))
63+
.partition(Partition(partitioner=XnnpackQuantizedPartitioner2))
64+
.check(["torch.ops.executorch_call_delegate"])
65+
.check_not(list(ops_after_quantization))
66+
.to_executorch()
67+
.serialize()
68+
.run_method()
69+
.compare_outputs()
70+
)

0 commit comments

Comments
 (0)