So, I’m trying to make sure that the computation graph is deleted after processing each batch, but none of the stuff I’ve tried seems to work:
model.eval()

for inputs, _ in loader:
      outputs = model(inputs)
      # Do stuff with outputs that requires grad
      x = some_func(outputs).detach()

      # Somehow delete computation graph

      del outputs
      model.zero_grad() # this doesn't seem to fix the memory problem.

Do I have to include backward() even though I don’t need to use it?