Skip to content

Adds Q/DQ layout support for embedding quantization with IntxWeightOnlyConfig #1972

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

Merged
merged 8 commits into from
Apr 8, 2025

Conversation

metascroy
Copy link
Contributor

This will be used to quantize embeddings in ET.

Copy link

pytorch-bot bot commented Mar 27, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1972

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 186f903 with merge base 5ded23c (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 27, 2025
@metascroy metascroy requested a review from jerryzh168 March 27, 2025 00:59
@metascroy metascroy force-pushed the add-intx-weight-only-for-embedding branch from 2c3b9ac to 05eec5d Compare April 6, 2025 02:15
@@ -1569,6 +1572,92 @@ def _uintx_weight_only_transform(
return module


@dataclass
class IntxWeightOnlyConfig(AOBaseConfig):
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewor14 can you have a look at this comment if there are any issues with it working well with QAT workflow with FakeQuantizeConfig.

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange that we have IntxWeightOnly and Int4WeightOnly

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I feel we should probably merge these two

has_weight_zeros=has_weight_zeros,
).quantize(quantized_model_reference)
quantize_(
quantized_model_reference,
Int8DynamicActivationIntxWeightConfig(
weight_dtype=weight_dtype,
granularity=granularity,
granularity=PerRow(),
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be PerAxis as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can't be because that's controlled by Int8DynamicActivationIntxWeightConfig, which uses PerRow until #1968 lands

@@ -155,7 +154,7 @@ def test_shared_embedding(self):
quantized_model = copy.deepcopy(model)
SharedEmbeddingQuantizer(
weight_dtype=weight_dtype,
granularity=granularity,
granularity=PerRow(),
Copy link
Contributor

Choose a reason for hiding this comment

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

and this

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

looks good overall, just need to change PerRow to PerAxis(axis=0) as we discussed in meeting

@metascroy metascroy merged commit 9516764 into main Apr 8, 2025
17 of 18 checks passed
jainapurva pushed a commit that referenced this pull request Apr 8, 2025
…lyConfig (#1972)

* up

* up

* up

* up

* up

* up

* up

* up
@@ -263,6 +269,9 @@ def _(func, types, args, kwargs):

@implements(torch.nn.functional.embedding)
def _(func, types, args, kwargs):
if _embedding_q_dq_check(args, kwargs):
return _embedding_q_dq_impl(args, kwargs)

Copy link
Contributor

Choose a reason for hiding this comment

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

why does line 299 only dequantizes weight bu tnot actually run embedding op?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants