Solved by Eta_C in post #2 
              
              
                [recommend] I think you can use nn.ModuleList instead of exec. 
example: 
# function __init__
self.hidden_list = nn.ModuleList()
for h in range(len(hidden_size) - 1):
    self.hidden_list.append(nn.Linear(self.hidden_size[h], self.hidden_size[h + 1]))

# function forward
for module in self.hidden_li…