title: GPU out of memory on evaluation : Pytorch
body: <p>The model trains fine when I only train and don't validate, however it runs out of memory during evaluation, but I don't understand why this might be a problem especially since I am using <code>torch.no_grad()</code> any ideas?</p>
  <pre class="lang-py prettyprint-override"><code>def test(epoch,net,testloader,optimizer):
      net.eval()
      test_loss = 0
      correct = 0
      total = 0
      idx = 0
      features_all = []
      for batch_idx, (inputs, targets) in enumerate(testloader):
          with torch.no_grad():
              idx = batch_idx
              # inputs, targets = inputs.cpu(), targets.cpu()
              if use_cuda:
                  inputs, targets = inputs.cuda(), targets.cuda()
              inputs, targets = Variable(inputs), Variable(targets)
              save_features, out, ce_loss = net(inputs,targets)
              test_loss += ce_loss.item()
              _, predicted = torch.max(out.data, 1)
              total += targets.size(0)
              correct += predicted.eq(targets.data).cpu().sum().item()
              features_all.append((save_features, predicted, targets.data))
      test_acc = 100.*correct/total
      test_loss = test_loss/(idx+1)
      logging.info('test, test_acc = %.4f,test_loss = %.4f' % (test_acc,test_loss))
      print('test, test_acc = %.4f,test_loss = %.4f' % (test_acc,test_loss))
      return features_all, test_acc
  </code></pre>