Met the same problem a couple of days ago. This error happens because you use a different tensor for each iteration. As the input tensor changes, Pytorch creates a different computation graph in each iteration. For some reason I still don’t know, Pytorch doesn’t release the graph immediately. Soon the GPU RAM will run out. Solution: use the same tensor, and copy the input image into that tensor in each iteration.