|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# Copyright 2024-2026 Arm Limited and/or its affiliates. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | + |
| 9 | +from typing import Tuple |
| 10 | + |
| 11 | +import torch |
| 12 | +from executorch.backends.arm.test import common |
| 13 | + |
| 14 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 15 | + EthosU55PipelineINT, |
| 16 | + EthosU85PipelineINT, |
| 17 | + TosaPipelineINT, |
| 18 | + VgfPipeline, |
| 19 | +) |
| 20 | + |
| 21 | +aten_op = "torch.ops.aten.log10.default" |
| 22 | +exir_op = "executorch_exir_dialects_edge__ops_aten_log10_default" |
| 23 | + |
| 24 | +input_t1 = Tuple[torch.Tensor] |
| 25 | + |
| 26 | + |
| 27 | +def _tensor(values): |
| 28 | + return torch.tensor(values, dtype=torch.float32) |
| 29 | + |
| 30 | + |
| 31 | +test_data_suite = { |
| 32 | + # (test_name, test_data) |
| 33 | + "tiny_positive": lambda: (_tensor([5e-4, 8e-4, 9e-4, 1e-3, 1.2e-3])), |
| 34 | + "mixed_range": lambda: (_tensor([1e-4, 5e-4, 2e-3, 1e-2, 5e-2])), |
| 35 | + "ones_rank4": lambda: (torch.ones(1, 10, 10, 10)), |
| 36 | + "ones_rank3": lambda: (torch.ones(10, 10, 10)), |
| 37 | + "rand": lambda: (torch.rand(10, 10) + 0.001), |
| 38 | + "randn_pos": lambda: (torch.randn(10) + 10), |
| 39 | + "randn_spread": lambda: (torch.max(torch.Tensor([0.1]), torch.randn(10) * 100)), |
| 40 | + "ramp": lambda: (torch.arange(0.01, 20, 0.2)), |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +class Log10(torch.nn.Module): |
| 45 | + def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 46 | + return torch.log10(x) |
| 47 | + |
| 48 | + |
| 49 | +@common.parametrize("test_data", test_data_suite) |
| 50 | +def test_log10_tosa_INT(test_data: input_t1): |
| 51 | + pipeline = TosaPipelineINT[input_t1](Log10(), (test_data(),), aten_op, exir_op) |
| 52 | + pipeline.run() |
| 53 | + |
| 54 | + |
| 55 | +@common.parametrize("test_data", test_data_suite) |
| 56 | +@common.XfailIfNoCorstone300 |
| 57 | +def test_log10_u55_INT(test_data: input_t1): |
| 58 | + EthosU55PipelineINT[input_t1]( |
| 59 | + Log10(), |
| 60 | + (test_data(),), |
| 61 | + aten_op, |
| 62 | + exir_op, |
| 63 | + ).run() |
| 64 | + |
| 65 | + |
| 66 | +@common.parametrize("test_data", test_data_suite) |
| 67 | +@common.XfailIfNoCorstone320 |
| 68 | +def test_log10_u85_INT(test_data: input_t1): |
| 69 | + EthosU85PipelineINT[input_t1]( |
| 70 | + Log10(), |
| 71 | + (test_data(),), |
| 72 | + aten_op, |
| 73 | + exir_op, |
| 74 | + ).run() |
| 75 | + |
| 76 | + |
| 77 | +@common.parametrize("test_data", test_data_suite) |
| 78 | +@common.SkipIfNoModelConverter |
| 79 | +def test_log10_vgf_quant(test_data: input_t1): |
| 80 | + pipeline = VgfPipeline[input_t1]( |
| 81 | + Log10(), |
| 82 | + (test_data(),), |
| 83 | + aten_op, |
| 84 | + exir_op, |
| 85 | + quantize=True, |
| 86 | + ) |
| 87 | + pipeline.run() |
0 commit comments