Split outlier features into a float matmul and the rest into int8
Why it matters Mixed int8 decomposition made 8-bit inference of large models accurate despite rare but huge activation outliers.
Some hidden dimensions carry activations much larger than the rest. Mixed-precision decomposition multiplies those few dimensions in float and everything else in int8, then adds the two results.
Write mixed_int8_matmul(X, W, threshold). X is (M, K), W is (K, N). Outlier dims are the columns j of X with max|X[:, j]| >= threshold. Compute Y_fp = X[:, O] @ W[O, :] in float. For the other dims R, quantize X[:, R] with a per-row absmax scale and W[R, :] with a per-column absmax scale (scale = max / 127, 0 becomes 1, q = clip(round(v / s), -127, 127)), multiply in integers and rescale. Return (Y_fp + Y_int8, sorted list of outlier dims). With no outliers the float part is zero; with no regular dims the int8 part is zero.
def mixed_int8_matmul(X, W, threshold)Example
X [[1, 100], [2, -50]], W [[1, 1], [0.5, 0]], threshold 6 gives Y [[51, 1], [-23, 2]] and outliers [1].
Understand the idea
Absmax int8 gives every row 255 evenly spaced levels between minus and plus its largest value. If one value in the row is 100 and the rest are around 1, the step size becomes 100 / 127, about 0.8, and all the small values collapse to 0 or 1. Mixed decomposition pulls the troublemakers out. Worked example: X column 1 holds 100 and -50, above threshold 6, so it is an outlier dim. Its float part is 100 x [0.5, 0] = [50, 0] for row 0. Column 0 alone is quantized: row 0 has scale 1 / 127, so 1 is exact and contributes [1, 1]. Total [51, 1]. Rule: Y = X[:, O] W[O] (float) + dequant(int8(X[:, R]) int8(W[R])). Usually fewer than one percent of dims are outliers, so almost all the work stays in int8.
Shapes and data flow
X (M, K) -> X[:, O] (M, |O|) and X[:, R] (M, |R|); W -> W[O] (|O|, N) and W[R] (|R|, N); both parts (M, N)