-
Notifications
You must be signed in to change notification settings - Fork 363
Add hqq support for Int4TilePackedTo4dTensor #2912
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
torchao/quantization/quantize_/workflows/int4/int4_choose_qparams_algorithm.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD 3-Clause license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| from enum import Enum | ||
|
|
||
|
|
||
| # can switch to StrEnum (https://docs.python.org/3/library/enum.html#enum.StrEnum) | ||
| # after python 3.10 is end of life (https://devguide.python.org/versions/) | ||
| class Int4ChooseQParamsAlgorithm(str, Enum): | ||
| """Variant of quantization algorithm to calculate scale and zero_point""" | ||
|
|
||
| """ | ||
| The choose qparams algorithm native for tinygemm kernel: | ||
| scale = (max_val - min_val) / float(quant_max - quant_min), where | ||
| max_val and min_val are the max/min for the slice of input Tensor based on block_size | ||
| quant_max and quant_min and max/min for the quantized value, e.g. 0, 15 for uint4 | ||
| zero_point = min_val + scale * mid_point, where | ||
| mid_point = (quant_max + quant_min + 1) / 2 | ||
|
|
||
| implemented in `torchao.quantization.quant_primitives._choose_qparams_affine_tinygemm | ||
| """ | ||
| TINYGEMM = "tinygemm" | ||
|
|
||
| """ | ||
| The choose qparams based on half-quadratic quantization: https://mobiusml.github.io/hqq_blog/ | ||
|
|
||
| implemented in `torchao.quantization.quant_primitives._choose_qparams_and_quantize_affine_hqq` | ||
| """ | ||
| HQQ = "hqq" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @mergennachin I added some more docs here, please let me know if this helps, only a subset of args will be used for each of the version right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation is good, but why not also do assertion?
If ignored field are present, don't you wanna throw an exception to the developer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, talked offline with @jerryzh168
The current approach seems fine. The increased complexity seems not worth it since we have to change the type to Optional.