Skip to content

Commit

Permalink
[Easy] Use prepend arg to register forward hooks in quantize.py (pyto…
Browse files Browse the repository at this point in the history
…rch#89391)

Differential Revision: [D41431110](https://our.internmc.facebook.com/intern/diff/D41431110)
Pull Request resolved: pytorch#89391
Approved by: https://github.com/awgu
  • Loading branch information
mrshenli authored and pytorchmergebot committed Nov 21, 2022
1 parent 1db5ce0 commit e0251de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions torch/ao/quantization/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e0251de

Please sign in to comment.