Quantize weights to 4-bit groups while keeping salient columns in float
Why it matters Keeping a small set of activation-salient channels in higher precision is a recurring trick in 4-bit LLM weight quantization.
A few input channels carry very large activations, and the weight columns that multiply them matter most. One practical recipe keeps those columns in full precision and quantizes everything else to 4-bit in groups.
Write quantize_keep_salient(W, act_scale, n_keep, group). W is (out, in). act_scale (in,) is the typical activation magnitude of each input channel. Keep the n_keep input columns with the largest act_scale (ties to the lower index) unchanged. Take the remaining columns in their original order, split them into consecutive groups of group columns (the last group may be smaller), and for every (row, group) apply asymmetric 4-bit quantization: lo = min, hi = max, scale = (hi - lo) / 15, zero = round(-lo / scale), q = clip(round(w / scale) + zero, 0, 15), w_hat = (q - zero) * scale. If hi == lo, w_hat = w exactly. Return (W_hat with the same shape as W, sorted list of kept columns).
def quantize_keep_salient(W, act_scale, n_keep, group)Example
W [[0.1, 5.0, 0.2, 0.3]], act_scale [1, 9, 1, 1], n_keep 1, group 3 gives W_hat [[0.1067, 5.0, 0.2, 0.2933]] (rounded to 4 places) with kept [1]: the salient column is exact and the other three land on a 4-bit grid.
Understand the idea
Imagine pricing items in a shop with only 16 price tags per shelf. Most shelves hold items of similar price, so 16 tags are enough. One shelf has a single luxury item worth far more; forcing it onto the same 16 tags would ruin every price on that shelf. Better to give the luxury item its own exact tag. In LLM layers, a few input channels see huge activations, so small weight errors in those columns get multiplied a lot. Worked example: act_scale [1, 9, 1, 1] makes column 1 salient. The other three weights 0.1, 0.2, 0.3 share one group: scale = 0.2 / 15, and each value lands close to a grid point. Rule: keep top-k columns by act_scale, quantize the rest per (row, group) with scale = (max - min) / 15. The kept columns cost a little extra memory but protect accuracy.
Shapes and data flow
W (out, in) -> keep k columns, rest (out, in - k) -> groups (out, group) each with scale, zero (out, 1)