-
Notifications
You must be signed in to change notification settings - Fork 25.7k
[quant][pt2] Support quantized conv bias in QAT fusion #112528
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
Conversation
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112528
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 6d2800e with merge base 46a34e8 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@andrewor14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) [ghstack-poisoned]
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar ghstack-source-id: 066ef7a Pull Request resolved: #112528
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) [ghstack-poisoned]
|
@andrewor14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) [ghstack-poisoned]
|
|
||
| # Step (3): Fold BN weights into conv | ||
| # Step (3): Copy over args for weight (and optionally bias) q - dq nodes | ||
| _copy_over_q_dq_args(*node_map["conv_weight_q"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if these can be simplified if we use these? https://github.com/pytorch/pytorch/blob/main/torch/ao/quantization/pt2e/utils.py#L291
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can explore that as a BE task along with the conv arg copying. I prefer to do that separately
|
@andrewor14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@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 |
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) [ghstack-poisoned]
Merge failedReason: New commits were pushed while merging. Please rerun the merge command. Details for Dev Infra teamRaised by workflow job |
|
@andrewor14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@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 |
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) Pull Request resolved: pytorch#112528 Approved by: https://github.com/jerryzh168
Summary: Previously QAT fusion assumes bias is not quantized. This works for the existing XNNPACKQuantizer, but not for custom quantizers that wish to quantize the bias. This commit supports this by adding the necessary patterns. This requires refactoring the code, however, since it previously assumed that there will only be one pair of q-dq (from conv weight) in the matched pattern, and this is no longer true. Test Plan: python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec Reviewers: jerryzh168, kimishpatel Subscribers: jerryzh168, kimishpatel, supriyar Differential Revision: [D50856377](https://our.internmc.facebook.com/intern/diff/D50856377) Pull Request resolved: pytorch#112528 Approved by: https://github.com/jerryzh168
Stack from ghstack (oldest at bottom):
Summary: Previously QAT fusion assumes bias is not quantized.
This works for the existing XNNPACKQuantizer, but not for custom
quantizers that wish to quantize the bias. This commit supports
this by adding the necessary patterns. This requires refactoring
the code, however, since it previously assumed that there will
only be one pair of q-dq (from conv weight) in the matched
pattern, and this is no longer true.
Test Plan:
python test/test_quantization.py TestQuantizePT2EQAT.test_qat_conv_bn_bias_derived_qspec
Reviewers: jerryzh168, kimishpatel
Subscribers: jerryzh168, kimishpatel, supriyar
Differential Revision: D50856377