forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init quantization backend config for inductor (pytorch#96476)
**Summary** Init the backend config file with quantization recipes for quantization 2.0 inductor path. In this PR, we only init the recipe for `convolution` and `convolution_relu`. **Test Plan** ``` clear && python -m pytest test_quantization.py -k test_inductor_backend_config_conv ``` Pull Request resolved: pytorch#96476 Approved by: https://github.com/jgong5, https://github.com/EikanWang, https://github.com/jerryzh168
- Loading branch information
1 parent
517a432
commit a6d8c70
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
torch/ao/quantization/backend_config/_x86_inductor_pt2e.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
from torch.ao.quantization.backend_config import ( | ||
BackendConfig, | ||
DTypeConfig, | ||
ObservationType, | ||
BackendPatternConfig, | ||
) | ||
|
||
weighted_op_quint8_dtype_config = DTypeConfig( | ||
input_dtype=torch.quint8, | ||
output_dtype=torch.quint8, | ||
weight_dtype=torch.qint8, | ||
bias_dtype=torch.float, | ||
) | ||
|
||
def get_conv_configs(): | ||
conv_configs = [] | ||
observation_type = ObservationType.OUTPUT_USE_DIFFERENT_OBSERVER_AS_INPUT | ||
dtype_configs = [weighted_op_quint8_dtype_config] | ||
conv_configs.append( | ||
BackendPatternConfig(torch.ops.aten.convolution.default) | ||
.set_observation_type(observation_type) # noqa: E131 | ||
.set_dtype_configs(dtype_configs) | ||
._set_input_type_to_index({"weight": 1, "bias": 2}) | ||
) | ||
conv_configs.append( | ||
BackendPatternConfig((torch.ops.aten.convolution.default, torch.ops.aten.relu.default)) | ||
.set_observation_type(observation_type) # noqa: E131 | ||
.set_dtype_configs(dtype_configs) | ||
._set_input_type_to_index({"weight": 1, "bias": 2}) | ||
) | ||
# TODO: remove when functionalization is supported in PT2 mode | ||
conv_configs.append( | ||
BackendPatternConfig((torch.ops.aten.convolution.default, torch.ops.aten.relu_.default)) | ||
.set_observation_type(observation_type) # noqa: E131 | ||
.set_dtype_configs(dtype_configs) | ||
._set_input_type_to_index({"weight": 1, "bias": 2}) | ||
) | ||
return conv_configs | ||
|
||
def get_x86_inductor_pt2e_backend_config(): | ||
return ( | ||
BackendConfig("inductor_pytorch_2.0_export") | ||
.set_backend_pattern_configs(get_conv_configs()) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters