pytorch
5e77999e - Add global hooks to `torch.nn.Module` (#38972)

Commit
4 years ago
Add global hooks to `torch.nn.Module` (#38972) Summary: This allows registering hooks that will be executed for every module. This idea arose in a discussion with tkerola and niboshi kindly proposed this approach. The use case for this is to avoid boilerplate code when registering the same hook for all the modules in a complex model, the internal use-case was to allow every model to accept a NumPy array in the forward pass in a simpler way. Other use cases involve general mechanisms for plotting or tracing & debugging. Currently, this is shared for all the modules but this can be worked out to have the hooks shared only per type of module. If this functionality is not needed feel free to close the PR. Pull Request resolved: https://github.com/pytorch/pytorch/pull/38972 Differential Revision: D22091364 Pulled By: albanD fbshipit-source-id: 204ff5f9e119eff5bdd9140c64cb5dc467bb23a2
Author
Emilio Castillo
Parents
Loading