IST-DASLab / gptq

Code for the ICLR 2023 paper "GPTQ: Accurate Post-training Quantization of Generative Pretrained Transformers".
https://arxiv.org/abs/2210.17323
Apache License 2.0
1.81k stars 145 forks source link

How to adopt GPTQ on Conv2d with `groups` attribute? #35

Open TMYuan opened 1 year ago

TMYuan commented 1 year ago

Hi,

Thanks for your impressive work! It really helps me quantize lots of large models. Recently, I try to implement GPTQ on grouped Conv2d layer, but the results seem to be not good. Could you provide some hints to support GPTQ on grouped Conv2d?

Here is my rough implementation now:

  1. In add_batch function, divide inp into different group and store hessian respectively.
  2. In fasterquant function, divide W into different group and apply GPTQ with chunk of W and corresponding hessian.
  3. Concat the different groups of Q to full Q.

Thank you in advance.

efrantar commented 1 year ago

Hi!

In general, your implementation sounds reasonable. One thing you can do for correctness verification is to check whether the squared errors reported by GPTQ (with very low dampening) match the actual squared error you measure on the quantized layer, using the same data.

However, one thing to note in general is that GPTQ is most effective if the Hessian is large as then there is a lot of room for error compensation when quantizing weights. For something like a 3x3 depthwise convolution, the Hessian is only 9x9 for each filter, hence GPTQ probably won't be very effective since there is only limited possibility for error compensation between weights. Perhaps this is also part of the problem you are seeing with groupwise convolutions. Fortunately, in practice, such layers are often quite small and it might thus make sense to just skip quantizing them (or quantize them to higher bitwidth).