-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[quant][eagermode][refactor] Add set/get method for quantization and fusion mappings #43990
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
…fusion mappings Summary: Allow user to register custom quantization and fusion patterns Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 3dc9ab6 (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 127 times. |
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
|
nice! any chance we could add an example usage of this API to register a custom pattern to the PR summary? would make it easier to review |
z-a-f
left a 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.
LGTM
torch/quantization/_numeric_suite.py
Outdated
| *data, | ||
| Logger=OutputLogger, | ||
| white_list=DEFAULT_NUMERIC_SUITE_COMPARE_MODEL_OUTPUT_WHITE_LIST, | ||
| white_list=None |
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.
Should we change the white_list while we are at it?
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 afraid this is bc breaking, would be better to change all at once
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
done |
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
| F.layer_norm: torch._ops.ops.quantized.layer_norm, | ||
| } | ||
|
|
||
| def register_static_quant_module_class(module_class, static_quant_module_class): |
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.
optional, how about something like this to improve readability
def register_static_quant_module_swap(fp_source_module_class, static_quant_target_module_class):
"""Registers a module swap of {fp_source_module_class} to {static_quant_target_module_class}
during static quant convert step. static_quant_target_module_class must have from_float
defined as a class method."""
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.
sure, will change to register_static_quant_module_mapping
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_class - get_static_quant_module_mapping - get_static_quant_module_class - register_dynamic_quant_module_class - get_dynamic_quant_module_mapping - register_qat_module_class - get_qat_module_mapping for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_class(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_class(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
…zation and fusion mappings" Summary: Allow user to register custom quantization and fusion patterns Custom quantization API: - register_static_quant_module_mapping - get_static_quant_module_mappings - get_static_quant_module_class - register_dynamic_quant_module_mapping - get_dynamic_quant_module_mappings - register_qat_module_mapping - get_qat_module_mappings for fx graph mode quantization - register_quantized_operator - get_quantized_operator Custom fusion API: - register_fuser_method - get_fuser_method Example: ``` register_static_quant_module_mapping(torch.nn.Conv2d, torch.nn.quantized.Conv2d) register_dynamic_quant_module_mapping(torch.nn.Conv2d, torch.nn.quantized.dynamic.Conv2d) register_qat_module_mapping(torch.nn.Conv2d, torch.nn.qat.Conv2d) register_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d), fuse_conv_bn) >> get_static_quant_module_class(torch.nn.Conv2d) torch.nn.quantized.Conv2d >> get_fuser_method((torch.nn.Conv2d, torch.nn.BatchNorm2d)) fuser_conv_bn ``` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D23485344](https://our.internmc.facebook.com/intern/diff/D23485344) [ghstack-poisoned]
Codecov Report
@@ Coverage Diff @@
## gh/jerryzh168/426/base #43990 +/- ##
==========================================================
- Coverage 68.05% 68.04% -0.02%
==========================================================
Files 382 384 +2
Lines 49468 49527 +59
==========================================================
+ Hits 33667 33699 +32
- Misses 15801 15828 +27
Continue to review full report at Codecov.
|
|
This pull request has been merged in 0c58a01. |
Stack from ghstack:
Summary:
Allow user to register custom quantization and fusion patterns
Custom quantization API:
register_static_quant_module_mapping
get_static_quant_module_mappings
get_static_quant_module_class
register_dynamic_quant_module_mapping
get_dynamic_quant_module_mappings
register_qat_module_mapping
get_qat_module_mappings
for fx graph mode quantization
Custom fusion API:
Example:
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D23485344