Thanks. Is it feasible to use forward and backward hooks to modify the forward and backward passes; that is, register a forward hook on a module that changes the output it sends to the next module, and register a backwards hook on the same module that changes the gradient it sends to the next module (the one preceding it in the forwards pass)? Or is creating a new module the way to do that?
Reason for asking being that I am trying to do so by creating a new module and applying a function that applies autograd.Function as in the tutorial from the site you mentioned, but the grad_output it receives in the backward function is full of either zeros or infinities, depending on how I implement it.
More specifically, I just added some backwards hooks to check whether requires_grad was true or not, and for almost all modules it was False. The model is set to train(). I am adjusting the VGG16 model. Looking at the implementation, when the hook was set to self.features it returned a reasonable tensor as grad_output, but when I added it to a convolutional layer it returned all 0s with requires_grad equal to False.