Could you check, if you are storing the output, loss or any other tensors, which might be attached to the computation graph in a list, dict or any other container?
If so, you should .detach() these tensors before storing them, as the whole computation graph would be stored as well otherwise.