-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Labels
actionablemodule: docsRelated to our documentation, both in docs/ and docblocksRelated to our documentation, both in docs/ and docblocksmodule: nnRelated to torch.nnRelated to torch.nntriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Description
📚 The doc issue
In current docstring of forward_hook, it says:
pytorch/torch/nn/modules/module.py
Lines 100 to 102 in 38b94f4
| The hook can modify the output. It can modify the input inplace but | |
| it will not have effect on forward since this is called after | |
| :func:`forward` is called. |
What's the meaning of It can modify the input inplace but it will not have effect on forward while The hook can modify the output. also holds?
When I check the implementation of Module, the result of forward is indeed overridden by hook_result as long as the hook function returns a modified result.
pytorch/torch/nn/modules/module.py
Lines 1130 to 1134 in 38b94f4
| if _global_forward_hooks or self._forward_hooks: | |
| for hook in (*_global_forward_hooks.values(), *self._forward_hooks.values()): | |
| hook_result = hook(self, input, result) | |
| if hook_result is not None: | |
| result = hook_result |
Suggest a potential alternative/fix
I suppose the above docstring to be modified as follows:
The hook can modify the module output as long as it returns
the modified output. It cannot modify the given argument `output`
inplace since this is called after :func:`forward` is called.
cc @brianjo @mruberry @albanD @jbschlosser @walterddr @kshitij12345
Metadata
Metadata
Assignees
Labels
actionablemodule: docsRelated to our documentation, both in docs/ and docblocksRelated to our documentation, both in docs/ and docblocksmodule: nnRelated to torch.nnRelated to torch.nntriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module