|
9 | 9 | from typing import Tuple
|
10 | 10 |
|
11 | 11 | import pytest
|
12 |
| - |
13 | 12 | import torch
|
14 |
| -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 |
15 | 18 |
|
16 | 19 | from executorch.backends.arm.test.tester.test_pipeline import (
|
17 | 20 | EthosU55PipelineINT,
|
|
20 | 23 | TosaPipelineINT,
|
21 | 24 | VgfPipeline,
|
22 | 25 | )
|
| 26 | +from executorch.backends.arm.tosa_specification import TosaSpecification |
| 27 | +from executorch.backends.xnnpack.test.tester import Quantize |
23 | 28 |
|
24 | 29 | aten_op = "torch.ops.aten.linear.default"
|
25 | 30 |
|
@@ -143,7 +148,6 @@ def test_linear_tosa_FP(test_data: torch.Tensor):
|
143 | 148 | pipeline.run()
|
144 | 149 |
|
145 | 150 |
|
146 |
| -@pytest.mark.flaky(reruns=5) # TODO: Investigate flakyness. |
147 | 151 | @common.parametrize("test_data", test_data_rank1_INT | test_data_rank4_INT)
|
148 | 152 | def test_linear_tosa_INT(test_data: torch.Tensor):
|
149 | 153 | test_data, out_features, has_bias, per_channel_quantization = test_data()
|
@@ -258,3 +262,64 @@ def test_linear_vgf_INT(test_data: torch.Tensor):
|
258 | 262 | per_channel_quantization=per_channel_quantization,
|
259 | 263 | )
|
260 | 264 | pipeline.run()
|
| 265 | + |
| 266 | + |
| 267 | +def get_symmetric_a16w8_linear_quantizer( |
| 268 | + u55_config=False, per_channel_quantization=False |
| 269 | +): |
| 270 | + tosa_version = conftest.get_option("tosa_version") |
| 271 | + tosa_profiles = { |
| 272 | + "1.0": TosaSpecification.create_from_string("TOSA-1.0+INT+int16"), |
| 273 | + } |
| 274 | + |
| 275 | + quantizer = TOSAQuantizer(tosa_profiles[tosa_version]) |
| 276 | + quantizer.set_global( |
| 277 | + get_symmetric_a16w8_quantization_config(is_per_channel=per_channel_quantization) |
| 278 | + ) |
| 279 | + quantizer.set_module_type( |
| 280 | + torch.nn.Linear, |
| 281 | + get_symmetric_a16w8_quantization_config( |
| 282 | + is_per_channel=per_channel_quantization |
| 283 | + ), |
| 284 | + ) |
| 285 | + |
| 286 | + return Quantize( |
| 287 | + quantizer, |
| 288 | + get_symmetric_a16w8_quantization_config( |
| 289 | + is_per_channel=per_channel_quantization |
| 290 | + ), |
| 291 | + ) |
| 292 | + |
| 293 | + |
| 294 | +@common.parametrize("test_data", test_data_rank1_INT | test_data_rank4_INT) |
| 295 | +@pytest.mark.xfail( |
| 296 | + reason="missing int16 linear ops support; fails at TOSA reference model run with Invalid TOSA graph" |
| 297 | +) |
| 298 | +def test_linear_16a8w_tosa_INT(test_data: torch.Tensor): |
| 299 | + """Test linear operation with 16A8W quantization (16-bit activations, 8-bit weights)""" |
| 300 | + test_data, out_features, has_bias, per_channel_quantization = test_data() |
| 301 | + in_features = test_data.shape[-1] |
| 302 | + |
| 303 | + # Create pipeline with custom 16A8W quantization config |
| 304 | + pipeline = TosaPipelineINT[input_t1]( |
| 305 | + Linear( |
| 306 | + in_features=in_features, |
| 307 | + out_features=out_features, |
| 308 | + bias=has_bias, |
| 309 | + ), |
| 310 | + (test_data,), |
| 311 | + aten_op, |
| 312 | + exir_op=[], |
| 313 | + per_channel_quantization=per_channel_quantization, |
| 314 | + use_to_edge_transform_and_lower=True, |
| 315 | + tosa_extensions=["int16"], |
| 316 | + ) |
| 317 | + |
| 318 | + pipeline.change_args( |
| 319 | + "quantize", |
| 320 | + get_symmetric_a16w8_linear_quantizer( |
| 321 | + per_channel_quantization=per_channel_quantization |
| 322 | + ), |
| 323 | + ) |
| 324 | + # Run the pipeline |
| 325 | + pipeline.run() |
0 commit comments