Skip to content
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

Feat (mx): unpadding during dequantization #1134

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

Giuseppe5
Copy link
Collaborator

@Giuseppe5 Giuseppe5 commented Dec 18, 2024

Reason for this PR

Groupwise quantization requires padding when the input channel shape is not divisible by groupsize.

Padding works well until it doesn't, and there are important edge cases that were not covered by the previous implementation.
(e.g., weight only quantization where padding was required. Until now, we also had to force activation quantization because otherwise we had shape mismatch).

Changes Made in this PR

With the current implementation, we un-pad when dequantizing, taking care of all the edge cases

Few todos:

  • Consolidate dequantization for groupwise tensors + inference export
  • Fix typing in runtime activations
  • Testing

Testing Summary

Risk Highlight

  • This PR includes code from another work (please detail).
  • This PR contains API-breaking changes.
  • This PR depends on work in another PR (please provide links/details).
  • This PR introduces new dependencies (please detail).
  • There are coverage gaps not covered by tests.
  • Documentation updates required in subsequent PR.

Checklist

  • Code comments added to any hard-to-understand areas, if applicable.
  • Changes generate no new warnings.
  • Updated any relevant tests, if applicable.
  • No conflicts with destination dev branch.
  • I reviewed my own code changes.
  • Initial CI/CD passing.
  • 1+ reviews given, and any review issues addressed and approved.
  • Post-review full CI/CD passing.

@@ -28,6 +28,7 @@ def apply_input_view(self, x):
return x.flatten(start_dim, start_dim + 1)

def create_quant_tensor(self, qt_args: Tuple[Any]) -> GroupwiseFloatQuantTensor:
shape = self.tracked_parameter_list[0].shape
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support weight quant sharing for groupwise anyway, so this is safe, but it is ugly.

new_zp = self.zero_point_

return new_value, new_scale, new_zp
from brevitas.utils.quant_utils import groupwise_dequant
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ugly, maybe the function should live somewhere else?

@Giuseppe5 Giuseppe5 requested a review from nickfraser December 19, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant