Skip to content

Commit 8edf7ab

Browse files
Arm backend: Fix shared qspec edge case (#11147)
Moving ops in the quantization annotator from _parent_shared_qspec to _one_to_one_shared_input_or_input_act_qspec makes sure they are properly annotated also when not preceeded by an annotated node. This removes the need for symmetric_io_quantization=True in the unittests for these ops. Signed-off-by: Adrian Lundell <[email protected]>
1 parent 00f2572 commit 8edf7ab

File tree

11 files changed

+13
-56
lines changed

11 files changed

+13
-56
lines changed

backends/arm/quantizer/quantization_annotator.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ def _match_pattern(
237237
torch.ops.aten.clamp.Tensor,
238238
]
239239

240-
# Operators that can inherit the quantization specs from its parent node
241-
# as SharedQuantizationSpec.
242-
_parent_shared_qspec = [
240+
_one_to_one_shared_input_or_input_act_qspec = [
241+
torch.ops.aten.clone.default,
243242
torch.ops.aten.hardtanh.default,
244243
torch.ops.aten.hardtanh_.default,
245244
torch.ops.aten.relu.default,
@@ -254,11 +253,6 @@ def _match_pattern(
254253
torch.ops.aten.flatten.using_ints,
255254
torch.ops.aten.dropout.default,
256255
torch.ops.aten.dropout_.default,
257-
torch.ops.aten.where,
258-
operator.getitem,
259-
]
260-
261-
_one_to_one_shared_input_or_input_act_qspec = [
262256
torch.ops.aten.adaptive_avg_pool2d.default,
263257
torch.ops.aten.alias_copy.default,
264258
]
@@ -404,6 +398,9 @@ def any_or_hardtanh_min_zero(n: Node):
404398
]
405399
quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type]
406400
elif node.target in _one_to_one_shared_input_or_input_act_qspec:
401+
if not isinstance(node.args[0], Node):
402+
return None
403+
407404
input_qspec = (
408405
SharedQuantizationSpec(node.args[0]) # type: ignore[arg-type]
409406
if is_output_annotated(node.args[0]) # type: ignore
@@ -458,19 +455,16 @@ def any_or_hardtanh_min_zero(n: Node):
458455
),
459456
]
460457
quant_properties.quant_output = None
461-
elif node.target in _parent_shared_qspec:
462-
if not isinstance(node.args[0], Node):
463-
return None
464-
465-
if not is_output_annotated(node.args[0]): # type: ignore[attr-defined]
458+
elif node.target in [torch.ops.aten.scalar_tensor.default]:
459+
quant_properties.quant_inputs = []
460+
quant_properties.quant_output = _QuantProperty(0, output_act_qspec)
461+
elif node.target in [operator.getitem]:
462+
if not is_output_annotated(node.args[0]): # type: ignore[attr-defined, arg-type]
466463
return None
467464

468-
shared_qspec = SharedQuantizationSpec(node.args[0])
465+
shared_qspec = SharedQuantizationSpec(node.args[0]) # type: ignore[arg-type]
469466
quant_properties.quant_inputs = [_QuantProperty(0, shared_qspec)] # type: ignore[arg-type]
470467
quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type]
471-
elif node.target in [torch.ops.aten.scalar_tensor.default]:
472-
quant_properties.quant_inputs = []
473-
quant_properties.quant_output = _QuantProperty(0, output_act_qspec)
474468
else:
475469
return None
476470

backends/arm/test/ops/test_avg_pool2d.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def test_avg_pool2d_tosa_BI(test_module):
9999
input_tensor,
100100
aten_op,
101101
exir_op,
102-
symmetric_io_quantization=True,
103102
run_on_tosa_ref_model=conftest.is_option_enabled("tosa_ref_model"),
104103
)
105104
if conftest.is_option_enabled("tosa_ref_model"):
@@ -118,7 +117,6 @@ def test_avg_pool2d_u55_BI(test_module):
118117
aten_op,
119118
exir_op,
120119
run_on_fvp=True,
121-
symmetric_io_quantization=True,
122120
)
123121
pipeline.change_args("run_method_and_compare_outputs", qtol=1, atol=1, rtol=1)
124122
pipeline.run()
@@ -135,7 +133,6 @@ def test_avg_pool2d_u85_BI(test_module):
135133
aten_op,
136134
exir_op,
137135
run_on_fvp=True,
138-
symmetric_io_quantization=True,
139136
)
140137
pipeline.change_args("run_method_and_compare_outputs", qtol=1, atol=1, rtol=1)
141138

@@ -164,7 +161,7 @@ def test_avg_pool2d_u85_BI(test_module):
164161

165162

166163
@common.parametrize("reject_module", reject_modules)
167-
def test_avg_pool2d_tosa_BI_not_delegated(reject_module):
164+
def test_avg_pool2d_u55_BI_not_delegated(reject_module):
168165

169166
model, test_data = reject_module()
170167

@@ -174,5 +171,6 @@ def test_avg_pool2d_tosa_BI_not_delegated(reject_module):
174171
non_delegated_ops={},
175172
n_expected_delegates=0,
176173
quantize=True,
174+
u55_subset=True,
177175
)
178176
pipeline.run()

backends/arm/test/ops/test_clamp.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def test_clamp_tosa_BI(test_data):
7777
(input_tensor,),
7878
aten_op,
7979
exir_op,
80-
symmetric_io_quantization=True,
8180
)
8281
pipeline.change_args("run_method_and_compare_outputs", qtol=1)
8382

@@ -97,7 +96,6 @@ def test_clamp_u55_BI(test_data):
9796
aten_op,
9897
exir_op,
9998
run_on_fvp=True,
100-
symmetric_io_quantization=True,
10199
)
102100

103101
pipeline.change_args("run_method_and_compare_outputs", qtol=1)
@@ -117,7 +115,6 @@ def test_clamp_u85_BI(test_data):
117115
aten_op,
118116
exir_op,
119117
run_on_fvp=True,
120-
symmetric_io_quantization=True,
121118
)
122119
pipeline.change_args("run_method_and_compare_outputs", qtol=1)
123120

backends/arm/test/ops/test_clone.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def test_clone_tosa_BI(test_data):
6565
test_data(),
6666
aten_op,
6767
exir_op,
68-
symmetric_io_quantization=True,
6968
)
7069
pipeline.run()
7170

@@ -82,7 +81,6 @@ def test_clone_u55_BI(test_data):
8281
aten_op,
8382
exir_op,
8483
run_on_fvp=True,
85-
symmetric_io_quantization=True,
8684
)
8785

8886
pipeline.run()
@@ -100,7 +98,6 @@ def test_clone_u85_BI(test_data):
10098
aten_op,
10199
exir_op,
102100
run_on_fvp=True,
103-
symmetric_io_quantization=True,
104101
)
105102

106103
pipeline.run()

backends/arm/test/ops/test_hardtanh.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_hardtanh_tosa_BI(test_data: torch.Tensor):
5858
(test_data(),),
5959
aten_op,
6060
exir_op,
61-
symmetric_io_quantization=True,
6261
)
6362
pipeline.run()
6463

@@ -72,7 +71,6 @@ def test_hardtanh_u55_BI(test_data: torch.Tensor):
7271
aten_op,
7372
exir_op,
7473
run_on_fvp=True,
75-
symmetric_io_quantization=True,
7674
)
7775
pipeline.run()
7876

@@ -86,6 +84,5 @@ def test_hardtanh_u85_BI(test_data: torch.Tensor):
8684
aten_op,
8785
exir_op,
8886
run_on_fvp=True,
89-
symmetric_io_quantization=True,
9087
)
9188
pipeline.run()

backends/arm/test/ops/test_max_pool.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def test_max_pool2d_tosa_BI(test_data: torch.Tensor):
7474
(test_data,),
7575
aten_op,
7676
exir_op,
77-
symmetric_io_quantization=True,
7877
)
7978
pipeline.run()
8079

@@ -88,7 +87,6 @@ def test_max_pool2d_u55_BI(test_data: torch.Tensor):
8887
(test_data,),
8988
aten_op,
9089
exir_ops=[],
91-
symmetric_io_quantization=True,
9290
run_on_fvp=True,
9391
).run()
9492

@@ -102,7 +100,6 @@ def test_max_pool2d_u85_BI(test_data: torch.Tensor):
102100
(test_data,),
103101
aten_op,
104102
exir_ops=[],
105-
symmetric_io_quantization=True,
106103
run_on_fvp=True,
107104
).run()
108105

@@ -127,7 +124,6 @@ def test_max_pool2d_tosa_BI_mult_batches(test_data: torch.Tensor):
127124
(test_data,),
128125
aten_op,
129126
exir_op,
130-
symmetric_io_quantization=True,
131127
)
132128
pipeline.run()
133129

@@ -145,7 +141,6 @@ def test_max_pool2d_u55_BI_mult_batches(test_data: torch.Tensor):
145141
aten_op,
146142
exir_ops=[],
147143
run_on_fvp=True,
148-
symmetric_io_quantization=True,
149144
use_to_edge_transform_and_lower=True,
150145
).run()
151146

@@ -160,7 +155,6 @@ def test_max_pool2d_u85_BI_mult_batches(test_data: torch.Tensor):
160155
aten_op,
161156
exir_op,
162157
run_on_fvp=True,
163-
symmetric_io_quantization=True,
164158
use_to_edge_transform_and_lower=True,
165159
).run()
166160

@@ -182,7 +176,6 @@ def test_max_pool2d_u55_BI_failure_set(test_data: Tuple):
182176
aten_op,
183177
exir_op,
184178
run_on_fvp=False,
185-
symmetric_io_quantization=True,
186179
use_to_edge_transform_and_lower=True,
187180
)
188181
pipeline.pop_stage("check_count.exir")

backends/arm/test/ops/test_permute.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def test_permute_tosa_BI(test_data: torch.Tensor):
6767
(test_data,),
6868
aten_op,
6969
exir_op,
70-
symmetric_io_quantization=True,
7170
)
7271
pipeline.run()
7372

@@ -88,7 +87,6 @@ def test_permute_u55_BI(test_data):
8887
aten_op,
8988
exir_ops="executorch_exir_dialects_edge__ops_aten_permute_copy_default",
9089
run_on_fvp=True,
91-
symmetric_io_quantization=True,
9290
)
9391
pipeline.run()
9492

@@ -104,6 +102,5 @@ def test_permute_u85_BI(test_data: torch.Tensor):
104102
aten_op,
105103
exir_ops="executorch_exir_dialects_edge__ops_aten_permute_copy_default",
106104
run_on_fvp=True,
107-
symmetric_io_quantization=True,
108105
)
109106
pipeline.run()

backends/arm/test/ops/test_reciprocal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_reciprocal_tosa_BI(test_data: torch.Tensor):
5858
(test_data(),),
5959
aten_op,
6060
exir_op=[],
61-
symmetric_io_quantization=True,
6261
)
6362
pipeline.run()
6463

@@ -72,7 +71,6 @@ def test_reciprocal_u55_BI(test_data: torch.Tensor):
7271
aten_op,
7372
exir_ops=[],
7473
run_on_fvp=False,
75-
symmetric_io_quantization=True,
7674
)
7775
pipeline.run()
7876

backends/arm/test/ops/test_relu.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def test_relu_tosa_BI(test_data: torch.Tensor):
6060
(test_data(),),
6161
aten_op,
6262
exir_op,
63-
symmetric_io_quantization=True,
6463
)
6564
pipeline.run()
6665

@@ -73,7 +72,6 @@ def test_relu_u55_BI(test_data: torch.Tensor):
7372
aten_op,
7473
exir_op,
7574
run_on_fvp=False,
76-
symmetric_io_quantization=True,
7775
)
7876
pipeline.run()
7977

@@ -86,6 +84,5 @@ def test_relu_u85_BI(test_data: torch.Tensor):
8684
aten_op,
8785
exir_op,
8886
run_on_fvp=False,
89-
symmetric_io_quantization=True,
9087
)
9188
pipeline.run()

backends/arm/test/ops/test_scalar_tensor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ def test_scalar_tensor_u55_BI(test_data):
8585
ScalarTensor(scalar, dtype),
8686
tuple(data),
8787
ScalarTensor.aten_op,
88-
symmetric_io_quantization=True,
8988
run_on_fvp=True,
9089
).run()
9190

@@ -98,6 +97,5 @@ def test_scalar_tensor_u85_BI(test_data):
9897
ScalarTensor(scalar, dtype),
9998
tuple(data),
10099
ScalarTensor.aten_op,
101-
symmetric_io_quantization=True,
102100
run_on_fvp=True,
103101
).run()

0 commit comments

Comments
 (0)