Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the norm not equal to 2 in find_params? #6

Closed
vinsis opened this issue Oct 19, 2023 · 3 comments
Closed

Why is the norm not equal to 2 in find_params? #6

vinsis opened this issue Oct 19, 2023 · 3 comments

Comments

@vinsis
Copy link

vinsis commented Oct 19, 2023

Thank you for this work!

The default value of the variable self.norm is 2.4 (used here). Why is that the case? More generally, what is the purpose of grid search over the values described by maxshrink and grid? I could not find anything related to it in the paper.

@efrantar
Copy link
Member

Hi, this part of the code and its hyper-parameters are mostly adapted from BRECQ. The purpose of this is to find a narrower quantization grid (relative to the min-max which includes all outliers) by minimizing the p-norm. Setting norm = 2.4 gives slightly more weight to outliers in this search than for norm = 2.

@vinsis
Copy link
Author

vinsis commented Oct 25, 2023

Ok thank you. Another question - where exactly is the quantization happening?

  • The quantize function is simply a chain of affine tranform, clamping and reverse affine transform. It does not reduce the number of bits to store the weights.
  • The bits variable is simply used to calculate maxq which is used to calculate the scale.

I am unable to find where a fp32 value is stored in a bits number of bits.

@vinsis
Copy link
Author

vinsis commented Oct 25, 2023

I guess you could add an extra line in the quantize function like so:

def quantize(x, scale, zero, maxq):
    q = torch.clamp(torch.round(x / scale) + zero, 0, maxq)
    q = convert_q_to_nbits(q, bits)
    return scale * (q - zero)

But I get why you didn't do it. Closing the issue now.

@vinsis vinsis closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants