-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[Quant][FX] Add backend config for onednn backend and fuse Linear-LeakyReLU #88665
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
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/88665
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 680c177: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
| .set_object_type(torch.nn.LayerNorm, qconfig_layernorm) \ | ||
|
|
||
| if backend == 'onednn': | ||
| qconfig_mapping.set_object_type(torch.nn.LeakyReLU, qconfig) \ |
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.
do we support quantization for standalone leakyrelu module/op?
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 think it's required that the fused module shares the same qconfig with separate modules/ops otherwise there will be an error in UT. So, I added these here.
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.
OK, sounds good, we should be able to configure qconfig for patterns I think, but this will come up a bit later, cc @andrewor14 as FYI
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.
can you add a TODO comment here? so that we will remember to remove this later when we support fusion patterns in QConfigMapping
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.
OK, I have added a TODO comment in this PR: #89188
| .set_backend_pattern_configs(_get_binary_op_configs(binary_op_dtype_configs)) \ | ||
| .set_backend_pattern_config(_get_cat_config(default_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_default_op_configs(default_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_fixed_qparams_op_configs(fixed_qparams_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_share_qparams_op_configs(share_qparams_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_bn_configs(default_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_rnn_op_configs(rnn_op_dtype_configs)) \ | ||
| .set_backend_pattern_configs(_get_embedding_op_configs(embedding_op_dtype_configs)) |
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.
are you sure onednn actually supports all the ops here?
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.
Well, I thought we needed all these configs set so I just copied them here. I will try to remove them.
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.
They are removed
cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
|
Hi @jerryzh168. Do you have more comments? Thanks! |
|
Hi @jerryzh168. Is it ok to land this? Thanks |
| return BackendConfig("onednn") \ | ||
| .set_backend_pattern_configs(conv_configs) \ | ||
| .set_backend_pattern_configs(linear_configs) |
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.
onednn backend only supports these?
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.
@jerryzh168 For other ops, do I need to copy default configs here or just ignore them? What is expected? Here is your previous comment: #88665 (comment)
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.
Looks like they are needed. I have added them back. Please take a look again. Thanks.
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.
OK looks good, so for the other ops do we just fallback to the default (fbgemm) implementation? e.g. quantized::layer_norm
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.
Yes, we use default native implementations for ops other than conv/linear. However, we still need to set pattern configs for other ops here. Otherwise, those ops are not quantized if we use onednn's backend config for prepare_fx and convert_fx.
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
| # 1.1 linear module + leaky_relu fusion config | ||
| # linear leaky_relu, linear module + leaky_relu module | ||
| linear_configs.append( | ||
| BackendPatternConfig((nn.LeakyReLU, nn.Linear)) |
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.
nit: we updated the pattern format recently, please take a look at #90698
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.
Thanks. It's fixed.
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [ghstack-poisoned]
… Linear-LeakyReLU" **Summary** Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First `Linear - LeakyReLU` fusion is implemented based on previous PRs. **Test plan** python test_quantization.py TestFuseFx cc jerryzh168 jianyuh raghuramank100 jamesr66a vkuzo jgong5 leslie-fang-intel mingfeima XiaobingSuper sanchitintel ashokei jingxu10 [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 |
…kyReLU ghstack-source-id: decdc40 Pull Request resolved: pytorch/pytorch#88665
Stack from ghstack (oldest at bottom):
Summary
Add backend config for onednn backend so that it can support more post op fusion for int8 inference. First
Linear - LeakyReLUfusion is implemented based on previous PRs.Test plan
python test_quantization.py TestFuseFx
cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @leslie-fang-intel @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10