Hello all!  I have a (hopefully) basic question regarding backward hooks.
I would like to set a hook on an intermediate variable in my model.
I try:
y.register_hook(lambda grad: print(grad.shape))

but that yields the error:
RuntimeError: cannot register a hook on a tensor that doesn't require gradient

So then I attempt to do:
y.requires_grad = True
y.register_hook(lambda grad: print(grad.shape))

but that yields the error
RuntimeError: you can only change requires_grad flags of leaf variables.

This seems circular?  I see a lot of examples where register_hook is used on intermediate variables.  What seems to be the error?
I am using Torch 1.6 on GPU