List hooks applied to layer

When adding a hook to a layer, let’s say by nn.utils.spectral_norm(my_layer), how can I confirm that the hook in fact registered?

If I added more hooks, could I list them all somehow?

I think you access this protected attribute of the layer
something like layer._forward_hooks which holds an OrderedDict of all registered forward hooks.

an example:

  1. get the model’s children: x = list(model.children())
  2. get forward hooks of the 1st layer: x[0]._forward_hooks

similarly, you can see:
layer._backward_hooks
layer._forward_pre_hooks

Thanks, I will try this out!

This was surprisingly difficult to find in thr documentation/tutorials.