|
7 | 7 |
|
8 | 8 | from typing import Tuple
|
9 | 9 |
|
| 10 | +import pytest |
10 | 11 | import torch
|
| 12 | +from executorch.backends.arm.quantizer.arm_quantizer import ( |
| 13 | + get_symmetric_a16w8_quantization_config, |
| 14 | + TOSAQuantizer, |
| 15 | +) |
11 | 16 |
|
12 |
| -from executorch.backends.arm.test import common |
| 17 | +from executorch.backends.arm.test import common, conftest |
13 | 18 |
|
14 | 19 | from executorch.backends.arm.test.tester.test_pipeline import (
|
15 | 20 | EthosU55PipelineINT,
|
|
18 | 23 | TosaPipelineINT,
|
19 | 24 | VgfPipeline,
|
20 | 25 | )
|
| 26 | +from executorch.backends.arm.tosa.specification import TosaSpecification |
| 27 | +from executorch.backends.xnnpack.test.tester import Quantize |
21 | 28 |
|
22 | 29 | aten_op = "torch.ops.aten.slice.Tensor"
|
23 | 30 | exir_op = "executorch_exir_dialects_edge__ops_aten_slice_copy"
|
@@ -119,3 +126,105 @@ def test_slice_tensor_vgf_INT(test_data: torch.Tensor):
|
119 | 126 | tosa_version="TOSA-1.0+INT",
|
120 | 127 | )
|
121 | 128 | pipeline.run()
|
| 129 | + |
| 130 | + |
| 131 | +def get_symmetric_a16w8_slice_quantizer(per_channel_quantization=False): |
| 132 | + tosa_version = conftest.get_option("tosa_version") |
| 133 | + tosa_profiles = { |
| 134 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 135 | + } |
| 136 | + |
| 137 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 138 | + quantizer.set_global( |
| 139 | + get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization) |
| 140 | + ) |
| 141 | + |
| 142 | + return Quantize( |
| 143 | + quantizer, |
| 144 | + get_symmetric_a16w8_quantization_config( |
| 145 | + is_per_channel=per_channel_quantization |
| 146 | + ), |
| 147 | + ) |
| 148 | + |
| 149 | + |
| 150 | +@common.parametrize("test_data", test_data_suite) |
| 151 | +@pytest.mark.xfail( |
| 152 | + reason="missing int16 slice ops support; fails at TOSA reference model with Unsupported operation type or rank. See: https://github.com/pytorch/executorch/issues/13976" |
| 153 | +) |
| 154 | +def test_slice_tensor_16a8w_tosa_INT(test_data: torch.Tensor): |
| 155 | + """Test slice operation with 16A8W quantization (16-bit activations, 8-bit weights)""" |
| 156 | + per_channel_quantization = False |
| 157 | + |
| 158 | + pipeline = TosaPipelineINT[input_t1]( |
| 159 | + Slice(), |
| 160 | + test_data(), |
| 161 | + aten_op, |
| 162 | + exir_op=[], |
| 163 | + per_channel_quantization=per_channel_quantization, |
| 164 | + use_to_edge_transform_and_lower=True, |
| 165 | + tosa_extensions=["int16"], |
| 166 | + ) |
| 167 | + |
| 168 | + pipeline.change_args( |
| 169 | + "quantize", |
| 170 | + get_symmetric_a16w8_slice_quantizer( |
| 171 | + per_channel_quantization=per_channel_quantization |
| 172 | + ), |
| 173 | + ) |
| 174 | + pipeline.run() |
| 175 | + |
| 176 | + |
| 177 | +@common.parametrize("test_data", test_data_suite) |
| 178 | +@common.XfailIfNoCorstone300 |
| 179 | +@pytest.mark.xfail( |
| 180 | + reason="Vela compilation fails with 'Invalid arguments' for int16 slice operations" |
| 181 | +) |
| 182 | +def test_slice_tensor_16a8w_u55_INT16(test_data: torch.Tensor): |
| 183 | + """Test slice operation with 16A8W quantization on U55 (16-bit activations, 8-bit weights)""" |
| 184 | + per_channel_quantization = False |
| 185 | + |
| 186 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 187 | + Slice(), |
| 188 | + test_data(), |
| 189 | + aten_ops=[], |
| 190 | + exir_ops=[], |
| 191 | + per_channel_quantization=per_channel_quantization, |
| 192 | + use_to_edge_transform_and_lower=True, |
| 193 | + run_on_fvp=True, |
| 194 | + ) |
| 195 | + |
| 196 | + pipeline.change_args( |
| 197 | + "quantize", |
| 198 | + get_symmetric_a16w8_slice_quantizer( |
| 199 | + per_channel_quantization=per_channel_quantization |
| 200 | + ), |
| 201 | + ) |
| 202 | + pipeline.run() |
| 203 | + |
| 204 | + |
| 205 | +@common.parametrize("test_data", test_data_suite) |
| 206 | +@common.XfailIfNoCorstone320 |
| 207 | +@pytest.mark.xfail( |
| 208 | + reason="Vela compilation fails with 'Invalid arguments' for int16 slice operations" |
| 209 | +) |
| 210 | +def test_slice_tensor_16a8w_u85_INT16(test_data: torch.Tensor): |
| 211 | + """Test slice operation with 16A8W quantization on U85 (16-bit activations, 8-bit weights)""" |
| 212 | + per_channel_quantization = False |
| 213 | + |
| 214 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 215 | + Slice(), |
| 216 | + test_data(), |
| 217 | + aten_ops=[], |
| 218 | + exir_ops=[], |
| 219 | + per_channel_quantization=per_channel_quantization, |
| 220 | + use_to_edge_transform_and_lower=True, |
| 221 | + run_on_fvp=True, |
| 222 | + ) |
| 223 | + |
| 224 | + pipeline.change_args( |
| 225 | + "quantize", |
| 226 | + get_symmetric_a16w8_slice_quantizer( |
| 227 | + per_channel_quantization=per_channel_quantization |
| 228 | + ), |
| 229 | + ) |
| 230 | + pipeline.run() |
0 commit comments