|
8 | 8 |
|
9 | 9 | from typing import Tuple |
10 | 10 |
|
| 11 | +import pytest |
11 | 12 | import torch |
| 13 | +from executorch.backends.arm.quantizer.arm_quantizer import ( |
| 14 | + get_symmetric_a16w8_quantization_config, |
| 15 | + TOSAQuantizer, |
| 16 | +) |
| 17 | +from executorch.backends.arm.test import common, conftest |
12 | 18 |
|
13 | | -from executorch.backends.arm.test import common |
14 | 19 | from executorch.backends.arm.test.tester.test_pipeline import ( |
15 | 20 | EthosU55PipelineINT, |
16 | 21 | EthosU85PipelineINT, |
17 | 22 | TosaPipelineFP, |
18 | 23 | TosaPipelineINT, |
19 | 24 | VgfPipeline, |
20 | 25 | ) |
21 | | - |
| 26 | +from executorch.backends.arm.tosa import TosaSpecification |
| 27 | +from executorch.backends.xnnpack.test.tester import Quantize |
22 | 28 |
|
23 | 29 | aten_op = "torch.ops.aten.rsqrt.default" |
24 | 30 | input_t1 = Tuple[torch.Tensor] # Input x |
@@ -104,3 +110,96 @@ def test_rsqrt_vgf_INT(test_tensor: torch.Tensor): |
104 | 110 | tosa_version="TOSA-1.0+INT", |
105 | 111 | ) |
106 | 112 | pipeline.run() |
| 113 | + |
| 114 | + |
| 115 | +def get_symmetric_a16w8_rsqrt_quantizer( |
| 116 | + u55_config=False, per_channel_quantization=False |
| 117 | +): |
| 118 | + tosa_version = conftest.get_option("tosa_version") |
| 119 | + tosa_profiles = { |
| 120 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 121 | + } |
| 122 | + |
| 123 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 124 | + quantizer.set_global( |
| 125 | + get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization) |
| 126 | + ) |
| 127 | + |
| 128 | + return Quantize( |
| 129 | + quantizer, |
| 130 | + get_symmetric_a16w8_quantization_config( |
| 131 | + is_per_channel=per_channel_quantization |
| 132 | + ), |
| 133 | + ) |
| 134 | + |
| 135 | + |
| 136 | +@common.parametrize("test_tensor", Rsqrt.test_parameters) |
| 137 | +def test_rsqrt_int16_tosa_INT(test_tensor: torch.Tensor): |
| 138 | + """Test rsqrt operation with int16 quantization""" |
| 139 | + pipeline = TosaPipelineINT[input_t1]( |
| 140 | + Rsqrt(), |
| 141 | + test_tensor(), |
| 142 | + aten_op, |
| 143 | + exir_op=[], |
| 144 | + per_channel_quantization=False, |
| 145 | + use_to_edge_transform_and_lower=True, |
| 146 | + tosa_extensions=["int16"], |
| 147 | + ) |
| 148 | + |
| 149 | + pipeline.change_args( |
| 150 | + "quantize", |
| 151 | + get_symmetric_a16w8_rsqrt_quantizer(per_channel_quantization=False), |
| 152 | + ) |
| 153 | + # Run the pipeline |
| 154 | + pipeline.run() |
| 155 | + |
| 156 | + |
| 157 | +@common.parametrize("test_tensor", Rsqrt.test_parameters) |
| 158 | +@common.XfailIfNoCorstone300 |
| 159 | +@pytest.mark.xfail( |
| 160 | + reason="MLETORCH-707: AssertionError: Output 0 does not match reference output." |
| 161 | +) |
| 162 | +def test_rsqrt_int16_u55_INT16(test_tensor: torch.Tensor): |
| 163 | + """Test rsqrt operation with int16 quantization on U55""" |
| 164 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 165 | + Rsqrt(), |
| 166 | + test_tensor(), |
| 167 | + aten_op, |
| 168 | + exir_ops=[], |
| 169 | + per_channel_quantization=True, |
| 170 | + use_to_edge_transform_and_lower=True, |
| 171 | + atol=1e-03, |
| 172 | + rtol=1e-03, |
| 173 | + run_on_fvp=True, |
| 174 | + ) |
| 175 | + |
| 176 | + pipeline.change_args( |
| 177 | + "quantize", |
| 178 | + get_symmetric_a16w8_rsqrt_quantizer(per_channel_quantization=True), |
| 179 | + ) |
| 180 | + pipeline.run() |
| 181 | + |
| 182 | + |
| 183 | +@common.parametrize("test_tensor", Rsqrt.test_parameters) |
| 184 | +@common.XfailIfNoCorstone320 |
| 185 | +@pytest.mark.xfail( |
| 186 | + reason="MLETORCH-707: AssertionError: Output 0 does not match reference output." |
| 187 | +) |
| 188 | +def test_rsqrt_int16_u85_INT16(test_tensor: torch.Tensor): |
| 189 | + """Test rsqrt operation with int16 quantization on U85""" |
| 190 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 191 | + Rsqrt(), |
| 192 | + test_tensor(), |
| 193 | + aten_op, |
| 194 | + exir_ops=[], |
| 195 | + use_to_edge_transform_and_lower=True, |
| 196 | + atol=1e-03, |
| 197 | + rtol=1e-03, |
| 198 | + run_on_fvp=True, |
| 199 | + ) |
| 200 | + |
| 201 | + pipeline.change_args( |
| 202 | + "quantize", |
| 203 | + get_symmetric_a16w8_rsqrt_quantizer(per_channel_quantization=False), |
| 204 | + ) |
| 205 | + pipeline.run() |
0 commit comments