Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compressed_tensors/quantization/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def compute_dynamic_scales_and_zp(

keep_dims = True
if args.strategy == QuantizationStrategy.TOKEN:
dim = {1, 2}
dim = {0, 1}
Copy link
Contributor

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

Copy link
Author

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.

reduce_dims = tuple(idx for idx in range(value.ndim) if idx not in dim)
elif args.strategy == QuantizationStrategy.TENSOR:
reduce_dims = None
Expand Down