8000 [Quant][Inductor] Bug fix: mutation nodes not handled correctly for QLinearPointwiseBinaryPT2E by Xia-Weiwen · Pull Request #127592 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[Quant][Inductor] Bug fix: mutation nodes not handled correctly for QLinearPointwiseBinaryPT2E #127592

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

Closed
wants to merge 12 commits into from

Conversation

Xia-Weiwen
Copy link
Collaborator
@Xia-Weiwen Xia-Weiwen commented May 31, 2024

Fixes #127402

  • Revert some changes to ir.MutationOutput and inductor/test_flex_attention.py
  • Add checks of mutation for QLinearPointwiseBinaryPT2E

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang

Copy link
pytorch-bot bot commented May 31, 2024

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (3 Unrelated Failures)

As of commit 90c1011 with merge base 786c24a (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was 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.

@Xia-Weiwen Xia-Weiwen added ciflow/trunk Trigger trunk jobs on your pull request intel This tag is for PR from Intel labels May 31, 2024
@Chillee
Copy link
Collaborator
Chillee commented May 31, 2024

Makes sense. I think you can also set MutationOutput if you wanted here. A description of how it works is here: #127151 (comment)

@Xia-Weiwen
Copy link
Collaborator Author

Makes sense. I think you can also set MutationOutput if you wanted here. A description of how it works is here: #127151 (comment)

@Chillee Thanks for the pointers. By "set MutationOutput" did you mean this

mark_node_as_mutating(packed, other)
? If so, we have done that in this IR.

Copy link
Collaborator
@leslie-fang-intel leslie-fang-intel left a comment

Choose a reason for hiding this comment

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

Maybe added an UT to get the generated code and check the number and post ops of QLinearBinary.

@@ -7307,6 +7308,12 @@ def codegen(self, wrapper):
if isinstance(self.layout, Layout):
self.codegen_size_asserts(wrapper)

def get_mutation_names(self):
return [self.inputs[self.idx_for_inplace_sum].get_name()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since post op sum and binary add reusing same IR and inplace mutation is only valid for post op sum, I think we should check it here for branch.

@Xia-Weiwen
Copy link
Collaborator Author

Maybe added an UT to get the generated code and check the number and post ops of QLinearBinary.

Good idea. How can I get the generated code in UT?

@leslie-fang-intel
Copy link
Collaborator
leslie-fang-intel commented May 31, 2024

Maybe added an UT to get the generated code and check the number and post ops of QLinearBinary.

Good idea. How can I get the generated code in UT?

There are some existing UTs in test_cpu_repro.py like

  _, code = run_and_get_cpp_code(
      torch._dynamo.optimize("inductor")(fn),
      x,
  )

@Xia-Weiwen
Copy link
Collaborator Author

Maybe added an UT to get the generated code and check the number and post ops of QLinearBinary.

Good idea. How can I get the generated code in UT?

There are some existing UTs in test_cpu_repro.py like

  _, code = run_and_get_cpp_code(
      torch._dynamo.optimize("inductor")(fn),
      x,
  )

Thanks. Checks are added in UT.

@Xia-Weiwen Xia-Weiwen marked this pull request as ready for review June 3, 2024 06:45
@Chillee
Copy link
Collaborator
Chillee commented Jun 3, 2024

I'm actually a little bit worried about the mutation support here. Actually, from reading the code, I would think that mark_node_as_mutating is sufficient to handle the mutation here. I'm worried that this patch isn't fixing the root cause and that there's another bug.

@Xia-Weiwen
Copy link
Collaborator Author

I'm actually a little bit worried about the mutation support here. Actually, from reading the code, I would think that mark_node_as_mutating is sufficient to handle the mutation here. I'm worried that this patch isn't fixing the root cause and that there's another bug.

Thanks for your comments. I will double check the logic behind it.

@Xia-Weiwen
Copy link
Collaborator Author

Hi @Chillee . I did some investigation. I may have found something, however, it looks too complicated to me. The thing is that, if we don't have that get_mutation_names for the IR, during compute_dependencies of the Scheduler, we won't enter this part about mutation:

for alt_name in node.get_mutations():
. And somehow the only user of the last QLinearPointwiseBinary node in graph, which is the output, is marked is_weak=True. Then, during dead_node_elimination, the QLinearPointwiseBinary node, along with its input nodes, is removed from the graph. So, the qlinear_binary op is missing in the final generated code. It therefore looks like this get_mutation_names method is necessary here. Could you please help take a look? Thanks.

@Xia-Weiwen Xia-Weiwen requested a review from Chillee June 3, 2024 14:42
@Xia-Weiwen
Copy link
Collaborator Author

Hi @Chillee Could you please take a look? Thanks!

@Chillee
Copy link
Collaborator
Chillee commented Jun 11, 2024

@Xia-Weiwen what's supposed to happen when I run the test case? It passes for me.

@Xia-Weiwen Xia-Weiwen changed the title [Quant][Inductor] Add get_mutation_names in QLinearPointwiseBinaryPT2E IR [Quant][Inductor] Bug fix: mutation nodes not handled correctly for QLinearPointwiseBinaryPT2E Jun 11, 2024
@Xia-Weiwen
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@Xia-Weiwen
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Xia-Weiwen added a commit to Xia-Weiwen/pytorch that referenced this pull request Jun 13, 2024
…LinearPointwiseBinaryPT2E (pytorch#127592)

Fixes pytorch#127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: pytorch#127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee
TharinduRusira pushed a commit to TharinduRusira/pytorch that referenced this pull request Jun 14, 2024
…LinearPointwiseBinaryPT2E (pytorch#127592)

Fixes pytorch#127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: pytorch#127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee
pytorchmergebot pushed a commit that referenced this pull request Jun 14, 2024
… for QLinearPointwiseBinaryPT2E (#128591)

Port #127592 from main to release/2.4

------
Fixes #127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: #127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee

Pull Request resolved: #128591
Approved by: https://github.com/jgong5, https://github.com/Chillee
ignaciobartol pushed a commit to ignaciobartol/pytorch that referenced this pull request Jun 14, 2024
…LinearPointwiseBinaryPT2E (pytorch#127592)

Fixes pytorch#127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: pytorch#127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee
ignaciobartol pushed a commit to ignaciobartol/pytorch that referenced this pull request Jun 14, 2024
… for QLinearPointwiseBinaryPT2E (pytorch#128591)

Port pytorch#127592 from main to release/2.4

------
Fixes pytorch#127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: pytorch#127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee

Pull Request resolved: pytorch#128591
Approved by: https://github.com/jgong5, https://github.com/Chillee
atalman pushed a commit that referenced this pull request Jun 19, 2024
… for QLinearPointwiseBinaryPT2E (#128591)

[Quant][Inductor] Bug fix: mutation nodes not handled correctly for QLinearPointwiseBinaryPT2E (#127592)

Fixes #127402

- Revert some changes to `ir.MutationOutput` and inductor/test_flex_attention.py
- Add checks of mutation for QLinearPointwiseBinaryPT2E

Pull Request resolved: #127592
Approved by: https://github.com/leslie-fang-intel, https://github.com/Chillee
@Xia-Weiwen Xia-Weiwen deleted the fix_qlinear_mutation branch November 13, 2024 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request intel This tag is for PR from Intel Merged module: inductor open source topic: not user facing topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[inductor][cpu]abnormal performance improvement and accuracy drop for huggingface suit static/dynamic quantization
5 participants
0