Skip to content

Arm backend: Refactor gt, ge, lt, le and eq tests to pipeline #8828

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
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
5 changes: 5 additions & 0 deletions backends/arm/operator_support/tosa_supported_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def is_node_supported(
exir_ops.edge.aten.bitwise_xor.Tensor,
exir_ops.edge.aten.amax.default,
exir_ops.edge.aten.amin.default,
exir_ops.edge.aten.eq.Tensor,
exir_ops.edge.aten.ge.Tensor,
exir_ops.edge.aten.gt.Tensor,
exir_ops.edge.aten.le.Tensor,
exir_ops.edge.aten.lt.Tensor,
]

if node.target in unsupported_ops:
Expand Down
255 changes: 123 additions & 132 deletions backends/arm/test/ops/test_eq.py
Original file line number Diff line number Diff line change
@@ -1,145 +1,136 @@
# Copyright 2025 Arm Limited and/or its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import unittest
from typing import Tuple

import pytest
import torch
from executorch.backends.arm.test import common
from executorch.backends.arm.test.tester.arm_tester import ArmTester
from executorch.exir.backend.compile_spec_schema import CompileSpec
from parameterized import parameterized

test_data_suite = [
# (test_name, input, other,) See torch.eq() for info
(
"op_eq_rank1_ones",
torch.ones(5),
torch.ones(5),
),
(
"op_eq_rank2_rand",
torch.rand(4, 5),
torch.rand(1, 5),
),
(
"op_eq_rank3_randn",
torch.randn(10, 5, 2),
torch.randn(10, 5, 2),
),
(
"op_eq_rank4_randn",
torch.randn(3, 2, 2, 2),
torch.randn(3, 2, 2, 2),
),
]


class TestEqual(unittest.TestCase):
class Equal(torch.nn.Module):
def forward(
self,
input_: torch.Tensor,
other_: torch.Tensor,
):
return input_ == other_

def _test_eq_tosa_MI_pipeline(
self,
compile_spec: list[CompileSpec],
module: torch.nn.Module,
test_data: tuple[torch.Tensor, torch.Tensor],
):
(
ArmTester(
module,
example_inputs=test_data,
compile_spec=compile_spec,
)
.export()
.check_count({"torch.ops.aten.eq.Tensor": 1})
.to_edge()
.partition()
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
.to_executorch()
.run_method_and_compare_outputs(inputs=test_data)
)

def _test_eq_tosa_BI_pipeline(
self,
compile_spec: list[CompileSpec],
module: torch.nn.Module,
test_data: tuple[torch.Tensor, torch.Tensor],
):
(
ArmTester(
module,
example_inputs=test_data,
compile_spec=compile_spec,
)
.quantize()
.export()
.check_count({"torch.ops.aten.eq.Tensor": 1})
.check(["torch.ops.quantized_decomposed"])
.to_edge()
.partition()
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
.to_executorch()
.run_method_and_compare_outputs(inputs=test_data)
)

@parameterized.expand(test_data_suite)
def test_eq_tosa_MI(
self,
test_name: str,
input_: torch.Tensor,
other_: torch.Tensor,
):
test_data = (input_, other_)
self._test_eq_tosa_MI_pipeline(
common.get_tosa_compile_spec("TOSA-0.80+MI"), self.Equal(), test_data
)

@parameterized.expand(test_data_suite)
def test_eq_tosa_BI(
self,
test_name: str,
input_: torch.Tensor,
other_: torch.Tensor,
):
test_data = (input_, other_)
self._test_eq_tosa_BI_pipeline(
common.get_tosa_compile_spec("TOSA-0.80+BI"), self.Equal(), test_data
)

@parameterized.expand(test_data_suite)
@unittest.skip
def test_eq_u55_BI(
self,
test_name: str,
input_: torch.Tensor,
other_: torch.Tensor,
):
test_data = (input_, other_)
self._test_eq_tosa_BI_pipeline(
common.get_u55_compile_spec(permute_memory_to_nhwc=True),
self.Equal(),
test_data,
)

@parameterized.expand(test_data_suite)
@unittest.skip
def test_eq_u85_BI(
from executorch.backends.arm.test.tester.test_pipeline import (
EthosU85PipelineBI,
OpNotSupportedPipeline,
TosaPipelineBI,
TosaPipelineMI,
)

aten_op = "torch.ops.aten.eq.Tensor"
exir_op = "executorch_exir_dialects_edge__ops_aten_eq_Tensor"

input_t = Tuple[torch.Tensor]


class Equal(torch.nn.Module):
def __init__(self, input, other):
super().__init__()
self.input_ = input
self.other_ = other

def forward(
self,
test_name: str,
input_: torch.Tensor,
other_: torch.Tensor,
):
test_data = (input_, other_)
self._test_eq_tosa_BI_pipeline(
common.get_u85_compile_spec(permute_memory_to_nhwc=True),
self.Equal(),
test_data,
)
return input_ == other_

def get_inputs(self):
return (self.input_, self.other_)


op_eq_rank1_ones = Equal(
torch.ones(5),
torch.ones(5),
)
op_eq_rank2_rand = Equal(
torch.rand(4, 5),
torch.rand(1, 5),
)
op_eq_rank3_randn = Equal(
torch.randn(10, 5, 2),
torch.randn(10, 5, 2),
)
op_eq_rank4_randn = Equal(
torch.randn(3, 2, 2, 2),
torch.randn(3, 2, 2, 2),
)

test_data_common = {
"eq_rank1_ones": op_eq_rank1_ones,
"eq_rank2_rand": op_eq_rank2_rand,
"eq_rank3_randn": op_eq_rank3_randn,
"eq_rank4_randn": op_eq_rank4_randn,
}


@common.parametrize("test_module", test_data_common)
def test_eq_tosa_MI(test_module):
pipeline = TosaPipelineMI[input_t](
test_module, test_module.get_inputs(), aten_op, exir_op
)
pipeline.run()


@common.parametrize("test_module", test_data_common)
def test_eq_tosa_BI(test_module):
pipeline = TosaPipelineBI[input_t](
test_module, test_module.get_inputs(), aten_op, exir_op
)
pipeline.run()


@common.parametrize("test_module", test_data_common)
def test_eq_u55_BI(test_module):
# EQUAL is not supported on U55.
pipeline = OpNotSupportedPipeline[input_t](
test_module,
test_module.get_inputs(),
"TOSA-0.80+BI+u55",
{exir_op: 1},
)
pipeline.run()


@common.parametrize("test_module", test_data_common)
def test_eq_u85_BI(test_module):
pipeline = EthosU85PipelineBI[input_t](
test_module,
test_module.get_inputs(),
aten_op,
exir_op,
run_on_fvp=False,
use_to_edge_transform_and_lower=True,
)
pipeline.run()


@common.parametrize("test_module", test_data_common)
@pytest.mark.skip(reason="The same as test_eq_u55_BI")
def test_eq_u55_BI_on_fvp(test_module):
# EQUAL is not supported on U55.
pipeline = OpNotSupportedPipeline[input_t](
test_module,
test_module.get_inputs(),
"TOSA-0.80+BI+u55",
{exir_op: 1},
)
pipeline.run()


@common.parametrize(
"test_module",
test_data_common,
xfails={"eq_rank4_randn": "4D fails because boolean Tensors can't be subtracted"},
)
@common.SkipIfNoCorstone320
def test_eq_u85_BI_on_fvp(test_module):
pipeline = EthosU85PipelineBI[input_t](
test_module,
test_module.get_inputs(),
aten_op,
exir_op,
run_on_fvp=True,
use_to_edge_transform_and_lower=True,
)
pipeline.run()
Loading
Loading