Hello,
I have a model ‘m’ which is a torch.nn.ModuleList of 30 fully connected layers. Now I have to send this model ‘m’ in the forward() method of another model ‘K’ in every training iteration.
Pseudo code of above description:

class M(nn.Module):
    def __init__(self,):
        super().__init__()
        nw_1 = nn.Linear(256, 256)
        nw_2 = nn.Linear(256, 256)
        nw_3 = nn.Linear(256, 256)
        ........................
        ........................
        nw_30 = nn.Linear(256, 256)

        self.nw_list = nn.ModuleList([nw_1, nw_2, ......, nw_30])

    def forward(self, x):
        out1 = nw_1(x)
        out2 = nw_2(x)
        out3 = nw_3(x)
        ..............
        ..............
        out30 = nw_30(x)

        return sum(out1, out2, ....,out30)


class K(nn.Module):
    def __init__(self,):
        super().__init__()
        pass 

    def forward(self, model):
        print(model)


mm = M()
kk = K()

kk(mm)


Question: Is it wise to send the model as a function parameter? Are there any better ways to it?