Solved by JuanFMontesinos in post #2 
              
              
                Hi, 
You should have a look at hookers 
https://pytorch.org/docs/stable/nn.html?highlight=hook#torch.nn.Module.register_forward_hook 
They are registered after the model is defined. (Good idea to look in the forum  )