Does anyone know how to pass quantization parameters of a constant tensor to the tflite converter?
What triggered that question are the qnn tests in the tflite frontend and specifically ADD with constant. I see that TOCO somehow assumes that the constant has the same qnn parameters as the other tensor but that won’t be correct if they have different fp32 range
with tf.Graph().as_default():
in_data = [array_ops.placeholder(shape=data[0].shape, dtype='float32', name='in_0')]
if quantized:
inq_data = [tf.quantization.fake_quant_with_min_max_args(in_data[0], min=-100, max=100, name="inq_0")]
inq_const = tf.quantization.fake_quant_with_min_max_args(data[1], min=-100, max=100, name="const_tensor")
# the 2nd tensor is treated as constant and directly added as part of the operation
out = math_op(inq_data, ops.convert_to_tensor(inq_const, dtype='float32', name='inq_const'))
out = with_fused_activation_function(out, fused_activation_function)
out_min, out_max = _test_elemwise_qnn_out_range(qnn_op)
out = tf.quantization.fake_quant_with_min_max_args(out, min=out_min, max=out_max, name="out")
compare_tflite_with_tvm(data[0], ['inq_0:0'], inq_data, [out], quantized=True)
What I tried was to manually add the qnn params for the constant tensor in the input_stats like below but somehow the converter ignores them (probably given the name of the tensor).
input_stats = {'inq_0': (128., 1.275),
'const_tensor': (100., 1.0)}
Any ideas? @apivovarov @janimesh @FrozenGene