another thing that can make your memory explote is if you want to track the accumulate loss of the training set without optimizing and you do not call .data or torch.no_grad(). For instance
COST=Loss(y,net(x))
acc_cost+=COST #do not do this
acc_cost+=COST.data # do this


calling .data is deprecated, however for this little thing I still find it the easiest and simple way.