Skip to content

Commit 8fe536a

Browse files
committed
use per op quantization check
1 parent dfd1a39 commit 8fe536a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

utensor_cgen/backend/utensor/_graph_lower/_op_lower.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from copy import deepcopy
2+
from itertools import chain
23

34
from utensor_cgen.backend.base import BackendPart
45
from utensor_cgen.logger import logger
@@ -49,23 +50,27 @@ class CheckQuantization(object):
4950

5051
@classmethod
5152
def apply(cls, ugraph):
52-
if cls._check_quantized(ugraph):
53-
for op_info in ugraph.get_ops_by_type('DepthwiseSeparableConvOperator'):
53+
for op_info in ugraph.get_ops_by_type('DepthwiseSeparableConvOperator'):
54+
if cls._check_quantized(op_info):
5455
op_info.op_type = 'QuantizedDepthwiseSeparableConvOperator'
55-
for op_info in ugraph.get_ops_by_type('FullyConnectedOperator'):
56+
for op_info in ugraph.get_ops_by_type('FullyConnectedOperator'):
57+
if cls._check_quantized(op_info):
5658
op_info.op_type = 'QuantizedFullyConnectedOperator'
5759
for op_info in ugraph.get_ops_by_type('DequantizeOperator'):
5860
op_info.code_gen_attributes['namespaces'] = ('TFLM',)
5961
for op_info in ugraph.get_ops_by_type('QuantizeOperator'):
6062
op_info.code_gen_attributes['namespaces'] = ('TFLM',)
6163

6264
@classmethod
63-
def _check_quantized(cls, ugraph):
64-
for op_info in ugraph.ops_info.values():
65-
for tensor_info in op_info.output_tensors:
66-
# FIXME: better way to check quantization
67-
if 'quantization_zeros' in tensor_info.attributes:
68-
return True
65+
def _check_quantized(cls, op_info):
66+
for tensor_info in chain(
67+
op_info.output_tensors,
68+
op_info.input_tensors
69+
):
70+
# FIXME: better way to check quantization
71+
if 'quantization_zeros' in tensor_info.attributes:
72+
return True
73+
return False
6974

7075
@classmethod
7176
def add_name_map(cls, generic_name, target_specific_name):

0 commit comments

Comments
 (0)