File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
backends/qualcomm/quantizer Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 9
9
import torch
10
10
11
11
from torch ._ops import OpOverload
12
+ from torch ._subclasses import FakeTensor
12
13
13
14
from torch .ao .quantization .quantizer import (
14
15
QuantizationAnnotation ,
@@ -41,6 +42,14 @@ def decorator(annotator: Callable):
41
42
42
43
return decorator
43
44
45
+ def _is_input_non_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 "val" not in node .meta or not isinstance (node .meta ["val" ], FakeTensor ):
50
+ return True
51
+ return node .meta ["val" ].dtype != torch .float32
52
+
44
53
45
54
def _is_annotated (nodes : List [Node ]):
46
55
"""
@@ -123,11 +132,11 @@ def annotate_binary(node: Node, quantization_config: QuantizationConfig) -> None
123
132
124
133
input_qspec_map = {}
125
134
input_act0 = node .args [0 ]
126
- if isinstance (input_act0 , Node ):
135
+ if isinstance (input_act0 , Node ) and not _is_input_non_float_tensor ( input_act0 ) :
127
136
input_qspec_map [input_act0 ] = input_act_qspec
128
137
129
138
input_act1 = node .args [1 ]
130
- if isinstance (input_act1 , Node ):
139
+ if isinstance (input_act1 , Node ) and not _is_input_non_float_tensor ( input_act1 ) :
131
140
input_qspec_map [input_act1 ] = input_act_qspec
132
141
133
142
node .meta [QUANT_ANNOTATION_KEY ] = QuantizationAnnotation (
You can’t perform that action at this time.
0 commit comments