do you mean something like this,
def func(name):
  def hook(module, grad_input, grad_output):
    # hook implementation
  return hook
for name, layer in model.named_modules():
  layer.register_backward_hook(func(name))