ModuleList itself is a module, so you can just do something like:
nn.ModuleList(nn.ModuleList(... for _ in range(5)) for _ in range(5)) to create a 5x5 “grid” of modules. If you need a more complex structure, you can just do nn.ModuleList([nn.ModuleList(...), ...]) in any format you need.



 jmaronas:

they represent connections in a matrix


However, this makes me think there might be a better way to do what you want. Could you be a bit more explicit?