Skip to content

Commit 7c92392

Browse files
Arm backend: Fix get_quant_properties return type
The function `get_quant_properties` can return `None`, which was not reflected in its return type annotation. This could cause type checker warnings or incorrect assumptions about its return value. Update the return type from `_OpQuantProperties` to `_OpQuantProperties | None` to correctly represent the possible outputs. Change-Id: I1f360ab1b9dcda119473f17a3eb46ffbaeba831c Signed-off-by: Sebastian Larsson <[email protected]>
1 parent ca6c501 commit 7c92392

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

backends/arm/quantizer/quantization_annotator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _match_pattern(
245245

246246
def get_quant_properties( # noqa: C901
247247
node: Node, gm: torch.fx.GraphModule, quantization_config
248-
) -> _OpQuantProperties:
248+
) -> _OpQuantProperties | None:
249249
input_act_qspec = quantization_config.get_input_act_qspec()
250250
weight_qspec = quantization_config.get_weight_qspec()
251251
output_act_qspec = quantization_config.get_output_act_qspec()
@@ -384,16 +384,16 @@ def any_or_hardtanh_min_zero(n: Node):
384384
quant_properties.quant_output = None
385385
elif node.target in _parent_shared_qspec:
386386
if not isinstance(node.args[0], Node):
387-
return None # type: ignore[return-value]
387+
return None
388388

389389
if not arm_quantizer_utils.is_output_annotated(node.args[0]): # type: ignore[attr-defined]
390-
return None # type: ignore[return-value]
390+
return None
391391

392392
shared_qspec = SharedQuantizationSpec(node.args[0])
393393
quant_properties.quant_inputs = [_QuantProperty(0, shared_qspec)] # type: ignore[arg-type]
394394
quant_properties.quant_output = _QuantProperty(0, shared_qspec) # type: ignore[arg-type]
395395
else:
396-
return None # type: ignore[return-value]
396+
return None
397397

398398
# Don't check if operator.getitem is ok for quantization, it's always ok
399399
if node.target == operator.getitem:
@@ -402,7 +402,7 @@ def any_or_hardtanh_min_zero(n: Node):
402402
# Check that each inputs/outputs can be quantized properly with the
403403
# provided quantization properties.
404404
if not _is_ok_for_quantization(node, quant_properties, gm):
405-
return None # type: ignore[return-value]
405+
return None
406406

407407
return quant_properties
408408

0 commit comments

Comments
 (0)