|
| 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 | +from executorch.backends.arm.test import common |
| 10 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 11 | + EthosU55PipelineBI, |
| 12 | + EthosU85PipelineBI, |
| 13 | + TosaPipelineBI, |
| 14 | + TosaPipelineMI, |
| 15 | +) |
| 16 | + |
| 17 | +aten_op = "torch.ops.aten.leaky_relu.default" |
| 18 | +exir_op = "executorch_exir_dialects_edge__ops_aten_leaky_relu_default" |
| 19 | +input_t1 = Tuple[torch.Tensor] # Input x |
| 20 | + |
| 21 | + |
| 22 | +class LeakyReLU(torch.nn.Module): |
| 23 | + def __init__(self, slope: float = 0.01): |
| 24 | + super().__init__() |
| 25 | + self.activation = torch.nn.LeakyReLU(slope) |
| 26 | + |
| 27 | + def forward(self, x: torch.Tensor): |
| 28 | + return self.activation(x) |
| 29 | + |
| 30 | + test_data: dict[str, input_t1] = { |
| 31 | + "zeros": ((torch.zeros(1, 1, 5, 5),), 0.01), |
| 32 | + "ones": ((torch.ones(1, 32, 112, 112),), 0.01), |
| 33 | + "rand": ((torch.rand(1, 96, 56, 56),), 0.2), |
| 34 | + "3Dtensor": ((torch.rand(5, 5, 5),), 0.001), |
| 35 | + "negative_slope": ((torch.rand(1, 16, 128, 128),), -0.002), |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | +@common.parametrize("test_data", LeakyReLU.test_data) |
| 40 | +def test_leaky_relu_tosa_MI(test_data): |
| 41 | + data, slope = test_data |
| 42 | + pipeline = TosaPipelineMI[input_t1]( |
| 43 | + LeakyReLU(slope), data, [], use_to_edge_transform_and_lower=True |
| 44 | + ) |
| 45 | + pipeline.add_stage_after( |
| 46 | + "to_edge_transform_and_lower", pipeline.tester.check_not, [exir_op] |
| 47 | + ) |
| 48 | + pipeline.run() |
| 49 | + |
| 50 | + |
| 51 | +@common.parametrize("test_data", LeakyReLU.test_data) |
| 52 | +def test_leaky_relu_tosa_BI(test_data): |
| 53 | + data, slope = test_data |
| 54 | + pipeline = TosaPipelineBI[input_t1]( |
| 55 | + LeakyReLU(slope), data, [], use_to_edge_transform_and_lower=True |
| 56 | + ) |
| 57 | + pipeline.add_stage_after("quantize", pipeline.tester.check_not, [aten_op]) |
| 58 | + pipeline.run() |
| 59 | + |
| 60 | + |
| 61 | +@common.parametrize("test_data", LeakyReLU.test_data) |
| 62 | +@common.XfailIfNoCorstone300 |
| 63 | +def test_leaky_relu_u55_BI(test_data): |
| 64 | + data, slope = test_data |
| 65 | + pipeline = EthosU55PipelineBI[input_t1]( |
| 66 | + LeakyReLU(slope), |
| 67 | + data, |
| 68 | + [], |
| 69 | + run_on_fvp=True, |
| 70 | + use_to_edge_transform_and_lower=True, |
| 71 | + ) |
| 72 | + pipeline.add_stage_after("quantize", pipeline.tester.check_not, [aten_op]) |
| 73 | + pipeline.run() |
| 74 | + |
| 75 | + |
| 76 | +@common.parametrize("test_data", LeakyReLU.test_data) |
| 77 | +@common.XfailIfNoCorstone320 |
| 78 | +def test_leaky_relu_u85_BI(test_data): |
| 79 | + data, slope = test_data |
| 80 | + pipeline = EthosU85PipelineBI[input_t1]( |
| 81 | + LeakyReLU(slope), |
| 82 | + data, |
| 83 | + [], |
| 84 | + run_on_fvp=True, |
| 85 | + use_to_edge_transform_and_lower=True, |
| 86 | + ) |
| 87 | + pipeline.add_stage_after("quantize", pipeline.tester.check_not, [aten_op]) |
| 88 | + pipeline.run() |
0 commit comments