Oh my.
So many indent problems in your code.
You should have put your error code here.
Your code is fine, I think you forgot to set self.nb_layers.
Also, I think it is better to use torch.nn.Sequential 125
The editor is really hard to use… I also got some indent problems with pasting my code.
import torch
from torch import nn
from torch.autograd import Variable
from torch.nn import functional as F


class DNN(nn.Module):
def __init__(self, nb_layers, nb_units, input_dim, output_dim):
    super(DNN, self).__init__()
    fc = []
    self.nb_layers = nb_layers
    for i in range(nb_layers):
        if i == 0:
            fc.append(nn.Linear(input_dim, nb_units))
        elif i == nb_layers-1:
            fc.append(nn.Linear(nb_units, output_dim))
        else:
            fc.append(nn.Linear(nb_units, nb_units))
    self.fc = fc

def forward(self, x):
    for i in range(self.nb_layers):
        if i == self.nb_layers-1:
             x = F.sigmoid(self.fc[i](x))
        else:
             x = F.relu(self.fc[i](x))
    return x

a = DNN(3, 100, 500, 500)

input = Variable(torch.Tensor(10, 500))

output = a(input)