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

Add codebook (look up table based) quantization flow in torchao #1195

Open
jerryzh168 opened this issue Oct 29, 2024 · 2 comments
Open

Add codebook (look up table based) quantization flow in torchao #1195

jerryzh168 opened this issue Oct 29, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@jerryzh168
Copy link
Contributor

Similar to affine quantization, we can implement codebook or look up table based quantization, which is another popular type of quantization, especially for lower bits like 4 bits or below (used in https://github.com/Vahe1994/AQLM, https://arxiv.org/abs/2402.04396 etc.). We can start with post training quantization and use k-means clustering to find the codebook / lookup table. You can check out #391 for the overall structure of torchao stack. Reference code for k-means can be found here.

After this we can also add more support for the advanced algorithms mentioned above.

API

quantize_(model, codebook_weight_only(dtype=torch.uint4))

Implementation details:

  • [PR1] Ops
    • quantize_codebook(tensor, codebook)
    • dequantize_codebook(tensor, codebook)
  • [PR2] Tensor Subclass
    • CodebookQuantizedTensor (similar to AffineQuantizedTensor)
      • clustering algorithm can be implemented in from_float function

Needs to flesh out the details of args etc. but can be done in the PR. I'd suggest to gradually add things and gather feedback.

Code Location: add a codebook folder under https://github.com/pytorch/ao/tree/main/torchao/prototype/quantization

@malinjawi
Copy link

Hey @jerryzh168 I am new to torchao but this sounds like an issue I would want to investigate with my partner @Harthi7. We will take a look and let you know how it goes. Cheers!

@DerekLiu35
Copy link

Hi, I am also new to torchao and I would like to do this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants