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