Skip to content

Conversation

leslie-fang-intel
Copy link
Collaborator

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

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

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

Copy link

pytorch-bot bot commented Nov 15, 2023

🔗 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 Failures

As of commit 29479ce with merge base 7bbc19a (image):
💚 Looks good so far! There are no failures yet. 💚

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

@github-actions github-actions bot added the module: cpu CPU specific problem (e.g., perf, algorithm) label Nov 15, 2023
leslie-fang-intel added a commit that referenced this pull request Nov 15, 2023
ghstack-source-id: 3950269
Pull Request resolved: #113733
@leslie-fang-intel leslie-fang-intel changed the title Enable QLinear input with multi dims [Quant] [PT2] Enable QLinear input with multi dims Nov 15, 2023
@leslie-fang-intel
Copy link
Collaborator Author

cc @jianan-gu

@leslie-fang-intel leslie-fang-intel added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 15, 2023
**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]
leslie-fang-intel added a commit to leslie-fang-intel/pytorch that referenced this pull request Nov 17, 2023
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]
leslie-fang-intel added a commit to leslie-fang-intel/pytorch that referenced this pull request Nov 20, 2023
ghstack-source-id: 7fd173b
Pull Request resolved: pytorch#113733
@leslie-fang-intel
Copy link
Collaborator Author

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]
@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

pytorchmergebot pushed a commit that referenced this pull request Dec 6, 2023
…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
pytorchmergebot pushed a commit that referenced this pull request Dec 6, 2023
… 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
@facebook-github-bot facebook-github-bot deleted the gh/leslie-fang-intel/41/head branch December 9, 2023 15:27
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
**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
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
…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
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
… 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
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 Merged module: cpu CPU specific problem (e.g., perf, algorithm) module: inductor open source release notes: quantization release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants