Parameters of the network

Hi,

I have a question about getting all parameters of the network. My network is defined as follow:

activation = nn.ReLU()
class OneInputBasis(nn.Module):
    def __init__(self):
        super().__init__()
        
        bo_b = True
        bo_last = False

        self.l1 = nn.Linear(200, 100, bias = bo_b).to(device)
        self.l4 = nn.Linear(100, 100, bias = bo_last).to(device)
        
    def forward(self, v):
        v = activation ( self.l1(v) )
        v = ( self.l4(v) )        

        return v

and

class node(nn.Module):
    def __init__(self):
        super().__init__()
        
        bo_b = True
        bo_last = False
        
        self.set_lay = []
        
        for jj in range(dim_output_space_basis):
            self.set_lay.append(OneInputBasis())
        
        
    def forward(self, v):

        w = self.set_lay[0](v)

        for ii in range(dim_output_space_basis-1):
            w = torch.cat((w, self.set_lay[ii+1](v)), dim = 1 )
        
        return w

and

class mesh(nn.Module):
    def __init__(self):
        super().__init__()
        
        bo_b = True
        bo_last = False

        self.l3 = nn.Linear(2, 100, bias = bo_b).to(device)
        self.l4 = nn.Linear(100, 100, bias = bo_b).to(device)
        self.l7 = nn.Linear(100, 10, bias = bo_last).to(device)
        
    def forward(self, w):
        w = activation ( self.l3(w) )
        w = activation ( self.l4(w) )
        w =  ( self.l7(w) )
        
        return w

finally, I have

activation = nn.ReLU()
class Test(nn.Module):
    def __init__(self):
        super().__init__()
        
        bo_b = True
        bo_last = False

        self.top = node()
        self.bottom = mesh()

    def forward(self, v, w, y):
        v = self.top(v)
        w = self.bottom(w)
        e = torch.bmm(w ,torch.bmm(v, y))

        return e[:, :, 0]

Now I define the network:

fnn_adam = Test()

When I print the parameters of the network, as

 for p in fnn_adam.parameters():
     print(p)

I can only see the parameters associated with fnn_adam.bottom, how can I print out the parameters associated with fnn_adam.top which is defined by the Class node()? Are the parameters associated with .top trainable? Thank you so much!

You are not properly registering the submodules (and thus their parameters) in node.
Using a plain Python list won’t work:

        self.set_lay = []
        
        for jj in range(dim_output_space_basis):
            self.set_lay.append(OneInputBasis())

and you would need to use an nn.ModuleList instead.