Skip to content
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
34 changes: 26 additions & 8 deletions backends/arm/test/ops/test_cat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# Copyright 2024 Arm Limited and/or its affiliates.
# Copyright 2024-2025 Arm Limited and/or its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
Expand Down Expand Up @@ -33,6 +33,8 @@ class Cat(torch.nn.Module):
),
-1,
),
((torch.randn(1, 2, 4, 4), torch.randn(1, 2, 4, 1)), 3),
((torch.randn(1, 2, 4, 4), torch.randn(1, 2, 4, 4)), 0),
((torch.randn(2, 2, 4, 4), torch.randn(2, 2, 4, 1)), 3),
(
(
Expand All @@ -47,8 +49,8 @@ class Cat(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, tensors: tuple[torch.Tensor, ...], dim: int) -> torch.Tensor:
return torch.cat(tensors, dim=dim)
def forward(self, t: tuple[torch.Tensor, ...], dim: int) -> torch.Tensor:
return torch.cat(t, dim=dim)

def _test_cat_tosa_MI_pipeline(
self, module: torch.nn.Module, test_data: Tuple[tuple[torch.Tensor, ...], int]
Expand Down Expand Up @@ -134,22 +136,38 @@ def test_cat_tosa_BI(self, operands: tuple[torch.Tensor, ...], dim: int):
test_data = (operands, dim)
self._test_cat_tosa_BI_pipeline(self.Cat(), test_data)

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(Cat.test_parameters)
@parameterized.expand(Cat.test_parameters[:-3])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_cat_u55_BI(self, operands: tuple[torch.Tensor, ...], dim: int):
test_data = (operands, dim)
self._test_cat_ethosu_BI_pipeline(
self.Cat(), common.get_u55_compile_spec(), test_data
)

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(Cat.test_parameters)
# MLETORCH-630 Cat does not work on FVP with batch>1
@parameterized.expand(Cat.test_parameters[-3:])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_cat_u55_BI_xfails(self, operands: tuple[torch.Tensor, ...], dim: int):
test_data = (operands, dim)
self._test_cat_ethosu_BI_pipeline(
self.Cat(), common.get_u55_compile_spec(), test_data
)

@parameterized.expand(Cat.test_parameters[:-3])
@pytest.mark.corstone_fvp
def test_cat_u85_BI(self, operands: tuple[torch.Tensor, ...], dim: int):
test_data = (operands, dim)
self._test_cat_ethosu_BI_pipeline(
self.Cat(), common.get_u85_compile_spec(), test_data
)

# MLETORCH-630 Cat does not work on FVP with batch>1
@parameterized.expand(Cat.test_parameters[-3:])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_cat_u85_BI_xfails(self, operands: tuple[torch.Tensor, ...], dim: int):
test_data = (operands, dim)
self._test_cat_ethosu_BI_pipeline(
self.Cat(), common.get_u85_compile_spec(), test_data
)
34 changes: 25 additions & 9 deletions backends/arm/test/ops/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ class Expand(torch.nn.Module):
test_parameters = [
(torch.rand(1), (2,)),
(torch.randn(1, 4), (1, -1)),
(torch.rand(1, 1, 2, 2), (4, 3, -1, 2)),
(torch.randn(1), (2, 2, 4)),
(torch.rand(3, 2, 4, 1), (-1, -1, -1, 3)),
(torch.randn(1, 1, 1, 5), (1, 4, -1, -1)),
(torch.randn(1, 1, 192), (1, -1, -1)),
(torch.randn(1, 1), (1, 2, 2, 4)),
(torch.randn(1, 1), (2, 2, 2, 4)),
(torch.randn(10, 1, 1, 97), (-1, 4, -1, -1)),
(torch.rand(1, 1, 2, 2), (4, 3, -1, 2)),
]

def forward(self, x: torch.Tensor, multiples: Sequence):
return x.expand(multiples)
def forward(self, x: torch.Tensor, m: Sequence):
return x.expand(m)

def _test_expand_tosa_MI_pipeline(self, module: torch.nn.Module, test_data: Tuple):
(
Expand Down Expand Up @@ -113,20 +115,34 @@ def test_expand_tosa_MI(self, test_input, multiples):
def test_expand_tosa_BI(self, test_input, multiples):
self._test_expand_tosa_BI_pipeline(self.Expand(), (test_input, multiples))

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(Expand.test_parameters)
@parameterized.expand(Expand.test_parameters[:-3])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_expand_u55_BI(self, test_input, multiples):
self._test_expand_ethosu_BI_pipeline(
common.get_u55_compile_spec(), self.Expand(), (test_input, multiples)
)

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(Expand.test_parameters)
# MLETORCH-629: Expand does not work on FVP with batch>1
@parameterized.expand(Expand.test_parameters[-3:])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_expand_u55_BI_xfails(self, test_input, multiples):
self._test_expand_ethosu_BI_pipeline(
common.get_u55_compile_spec(), self.Expand(), (test_input, multiples)
)

@parameterized.expand(Expand.test_parameters[:-3])
@pytest.mark.corstone_fvp
def test_expand_u85_BI(self, test_input, multiples):
self._test_expand_ethosu_BI_pipeline(
common.get_u85_compile_spec(), self.Expand(), (test_input, multiples)
)

# MLETORCH-629: Expand does not work on FVP with batch>1
@parameterized.expand(Expand.test_parameters[-3:])
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_expand_u85_BI_xfails(self, test_input, multiples):
self._test_expand_ethosu_BI_pipeline(
common.get_u85_compile_spec(), self.Expand(), (test_input, multiples)
)
4 changes: 0 additions & 4 deletions backends/arm/test/ops/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,16 @@ def test_full_tosa_MI(self, test_tensor: Tuple):
def test_full_tosa_BI(self, test_tensor: Tuple):
self._test_full_tosa_BI_pipeline(self.AddVariableFull(), test_tensor)

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(AddVariableFull.test_parameters)
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_full_u55_BI(self, test_tensor: Tuple):
self._test_full_tosa_u55_pipeline(
self.AddVariableFull(),
test_tensor,
)

# Mismatch in provided number of inputs and model signature, MLETORCH 519
@parameterized.expand(AddVariableFull.test_parameters)
@pytest.mark.corstone_fvp
@conftest.expectedFailureOnFVP
def test_full_u85_BI(self, test_tensor: Tuple):
self._test_full_tosa_u85_pipeline(
self.AddVariableFull(),
Expand Down
22 changes: 8 additions & 14 deletions backends/arm/test/runner_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ def get_input_names(program: ExportedProgram) -> list[str]:
Returns:
A list of strings with the names of the model input.
"""
input_names = []

# E.g. bias and weights are 'placeholders' as well. This is used to
# get only the use inputs.
usr_inputs = program.graph_signature.user_inputs
for node in program.graph.nodes:
if node.op == "placeholder" and node.name in usr_inputs:
input_names.append(node.name)

return input_names
return [spec.arg.name for spec in program.graph_signature.input_specs]


def get_input_quantization_params(
Expand Down Expand Up @@ -334,13 +325,16 @@ def run_corstone(


def prep_data_for_save(
data: torch.Tensor,
data,
input_name: str,
quant_param: Optional[QuantizationParams] = None,
):
data_np = np.array(data.detach(), order="C").astype(
torch_to_numpy_dtype_dict[data.dtype]
)
if isinstance(data, torch.Tensor):
data_np = np.array(data.detach(), order="C").astype(
torch_to_numpy_dtype_dict[data.dtype]
)
else:
data_np = np.array(data)
if quant_param is not None:
assert quant_param.node_name in input_name, (
f"The quantization params name '{quant_param.node_name}' does not "
Expand Down
Loading