Skip to content

[PT2E][X86] Migrate fusion passes in Inductor to torchao #2140

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Xia-Weiwen
Copy link
Collaborator

Summary
In this PR, we copied the fusion passes of quantized ops for X86Inductor backend from PyTorch Inductor source code to Torchao. This is the first step to migrate quantization-related fusion passes in PyTorch core to Torchao.
We plan to do it in the following steps:

  • Copy fusion passes from PyTorch core to Torchao (this PR)
  • Depreacte and remove fusion passes in PyTorch core (TODO)
  • Switch to new quantize/dequantize ops in Torchao (TODO)

With this PR landed, we can add fusion passes for new ops in Torchao instead of in PyTorch core.

Since fusion passes need to be registered to Inductor, this PR wrapped the registration in the API lower_pt2e_quantized_to_x86. So, users need to call lowerlower_pt2e_quantized_to_x86 instead of torch.compile to get lowered model with torch.compile. The API is updated as below:

def lower_pt2e_quantized_to_x86(
    model: torch.fx.GraphModule,
    example_inputs: Optional[tuple[torch.Tensor, ...]] = None,
    compile: bool = True,
    **compile_options: Optional[dict],
) -> torch.fx.GraphModule

The compile flag indicates using torch.compile or not (eager mode). For eager mode, users just set compile=False.

Test plan
We copied related UTs from https://github.com/pytorch/pytorch/blob/main/test/inductor/test_mkldnn_pattern_matcher.py

pytest test/quantization/pt2e/test_x86inductor_fusion.py

Copy link

pytorch-bot bot commented Apr 28, 2025

🔗 Helpful Links

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

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

❌ 6 New Failures, 2 Pending

As of commit 1c2a948 with merge base e3db2b2 (image):

NEW FAILURES - The following jobs have 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 Apr 28, 2025
@Xia-Weiwen Xia-Weiwen added topic: new feature Use this tag if this PR adds a new feature and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Apr 28, 2025
@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 Apr 28, 2025
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. topic: new feature Use this tag if this PR adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants