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 general fake_quantize_affine op #492

Merged
merged 1 commit into from
Jul 11, 2024
Merged

Conversation

andrewor14
Copy link
Contributor

Summary: Add a general fake_quantize_affine op that simulates quantize_affine + dequantize_affine but without casting the intermediate quantized values to lower bit-widths, intended for quantization-aware training (QAT).

Test Plan:
python test/quantization/test_quant_primitives.py -k test_fake_quantize_affine

Copy link

pytorch-bot bot commented Jul 9, 2024

🔗 Helpful Links

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

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:

✅ No Failures

As of commit 9c60424 with merge base 12ac498 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@andrewor14 andrewor14 requested a review from jerryzh168 July 9, 2024 20:57
@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 Jul 9, 2024
@@ -335,6 +378,62 @@ def _dequantize_affine(

return dequant.view(original_shape).to(output_dtype)


def _fake_quantize_affine(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a top level quant primitive I think

Summary: Add a general `fake_quantize_affine` op that simulates
`quantize_affine` + `dequantize_affine` but without casting the
intermediate quantized values to lower bit-widths, intended for
quantization-aware training (QAT).

Test Plan:
python test/quantization/test_quant_primitives.py -k test_fake_quantize_affine
@andrewor14 andrewor14 force-pushed the fake_quantize_affine branch from 3ae3a6a to 9c60424 Compare July 11, 2024 14:47
@andrewor14 andrewor14 merged commit 2ed010a into main Jul 11, 2024
13 checks passed
dbyoung18 pushed a commit to dbyoung18/ao that referenced this pull request Jul 31, 2024
Summary: Add a general `fake_quantize_affine` op that simulates
`quantize_affine` + `dequantize_affine` but without casting the
intermediate quantized values to lower bit-widths, intended for
quantization-aware training (QAT).

Test Plan:
python test/quantization/test_quant_primitives.py -k test_fake_quantize_affine
yanbing-j pushed a commit to yanbing-j/ao that referenced this pull request Dec 9, 2024
Fixes FP16 + BF16 issue in aoti runner.

```
torchchat % ./cmake-out/aoti_run ./model_bf16.so -z ./.model-artifacts/meta-llama/Llama-2-7b-chat-hf/tokenizer.bin -t 0 -i "Once upon a time"
Failed to load ./.model-artifacts/meta-llama/Llama-2-7b-chat-hf/tokenizer.bin into a Tiktoken tokenizer. Trying sentencepiece tokenizer..
Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, red ball in the sky. It was the sun! She thought it was so pretty.
Lily wanted to play with the ball, but it was too high up in the sky. She tried to jump and reach it, but she couldn't. Then, she had an idea. She would use a stick to get the ball down.
Lily found a long stick and tried to reach the ball. She poked and poked, but the ball didn't come down. She was sad. But then, she saw a bird flying by. The bird had a big, red ball in its beak! Lily was so happy! She thanked the bird and played with her new ball all day long.
achieved tok/s: 65.842124
```
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