Solved by ptrblck in post #2 
              
              
                These lines of code will append to losses, which are still attached to the computation graph, and will thus increase the memory usage in each iteration: 
training_losses.append(total_train_loss) 
validation_losses.append(total_val_loss)

To store the loss value for printing or debugging purposes, yo…