Having problems with linear pytorch model initialization
I am trying to figure out what is wrong with my initialization of the neural network model. I have already set a pdb trace to see that the defining neural network part is the source of error. Also, I get yellow marks on the defining neural network code because the module is expected to be returned but if I return the module, it causes a recursion error. It is a linear model that has to have an input dimension of the batch size * 81 and an output dimension of the batch size * 1. I am relatively new at pytorch and defining deep neural networks so this may not be a good question. My syntax may also be very bad. Any help is appreciated. The code below is the defining of the neural network and training of the pytorch model.
def get_nnet_model(module_list=nn.ModuleList(), input_dim: int = 8100, layer_dim: int = 100) -&gt; nn.Module:
    &quot;&quot;&quot; Get the neural network model
    @return: neural network model
    &quot;&quot;&quot;
    device = torch.device('cpu')

    module_list.append(nn.Linear(input_dim, layer_dim))
    module_list[-1].weight.data.normal_(0, 0.1)
    module_list[-1].bias.data.zero_()


def train_nnet(nnet: nn.Module, states_nnet: np.ndarray, outputs: np.ndarray, batch_size: int = 100, num_itrs: int = 10000, train_itr: int = 10000, device: torch.device, lr=0.01, lr_d=1):
    nnet.train()

    criterion = nn.MSELoss()
    optimizer = optim.Adam(nnet.parameters(), lr=lr)

    while train_itr &lt; num_itrs:
        optimizer.zero_grad()

        lr_itr = lr + (lr_d ** train_itr)
        for param_group in optimizer.param_groups:
            param_group['lr'] = lr_itr

        data = pickle.load(open(&quot;data/data.pkl&quot;, &quot;rb&quot;))
        nnet_inputs_np, nnet_targets_np = data
        nnet_inputs_np = nnet_inputs_np.astype(np.float32)

        nnet_inputs = torch.tensor(nnet_inputs_np, device=device)
        nnet_targets = torch.tensor(nnet_targets_np, device=device)

        nnet_inputs = nnet_inputs.float()
        nnet_outputs = nnet(nnet_inputs)

        loss = criterion(nnet_outputs, nnet_targets)
        loss.backward()
        optimizer.step()


Based on your comment, somewhere else in your code you have something like:
nnet = get_nnet_model(...)

However, get_nnet_model(...) isn't returning anything. Change the def get_nnet_model to:
def get_nnet_model(module_list=nn.ModuleList(), input_dim: int = 8100, layer_dim: int = 100) -&gt; nn.Module:
    &quot;&quot;&quot; Get the neural network model
    @return: neural network model
    &quot;&quot;&quot;
    device = torch.device('cpu')

    module_list.append(nn.Linear(input_dim, layer_dim))
    module_list[-1].weight.data.normal_(0, 0.1)
    module_list[-1].bias.data.zero_()

    return module_list  # add this one

