Error: optimizer got an empty parameter list. How can i modify my code?
Here is code:
class MLP(nn.Module):  
    def __ini__(self):
         super (MLP, self). __init__()  
         self.model=nn.nn.Sequential(  
            nn.Linear(784, 200),
            nn.LeakyReLU(inplace=True),  
            nn.Linear(200, 200),
            nn.LeakyReLU(inplace=True),
            nn.Linear(200, 10),
            nn.LeakyReLU(inplace=True),
            )

    def forward(self,x):
                x=self.model(x)
                return 
device= torch.device('cuda:0')
net = MLP().to(device)

when running these codes
optimizer = optim.SGD(net.parameters(),lr=learning_rate)

I get

ValueError: optimizer got an empty parameter list&quot;

I am trying to imitate this notebook.

There are several issues with your code. Currently your code is equivalent to:
class MLP(nn.Module):
    def forward(self, x):
        pass

Here are the issues:

Your initializer is named __init__.

forward should return a value, here x.

Replace nn.nn.Sequential with nn.Sequential.



class MLP(nn.Module):
    def __init__(self):
        super (MLP, self).__init__()  
        self.model = nn.Sequential(  
            nn.Linear(784, 200),
            nn.LeakyReLU(inplace=True),  
            nn.Linear(200, 200),
            nn.LeakyReLU(inplace=True),
            nn.Linear(200, 10),
            nn.LeakyReLU(inplace=True))

    def forward(self,x):
        x = self.model(x)
        return x

device= torch.device('cuda:0')
net = MLP().to(device)

optimizer = torch.optim.SGD(net.parameters(), lr=learning_rate)

