Sorry if I misunderstood. Based on what you mentioned above:



 colesbury:

You can rewrite your program to avoid keeping two versions of out1 alive at once:
def eval(network, input):
  out1 = network(input)
  # maybe use out1 here

for i in range(10):
  eval(net, data1)

As long as you don’t return out1 from eval , out1 will be freed before the next call, so you’ll only use 2872Mi .


I took the prediction of output out of the for loop and as suggested used the output in that function and calculated loss and accuracy there and only returned the loss and predicted tensor. output was not returned from the function.
I would eventually have to assign the input in a for loop as that is how I would get data from mt DataLoader in order to pass to the evaluation function. I dont see how I would get this to work without returning loss for loss.backward() and without using a for loop fro the data loading.