GPTQ › Optimal Brain Quantization
Language AI HandbookAll chapters GPTQ › Optimal Brain QuantizationOne section · Sections in this chapter4 / 17 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
GPTQ builds on a framework called Optimal Brain Quantization (OBQ), which itself descends from classical work on neural network pruning. The historical connection is illuminating: pruning and quantization are closely related problems. In pruning, we set certain weights exactly to zero. In quantization, we round weights to the nearest value in a discrete set. Both operations introduce error, and in both cases we want to minimize the impact on the network's output. The mathematics that describes the optimal pruning correction turns out to describe the optimal quantization correction as well.
The core insight of OBQ is that when you quantize one weight, you can compute the optimal adjustment to all remaining weights that minimizes the resulting increase in loss. This is not a heuristic or an approximation: given the quadratic structure of our loss function, there exists a closed-form formula for the best possible compensation. The formula emerges from setting the derivative of the loss (after fixing one weight to its quantized value) to zero with respect to the remaining weights and solving analytically.
Think of OBQ as a chess player who, after being forced to sacrifice a piece, immediately recalculates the optimal position for all remaining pieces. The sacrifice introduces a loss, but the player compensates by repositioning everything else to minimize the damage. In GPTQ, the "sacrifice" is the rounding error introduced when a weight is quantized, and the "repositioning" is the adjustment applied to all remaining weights.
Suppose we have decided to quantize weight to value . We want to adjust the remaining weights (where denotes the set of weights not yet quantized) to minimize the resulting loss. Taking the derivative of the loss with respect to and setting it to zero yields the optimal adjustment:
where:
- : the optimal adjustment vector for the remaining unquantized weights
- : the quantization error for the current weight , the difference between what we wanted and what we got after rounding
- : the diagonal element of the inverse Hessian corresponding to weight
- : the elements of the -th column of the inverse Hessian for all remaining weights
Let us unpack this formula carefully to build intuition for what each component contributes. The numerator is the quantization error for weight : simply the difference between what we wanted and what we got after rounding. Larger errors require larger compensations.
The denominator is the inverse curvature, measuring how flexible the loss landscape is with respect to weight . When this value is large, the curvature of the loss with respect to is small, meaning errors in this weight are relatively easy to absorb through small adjustments elsewhere. When this value is small, the curvature is high, meaning errors in this weight are costly and difficult to compensate.
The vector determines how this error should be distributed across remaining weights. It acts like a routing map: weights that are strongly correlated with through the inverse Hessian receive larger adjustments, because adjusting them has the greatest effect on undoing the damage caused by the rounding error in .
The resulting increase in loss from quantizing weight (after optimal compensation) is:
where:
- : the unavoidable increase in reconstruction error caused by quantizing weight
- : the squared quantization error (larger errors cost more)
- : the inverse curvature, representing the "stiffness" of weight ; smaller values mean more damage per unit of rounding error
This formula tells us exactly how much each quantization decision costs, accounting for optimal compensation. It has an elegant structure: cost is proportional to the squared rounding error and inversely proportional to the inverse curvature. Weights where is large can be quantized with relatively low cost even if the rounding error is substantial. Conversely, weights with small values are stiff: even small errors cause significant loss increases. This cost formula is exactly what OBQ uses to decide which weight to quantize next, always choosing the one with minimum .