Hi there,
PyTorch dynamically generates the computational graph which represents the neural network. In short, PyTorch does not know that your validation set is a validation set.
In order not to compute the backward over the validation set you need to use
with torch.no_grad():
      validation_operations ...

It means torch shouldn’t keep tracking of gradients for those operations.
You also may want to use model.eval() which turns your model into evaluation mode, deactivating batch normalization layers nor dropout.
remember to set model.train() before computing training operations.
Edit,
When you attach loss to the list, you are also picking the history of the loss, not only the numerical data. That’s why you get out of memory after certain amonut of iterations.
Use  loss += loss.item() to catch just the number.
Regards