How to find which module that a variable belongs to?

Hello, I am trying to find some modules that have certain variables contained inside. I now can find these variables using model.named_parameters().
For instance, I may get a parameter and its name module.layer1.0.conv1.weight, how can I find the corresponding conv1 module it belongs to, in order to access other parameters inside this module? Is there any functions that I can use? Thanks in advance!

(I know that I can look for the module that is a instance of nn.Conv using model.children() or model.module(), but problem is that it may contain other stuff like nn.Sequential and other bigger blocks that contains conv, making the code very complicated)

I don’t think there is anything.
But you can simply access the attributes by doing name.split()[:-1] to get all the names. And then mod = getattr(mod, mod_name). for each entry in the list.