Using forward hooks to modify the output of the neural network

I have a simple neural network and I want to modify the value of the output layer for a given input ‘I’ to the input layer.

Pytorch documentation has this tutorial which says -

We’ve inspected the weights and the gradients. But how about inspecting / modifying the output and grad_output of a layer?

We introduce hooks for this purpose.
The tutorial just says this can be done but does not show how to actually do it. Can someone please provide some code that shows how to change/set the outputs?

tl;tr: torch >=v1.2.0

Hey @dakshanand,
I just ran into the same issue. In case anybody else is wondering: Update torch to >=1.2.0. Before this version, hooks were read-only, now they can modify the output.