-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Quant] [PT2] Enable QLinear input with multi dims #113733
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
[Quant] [PT2] Enable QLinear input with multi dims #113733
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/113733
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 29479ce with merge base 7bbc19a ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
cc @jianan-gu |
**Summary** Previously QLinear implementation assumes inputs is with dim of 2. In this diff, we make QLinear accepts input of dim more than 2 with input and output reshape. **Test Plan** ``` python -u -m pytest -s -v test_quantized_op.py -k test_qlinear_pt2e ``` cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
**Summary** In the previous QLinear implementation, it was assumed that inputs have a dimension of 2. In this update, we have modified QLinear to accept inputs with a dimension greater than 2, incorporating input and output reshaping accordingly. **Test Plan** ``` python -u -m pytest -s -v test_quantized_op.py -k test_qlinear_pt2e ``` cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 voznesenskym penguinwu EikanWang Guobing-Chen zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
ghstack-source-id: b1796d3 Pull Request resolved: pytorch#113733
**Summary** In the previous QLinear implementation, it was assumed that inputs have a dimension of 2. In this update, we have modified QLinear to accept inputs with a dimension greater than 2, incorporating input and output reshaping accordingly. **Test Plan** ``` python -u -m pytest -s -v test_quantized_op.py -k test_qlinear_pt2e ``` cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 voznesenskym penguinwu EikanWang Guobing-Chen zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
ghstack-source-id: 7fd173b Pull Request resolved: pytorch#113733
Hi @jerryzh168, could you kindly help to take a look of this PR? |
**Summary** In the previous QLinear implementation, it was assumed that inputs have a dimension of 2. In this update, we have modified QLinear to accept inputs with a dimension greater than 2, incorporating input and output reshaping accordingly. **Test Plan** ``` python -u -m pytest -s -v test_quantized_op.py -k test_qlinear_pt2e ``` cc jgong5 mingfeima XiaobingSuper sanchitintel ashokei jingxu10 voznesenskym penguinwu EikanWang Guobing-Chen zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
@pytorchbot merge |
Merge startedYour 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 |
…on size exceeds 2 (#113912) **Summary** When decomposing `Linear` to `addmm` or `mm` within Inductor, if the input dimension size exceeds 2, `reshape` nodes are introduced to convert the input into a 2-dimensional form before and after the `addmm` or `mm` node. It is essential to identify and match this pattern during quantization for dequantization promotion. For instance, ``` # quant # + - - - | - - - + # | dequant | # | | | # | reshape | # | / \ | # | node1 node2 | # + - | - - - | - + # reshape reshape # + - | - - - | - + # quant quant ``` In this PR, we mainly do 2 things: - Extend support for the dequantization pattern in QLinear when the input dimension size exceeds 2. - Revise the implementation of the dequant promotion pass, as it now needs to accommodate the matching of four different patterns. **Test Plan** ``` python -m pytest test_mkldnn_pattern_matcher.py -k input_dim_exceeds_2 ``` Pull Request resolved: #113912 Approved by: https://github.com/jgong5, https://github.com/eellison ghstack dependencies: #113733
… size exceeds 2 (#113928) **Summary** Enable the qlinear weight prepack when input dimension size exceeds 2. There are extra reshape node before and after the `addmm` or `mm` node if input dimension size exceeds 2. **Test Plan** ``` python -m pytest test_mkldnn_pattern_matcher.py -k input_dim_exceeds_2 ``` Pull Request resolved: #113928 Approved by: https://github.com/jgong5, https://github.com/eellison ghstack dependencies: #113733, #113912
**Summary** In the previous QLinear implementation, it was assumed that inputs have a dimension of 2. In this update, we have modified QLinear to accept inputs with a dimension greater than 2, incorporating input and output reshaping accordingly. **Test Plan** ``` python -u -m pytest -s -v test_quantized_op.py -k test_qlinear_pt2e ``` Pull Request resolved: pytorch#113733 Approved by: https://github.com/jgong5, https://github.com/eellison
…on size exceeds 2 (pytorch#113912) **Summary** When decomposing `Linear` to `addmm` or `mm` within Inductor, if the input dimension size exceeds 2, `reshape` nodes are introduced to convert the input into a 2-dimensional form before and after the `addmm` or `mm` node. It is essential to identify and match this pattern during quantization for dequantization promotion. For instance, ``` # quant # + - - - | - - - + # | dequant | # | | | # | reshape | # | / \ | # | node1 node2 | # + - | - - - | - + # reshape reshape # + - | - - - | - + # quant quant ``` In this PR, we mainly do 2 things: - Extend support for the dequantization pattern in QLinear when the input dimension size exceeds 2. - Revise the implementation of the dequant promotion pass, as it now needs to accommodate the matching of four different patterns. **Test Plan** ``` python -m pytest test_mkldnn_pattern_matcher.py -k input_dim_exceeds_2 ``` Pull Request resolved: pytorch#113912 Approved by: https://github.com/jgong5, https://github.com/eellison ghstack dependencies: pytorch#113733
… size exceeds 2 (pytorch#113928) **Summary** Enable the qlinear weight prepack when input dimension size exceeds 2. There are extra reshape node before and after the `addmm` or `mm` node if input dimension size exceeds 2. **Test Plan** ``` python -m pytest test_mkldnn_pattern_matcher.py -k input_dim_exceeds_2 ``` Pull Request resolved: pytorch#113928 Approved by: https://github.com/jgong5, https://github.com/eellison ghstack dependencies: pytorch#113733, pytorch#113912
Stack from ghstack (oldest at bottom):
Summary
In the previous QLinear implementation, it was assumed that inputs have a dimension of 2. In this update, we have modified QLinear to accept inputs with a dimension greater than 2, incorporating input and output reshaping accordingly.
Test Plan
cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @voznesenskym @penguinwu @EikanWang @Guobing-Chen @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler