Hi,
You should not rely on regiter_backward_hook as, as mentionned in the doc, they are mostly broken at the moment 
Also for such apporaches, I would recommend using autograd.grad so that you can directly provide the Tensors you want the gradients for.