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

[WIP] Codebook quantization flow #1299

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

DerekLiu35
Copy link

This PR adds codebook quantization flow per #1195

Usage

import torch
from torchao.prototype.quantization.codebook.codebook_quantized_tensor import CodebookQuantizedTensor

input_tensor = torch.randn(1024, 1024,  device='cuda')

block_size = (1, 1)
code_dtype = torch.uint4

quantized_tensor = CodebookQuantizedTensor.from_float(input_tensor, block_size, code_dtype)

dequantized_tensor = quantized_tensor.dequantize()

ToDo

  • make fit_kmeans faster. Right now it takes >1 hour if you try to quantize a 1B model.

Copy link

pytorch-bot bot commented Nov 16, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1299

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2024
@jerryzh168
Copy link
Contributor

thanks for the contribution! yeah "> 1hour" seems a bit too slow, any ideas to speedup?

@jerryzh168
Copy link
Contributor

also after this is done, it would useful if you can add codebookquant to generate.py (

if quantization:
) and eval (
if quantization:
) to test the e2e model performance and accuracy

@DerekLiu35
Copy link
Author

thanks for the contribution! yeah "> 1hour" seems a bit too slow, any ideas to speedup?

I think

  • For block_size = (1, 1), It's similar to nf4tensor, so we can use absolute distance for scalars instead of euclidean distance
  • We could also decrease max_iter from 1000 to 200 for fit_kmeans but this would increase quantization error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants