Skip to content
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

[Inductor] [Quant] Re-structure Quantization testcase pattern matcher check #112570

Conversation

leslie-fang-intel
Copy link
Collaborator

@leslie-fang-intel leslie-fang-intel commented Nov 1, 2023

Stack from ghstack (oldest at bottom):

Summary
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

TestPlan

python -m pytest test_mkldnn_pattern_matcher.py -k test_q

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler

Copy link

pytorch-bot bot commented Nov 1, 2023

🔗 Helpful Links

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

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

✅ You can merge normally! (3 Unrelated Failures)

As of commit ab5a900 with merge base 871e27a (image):

UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:

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

leslie-fang-intel added a commit that referenced this pull request Nov 1, 2023
… check

ghstack-source-id: d504af3d68890be1a3b4d7bd36378ebf7f79858a
Pull Request resolved: #112570
@leslie-fang-intel leslie-fang-intel added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 1, 2023
…ern matcher check"


**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
leslie-fang-intel added a commit that referenced this pull request Nov 1, 2023
… check

ghstack-source-id: 5b4413162ccf704e4b0fb7fd8eacb61c2bd09e65
Pull Request resolved: #112570
…ern matcher check"


**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
leslie-fang-intel added a commit that referenced this pull request Nov 1, 2023
… check

ghstack-source-id: 21cabe3c665fa1f530b0ebabc4e19d5ba2bcb884
Pull Request resolved: #112570
…ern matcher check"


**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
leslie-fang-intel added a commit that referenced this pull request Nov 1, 2023
… check

ghstack-source-id: a051f23e78aef9c3f9c1ec30b94a7f0f6101441a
Pull Request resolved: #112570
@leslie-fang-intel
Copy link
Collaborator Author

Hi @jerryzh168 @jgong5, could you help to take a look of this PR again for simplifying the match checker in test_mkldnn_pattern_matcher? If we can land this PR firstly, I think it can also help us simplifying the changes made in several PRs (like #112550) for enabling of int8-mixed-bf16 quantization.

Copy link
Collaborator

@jgong5 jgong5 left a comment

Choose a reason for hiding this comment

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

LGTM. One minor suggestion FYI.

counters["inductor"]["qlinear_weight_prepack_matcher_count"], 3
)
self.assertEqual(
counters["inductor"]["qlinear_weight_prepack_matcher_nodes"], 18
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it's possible to have a function to calculate the number of matcher nodes from the pattern? Then, we don't have to hard-code the numbers here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yean, I think it depends on how to write a graph analysis function with specific heuristic for calculating the expected pattern kind and pattern number given a input fx graph (after quantization flow).

If we we can get that pattern kind and numbers, then we can define a pre-known table match from pattern kind to pattern matcher node number, for example

{conv2d_weight_prepack: 6, conv2d_relu_fp32_output: 2, conv2d_relu_int8_output: 7, .....}

…ern matcher check"


**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler

[ghstack-poisoned]
leslie-fang-intel added a commit that referenced this pull request Nov 3, 2023
… check

ghstack-source-id: ed686714eb513bc44da94faf7670066c3ca804fd
Pull Request resolved: #112570
counters["inductor"]["qconv2d_weight_prepack_matcher_count"], 1
)
self.assertEqual(
counters["inductor"]["qconv2d_weight_prepack_matcher_nodes"], 6
Copy link
Contributor

@jerryzh168 jerryzh168 Nov 4, 2023

Choose a reason for hiding this comment

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

do you need this? what is this used for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ideally, we only need to check matcher_count. matcher_nodes is a stricter restriction to check a node number in each matcher pattern.

# [convert_element_type_1, sub, mul_1, dequantize_per_channel, clone, convolution]
def matcher_check_fn():
# 1. Dequant-Conv2D pattern matched in QConv2D weight prepack * 1
# [convert_element_type_1, sub, mul_1, dequantize_per_channel, clone, convolution]
Copy link
Contributor

Choose a reason for hiding this comment

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

how do we get this list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By printing the m.nodes here, we can the nodes list in each matched pattern

counters["inductor"]["pattern_matcher_nodes"] += len(m.nodes)

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.

not sure why you need the matcher_nodes count

@leslie-fang-intel
Copy link
Collaborator Author

not sure why you need the matcher_nodes count

Thanks. Yean, matcher_nodes is not a must have. We can only keep the matcher_nodes checker for some important pattern.

@leslie-fang-intel
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

@leslie-fang-intel
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

xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Nov 7, 2023
… check (pytorch#112570)

**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

Pull Request resolved: pytorch#112570
Approved by: https://github.com/jgong5, https://github.com/jerryzh168
@facebook-github-bot facebook-github-bot deleted the gh/leslie-fang-intel/42/head branch November 7, 2023 15:24
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
… check (pytorch#112570)

**Summary**
This Diff re-structures Quantization testcase pattern matcher check. Instead of checking all the pattern matched in the Inductor, we will only check the core pattern match count and node numbers such as: dequant promotion, QConv/Linear Unary and QConv Binary.

**TestPlan**
```
python -m pytest test_mkldnn_pattern_matcher.py -k test_q
```

Pull Request resolved: pytorch#112570
Approved by: https://github.com/jgong5, https://github.com/jerryzh168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants