|
| 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 | + |
| 10 | +from executorch.backends.arm.test import common |
| 11 | + |
| 12 | +from executorch.backends.arm.test.tester.test_pipeline import ( |
| 13 | + EthosU55PipelineBI, |
| 14 | + EthosU85PipelineBI, |
| 15 | + TosaPipelineBI, |
| 16 | + TosaPipelineMI, |
| 17 | +) |
| 18 | + |
| 19 | +exir_op = "executorch_exir_dialects_edge__ops_aten_avg_pool2d_default" |
| 20 | + |
| 21 | +input_t = Tuple[torch.Tensor] |
| 22 | + |
| 23 | + |
| 24 | +class AdaptiveAvgPool2d(torch.nn.AdaptiveAvgPool2d): |
| 25 | + def forward(self, *args, **kwargs): |
| 26 | + return super().forward(*args, **kwargs) |
| 27 | + |
| 28 | + |
| 29 | +test_modules = { |
| 30 | + "output_bigger_than_input_1_to_3": lambda: ( |
| 31 | + AdaptiveAvgPool2d((3, 3)), |
| 32 | + (torch.rand(1, 3, 1, 1),), |
| 33 | + ), |
| 34 | + "output_bigger_than_input_7_to_10": lambda: ( |
| 35 | + AdaptiveAvgPool2d((10, 10)), |
| 36 | + (torch.rand(1, 3, 7, 7),), |
| 37 | + ), |
| 38 | + "output_1x1": lambda: (AdaptiveAvgPool2d((1, 1)), (torch.rand(1, 4, 8, 8),)), |
| 39 | + "output_2x2": lambda: (AdaptiveAvgPool2d((2, 2)), (torch.rand(1, 4, 10, 10),)), |
| 40 | + "output_4x4": lambda: (AdaptiveAvgPool2d((4, 4)), (torch.rand(1, 5, 15, 15),)), |
| 41 | + "output_2x3": lambda: (AdaptiveAvgPool2d((2, 3)), (torch.rand(1, 3, 9, 13),)), |
| 42 | + "output_h_keep": lambda: ( |
| 43 | + AdaptiveAvgPool2d((2, None)), |
| 44 | + (torch.rand(1, 3, 10, 16),), |
| 45 | + ), |
| 46 | + "output_w_keep": lambda: ( |
| 47 | + AdaptiveAvgPool2d((None, 4)), |
| 48 | + (torch.rand(1, 3, 14, 20),), |
| 49 | + ), |
| 50 | + "output_5x5": lambda: (AdaptiveAvgPool2d((5, 5)), (torch.rand(1, 3, 25, 25),)), |
| 51 | + "output_3x5": lambda: (AdaptiveAvgPool2d((3, 5)), (torch.rand(1, 3, 15, 20),)), |
| 52 | + "output_7x1": lambda: (AdaptiveAvgPool2d((7, 1)), (torch.rand(1, 3, 21, 3),)), |
| 53 | + "output_1x7": lambda: (AdaptiveAvgPool2d((1, 7)), (torch.rand(1, 3, 3, 21),)), |
| 54 | + "output_3xNone": lambda: (AdaptiveAvgPool2d((3, None)), (torch.rand(1, 3, 9, 24),)), |
| 55 | + "output_Nonex3": lambda: (AdaptiveAvgPool2d((None, 3)), (torch.rand(1, 3, 24, 9),)), |
| 56 | + "pool_h_static_w_none": lambda: ( |
| 57 | + AdaptiveAvgPool2d((3, None)), |
| 58 | + (torch.rand(1, 3, 9, 17),), |
| 59 | + ), |
| 60 | + "pool_h_none_w_static": lambda: ( |
| 61 | + AdaptiveAvgPool2d((None, 5)), |
| 62 | + (torch.rand(1, 3, 15, 25),), |
| 63 | + ), |
| 64 | + "identity_pool": lambda: ( |
| 65 | + AdaptiveAvgPool2d((10, 10)), |
| 66 | + (torch.rand(1, 3, 10, 10),), |
| 67 | + ), |
| 68 | + "non_divisible_5x5_from_17x17": lambda: ( |
| 69 | + AdaptiveAvgPool2d((5, 5)), |
| 70 | + (torch.rand(1, 3, 17, 17),), |
| 71 | + ), |
| 72 | + "pool_height_only": lambda: ( |
| 73 | + AdaptiveAvgPool2d((1, 6)), |
| 74 | + (torch.rand(1, 3, 12, 6),), |
| 75 | + ), |
| 76 | + "pool_width_only": lambda: ( |
| 77 | + AdaptiveAvgPool2d((6, 1)), |
| 78 | + (torch.rand(1, 3, 6, 12),), |
| 79 | + ), |
| 80 | + "extreme_input_large": lambda: ( |
| 81 | + AdaptiveAvgPool2d((1, 1)), |
| 82 | + (torch.rand(1, 3, 128, 128),), |
| 83 | + ), |
| 84 | + "single_channel_input": lambda: ( |
| 85 | + AdaptiveAvgPool2d((4, 4)), |
| 86 | + (torch.rand(1, 1, 16, 16),), |
| 87 | + ), |
| 88 | + "high_channel_count": lambda: ( |
| 89 | + AdaptiveAvgPool2d((2, 2)), |
| 90 | + (torch.rand(1, 1024, 32, 32),), |
| 91 | + ), |
| 92 | + # Common input/output sizes found in models |
| 93 | + "output_7x7_from_14x14": lambda: ( |
| 94 | + AdaptiveAvgPool2d((7, 7)), |
| 95 | + (torch.rand(1, 512, 14, 14),), |
| 96 | + ), |
| 97 | + "output_1x1_from_8x8": lambda: ( |
| 98 | + AdaptiveAvgPool2d((1, 1)), |
| 99 | + (torch.rand(1, 2048, 8, 8),), |
| 100 | + ), |
| 101 | + "output_1x1_from_19": lambda: ( |
| 102 | + AdaptiveAvgPool2d((1, 1)), |
| 103 | + (torch.rand(1, 2560, 19, 19),), |
| 104 | + ), |
| 105 | + "output_1x1_from_7x7": lambda: ( |
| 106 | + AdaptiveAvgPool2d((1, 1)), |
| 107 | + (torch.rand(1, 1280, 7, 7),), |
| 108 | + ), |
| 109 | +} |
| 110 | + |
| 111 | + |
| 112 | +@common.parametrize("test_module", test_modules) |
| 113 | +def test_adaptive_avg_pool2d_tosa_MI(test_module): |
| 114 | + model, input_tensor = test_module() |
| 115 | + |
| 116 | + pipeline = TosaPipelineMI[input_t]( |
| 117 | + model, |
| 118 | + input_tensor, |
| 119 | + aten_op=[], |
| 120 | + exir_op=exir_op, |
| 121 | + ) |
| 122 | + pipeline.run() |
| 123 | + |
| 124 | + |
| 125 | +@common.parametrize("test_module", test_modules) |
| 126 | +def test_adaptive_avg_pool2d_tosa_BI(test_module): |
| 127 | + model, input_tensor = test_module() |
| 128 | + |
| 129 | + pipeline = TosaPipelineBI[input_t]( |
| 130 | + model, |
| 131 | + input_tensor, |
| 132 | + aten_op=[], |
| 133 | + exir_op=exir_op, |
| 134 | + ) |
| 135 | + pipeline.run() |
| 136 | + |
| 137 | + |
| 138 | +@common.parametrize("test_module", test_modules) |
| 139 | +@common.XfailIfNoCorstone300 |
| 140 | +def test_adaptive_avg_pool2d_u55_BI(test_module): |
| 141 | + model, input_tensor = test_module() |
| 142 | + |
| 143 | + pipeline = EthosU55PipelineBI[input_t]( |
| 144 | + model, |
| 145 | + input_tensor, |
| 146 | + aten_ops=[], |
| 147 | + exir_ops=exir_op, |
| 148 | + ) |
| 149 | + pipeline.run() |
| 150 | + |
| 151 | + |
| 152 | +@common.parametrize("test_module", test_modules) |
| 153 | +@common.XfailIfNoCorstone320 |
| 154 | +def test_adaptive_avg_pool2d_u85_BI(test_module): |
| 155 | + model, input_tensor = test_module() |
| 156 | + |
| 157 | + pipeline = EthosU85PipelineBI[input_t]( |
| 158 | + model, |
| 159 | + input_tensor, |
| 160 | + aten_ops=[], |
| 161 | + exir_ops=exir_op, |
| 162 | + ) |
| 163 | + pipeline.run() |
0 commit comments