Model parameters inside a list cannot be update

I have been recently use PyTorch Lightning to build models. But I encountered a problem. In my model, I used a list to store a number of encoders and decoders. And I store the their respective model parameters in a list too. But I found that the parameters in the list won’t be updated.

To be more specific, say
pare =
for i in range(n):
tmp_para = torch.nn.Parameter(torch.randn(n_input))
para.append(tmp_para)
self.para_list = para
the model parameters in the para list will not be updated. I didn’t check if the parameters of the encoders and decoders have been updated, but I think they are not either.

How can I fix this problem? Will a dict help?

Hello,

Consider using a nn.ModuleList wrapper on the list of encoder and decoder modules. This enables the attributed class to see that the elements of the lists are also modules and enables parameter tracking.

Thanks. Got that. And for the parameter, I used the nn.ParameterList. Problem solved.