|
12 | 12 |
|
13 | 13 | import torch |
14 | 14 |
|
| 15 | +from executorch.backends.arm.quantizer.arm_quantizer import ( |
| 16 | + get_symmetric_a16w8_quantization_config, |
| 17 | + TOSAQuantizer, |
| 18 | +) |
15 | 19 | from executorch.backends.arm.test import common |
16 | 20 |
|
17 | 21 | from executorch.backends.arm.test.tester.test_pipeline import ( |
|
22 | 26 | TosaPipelineINT, |
23 | 27 | VgfPipeline, |
24 | 28 | ) |
| 29 | +from executorch.backends.arm.tosa import TosaSpecification |
| 30 | +from executorch.backends.xnnpack.test.tester import Quantize |
25 | 31 |
|
26 | 32 | aten_op = "torch.ops.aten.avg_pool2d.default" |
27 | 33 | exir_op = "executorch_exir_dialects_edge__ops_aten_avg_pool2d_default" |
@@ -232,3 +238,97 @@ def test_avg_pool2d_u55_INT_not_delegated(reject_module): |
232 | 238 | u55_subset=True, |
233 | 239 | ) |
234 | 240 | pipeline.run() |
| 241 | + |
| 242 | + |
| 243 | +def get_symmetric_a16w8_avg_pool2d_quantizer(per_channel_quantization=False): |
| 244 | + tosa_version = conftest.get_option("tosa_version") |
| 245 | + tosa_profiles = { |
| 246 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 247 | + } |
| 248 | + |
| 249 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 250 | + quantizer.set_global( |
| 251 | + get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization) |
| 252 | + ) |
| 253 | + |
| 254 | + return Quantize( |
| 255 | + quantizer, |
| 256 | + get_symmetric_a16w8_quantization_config( |
| 257 | + is_per_channel=per_channel_quantization |
| 258 | + ), |
| 259 | + ) |
| 260 | + |
| 261 | + |
| 262 | +@common.parametrize("test_module", test_modules) |
| 263 | +def test_avg_pool2d_16a8w_tosa_INT(test_module): |
| 264 | + """Test avg_pool2d operation with 16A8W quantization (16-bit activations, 8-bit weights)""" |
| 265 | + model, input_tensor = test_module() |
| 266 | + per_channel_quantization = False |
| 267 | + |
| 268 | + pipeline = TosaPipelineINT[input_t]( |
| 269 | + model, |
| 270 | + input_tensor, |
| 271 | + aten_op, |
| 272 | + exir_op=[], |
| 273 | + per_channel_quantization=per_channel_quantization, |
| 274 | + use_to_edge_transform_and_lower=True, |
| 275 | + tosa_extensions=["int16"], |
| 276 | + ) |
| 277 | + |
| 278 | + pipeline.change_args( |
| 279 | + "quantize", |
| 280 | + get_symmetric_a16w8_avg_pool2d_quantizer( |
| 281 | + per_channel_quantization=per_channel_quantization |
| 282 | + ), |
| 283 | + ) |
| 284 | + pipeline.run() |
| 285 | + |
| 286 | + |
| 287 | +@common.parametrize("test_module", test_modules) |
| 288 | +@common.XfailIfNoCorstone300 |
| 289 | +def test_avg_pool2d_16a8w_u55_INT16(test_module): |
| 290 | + """Test avg_pool2d operation with 16A8W quantization on U55 (16-bit activations, 8-bit weights)""" |
| 291 | + model, input_tensor = test_module() |
| 292 | + per_channel_quantization = False |
| 293 | + |
| 294 | + pipeline = EthosU55PipelineINT[input_t]( |
| 295 | + model, |
| 296 | + input_tensor, |
| 297 | + aten_op, |
| 298 | + exir_op, |
| 299 | + per_channel_quantization=per_channel_quantization, |
| 300 | + use_to_edge_transform_and_lower=True, |
| 301 | + ) |
| 302 | + |
| 303 | + pipeline.change_args( |
| 304 | + "quantize", |
| 305 | + get_symmetric_a16w8_avg_pool2d_quantizer( |
| 306 | + per_channel_quantization=per_channel_quantization |
| 307 | + ), |
| 308 | + ) |
| 309 | + pipeline.run() |
| 310 | + |
| 311 | + |
| 312 | +@common.parametrize("test_module", test_modules) |
| 313 | +@common.XfailIfNoCorstone320 |
| 314 | +def test_avg_pool2d_16a8w_u85_INT16(test_module): |
| 315 | + """Test avg_pool2d operation with 16A8W quantization on U85 (16-bit activations, 8-bit weights)""" |
| 316 | + model, input_tensor = test_module() |
| 317 | + per_channel_quantization = False |
| 318 | + |
| 319 | + pipeline = EthosU85PipelineINT[input_t]( |
| 320 | + model, |
| 321 | + input_tensor, |
| 322 | + aten_op, |
| 323 | + exir_op, |
| 324 | + per_channel_quantization=per_channel_quantization, |
| 325 | + use_to_edge_transform_and_lower=True, |
| 326 | + ) |
| 327 | + |
| 328 | + pipeline.change_args( |
| 329 | + "quantize", |
| 330 | + get_symmetric_a16w8_avg_pool2d_quantizer( |
| 331 | + per_channel_quantization=per_channel_quantization |
| 332 | + ), |
| 333 | + ) |
| 334 | + pipeline.run() |
0 commit comments