I moved model.cuda and model.cross_entropy_loss outside the for loop but I am still getting the out of memory error. The exact is error message is posted below.

RuntimeError: cuda runtime error (2) : out of memory at/pytorch/torch/lib/THC/generic/THCStorage.cu:58