I’d like to register forward hooks for each module in my network. I have a working code for one module. The most important part looks this way:
    def __init__(self, model, layer_name):
        self.hook = model.module.linear1.register_forward_hook(self.hook_fn)

I don’t know, however, how to access modules using layer_name variable.
So I suspect there’s some better way to do this. First, I’d like to list all the layers names (model.children() or model.named_parameters() don’t do this) and second, I’d like to use them somehow with the attached code.