From 6c3ebccc00dfca217094357a63e2be901ad7beb4 Mon Sep 17 00:00:00 2001 From: Charles David Hernandez Date: Thu, 19 Aug 2021 13:04:48 -0700 Subject: [PATCH] Updating the names of these functions (#63513) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/63513 updating these names per Jerry's nits in the previous pr Test Plan: Imported from OSS Reviewed By: jerryzh168 Differential Revision: D30406710 fbshipit-source-id: a9f1577a2b8c4a93f5005e0f6278b7d7348d8b66 --- torch/quantization/fx/prepare.py | 4 ++-- torch/quantization/qconfig.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/torch/quantization/fx/prepare.py b/torch/quantization/fx/prepare.py index 23d1d40..29600b8 100644 --- a/torch/quantization/fx/prepare.py +++ b/torch/quantization/fx/prepare.py @@ -15,7 +15,7 @@ from torch.fx.graph import ( ) from torch.fx.node import Argument -from ..qconfig import QConfigAny, qconfig_function_equality +from ..qconfig import QConfigAny, qconfig_equals from .qconfig_utils import ( convert_dict_to_ordered_dict, generate_qconfig_map, @@ -195,7 +195,7 @@ def update_qconfig_for_fusion( # Raise an error if the modules in the fused module have # different qconfigs specified in the qconfig_dict for op in ops: - if not qconfig_function_equality(object_type_dict.get(op, None), fused_qconfig): + if not qconfig_equals(object_type_dict.get(op, None), fused_qconfig): raise LookupError("During fusion, we need to specify the same " + f"qconfigs for both modules in {module_type}.") diff --git a/torch/quantization/qconfig.py b/torch/quantization/qconfig.py index 01d67dd..ae89b4a 100644 --- a/torch/quantization/qconfig.py +++ b/torch/quantization/qconfig.py @@ -211,9 +211,9 @@ def add_module_to_qconfig_obs_ctr( return QConfigDynamic(activation, weight) -def qconfig_function_equality(q1: QConfigAny, q2: QConfigAny): +def qconfig_equals(q1: QConfigAny, q2: QConfigAny): # functools.partial has no __eq__ operator defined so '==' defaults to 'is' - def compare_partial(p1, p2): + def partial_equals(p1, p2): same = p1.func == p2.func same = same and p1.args == p2.args return same and p1.keywords == p2.keywords @@ -223,6 +223,6 @@ def qconfig_function_equality(q1: QConfigAny, q2: QConfigAny): else: assert q1 is not None and q2 is not None try: - return compare_partial(q1.activation.p, q2.activation.p) and compare_partial(q1.weight.p, q2.weight.p) + return partial_equals(q1.activation.p, q2.activation.p) and partial_equals(q1.weight.p, q2.weight.p) except AttributeError: return q1 == q2 -- 2.7.4