Skip to content

[X86] Add convert_element_type to smooth quant pattern#3784

Open
cyxlily wants to merge 15 commits intopytorch:mainfrom
cyxlily:smooth_quant_pattern
Open

[X86] Add convert_element_type to smooth quant pattern#3784
cyxlily wants to merge 15 commits intopytorch:mainfrom
cyxlily:smooth_quant_pattern

Conversation

@cyxlily
Copy link
Copy Markdown
Contributor

@cyxlily cyxlily commented Jan 30, 2026

No description provided.

Signed-off-by: Cui, Lily <lily.cui@intel.com>
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Jan 30, 2026

🔗 Helpful Links

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

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

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

@meta-cla meta-cla 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 Jan 30, 2026
@Xia-Weiwen Xia-Weiwen requested a review from Copilot January 30, 2026 08:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the smooth quantization pattern matching to support operations that include convert_element_type nodes. The changes enable the pattern matcher to recognize and handle quantization patterns with additional type conversion operations.

Changes:

  • Added convert_a parameter to get_pattern_no_bias function to generate patterns with extra convert_element_type nodes
  • Created new pattern variants (pattern_no_bias_1_c1, pattern_no_bias_1_c2, etc.) to match different combinations of conversion operations
  • Updated validation logic to accept additional match node counts (8, 9, 12) for the new patterns
  • Modified keyword argument handling to use x_scale_dtype and make dtype optional with fallback

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Xia-Weiwen Xia-Weiwen changed the title Add convert_element_type to smooth quant pattern [X86] Add convert_element_type to smooth quant pattern Jan 30, 2026
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Copy link
Copy Markdown
Collaborator

@Xia-Weiwen Xia-Weiwen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please also add a UT.

Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Signed-off-by: Cui, Lily <lily.cui@intel.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1863 to 1871
def _validate_pattern(match: Match):
if len(match.nodes) not in [4, 5, 6, 7, 10]:
# Valid node counts correspond to different pattern variations:
# 4: pattern1_with_no_outer_or_act_reshape (int_mm + convert + mul + mul)
# 6: pattern_no_bias_1 (reshape + int_mm + convert + mul + mul + reshape)
# 7: pattern_with_bias_1 (pattern_no_bias_1 + add)
# 8: pattern_no_bias_1_with_output_convert (pattern_no_bias_1 with dot scaled + output convert)
# 9: pattern_with_bias_1_with_output_convert (pattern_with_bias_1 with dot scaled + output convert)
if len(match.nodes) not in [4, 6, 7, 8, 9]:
return False
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cyxlily Please take a look.

Comment on lines 1788 to 1789
# When torch.compile'ing with dynamic=True, the expand node and the two tailing reshape nodes exist
# When torch.compile'ing with dynamic=False, they don't exist
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cyxlily Please take a look.

Comment on lines +1790 to +1791
def get_pattern_no_bias(reshape_a: bool = True, convert_a: bool = False):
int_mm_pattern = CallFunction(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@cyxlily Please consider renaming here.

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