File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
ai_edge_quantizer/algorithms/uniform_quantize Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -416,12 +416,21 @@ def materialize_sum(
416
416
tensor_name_to_qsv : dict [str , Any ],
417
417
) -> list [qtyping .TensorTransformationParams ]:
418
418
"""Materialize tensors in tfl.sum."""
419
+ # For 8 bits the reference kernel calls a function without input/output
420
+ # constraints. For all others it calls a function that enforces input/output
421
+ # scale/zero point checks. See:
422
+ # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/kernels/reduce.cc#L909
423
+ activation_config = op_info .op_quant_config .activation_tensor_config
424
+ if activation_config is not None and activation_config .num_bits == 8 :
425
+ constraint = _OpQuantConstraint .NO_CONSTRAIN
426
+ else :
427
+ constraint = _OpQuantConstraint .SAME_AS_INPUT_SCALE
419
428
return common_utils .materialize_standard_op (
420
429
op_info ,
421
430
graph_info ,
422
431
tensor_name_to_qsv ,
423
432
get_tensor_quant_params_fn ,
424
- constraint = _OpQuantConstraint . SAME_AS_INPUT_SCALE ,
433
+ constraint = constraint ,
425
434
inputs_to_ignore = [1 ], # Axis index does not need to be quantized.
426
435
)
427
436
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ def test_materialize_sum_succeeds(
102
102
self ._op_test_info ,
103
103
common_quantize .materialize_sum ,
104
104
get_tensor_quant_params_func ,
105
- same_input_output_params = True ,
105
+ same_input_output_params = num_bits != 8 , # No constraint for 8 bits.
106
106
inputs_to_ignore = [1 ], # Ignore axis tensor.
107
107
)
108
108
You can’t perform that action at this time.
0 commit comments