From 41e897a00c28acc53877f5e3b703141f84e40583 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 10 Oct 2022 13:54:37 -0700 Subject: [PATCH 1/2] [quant] Move the order of x86 engine to avoid changing the default qengine since the default qengine is the last element of the engine in supported_engines list, adding x86 qengine in the end of the list changes the default quantized engine as well. this PR will be a short term fix to revert the changes. We have an issue here to track the proper fix: https://github.com/pytorch/pytorch/issues/86404 [ghstack-poisoned] --- aten/src/ATen/Context.cpp | 2 +- torch/ao/quantization/qconfig.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aten/src/ATen/Context.cpp b/aten/src/ATen/Context.cpp index 35855b99982b0..c96b36975214e 100644 --- a/aten/src/ATen/Context.cpp +++ b/aten/src/ATen/Context.cpp @@ -324,9 +324,9 @@ const std::vector& Context::supportedQEngines() { #ifdef USE_FBGEMM if (fbgemm::fbgemmSupportedCPU()) { - engines.push_back(at::kFBGEMM); // The X86 qengine is available if and only if FBGEMM is available engines.push_back(at::kX86); + engines.push_back(at::kFBGEMM); } #endif diff --git a/torch/ao/quantization/qconfig.py b/torch/ao/quantization/qconfig.py index a0c3377d4ea2d..8e662e5745ce6 100644 --- a/torch/ao/quantization/qconfig.py +++ b/torch/ao/quantization/qconfig.py @@ -223,13 +223,13 @@ def __new__(cls, activation=torch.nn.Identity, weight=torch.nn.Identity): Default qconfig for operators that reuse the observers from input Tensor, e.g. reshape """ -def get_default_qconfig(backend='x86', version=0): +def get_default_qconfig(backend='fbgemm', version=0): """ Returns the default PTQ qconfig for the specified backend. Args: * `backend`: a string representing the target backend. Currently supports - `x86` (default), `fbgemm`, `qnnpack` and `onednn`. + `x86`, `fbgemm` (default), `qnnpack` and `onednn`. Return: qconfig @@ -298,13 +298,13 @@ def get_default_qconfig(backend='x86', version=0): default_embedding_qat_qconfig_4bit = QConfig(activation=NoopObserver.with_args(dtype=torch.float32), weight=default_embedding_fake_quant_4bit) -def get_default_qat_qconfig(backend='x86', version=1): +def get_default_qat_qconfig(backend='fbgemm', version=1): """ Returns the default QAT qconfig for the specified backend. Args: * `backend`: a string representing the target backend. Currently supports - `x86`(default), `fbgemm`, `qnnpack` and `onednn`. + `x86`, `fbgemm` (default), `qnnpack` and `onednn`. * `version`: version, for backwards compatibility. Can be `None` or `1`. Return: @@ -392,13 +392,13 @@ def get_default_qat_qconfig(backend='x86', version=1): eps=2 ** -12), weight=fused_per_channel_wt_fake_quant_range_neg_127_to_127) -def get_default_qconfig_dict(backend='x86', version=0): +def get_default_qconfig_dict(backend='fbgemm', version=0): warnings.warn( "torch.ao.quantization.get_default_qconfig_dict is deprecated and will be removed in " "a future version. Please use torch.ao.quantization.get_default_qconfig_mapping instead.") return torch.ao.quantization.get_default_qconfig_mapping(backend, version).to_dict() -def get_default_qat_qconfig_dict(backend='x86', version=1): +def get_default_qat_qconfig_dict(backend='fbgemm', version=1): warnings.warn( "torch.ao.quantization.get_default_qat_qconfig_dict is deprecated and will be removed in " "a future version. Please use torch.ao.quantization.get_default_qat_qconfig_mapping instead.") From b49927df712ff52fd4e6c4b17bb95d0103ae8d71 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Mon, 10 Oct 2022 13:58:09 -0700 Subject: [PATCH 2/2] Update on "[quant] Move the order of x86 engine to avoid changing the default qengine" since the default qengine is the last element of the engine in supported_engines list, adding x86 qengine in the end of the list changes the default quantized engine as well. this PR will be a short term fix to revert the changes. We have an issue here to track the proper fix: https://github.com/pytorch/pytorch/issues/86404 [ghstack-poisoned] --- torch/ao/quantization/qconfig_mapping.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/torch/ao/quantization/qconfig_mapping.py b/torch/ao/quantization/qconfig_mapping.py index c6e2248455e79..ac54264145286 100644 --- a/torch/ao/quantization/qconfig_mapping.py +++ b/torch/ao/quantization/qconfig_mapping.py @@ -120,25 +120,25 @@ def _get_default_qconfig_mapping(is_qat: bool, backend: str, version: int) -> QC return qconfig_mapping -def get_default_qconfig_mapping(backend="x86", version=0) -> QConfigMapping: +def get_default_qconfig_mapping(backend="fbgemm", version=0) -> QConfigMapping: """ Return the default QConfigMapping for post training quantization. Args: * ``backend`` : the quantization backend for the default qconfig mapping, should be - one of ["x86" (default), "fbgemm", "qnnpack", "onednn"] + one of ["x86", "fbgemm" (default), "qnnpack", "onednn"] * ``version`` : the version for the default qconfig mapping """ # TODO: add assert for backend choices return _get_default_qconfig_mapping(False, backend, version) -def get_default_qat_qconfig_mapping(backend="x86", version=1) -> QConfigMapping: +def get_default_qat_qconfig_mapping(backend="fbgemm", version=1) -> QConfigMapping: """ Return the default QConfigMapping for quantization aware training. Args: * ``backend`` : the quantization backend for the default qconfig mapping, should be - one of ["x86" (default), "fbgemm", "qnnpack", "onednn"] + one of ["x86", "fbgemm" (default), "qnnpack", "onednn"] * ``version`` : the version for the default qconfig mapping """ return _get_default_qconfig_mapping(True, backend, version)