mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[ao] Removing unused allow list arguments from propagate_qconfig and helper (#71104)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/71104 This shouldn't change any functionality given that those variables were not used. It should be noted that a similar variable is used in add_observer which is why it wasn't removed from there. ghstack-source-id: 146940043 Test Plan: python test/test_quantization.py Imported from OSS Reviewed By: vkuzo Differential Revision: D33510352 fbshipit-source-id: c66ed72c2b71a6e1822f9311467adaa1f4b730d0
This commit is contained in:
parent
e7c87e8b44
commit
e47771cca0
|
|
@ -30,7 +30,8 @@ def is_activation_post_process(module):
|
|||
return (isinstance(module, torch.ao.quantization.ObserverBase) or
|
||||
isinstance(module, torch.ao.quantization.FakeQuantizeBase))
|
||||
|
||||
def _propagate_qconfig_helper(module, qconfig_dict, allow_list=None,
|
||||
|
||||
def _propagate_qconfig_helper(module, qconfig_dict,
|
||||
qconfig_parent=None, prefix=''):
|
||||
r"""This is a helper function for `propagate_qconfig_`
|
||||
|
||||
|
|
@ -38,7 +39,6 @@ def _propagate_qconfig_helper(module, qconfig_dict, allow_list=None,
|
|||
module: input module
|
||||
qconfig_dict: dictionary that maps from name of submodule to quantization
|
||||
configuration
|
||||
allow_list: list of quantizable modules
|
||||
qconfig_parent: quantization config of parent module, we will fallback to
|
||||
this config when there is no specified config for current
|
||||
module
|
||||
|
|
@ -48,9 +48,6 @@ def _propagate_qconfig_helper(module, qconfig_dict, allow_list=None,
|
|||
Return:
|
||||
None, module is modified inplace with qconfig attached
|
||||
"""
|
||||
# TODO: Add test
|
||||
if allow_list is None:
|
||||
allow_list = get_default_qconfig_propagation_list()
|
||||
|
||||
module_qconfig = qconfig_dict.get(type(module), qconfig_parent)
|
||||
module_qconfig = qconfig_dict.get(prefix, module_qconfig)
|
||||
|
|
@ -63,10 +60,10 @@ def _propagate_qconfig_helper(module, qconfig_dict, allow_list=None,
|
|||
|
||||
for name, child in module.named_children():
|
||||
module_prefix = prefix + '.' + name if prefix else name
|
||||
_propagate_qconfig_helper(child, qconfig_dict, allow_list,
|
||||
_propagate_qconfig_helper(child, qconfig_dict,
|
||||
qconfig_with_device_check, module_prefix)
|
||||
|
||||
def propagate_qconfig_(module, qconfig_dict=None, allow_list=None):
|
||||
def propagate_qconfig_(module, qconfig_dict=None):
|
||||
r"""Propagate qconfig through the module hierarchy and assign `qconfig`
|
||||
attribute on each leaf module
|
||||
|
||||
|
|
@ -76,14 +73,13 @@ def propagate_qconfig_(module, qconfig_dict=None, allow_list=None):
|
|||
quantization configuration, qconfig applies to all submodules of a
|
||||
given module unless qconfig for the submodules are specified (when
|
||||
the submodule already has qconfig attribute)
|
||||
allow_list: a set that lists out allowable modules to be propagated with qconfig
|
||||
|
||||
Return:
|
||||
None, module is modified inplace with qconfig attached
|
||||
"""
|
||||
if qconfig_dict is None:
|
||||
qconfig_dict = {}
|
||||
_propagate_qconfig_helper(module, qconfig_dict, allow_list)
|
||||
_propagate_qconfig_helper(module, qconfig_dict)
|
||||
|
||||
def _observer_forward_hook(self, input, output):
|
||||
r"""Forward hook that calls observer on the output
|
||||
|
|
@ -105,6 +101,7 @@ def register_activation_post_process_hook(module, pre_hook=False):
|
|||
handle = module.register_forward_hook(_observer_forward_hook)
|
||||
module._forward_hooks.move_to_end(handle.id, last=False)
|
||||
|
||||
|
||||
def add_observer_(module, qconfig_propagation_list=None, non_leaf_module_list=None, device=None, custom_module_class_mapping=None):
|
||||
r"""Add observer for the leaf child of the module.
|
||||
|
||||
|
|
@ -113,6 +110,8 @@ def add_observer_(module, qconfig_propagation_list=None, non_leaf_module_list=No
|
|||
|
||||
Args:
|
||||
module: input module with qconfig attributes for all the leaf modules that we want to quantize
|
||||
qconfig_propagation_list: a list of quantizable modules that will have observers added to them
|
||||
if they are leaf nodes
|
||||
device: parent device, if any
|
||||
non_leaf_module_list: list of non-leaf modules we want to add observer
|
||||
|
||||
|
|
@ -253,7 +252,7 @@ def prepare(model, inplace=False, allow_list=None,
|
|||
|
||||
# TODO: remove allow_list
|
||||
qconfig_propagation_list = allow_list
|
||||
if qconfig_propagation_list is None:
|
||||
if allow_list is None:
|
||||
qconfig_propagation_list = get_default_qconfig_propagation_list()
|
||||
propagate_qconfig_(model, qconfig_dict=None)
|
||||
|
||||
|
|
@ -418,7 +417,7 @@ def quantize_dynamic(model, qconfig_spec=None, dtype=torch.qint8,
|
|||
convert(model, mapping, inplace=True)
|
||||
return model
|
||||
|
||||
def prepare_qat(model, mapping=None, inplace=False, allow_list=None):
|
||||
def prepare_qat(model, mapping=None, inplace=False):
|
||||
r"""
|
||||
Prepares a copy of the model for quantization calibration or
|
||||
quantization-aware training and converts it to quantized version.
|
||||
|
|
@ -432,7 +431,6 @@ def prepare_qat(model, mapping=None, inplace=False, allow_list=None):
|
|||
replaced.
|
||||
inplace: carry out model transformations in-place, the original module
|
||||
is mutated
|
||||
allow_list: a set that lists out allowable modules to be propagated with qconfig
|
||||
"""
|
||||
torch._C._log_api_usage_once("quantization_api.quantize.prepare_qat")
|
||||
assert model.training, "prepare_qat only works on models in training mode"
|
||||
|
|
@ -442,7 +440,7 @@ def prepare_qat(model, mapping=None, inplace=False, allow_list=None):
|
|||
if not inplace:
|
||||
model = copy.deepcopy(model)
|
||||
|
||||
propagate_qconfig_(model, qconfig_dict=None, allow_list=allow_list)
|
||||
propagate_qconfig_(model, qconfig_dict=None)
|
||||
convert(model, mapping=mapping, inplace=True, remove_qconfig=False)
|
||||
prepare(model, observer_non_leaf_module_list=set(mapping.values()), inplace=True)
|
||||
return model
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user