-
Notifications
You must be signed in to change notification settings - Fork 312
Expose zero_point_domain as arguments #1401
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 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
50be736
export zero_point_domain as arguments
airMeng 1db5ee3
assert for combination of TensorCoreTiledLayout and integer zero points
airMeng 1dbf9aa
change the default zero_point_domain to None
airMeng 17b8bf1
maintain layout and zero_point_domain in a dict
airMeng e4a28a8
nit
airMeng f384133
fix key errors
airMeng 836d508
nit
airMeng 51a4505
add zero_point_domian arguments in documents
airMeng e4237e0
update documemts
airMeng 5496c4c
Apply automatic Ruff fixes
ruff 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
PlainLayout, | ||
SemiSparseLayout, | ||
TensorCoreTiledLayout, | ||
Int4CPULayout, | ||
UintxLayout, | ||
to_affine_quantized_floatx, | ||
to_affine_quantized_floatx_static, | ||
|
@@ -110,6 +111,18 @@ | |
"Int8DynActInt4WeightGPTQQuantizer", | ||
] | ||
|
||
# update according to the support matrix | ||
LAYOUT_TO_ZERO_POINT_DOMAIN = { | ||
TensorCoreTiledLayout: [ZeroPointDomain.FLOAT], | ||
MarlinSparseLayout: [ZeroPointDomain.INT], | ||
Int4CPULayout: [ZeroPointDomain.FLOAT] | ||
} | ||
|
||
LAYOUT_TO_PRESERVE_ZEROS = { | ||
TensorCoreTiledLayout: False, | ||
MarlinSparseLayout: True, | ||
Int4CPULayout: False | ||
} | ||
|
||
###### | ||
# TO BE DEPRECATED START | ||
|
@@ -630,7 +643,8 @@ def int8_dynamic_activation_int4_weight( | |
|
||
|
||
def int4_weight_only( | ||
group_size=128, layout=TensorCoreTiledLayout(inner_k_tiles=8), use_hqq=False | ||
group_size=128, layout=TensorCoreTiledLayout(inner_k_tiles=8), use_hqq=False, | ||
zero_point_domain=None | ||
): | ||
""" | ||
Applies uint4 weight-only asymmetric per-group quantization to linear layers, using | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please update docs for zero_point_domain before landing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update in 51a4505 |
||
|
@@ -665,17 +679,22 @@ def apply_int4_weight_only_quant(weight): | |
quant_min = 0 | ||
quant_max = 15 | ||
eps = 1e-6 | ||
preserve_zero = False | ||
zero_point_dtype = torch.bfloat16 | ||
zero_point_domain = ZeroPointDomain.FLOAT | ||
|
||
nonlocal zero_point_domain | ||
assert type(layout) in LAYOUT_TO_ZERO_POINT_DOMAIN.keys(), f"Only support layout: {LAYOUT_TO_ZERO_POINT_DOMAIN.keys()}" | ||
if zero_point_domain is None: | ||
# the first value is the default one | ||
zero_point_domain = LAYOUT_TO_ZERO_POINT_DOMAIN[type(layout)][0] | ||
preserve_zero = LAYOUT_TO_PRESERVE_ZEROS[type(layout)] | ||
else: | ||
assert zero_point_domain in LAYOUT_TO_ZERO_POINT_DOMAIN[type(layout)], f"Layout only support {LAYOUT_TO_ZERO_POINT_DOMAIN[layout]}" | ||
|
||
# Sparse Marlin only supports symmetric quantization. | ||
# NOTE: If we start having lots of layouts that require different configurations, | ||
airMeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# we should consider moving this logic somewhere else. | ||
if isinstance(layout, MarlinSparseLayout): | ||
mapping_type = MappingType.SYMMETRIC | ||
preserve_zero = True | ||
zero_point_domain = ZeroPointDomain.INT | ||
assert ( | ||
group_size == 128 or group_size == weight.shape[-1] | ||
), f"MarlinSparseLayout only supports 128 group size or per channel quantization, got {group_size}" | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.