A new solution to GPTQ quantization algorithm

GPTQ quantizes each row in parallel, one weight () at a time; here the first two columns have already been quantized (shown in amber).


0. Introduction

The papers Optimal Brain Compression and GPTQ introduced a post-training quantization method that is one of the most popular quantization methods at the moment. The algorithm quantizes the rows of a matrix independently. In each row, a weight is quantized at a time and the remaining unquantized weights are modified to minimize the quantization error. The quantization error and the modified weights both have closed form solutions provided in the papers above. I have also provided a proof of these equations here.

Here I will provide a novel way to approach the problem and come up with a different solution. It has an expression that is easier to comprehend and make sense of geometrically. Finally I will show that the solution is equivalent to the one provided in the papers above.


1. Problem setup

Let be a vector of weights that needs to be quantized, and be a perturbation of weights. Here the first weight has been quantized already and we want to find out the perturbation for the remaining weights that minimizes the quantization error (which is the mean squared error).

where is:

We want to find how to modify the unquantized weights after the first weight has been quantized to minimize the error.


2. Solution

In the original proof, the already quantized weight is used as a constraint to form a Lagrangian. Here we will use a different approach. The first thing we do is break down the Hessian into its Cholesky decomposition: which immediately gives us (ignoring the constant 0.5):

Thus we simplified the problem to find which minimizes the squared norm of a sum of vectors. I wrote about this problem and its solution here. Thus the solution to our problem is given by:

In addition, we also get an insight into what the optimal weights do geometrically:

The optimal weights negate the projection of onto the column space of .

Next, let us express and in terms of and . Note that the i-th column of is i+1-th column of or the i+1-th row of . In other words:

Thus, is just the bottom right block of

M

The grey squares are the upper triangular matrix and the teal block is .

and the vector is:

Finally, note that

We re-write the final expression as:


3. Equivalence to the original solution

The original solution is given by:

Note that in this expression, the matrix blocks come from whereas in the expression above, the matrix blocks come from . To connect these two, we express in terms of using the Schur complement:

Substituting this into the expression above:

This proves the equivalence. The exact value of does not matter here since it will be canceled out (assuming it is non-zero) but for sake of completion, .


Related articles: