|
8 | 8 |
|
9 | 9 | from typing import Tuple
|
10 | 10 |
|
| 11 | +import pytest |
11 | 12 | import torch
|
12 |
| -from executorch.backends.arm.test import common |
| 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 |
13 | 18 | from executorch.backends.arm.test.tester.test_pipeline import (
|
14 | 19 | EthosU55PipelineINT,
|
15 | 20 | EthosU85PipelineINT,
|
16 | 21 | TosaPipelineFP,
|
17 | 22 | TosaPipelineINT,
|
18 | 23 | VgfPipeline,
|
19 | 24 | )
|
| 25 | +from executorch.backends.arm.tosa.specification import TosaSpecification |
| 26 | +from executorch.backends.xnnpack.test.tester import Quantize |
20 | 27 |
|
21 | 28 | aten_op = "torch.ops.aten.sigmoid.default" # Used for checking that we do not have softmax in the graph after decompose
|
22 | 29 | exir_op = "executorch_exir_dialects_edge__ops_aten_sigmoid_default"
|
@@ -253,3 +260,105 @@ def test_sigmoid_vgf_INT_add_3():
|
253 | 260 | tosa_version="TOSA-1.0+INT",
|
254 | 261 | )
|
255 | 262 | pipeline.run()
|
| 263 | + |
| 264 | + |
| 265 | +def get_symmetric_a16w8_sigmoid_quantizer(per_channel_quantization=False): |
| 266 | + tosa_version = conftest.get_option("tosa_version") |
| 267 | + tosa_profiles = { |
| 268 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 269 | + } |
| 270 | + |
| 271 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 272 | + quantizer.set_global( |
| 273 | + get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization) |
| 274 | + ) |
| 275 | + |
| 276 | + return Quantize( |
| 277 | + quantizer, |
| 278 | + get_symmetric_a16w8_quantization_config( |
| 279 | + is_per_channel=per_channel_quantization |
| 280 | + ), |
| 281 | + ) |
| 282 | + |
| 283 | + |
| 284 | +@common.parametrize("test_data", test_data_suite) |
| 285 | +@pytest.mark.xfail( |
| 286 | + reason="missing int16 sigmoid ops support; fails at TOSA reference model with Unsupported operation type or rank. See: https://github.com/pytorch/executorch/issues/13974" |
| 287 | +) |
| 288 | +def test_sigmoid_16a8w_tosa_INT(test_data: torch.Tensor): |
| 289 | + """Test sigmoid operation with 16A8W quantization (16-bit activations, 8-bit weights)""" |
| 290 | + per_channel_quantization = False |
| 291 | + |
| 292 | + pipeline = TosaPipelineINT[input_t1]( |
| 293 | + Sigmoid(), |
| 294 | + (test_data(),), |
| 295 | + aten_op, |
| 296 | + exir_op=[], |
| 297 | + per_channel_quantization=per_channel_quantization, |
| 298 | + use_to_edge_transform_and_lower=True, |
| 299 | + tosa_extensions=["int16"], |
| 300 | + ) |
| 301 | + |
| 302 | + pipeline.change_args( |
| 303 | + "quantize", |
| 304 | + get_symmetric_a16w8_sigmoid_quantizer( |
| 305 | + per_channel_quantization=per_channel_quantization |
| 306 | + ), |
| 307 | + ) |
| 308 | + pipeline.run() |
| 309 | + |
| 310 | + |
| 311 | +@common.parametrize("test_data", test_data_suite) |
| 312 | +@common.XfailIfNoCorstone300 |
| 313 | +@pytest.mark.xfail( |
| 314 | + reason="Vela compilation fails with 'Invalid arguments' for int16 sigmoid operations" |
| 315 | +) |
| 316 | +def test_sigmoid_16a8w_u55_INT16(test_data: torch.Tensor): |
| 317 | + """Test sigmoid operation with 16A8W quantization on U55 (16-bit activations, 8-bit weights)""" |
| 318 | + per_channel_quantization = False |
| 319 | + |
| 320 | + pipeline = EthosU55PipelineINT[input_t1]( |
| 321 | + Sigmoid(), |
| 322 | + (test_data(),), |
| 323 | + aten_op, |
| 324 | + exir_op, |
| 325 | + per_channel_quantization=per_channel_quantization, |
| 326 | + use_to_edge_transform_and_lower=True, |
| 327 | + run_on_fvp=True, |
| 328 | + ) |
| 329 | + |
| 330 | + pipeline.change_args( |
| 331 | + "quantize", |
| 332 | + get_symmetric_a16w8_sigmoid_quantizer( |
| 333 | + per_channel_quantization=per_channel_quantization |
| 334 | + ), |
| 335 | + ) |
| 336 | + pipeline.run() |
| 337 | + |
| 338 | + |
| 339 | +@common.parametrize("test_data", test_data_suite) |
| 340 | +@common.XfailIfNoCorstone320 |
| 341 | +@pytest.mark.xfail( |
| 342 | + reason="Vela compilation fails with 'Invalid arguments' for int16 sigmoid operations" |
| 343 | +) |
| 344 | +def test_sigmoid_16a8w_u85_INT16(test_data: torch.Tensor): |
| 345 | + """Test sigmoid operation with 16A8W quantization on U85 (16-bit activations, 8-bit weights)""" |
| 346 | + per_channel_quantization = False |
| 347 | + |
| 348 | + pipeline = EthosU85PipelineINT[input_t1]( |
| 349 | + Sigmoid(), |
| 350 | + (test_data(),), |
| 351 | + aten_op, |
| 352 | + exir_op, |
| 353 | + per_channel_quantization=per_channel_quantization, |
| 354 | + use_to_edge_transform_and_lower=True, |
| 355 | + run_on_fvp=True, |
| 356 | + ) |
| 357 | + |
| 358 | + pipeline.change_args( |
| 359 | + "quantize", |
| 360 | + get_symmetric_a16w8_sigmoid_quantizer( |
| 361 | + per_channel_quantization=per_channel_quantization |
| 362 | + ), |
| 363 | + ) |
| 364 | + pipeline.run() |
0 commit comments