|
| 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 | +import torch.nn.functional as F |
| 10 | +from executorch.backends.arm.test import common |
| 11 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 12 | + EthosU55PipelineINT, |
| 13 | + EthosU85PipelineINT, |
| 14 | + TosaPipelineFP, |
| 15 | + TosaPipelineINT, |
| 16 | + VgfPipeline, |
| 17 | +) |
| 18 | + |
| 19 | +aten_op = "torch.ops.aten.glu.default" |
| 20 | +exir_op = "executorch_exir_dialects_edge__ops_aten__glu_default" |
| 21 | + |
| 22 | + |
| 23 | +input_t1 = Tuple[torch.Tensor] |
| 24 | + |
| 25 | +test_data_suite = { |
| 26 | + "zeros": [torch.zeros(10, 10, 2), -1], |
| 27 | + "ones": [torch.ones(10, 10, 2), -1], |
| 28 | + "rand": [torch.rand(10, 10, 2) - 0.5, -1], |
| 29 | + "randn_pos": [torch.randn(10, 2) + 10, -1], |
| 30 | + "randn_neg": [torch.randn(10, 2) - 10, -1], |
| 31 | + "ramp": [torch.linspace(-16, 15.8, 160).reshape(-1, 2), -1], |
| 32 | + "zeros_custom_dim": [torch.zeros(7, 10, 5), 1], |
| 33 | + "rand_custom_dim": [torch.rand(10, 3, 3) - 0.5, 0], |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +class Glu(torch.nn.Module): |
| 38 | + |
| 39 | + def forward(self, a: torch.Tensor, dim: int) -> torch.Tensor: |
| 40 | + return F.glu(a, dim=dim) |
| 41 | + |
| 42 | + |
| 43 | +@common.parametrize( |
| 44 | + "test_data", |
| 45 | + test_data_suite, |
| 46 | +) |
| 47 | +def test_glu_tosa_FP(test_data: Tuple): |
| 48 | + pipeline = TosaPipelineFP[input_t1]( |
| 49 | + Glu(), |
| 50 | + (*test_data,), |
| 51 | + aten_op, |
| 52 | + exir_op, |
| 53 | + ) |
| 54 | + pipeline.run() |
| 55 | + |
| 56 | + |
| 57 | +@common.parametrize( |
| 58 | + "test_data", |
| 59 | + test_data_suite, |
| 60 | +) |
| 61 | +def test_glu_tosa_INT(test_data: Tuple): |
| 62 | + pipeline = TosaPipelineINT[input_t1]( |
| 63 | + Glu(), |
| 64 | + (*test_data,), |
| 65 | + aten_op=[], |
| 66 | + exir_op=exir_op, |
| 67 | + ) |
| 68 | + pipeline.run() |
| 69 | + |
| 70 | + |
| 71 | +@common.parametrize( |
| 72 | + "test_data", |
| 73 | + test_data_suite, |
| 74 | +) |
| 75 | +@common.XfailIfNoCorstone300 |
| 76 | +def test_glu_u55_INT(test_data: Tuple): |
| 77 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 78 | + Glu(), |
| 79 | + (*test_data,), |
| 80 | + aten_ops=[], |
| 81 | + exir_ops=exir_op, |
| 82 | + ) |
| 83 | + pipeline.run() |
| 84 | + |
| 85 | + |
| 86 | +@common.parametrize( |
| 87 | + "test_data", |
| 88 | + test_data_suite, |
| 89 | +) |
| 90 | +@common.XfailIfNoCorstone320 |
| 91 | +def test_glu_u85_INT(test_data: Tuple): |
| 92 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 93 | + Glu(), |
| 94 | + (*test_data,), |
| 95 | + aten_ops=[], |
| 96 | + exir_ops=exir_op, |
| 97 | + ) |
| 98 | + pipeline.run() |
| 99 | + |
| 100 | + |
| 101 | +@common.parametrize( |
| 102 | + "test_data", |
| 103 | + test_data_suite, |
| 104 | +) |
| 105 | +@common.SkipIfNoModelConverter |
| 106 | +def test_glu_vgf_FP(test_data: input_t1): |
| 107 | + pipeline = VgfPipeline[input_t1]( |
| 108 | + Glu(), |
| 109 | + (*test_data,), |
| 110 | + [], |
| 111 | + [], |
| 112 | + tosa_version="TOSA-1.0+FP", |
| 113 | + ) |
| 114 | + pipeline.run() |
| 115 | + |
| 116 | + |
| 117 | +@common.parametrize( |
| 118 | + "test_data", |
| 119 | + test_data_suite, |
| 120 | +) |
| 121 | +@common.SkipIfNoModelConverter |
| 122 | +def test_glu_vgf_INT(test_data: input_t1): |
| 123 | + pipeline = VgfPipeline[input_t1]( |
| 124 | + Glu(), |
| 125 | + (*test_data,), |
| 126 | + [], |
| 127 | + [], |
| 128 | + tosa_version="TOSA-1.0+INT", |
| 129 | + ) |
| 130 | + pipeline.run() |
0 commit comments