GPTQ › The Hessian and Its Role
Language AI HandbookAll chapters GPTQ › The Hessian and Its RoleOne section · Sections in this chapter3 / 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
The matrix is called the Hessian because it equals the second derivative of the reconstruction loss with respect to the weights. This naming shows a deep connection to optimization theory. The Hessian matrix characterizes the local curvature of the loss landscape, telling us how rapidly the loss changes as we move in different directions through weight space. High curvature in a particular direction means that small weight changes in that direction cause large changes in the loss; low curvature means the loss is relatively insensitive to perturbations in that direction.
Think of the Hessian as a topographic map of the loss landscape around the current weights. A standard map shows elevation as a function of position; the Hessian shows how steeply the loss rises in every direction from the current point. Directions with high curvature correspond to "steep valleys" where we must be precise. Directions with low curvature correspond to "flat plains" where we have freedom to move without much consequence. GPTQ uses this map to prioritize accuracy in the steep valleys while accepting more error on the flat plains.
To see why this matrix is second derivatives, consider the loss for a single output neuron. We want to find weights that make the neuron's output match what it would produce with the original weights:
where:
- : the weight vector being optimized
- : the -th input vector from the calibration set
- : the target output scalar, computed using the original weights applied to
- : the total number of calibration tokens
This is a standard least-squares objective. To find its minimum, we compute the gradient by differentiating with respect to each weight component:
where:
- : the gradient vector of the loss with respect to the weights
- : the prediction error for the -th calibration sample
- : the -th input vector, which scales how each prediction error affects each weight
Taking the derivative once more, we obtain the Hessian, which tells us how the gradient itself changes as we modify the weights:
where:
- : the Hessian matrix (second-order derivative of the loss)
- : the matrix of all second partial derivatives
- : the outer product of each input with itself, a matrix
- : the matrix of all calibration inputs stacked as columns
The Hessian captures the curvature of the loss landscape around the current weights. Each element of this matrix has a specific interpretation. The diagonal elements indicate how sensitive the loss is to changes in weight : a large value means that small perturbations to this weight cause large changes in the output, making this weight "important" in the sense that we must quantize it carefully. The off-diagonal elements capture interactions between weights: they tell us how changes in one weight affect the optimal value of another. When two weights have a large off-diagonal element, their quantization errors are not independent, and an error in one can be partially offset by adjusting the other.
The Hessian is simply a scaled version of the unnormalized sample covariance matrix of the layer's inputs. We don't need access to labels or backpropagation to compute it. We just need to observe what inputs flow through the layer during a forward pass on calibration data. This means computing the Hessian is cheap: a single forward pass suffices. The fact that a second-order quantity, which normally requires expensive Hessian-vector products, can be computed from raw activations is what makes GPTQ practical at scale.
The key insight here is that the Hessian tells us which weights are important and how their importance relates to the actual data distribution. A weight connected to an input feature that never activates has zero curvature; no amount of error there will hurt the model. A weight connected to a feature that activates strongly and frequently has high curvature; errors there propagate directly into output degradation. GPTQ uses these curvature measurements as a lens through which every quantization decision is filtered.
This observation has significant practical implications. Computing the Hessian requires only a forward pass through the network on calibration data. We never need to differentiate through the model or compute any target labels. The Hessian emerges naturally from the statistics of the inputs that the layer observes during normal operation. This makes GPTQ a true post-training quantization method: we take a pre-trained model, run it on some representative data, and use the resulting statistics to guide quantization. No fine-tuning, no gradient computation through the model, and no labeled data are required.