Hi there, I had a somewhat related problem, with the use case of applying some function to specific modules based on their name (as state_dict and named_modules do return some kind of names) instead of based on their type (as I’ve seen everywhere by now, e.g. here 25).
And I ended up with this hack - calling it hack as I’m pretty new to PyTorch and not sure yet it is 100% safe - just create the names by yourself:
for n, m in model.named_modules():
     m.auto_name = n

You can then filter when iterating over e.g. model.modules(), using .auto_name.
Hope this helps!