Skip to content

Arm backend: Add MobileNet v3 testcase #9223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backends/arm/quantizer/quantization_annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def _match_pattern(
torch.ops.aten.sum.dim_IntList,
torch.ops.aten.hardsigmoid.default,
torch.ops.aten.hardswish.default,
torch.ops.aten.hardswish_.default,
torch.ops.aten.full_like.default,
]

Expand Down Expand Up @@ -196,6 +197,7 @@ def _match_pattern(
torch.ops.aten.full.default,
torch.ops.aten.flatten.using_ints,
torch.ops.aten.dropout.default,
torch.ops.aten.dropout_.default,
torch.ops.aten.clamp.default,
torch.ops.aten.clamp.Tensor,
operator.getitem,
Expand Down
86 changes: 86 additions & 0 deletions backends/arm/test/models/test_mobilenet_v3_arm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from typing import Tuple

import common
import pytest

import torch

from executorch.backends.arm.test.tester.test_pipeline import (
EthosU55PipelineBI,
EthosU85PipelineBI,
TosaPipelineBI,
TosaPipelineMI,
)

from torchvision import models, transforms

mv3 = models.mobilenet_v3_small(weights=models.MobileNet_V3_Small_Weights)
mv3 = mv3.eval()

normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])

input_tensor = torch.rand(1, 3, 232, 232)

model_inputs = (normalize(input_tensor),)
input_t = Tuple[torch.Tensor]


@pytest.mark.slow
def test_mv3_tosa_MI():
pipeline = TosaPipelineMI[input_t](
mv3, model_inputs, aten_op=[], exir_op=[], use_to_edge_transform_and_lower=True
)
pipeline.run()


@pytest.mark.slow
def test_mv3_tosa_BI():
pipeline = TosaPipelineBI[input_t](
mv3,
model_inputs,
aten_op=[],
exir_op=[],
use_to_edge_transform_and_lower=True,
atol=0.3,
qtol=1,
)
pipeline.run()


@pytest.mark.slow
@pytest.mark.corstone_fvp
@common.XfailIfNoCorstone300
def test_mv3_u55_BI():
pipeline = EthosU55PipelineBI[input_t](
mv3,
model_inputs,
aten_ops=[],
exir_ops=[],
run_on_fvp=True,
use_to_edge_transform_and_lower=True,
atol=0.3,
qtol=1,
)
pipeline.run()


@pytest.mark.slow
@pytest.mark.corstone_fvp
@common.XfailIfNoCorstone320
def test_mv3_u85_BI():
pipeline = EthosU85PipelineBI[input_t](
mv3,
model_inputs,
aten_ops=[],
exir_ops=[],
run_on_fvp=True,
use_to_edge_transform_and_lower=True,
atol=0.3,
qtol=1,
)
pipeline.run()
32 changes: 28 additions & 4 deletions backends/arm/test/tester/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ def __init__(
symmetric_io_quantization: bool = False,
use_to_edge_transform_and_lower: bool = True,
custom_path: str = None,
atol: float = 1e-03,
rtol: float = 1e-03,
qtol: int = 0,
):
compile_spec = common.get_tosa_compile_spec(
tosa_version, custom_path=custom_path
Expand Down Expand Up @@ -322,7 +325,11 @@ def __init__(
)

self.add_stage(
self.tester.run_method_and_compare_outputs, inputs=self.test_data
self.tester.run_method_and_compare_outputs,
atol=atol,
rtol=rtol,
qtol=qtol,
inputs=self.test_data,
)


Expand Down Expand Up @@ -353,6 +360,9 @@ def __init__(
tosa_version: str = "TOSA-0.80+MI",
use_to_edge_transform_and_lower: bool = True,
custom_path: str = None,
atol: float = 1e-03,
rtol: float = 1e-03,
qtol: int = 0,
):
compile_spec = common.get_tosa_compile_spec(
tosa_version, custom_path=custom_path
Expand All @@ -376,7 +386,11 @@ def __init__(
)

self.add_stage(
self.tester.run_method_and_compare_outputs, inputs=self.test_data
self.tester.run_method_and_compare_outputs,
atol=atol,
rtol=rtol,
qtol=qtol,
inputs=self.test_data,
)


Expand Down Expand Up @@ -406,6 +420,9 @@ def __init__(
symmetric_io_quantization: bool = False,
use_to_edge_transform_and_lower: bool = False,
custom_path: str = None,
atol: float = 1e-03,
rtol: float = 1e-03,
qtol: int = 1,
):
compile_spec = common.get_u55_compile_spec(custom_path=custom_path)
quant_stage = (
Expand Down Expand Up @@ -458,7 +475,9 @@ def __init__(
self.add_stage(self.tester.serialize)
self.add_stage(
self.tester.run_method_and_compare_outputs,
qtol=1,
atol=atol,
rtol=rtol,
qtol=qtol,
inputs=self.test_data,
)

Expand Down Expand Up @@ -489,6 +508,9 @@ def __init__(
symmetric_io_quantization: bool = False,
use_to_edge_transform_and_lower: bool = False,
custom_path: str = None,
atol: float = 1e-03,
rtol: float = 1e-03,
qtol: int = 1,
):
compile_spec = common.get_u85_compile_spec(custom_path=custom_path)
quant_stage = (
Expand Down Expand Up @@ -541,7 +563,9 @@ def __init__(
self.add_stage(self.tester.serialize)
self.add_stage(
self.tester.run_method_and_compare_outputs,
qtol=1,
atol=atol,
rtol=rtol,
qtol=qtol,
inputs=self.test_data,
)

Expand Down
Loading