diff --git a/torch/ao/quantization/quantize.py b/torch/ao/quantization/quantize.py index 51eb2c1c1ec..8b149b44ad3 100644 --- a/torch/ao/quantization/quantize.py +++ b/torch/ao/quantization/quantize.py @@ -143,11 +143,13 @@ def register_activation_post_process_hook(module, pre_hook=False): assert hasattr(module, 'activation_post_process'), \ 'Expect activation_post_process attribute already attached to the module' if pre_hook: - handle = module.register_forward_pre_hook(_observer_forward_pre_hook) - module._forward_pre_hooks.move_to_end(handle.id, last=False) + handle = module.register_forward_pre_hook( + _observer_forward_pre_hook, prepend=True + ) else: - handle = module.register_forward_hook(_observer_forward_hook) - module._forward_hooks.move_to_end(handle.id, last=False) + handle = module.register_forward_hook( + _observer_forward_hook, prepend=True + ) def add_observer_(module, qconfig_propagation_list=None, non_leaf_module_list=None, device=None, custom_module_class_mapping=None):