Skip to content

Add module swap quantization API from Quanty #1886

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

Merged
merged 1 commit into from
Mar 14, 2025
Merged

Conversation

andrewor14
Copy link
Contributor

Summary: This commit adds a module-swap-based PTQ API from Quanty, including:

  • Quantized linear and embedding modules
  • IntQuantizer to specify how to quantize weights and activations
  • CodeBookQuantizer as an alternative to IntQuantizer
  • Implementation of K-means to be used for codebook quantization
  • Range setting and data getter utility

These new APIs will complement our existing quantize_ API, which is primarily used for tensor-subclass-based quantization today (though it can also support module swaps). All APIs introduced in this commit are under prototype and highly subject to change. In particular, we plan to delete quantize_module_swap and QuantizationRecipe, and instead integrate this flow with the quantize_ API by creating a new AOBaseConfig.

All code is migrated from Quanty and written by @TiRune.

Test Plan:
python test/quantization/module_swap/test_*

Copy link

pytorch-bot bot commented Mar 13, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure

As of commit 5001ba6 with merge base 8c81863 (image):

NEW FAILURE - The following job has failed:

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 Mar 13, 2025
@andrewor14 andrewor14 added the topic: new feature Use this tag if this PR adds a new feature label Mar 13, 2025
@andrewor14 andrewor14 force-pushed the module-swap-ptq branch 2 times, most recently from bf0a842 to 715d6cd Compare March 13, 2025 20:33
@@ -0,0 +1,56 @@
import copy
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO these tests should be in test/prototype/quantization/module_swap

@andrewor14 andrewor14 force-pushed the module-swap-ptq branch 4 times, most recently from 31bd9f1 to 38b1361 Compare March 14, 2025 15:35
Copy link
Contributor

@vkuzo vkuzo left a comment

Choose a reason for hiding this comment

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

a short README.md of prototype/module_swap_quantization would be nice as well

@andrewor14 andrewor14 force-pushed the module-swap-ptq branch 6 times, most recently from 2ed4d2d to 16022cf Compare March 14, 2025 18:12
**Summary:** This commit adds a module-swap-based PTQ API from
Quanty, including:

- Quantized linear and embedding modules
- `IntQuantizer` to specify how to quantize weights and activations
- `CodeBookQuantizer` as an alternative to IntQuantizer
- Implementation of K-means to be used for codebook quantization
- Range setting and data getter utility

These new APIs will complement our existing `quantize_` API,
which is primarily used for tensor-subclass-based quantization
today (though it can also support module swaps). All APIs
introduced in this commit are under prototype and highly subject
to change. In particular, we plan to delete `quantize_module_swap`
and `QuantizationRecipe`, and instead integrate this flow with
the `quantize_` API by creating a new `AOBaseConfig`.

All code is migrated from Quanty and written by @TiRune.

**Test Plan:**
python test/quantization/module_swap/test_*
@andrewor14
Copy link
Contributor Author

Thanks, added the README. Merging this!

@andrewor14 andrewor14 merged commit 8c8388d into main Mar 14, 2025
17 of 18 checks passed
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. topic: new feature Use this tag if this PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants