quantization -- fp16 → int4, group-wise

A model is billions of numbers, and how many bits each one is stored in decides whether it fits on your machine. Four bits is a quarter of sixteen, but each group also stores a scale and a zero-point, so at four bits the file is larger than that quarter. Four bits is only sixteen distinct values, so the numbers cannot be kept as they are. Instead a small group of neighbouring numbers — the model's weights — is taken, its smallest and largest noted, and each weight recorded as one of sixteen evenly spaced steps between them, along with the two extra numbers needed to undo that later. The rounding is the price, and it is worst when one freak large value stretches its group's range and coarsens every neighbour — which is why the groups are kept small, and why small groups give part of the saving back.

Interactive page: group-wise affine weight quantization -- how fp16 weights become low-bit integers (int4, even int3/int2) so a large model fits in a small amount of memory, and what error that costs. Anchor: G (quantization / deployment); Family G.

What it shows

Weights are chopped into groups of G. Per group:

s = (max − min) / (2^bits − 1) scale
z = round(−min / s) integer zero-point
q = clamp(round(x/s) + z, 0, 2^bits−1) the stored code
x′ = (q − z) · s dequantized value

z is an integer, so x′ = (q − z)·s is not the same reconstruction as min + s·q on a group where −min/s is not already an integer. The bars, the readout, and the level lines all use (q − z)·s.

The weights panel draws, per weight, the dequantized bar x′ with a black tick at the original x -- the gap between them is the quantization error. Faint horizontal lines mark each group's 2^bits reconstruction levels, (k − z)·s for every code k, so you can see the weights snapping onto them. Two knobs trade off:

Pick the outlier preset (or drag any weight to an extreme) and watch its group's scale stretch and every neighbour in that group get coarser -- exactly why small groups and outlier-aware methods (AWQ/GPTQ) exist.

Drag a weight ↕ to change it; sliders for bits and seed; selects for the weight distribution and group size; the group scan animates; hover a weight to see its x / q / x′ / err.

Render tier

T1 (Canvas2D: the weights bar panel with level lines + the RMSE-vs-bits curve).

Wiring

layout.mount + controls (preset, bits, G, seed) + animate (the group scan) + onPointer drag-the-weight + hover. ?preset / ?bits / ?G / ?seed / ?drag / ?hover hooks. Source: page.js.