Can I nest nn.ModuleDict()?

I want to organise my submodules into groups of modules. Within the groups the modules aren’t necessarily applied sequentially but the groups are then applied one after another. Can I nest a ModuleDict so that I can index a group, which itself is a ModuleDict?

Also, can I add non-module attributes to a ModuleDict? Like a normal string? Or would I need a separate dictionary to track non-module items?

1 Like


You can nest ModuleDict, they are nn.Module and can contain any nn.Module.
I think you can store anything in a Module dict, I can’t see any restriction.