Can you tell us what model you are using and also what batch size and what image size.
I have run your code on mobilenet with 128x128 images and batchsize 200 and it needs 5,6GB so 8 should be fine.


According to your error message you have 4GB and not 8GB of VRAM. Which is also what NVIDIAs website says the GTX1650 has.


Could you tell us what pytorch version you are using? I noticed you are using Variable() which has been deprecated since pytorch version 0.4.0


Is the error coming up right at the beginning or sometime later, during training? If it comes up later, it is usually a problem of accumulating tensors which still have there grad attached.
But since you are using runningLoss += loss.detach() I do not think this is the problem.


A few tips:
If your loss is a single value you can use loss.item() instead of loss.detach() it will give you a python number instead of a detached tensor, which is a bit more lightweight (it also detaches the grad obviously).
You can wrap your test code into with torch.no_grad():. This will make sure your tensors do not have a grad attached when testing (grad is not necessary during test since you are not backpropagating). You can do it like so:


with torch.no_grad():
    #code for getting test acc here