[XNNPACK] resolve ambiguity around 2d affine quantized tensors#8958
Merged
facebook-github-bot merged 1 commit intopytorch:mainfrom Mar 15, 2025
Merged
[XNNPACK] resolve ambiguity around 2d affine quantized tensors#8958facebook-github-bot merged 1 commit intopytorch:mainfrom
facebook-github-bot merged 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/8958
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 89a248a with merge base 1011fdc ( BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
4febe74 to
0a6b599
Compare
jackzhxng
approved these changes
Mar 6, 2025
Contributor
jackzhxng
left a comment
There was a problem hiding this comment.
This is needed to resolve numerical inaccuracies introduced by switching to the quantize_ API here: #8772. Will leave to @digantdesai / @kimishpatel for final stamp
Contributor
|
@mcr229 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
GregoryComer
approved these changes
Mar 7, 2025
Summary: There is some ambiguity around deriving per_token and per_channel_group semantics from quantize affine. Specifically when rank is two. Take for example the following input shape with the following group size: - input_shape (5, 2048) - group_size (1, 2048) This tensor has 5 scales, and can be seen has having one scale per batch dimension. Or one scale per token. However, this can also be seen as a single weight in which each group is the size of a channel, effectively giving per_channel semantics. This ambiguity does not play well within the XNNPACK Backend as we are must parse these differing quantization types. For now we rely on the fact that per_token quantization happens dynamically. Meaning that the scales and zero points are dynamically choosen. As a result, we check that the scales come from getitem and is dynamically chosen. We further ensure that per_channel_group checks are not per_token. Test Plan: ``` python -m unittest backends.xnnpack.test.ops.test_linear.TestLinear.test_linear_qd8_f32_per_token_weight_per_channel_group_int4 ``` Reviewed By: GregoryComer Differential Revision: D70719546 Pulled By: mcr229
0a6b599 to
89a248a
Compare
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D70719546 |
This was referenced Mar 17, 2025
DannyYuyang-quic
pushed a commit
to CodeLinaro/executorch
that referenced
this pull request
Apr 2, 2025
Differential Revision: D70719546 Pull Request resolved: pytorch#8958
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.
Summary
There is some ambiguity around deriving per_token and per_channel_group semantics from quantize affine. Specifically when rank is two. Take for example the following input shape with the following group size:
This tensor has 5 scales, and can be seen has having one scale per batch dimension. Or one scale per token. However, this can also be seen as a single weight in which each group is the size of a channel, effectively giving per_channel semantics. This ambiguity does not play well within the XNNPACK Backend as we are must parse these differing quantization types. For now we rely on the fact that per_token quantization happens dynamically. Meaning that the scales and zero points are dynamically choosen. As a result, we check that the scales come from getitem and is dynamically chosen. We further ensure that per_channel_group checks are not per_token.
Test plan