Skip to content

Commit 8175bb3

Browse files
Martin LindströmMartin Lindström
authored andcommitted
Arm backend: Make per-channel quantization default
Update the default quantization granularity to per channel rather than per tensor. Change-Id: I35d5c62741c7f93b916560874689245db96a588b
1 parent 7ede6be commit 8175bb3

File tree

5 files changed

+28
-40
lines changed

5 files changed

+28
-40
lines changed

backends/arm/quantizer/arm_quantizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
@functools.lru_cache
6262
def get_symmetric_quantization_config(
63-
is_per_channel: bool = False,
63+
is_per_channel: bool = True,
6464
is_qat: bool = False,
6565
is_dynamic: bool = False,
6666
act_qmin: int = -128,

backends/arm/test/models/test_mobilenet_v2_arm.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def test_mv2_tosa_BI():
4646
aten_op=[],
4747
exir_op=[],
4848
use_to_edge_transform_and_lower=True,
49-
per_channel_quantization=True,
5049
atol=0.25,
5150
qtol=1,
5251
)
@@ -63,7 +62,6 @@ def test_mv2_u55_BI():
6362
exir_ops=[],
6463
run_on_fvp=True,
6564
use_to_edge_transform_and_lower=True,
66-
per_channel_quantization=True,
6765
atol=0.25,
6866
qtol=1,
6967
)
@@ -80,7 +78,6 @@ def test_mv2_u85_BI():
8078
exir_ops=[],
8179
run_on_fvp=True,
8280
use_to_edge_transform_and_lower=True,
83-
per_channel_quantization=True,
8481
atol=0.25,
8582
qtol=1,
8683
)

backends/arm/test/tester/test_pipeline.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def __init__(
299299
run_on_tosa_ref_model: bool = True,
300300
tosa_version: str = "TOSA-0.80+BI",
301301
symmetric_io_quantization: bool = False,
302-
per_channel_quantization: bool = False,
302+
per_channel_quantization: bool = True,
303303
use_to_edge_transform_and_lower: bool = True,
304304
custom_path: str = None,
305305
atol: float = 1e-03,
@@ -316,16 +316,14 @@ def __init__(
316316
compile_spec = common.get_tosa_compile_spec(
317317
tosa_profiles[tosa_version], custom_path=custom_path
318318
)
319-
if symmetric_io_quantization or per_channel_quantization:
320-
quantizer = TOSAQuantizer(tosa_profiles[tosa_version])
321-
quantization_config = get_symmetric_quantization_config(
322-
is_per_channel=per_channel_quantization
323-
)
324-
if symmetric_io_quantization:
325-
quantizer.set_io(quantization_config)
326-
quant_stage = Quantize(quantizer, quantization_config)
327-
else:
328-
quant_stage = None
319+
320+
quantizer = TOSAQuantizer(tosa_profiles[tosa_version])
321+
quantization_config = get_symmetric_quantization_config(
322+
is_per_channel=per_channel_quantization
323+
)
324+
if symmetric_io_quantization:
325+
quantizer.set_io(quantization_config)
326+
quant_stage = Quantize(quantizer, quantization_config)
329327

330328
super().__init__(
331329
module,
@@ -474,24 +472,21 @@ def __init__(
474472
exir_ops: Optional[str | List[str]] = None,
475473
run_on_fvp: bool = True,
476474
symmetric_io_quantization: bool = False,
477-
per_channel_quantization: bool = False,
475+
per_channel_quantization: bool = True,
478476
use_to_edge_transform_and_lower: bool = True,
479477
custom_path: str = None,
480478
atol: float = 1e-03,
481479
rtol: float = 1e-03,
482480
qtol: int = 1,
483481
):
484482
compile_spec = common.get_u55_compile_spec(custom_path=custom_path)
485-
if symmetric_io_quantization or per_channel_quantization:
486-
quantizer = EthosUQuantizer(compile_spec)
487-
quantization_config = get_symmetric_quantization_config(
488-
is_per_channel=per_channel_quantization
489-
)
490-
if symmetric_io_quantization:
491-
quantizer.set_io(quantization_config)
492-
quant_stage = Quantize(quantizer, quantization_config)
493-
else:
494-
quant_stage = None
483+
quantizer = EthosUQuantizer(compile_spec)
484+
quantization_config = get_symmetric_quantization_config(
485+
is_per_channel=per_channel_quantization
486+
)
487+
if symmetric_io_quantization:
488+
quantizer.set_io(quantization_config)
489+
quant_stage = Quantize(quantizer, quantization_config)
495490

496491
super().__init__(
497492
module,
@@ -564,24 +559,21 @@ def __init__(
564559
exir_ops: str | List[str] = None,
565560
run_on_fvp: bool = True,
566561
symmetric_io_quantization: bool = False,
567-
per_channel_quantization: bool = False,
562+
per_channel_quantization: bool = True,
568563
use_to_edge_transform_and_lower: bool = True,
569564
custom_path: str = None,
570565
atol: float = 1e-03,
571566
rtol: float = 1e-03,
572567
qtol: int = 1,
573568
):
574569
compile_spec = common.get_u85_compile_spec(custom_path=custom_path)
575-
if symmetric_io_quantization or per_channel_quantization:
576-
quantizer = EthosUQuantizer(compile_spec)
577-
quantization_config = get_symmetric_quantization_config(
578-
is_per_channel=per_channel_quantization
579-
)
580-
if symmetric_io_quantization:
581-
quantizer.set_io(quantization_config)
582-
quant_stage = Quantize(quantizer, quantization_config)
583-
else:
584-
quant_stage = None
570+
quantizer = EthosUQuantizer(compile_spec)
571+
quantization_config = get_symmetric_quantization_config(
572+
is_per_channel=per_channel_quantization
573+
)
574+
if symmetric_io_quantization:
575+
quantizer.set_io(quantization_config)
576+
quant_stage = Quantize(quantizer, quantization_config)
585577

586578
super().__init__(
587579
module,

examples/arm/aot_arm_compiler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ def quantize(
160160
else:
161161
raise RuntimeError("Unsupported compilespecs for quantization!")
162162

163-
# if we set is_per_channel to True, we also need to add out_variant of quantize_per_channel/dequantize_per_channel
164-
operator_config = get_symmetric_quantization_config(is_per_channel=False)
163+
operator_config = get_symmetric_quantization_config()
165164
quantizer.set_global(operator_config)
166165
m = prepare_pt2e(model, quantizer)
167166

examples/arm/ethos_u_minimal_example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"\n",
102102
"# Create and configure quantizer to use a symmetric quantization config globally on all nodes\n",
103103
"quantizer = EthosUQuantizer(compile_spec)\n",
104-
"operator_config = get_symmetric_quantization_config(is_per_channel=False)\n",
104+
"operator_config = get_symmetric_quantization_config(is_per_channel=True)\n",
105105
"quantizer.set_global(operator_config)\n",
106106
"\n",
107107
"# Post training quantization\n",

0 commit comments

Comments
 (0)