Sorry for the misunderstanding. I haven’t realized you would like to see the gradient of your loss.
In that case, @zhl515 is right, and you would need to use hooks to get the gradients w.r.t. some intermediate values (i.e. calculated from leaf variables).
Could you try to add loss.register_hook(lambda grad: print(grad)) before the backward call?