Solved by ptrblck in post #6 
              
              
                I think your code registers the hooks too late (after the backward call). 
Note that the hook will be called during the gradient calculation. 
You could register the hooks during setup and use the standard training loop without removing and adding the hooks again.