@hamedB you need to register hooks on the intermediate variables to get the grad
https://pytorch.org/docs/stable/generated/torch.Tensor.register_hook.html