-
Notifications
You must be signed in to change notification settings - Fork 18
[Bugfix] Fix Per-Token Dynamic Activation Quantization #393
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
base: main
Are you sure you want to change the base?
Conversation
Hi @max410011 , appreciate the thorough detail in the issue! I tried your PR, and both original main and your branch seem to work, the resultant models can be loaded up and run in |
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.
i validated that this gives the shape described in #394 , and after internal conversations this is correct. This is only an issue when running outside of vllm
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.
Could you add a test to demonstrate and verify that these changes are correct? Awesome catch and resolution, thanks!
@@ -167,7 +167,7 @@ def compute_dynamic_scales_and_zp( | |||
|
|||
keep_dims = True | |||
if args.strategy == QuantizationStrategy.TOKEN: | |||
dim = {1, 2} | |||
dim = {0, 1} |
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.
Shouldn't this be generalized to reflect all dims except the last? There are cases where activations are passed with 4 or 5 dimensions, not just 3
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.
As far as I know, the input/output to a linear layer in typical LLMs usually has the shape (bs, seq_len, hidden_dim).
Other activation shapes, such as (bs, num_heads, seq_len, head_dim), generally appear in the attention computation (e.g., Q @ K^T, attention_weights @ V). If we intend for this function to support quantization in those parts as well, then yes, it makes sense to generalize it accordingly.
Summary
This PR fixes the activation quantization issue described in Issue #394, where the input scale shape was incorrect when using the Dynamic TOKEN strategy.
Fix
(batch_size, seq_len, 1)
instead of(1, seq_len, hidden_dim)
.