I am not sure where to put Autograd?
My training and evaluation part is as follows:
for epoch in range(n_epochs):

    # X is a torch Variable
    permutation1 = torch.randperm(new_x_train.size()[0])

    for i in range(0,new_x_train.size()[0], batch_size):
        

        indices1 = permutation1[i:i+batch_size]
        batch_x_train, batch_y_train = new_x_train[indices1], new_y_train[indices1]

        # in case you wanted a semi-full example
        model.train()
        print(i)
        outputs = model.forward(batch_x_train)
        train_loss = criterion(outputs,batch_y_train)

        optimizer.zero_grad()
        train_loss.backward()
        optimizer.step()
        
        loss_train.append(train_loss.item())
        
    model.eval()
    y_pred = model(new_x_val)
    val_loss = criterion(y_pred, new_y_val)