Skip to content

Commit 6c5b7e5

Browse files
tom-armzingo
authored andcommitted
Arm: Add MobileNet v3 testcase
* Add missing inplace operators to quantization annotator. * Add atol, rtol & qtol to test_pipeline classes. Co-authored-by: Oscar Andersson <[email protected]> Signed-off-by: Tom Allsop <[email protected]> Change-Id: Idca2bcfdaf8039430a73148e9742f747b03b3e6b
1 parent cb1d175 commit 6c5b7e5

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

backends/arm/quantizer/quantization_annotator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def _match_pattern(
137137
torch.ops.aten.sum.dim_IntList,
138138
torch.ops.aten.hardsigmoid.default,
139139
torch.ops.aten.hardswish.default,
140+
torch.ops.aten.hardswish_.default,
140141
torch.ops.aten.full_like.default,
141142
]
142143

@@ -196,6 +197,7 @@ def _match_pattern(
196197
torch.ops.aten.full.default,
197198
torch.ops.aten.flatten.using_ints,
198199
torch.ops.aten.dropout.default,
200+
torch.ops.aten.dropout_.default,
199201
torch.ops.aten.clamp.default,
200202
torch.ops.aten.clamp.Tensor,
201203
operator.getitem,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
from typing import Tuple
7+
8+
import torch
9+
10+
from executorch.backends.arm.test.tester.test_pipeline import (
11+
EthosU55PipelineBI,
12+
EthosU85PipelineBI,
13+
TosaPipelineBI,
14+
TosaPipelineMI,
15+
)
16+
17+
from torchvision import models, transforms
18+
19+
mv3 = models.mobilenet_v3_small(weights=models.MobileNet_V3_Small_Weights)
20+
mv3 = mv3.eval()
21+
22+
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
23+
24+
input_tensor = torch.rand(1, 3, 232, 232)
25+
26+
model_inputs = (normalize(input_tensor),)
27+
input_t = Tuple[torch.Tensor]
28+
29+
30+
def test_mv3_tosa_MI():
31+
pipeline = TosaPipelineMI[input_t](
32+
mv3, model_inputs, aten_op=[], exir_op=[], use_to_edge_transform_and_lower=True
33+
)
34+
pipeline.run()
35+
36+
37+
def test_mv3_tosa_BI():
38+
pipeline = TosaPipelineBI[input_t](
39+
mv3,
40+
model_inputs,
41+
aten_op=[],
42+
exir_op=[],
43+
use_to_edge_transform_and_lower=True,
44+
atol=0.3,
45+
qtol=1,
46+
)
47+
pipeline.run()
48+
49+
50+
def test_mv3_u55_BI():
51+
pipeline = EthosU55PipelineBI[input_t](
52+
mv3,
53+
model_inputs,
54+
aten_ops=[],
55+
exir_ops=[],
56+
run_on_fvp=True,
57+
use_to_edge_transform_and_lower=True,
58+
atol=0.3,
59+
qtol=1,
60+
)
61+
pipeline.run()
62+
63+
64+
def test_mv3_u85_BI():
65+
pipeline = EthosU85PipelineBI[input_t](
66+
mv3,
67+
model_inputs,
68+
aten_ops=[],
69+
exir_ops=[],
70+
run_on_fvp=True,
71+
use_to_edge_transform_and_lower=True,
72+
atol=0.3,
73+
qtol=1,
74+
)
75+
pipeline.run()

backends/arm/test/tester/test_pipeline.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ def __init__(
274274
symmetric_io_quantization: bool = False,
275275
use_to_edge_transform_and_lower: bool = True,
276276
custom_path: str = None,
277+
atol: float = 1e-03,
278+
rtol: float = 1e-03,
279+
qtol: int = 0,
277280
):
278281
compile_spec = common.get_tosa_compile_spec(
279282
tosa_version, custom_path=custom_path
@@ -322,7 +325,11 @@ def __init__(
322325
)
323326

324327
self.add_stage(
325-
self.tester.run_method_and_compare_outputs, inputs=self.test_data
328+
self.tester.run_method_and_compare_outputs,
329+
atol=atol,
330+
rtol=rtol,
331+
qtol=qtol,
332+
inputs=self.test_data,
326333
)
327334

328335

@@ -353,6 +360,9 @@ def __init__(
353360
tosa_version: str = "TOSA-0.80+MI",
354361
use_to_edge_transform_and_lower: bool = True,
355362
custom_path: str = None,
363+
atol: float = 1e-03,
364+
rtol: float = 1e-03,
365+
qtol: int = 0,
356366
):
357367
compile_spec = common.get_tosa_compile_spec(
358368
tosa_version, custom_path=custom_path
@@ -376,7 +386,11 @@ def __init__(
376386
)
377387

378388
self.add_stage(
379-
self.tester.run_method_and_compare_outputs, inputs=self.test_data
389+
self.tester.run_method_and_compare_outputs,
390+
atol=atol,
391+
rtol=rtol,
392+
qtol=qtol,
393+
inputs=self.test_data,
380394
)
381395

382396

@@ -406,6 +420,9 @@ def __init__(
406420
symmetric_io_quantization: bool = False,
407421
use_to_edge_transform_and_lower: bool = False,
408422
custom_path: str = None,
423+
atol: float = 1e-03,
424+
rtol: float = 1e-03,
425+
qtol: int = 1,
409426
):
410427
compile_spec = common.get_u55_compile_spec(custom_path=custom_path)
411428
quant_stage = (
@@ -458,7 +475,9 @@ def __init__(
458475
self.add_stage(self.tester.serialize)
459476
self.add_stage(
460477
self.tester.run_method_and_compare_outputs,
461-
qtol=1,
478+
atol=atol,
479+
rtol=rtol,
480+
qtol=qtol,
462481
inputs=self.test_data,
463482
)
464483

@@ -489,6 +508,9 @@ def __init__(
489508
symmetric_io_quantization: bool = False,
490509
use_to_edge_transform_and_lower: bool = False,
491510
custom_path: str = None,
511+
atol: float = 1e-03,
512+
rtol: float = 1e-03,
513+
qtol: int = 1,
492514
):
493515
compile_spec = common.get_u85_compile_spec(custom_path=custom_path)
494516
quant_stage = (
@@ -541,7 +563,9 @@ def __init__(
541563
self.add_stage(self.tester.serialize)
542564
self.add_stage(
543565
self.tester.run_method_and_compare_outputs,
544-
qtol=1,
566+
atol=atol,
567+
rtol=rtol,
568+
qtol=qtol,
545569
inputs=self.test_data,
546570
)
547571

0 commit comments

Comments
 (0)