Basis Lab

Answers · Putting a model into service

Why does one outlier weight wreck 4-bit quantization for the whole layer?

In shortA single huge value sets the rounding step for the whole layer, so ordinary weights fall below one step and round to zero.

The scale is set by the largest magnitude in the group, not by the average. In signed 4-bit quantisation one weight of magnitude 112 forces a step of 16, so an ordinary weight of 0.9 sits at 0.056 of a step and rounds to zero.

s=max⁡∣w∣7,q(w)=round⁡ ⁣(ws)ss = \frac{\max |w|}{7}, \qquad q(w) = \operatorname{round}\!\left(\frac{w}{s}\right) s

Take a layer whose weights are mostly around 0.9, with one weight at 112. The largest magnitude is 112, so s=112/7=16s=112/7=16. For w=0.9w=0.9, w/s=0.05625w/s=0.05625, which rounds to 0, so the output is 0 and the error is 0.9. For w=3.4w=3.4, w/s=0.2125w/s=0.2125, which also rounds to 0, so the error is 3.4. Now hold the outlier aside. The largest remaining magnitude is 3.4, so s=3.4/7=0.485714s=3.4/7=0.485714. The same 0.9 gives 0.9/0.485714=1.8520.9/0.485714=1.852, which rounds to 2, so the output is 2×0.485714=0.9714292\times0.485714=0.971429 and the error is 0.971429−0.9=0.0714290.971429-0.9=0.071429. The same 3.4 gives exactly 7 steps and is represented exactly. The step has fallen by a factor of 16/0.485714=32.916/0.485714=32.9, and the typical weight's error has fallen from 0.9 to 0.071429, a factor of 0.9/0.071429=12.60.9/0.071429=12.6.

The whole layer suffers because a per-tensor scale is shared. The outlier does not need to be large in error terms; it only needs to be large enough to set the step for every other weight. With four bits there are only 24=162^4=16 levels across the full range, so once the range is stretched to cover 112 the bins between levels are wider than most of the weights that need representing.

The natural guess fails

The natural guess is that weights vote on the range, so one unusual value is outvoted by millions of ordinary ones. Quantisation does not average. It takes an extreme, usually the maximum absolute value, and sets the step from it. That is why one outlier can dominate a tensor: it is the only value that defines the edge of the range.

Where the real outlier often sits

The same arithmetic applies to any group of numbers that share a scale, but in large transformers the extreme values that actually wreck a layer are usually in the activations, not in the stored weights. A small number of channels carry values one or two orders of magnitude above the rest for every input. If you choose the activation scale from the maximum, that one channel stretches the range and the ordinary channels lose resolution.

That matters because a weight that looks ordinary can be important through what it multiplies. Suppose a weight of 0.9 is multiplied by an activation of 112. Its product is 0.9×112=100.80.9\times112=100.8; the same weight multiplied by a typical activation of 0.9 gives 0.9×0.9=0.810.9\times0.9=0.81. An error in that weight is multiplied by 112, not by 0.9, so a sensitivity sweep that looks only at stored weights will rank it as harmless.

What changes the answer

The failure is not a property of 4-bit arithmetic in the abstract; it is a property of sharing one scale. If you quantise per channel, an outlier damages its own channel and leaves the others alone. If you clip the top of the range, you trade a little saturation on the outlier for much finer steps everywhere else, which can be the better trade when the outlier is rare. If you hold the extreme channel aside and keep it at higher precision, the remaining range collapses and the ordinary weights quantise cleanly. The cost of that exception is the memory you give back, and it is usually small because the exception is a small fraction of the weights.

The practical consequence is that a uniform bit width is always wrong somewhere. The damage is not spread evenly across a model: rounding one part and leaving everything else exact shows some parts cost an order of magnitude more than others. The right question is not whether to use four bits, but which parts to keep precise. Measure one part at a time, rank by cost per per cent of weights, then measure the whole plan together, because individual costs do not simply add.

A single exception can be cheap and decisive. Keeping a small sensitive fraction at sixteen bits and the rest at four still gives most of the memory saving, while the first few per cent of exceptions recover most of the quality.

Worth keeping

  • In 4-bit quantisation a single magnitude of 112 forces a step of 16, which is larger than most weights in the layer.
  • The damage from rounding is not spread evenly, so the useful question is which parts to keep precise, not what bit width to use everywhere.
  • An extreme activation channel can make an ordinary weight important, so measuring weights alone can miss the cause.

Where this goes next

This question is one step of Making a Model Smaller, a course that works through its subject from the beginning. The page that teaches this part of it is Where the Precision Still Matters, and it reads the whole way through whether or not you have an account.

What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.

Read that pageThe whole course

Other questions people ask about this

  1. Why does the memory used by a model keep growing as the conversation gets longer?The model's weights do not grow. It keeps a cache of keys and values for every earlier token, so memory rises with conversation length and with how many conversations run at once.
  2. What do the scale and zero-point actually do in 4-bit quantization?The scale sets the spacing between the sixteen levels, and the zero-point slides the whole grid so it lines up with the weights you actually have.
  3. Why does quantization-aware training use fake quantization instead of just quantizing at the end?Fake quantisation lets training see the rounded weights in the forward pass while still updating the exact weights, so the model learns weights that survive rounding instead of being rounded only after training.
  4. Why doesn't pruning half the weights make the model twice as fast?Because the zeros stay in the matrix: they are still stored and still multiplied, so the model is the same size and the same speed as before.
  5. Why does the model return JSON wrapped in extra text when I asked for JSON?A request for JSON does not force the model to return only JSON, so you need to validate the reply and repair it once rather than assume it will parse.
  6. Why do the numbers look good while users keep complaining?Because the score measures a fixed set of cases with a fixed rule, and the users are living through behaviour that the set and the rule never covered.

Read alongside