Depending on the used model the input might be alright or huge. Given that you are able to use ~50 iterations before the OOM is raised, I would recommend to check, if the memory usage is increasing inside the loop. If that’s the case you might (accidentally) store tensors attached to the computation graph and could try to isolate it by calling detach() on tensors.