6 分钟阅读
算法
8-bit 与float转换
threshold
per-axis 与 per-tensor
算法
8-bit 与float转换
[real_value = (int8_value - zero_point)\times scale]
简写为:$ r = S(q-Z) $
int8_value的weight范围是[-127, 127],zero_point为0;activations/inputs范围是[-128, 127],zero_point范围是[-128, 127]
threshold
threshold理解为某个tensor的元素最大值,则:
[Y = F(X) \text{(float运算)} => y = f(x) \text{(int8运算)}]
其中 $ x = X \times \frac{128}{threshold_x}, Y = y \times \frac{threshold_y}{128} $
per-axis 与 per-tensor
per-axis,表示某个维度每一片都有一个scale和zero_point,比如per-channel表示每个channel都有一个scale和zero_point
per-tensor,表示整个tensor用一个scale和zero_point