Support dynamic activation quant for per-channel quantized matmul#7867
Merged
Support dynamic activation quant for per-channel quantized matmul#7867
Conversation
1783e1f to
b05276a
Compare
b05276a to
ec98e8e
Compare
Collaborator
|
sorry I might not have time for this one today, will try to look into it tmr |
JackCaoG
reviewed
Aug 20, 2024
| x, w, (([-1], [-1]), ()), preferred_element_type=torch.int32) | ||
| else: | ||
| out = F.linear(x, w) | ||
| out = out * scaler |
Collaborator
There was a problem hiding this comment.
so the output dtype will be int32?
Collaborator
Author
There was a problem hiding this comment.
yes
Matmul between x_int and w_int with int32 output dtype to avoid overflow matmul(x_int, w_int) -> matmul_out: int32[bs, seq, out_dim]`
Collaborator
Author
There was a problem hiding this comment.
The final output will be in bf16, since there will be scaler multiplying the int32 result
JackCaoG
approved these changes
Aug 20, 2024
Collaborator
JackCaoG
left a comment
There was a problem hiding this comment.
lgtm, do you need to run TPU CI on this pr?
Collaborator
Author
Right now it's not in TPU CI, the err threshold need to be adjusted to pass on TPU. I can do that in following PR. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Need #7863 to land first
For dynamic activation quant. the quantized mamtul will be:
The weight is quantized from
w: bf16[out_dim, in_dim]tow_int: int8[out_dim, in_dim]andw_scale: bf16[out_dim]xwith shapebf16[bs, seq, in_dim]tox_int: int8[bs, seq, in_dim]andx_scale: bf16[bs,seq]x_intandw_intwithint32output dtype to avoid overflow `matmul(x_int, w_int) -> matmul_out: int32[bs, seq, out_dim]w_scalerandx_scaler: `final_out = matmul_out * w_scale * x_scaleTest
Added unit tests