In my understanding, from your code, I can see that you are not using any loss function to back propagate and just running the forward calls for 30 mini-batches. If thats the case, the computation graphs are never cleared out of your RAM and they are still residing in the RAM. If you do not wish to back propagate, call the models under with torch.no_grad() decorator, which will avoid creation of computation graphs.