Skip to content

Commit 3b56b58

Browse files
cccclaipytorchbot
authored andcommitted
Skip annotate boolean input (#2957)
Summary: Pull Request resolved: #2957 ghstack-source-id: 222200589 exported-using-ghexport It only makes sense to quantize fp tensor, but not boolean. Add a check to make sure only fp tensor are annotated in quantizer Reviewed By: jerryzh168 Differential Revision: D55946526 fbshipit-source-id: d94bfee38ab2d29fc9672ab631b4d5d0c5239d25 (cherry picked from commit ce344bc)
1 parent 16c3afc commit 3b56b58

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

backends/qualcomm/quantizer/utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import torch
1010

1111
from torch._ops import OpOverload
12+
from torch._subclasses import FakeTensor
1213

1314
from torch.ao.quantization.quantizer import (
1415
QuantizationAnnotation,
@@ -41,6 +42,18 @@ def decorator(annotator: Callable):
4142

4243
return decorator
4344

45+
def _is_input_float_tensor(node: Node):
46+
"""Check if the input is not a float tensor, so that we can skip quantization for the node
47+
since observers only works with float Tensors
48+
"""
49+
if (
50+
not isinstance(node, Node)
51+
or "val" not in node.meta
52+
or not isinstance(node.meta["val"], FakeTensor)
53+
):
54+
return False
55+
return node.meta["val"].dtype == torch.float32
56+
4457

4558
def _is_annotated(nodes: List[Node]):
4659
"""
@@ -123,11 +136,11 @@ def annotate_binary(node: Node, quantization_config: QuantizationConfig) -> None
123136

124137
input_qspec_map = {}
125138
input_act0 = node.args[0]
126-
if isinstance(input_act0, Node):
139+
if _is_input_float_tensor(input_act0):
127140
input_qspec_map[input_act0] = input_act_qspec
128141

129142
input_act1 = node.args[1]
130-
if isinstance(input_act1, Node):
143+
if _is_input_float_tensor(input_act1):
131144
input_qspec_map[input_act1] = input_act_qspec
132145

133146
node.meta[QUANT_ANNOTATION_KEY] = QuantizationAnnotation(

0 commit comments

Comments
 (0)