Optimizer got an empty parameter list error

I define a list of fully connected layers. And it gives me this error that says “optimizer got an empty parameter list.” When I enumerate all layers as separate variables, I do not get this error. What is the workaround for this issue beside enumerating layers as separate variables?

You should use nn.ModuleList.