You can try to empty the cache if you need it for other applications using the GPU memory.
If you just use the GPU for the model training in PyTorch, you don’t need to call it.
It seems you are saving some unnecessary computation graphs in the test procedure:
test_mse=test_mse+t_loss

Here t_loss was calculated from your criterion, so you are adding the graph to test_mse every time you call it.
Change this line to test_mse = test_mse + t_loss.data[0] and see if the out of memory error still occurs.