Hi,
The simplest is to use t.register_hook(your_fn) on any Tensor for which you want to be able to access the gradients.
You can add there either during the forward on your x Tensors or by adding mod.register_forward_hook(fw_hook) on the modules of your model to get access to these Tensors.