You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""For ADD and SUB with int16 inputs, we rescale to int32 using a different common scale(2*max(left scale,right scale))
84
+
compared to all the other cases. We multiply the left and right scales by 1<<12 giving us extra precision
85
+
for the computation without overflowing.
86
+
87
+
Returns a list of the rescaled nodes and the scale factor used,
88
+
needed by insert_rescale_op_to_int16.
89
+
"""
90
+
91
+
iflen(inputs) >2:
92
+
raiseValueError("More than two inputs not supported")
93
+
94
+
tensors=inputs.copy()
95
+
# Reshape tensor according to TOSA dim order
96
+
fortensorintensors:
97
+
dim_order=tensor.dim_order
98
+
tensor.shape= [tensor.shape[i] foriindim_order]
99
+
100
+
input_qparams=get_input_qparams(node)
101
+
lhs_qparams, rhs_qparams=input_qparams.values()
102
+
lhs_scale=lhs_qparams.get_scale_per_tensor()
103
+
rhs_scale=rhs_qparams.get_scale_per_tensor()
104
+
# Common scale for the two numbers
105
+
max_scale_2x=2*max(lhs_scale, rhs_scale)
106
+
SHIFT_INT16=12
107
+
# We are adding two int16 numbers. If the zero point is non-null, the result will be in the range [-131070;131070], therefore we need 18 bits for the result.
108
+
# We have a 32-bit accumulator, so we can shift to the left by 12 bits and not overflow. In reality, because we divide by the 2*max(lhs_scale,rhs_scale)
0 commit comments