title: Pytorch 1.6.0 - RuntimeError: CUDA error: device-side assert triggered where (predicted==labels)
body: <p>When I run this function:</p>
  <pre><code>def evaluate(model, dataloader, calc_loss=False):
  '''
  Helper function to get classification accuracy and (optional) loss for a model over the items in dataloader
  This function can just return the accuracy, or calculate the losses if &quot;calc_loss&quot; is set to &quot;True&quot;
  '''
  correct = 0
  total = 0
  losses = []
  
  # don't compute gradients
  with torch.no_grad():
      for batch in dataloader:
          
          inputs, labels = batch
          # forward pass through the model
          outputs = model(inputs)
          print('pass 1')
          # calculate loss if parameter set to True
          if (calc_loss==True):            
              loss = F.cross_entropy(outputs, labels)   # Calculate loss
              losses.append(loss.detach)
          
          # Get the prediction of the net on the images
          print('pass 2')
          _, predicted = torch.max(outputs.data, dim=1)
          total += labels.size(0)
  
          # Count those we got correct
          right = torch.sum(predicted==labels).item()
          
          print('pass 3', right)
          break
          
      # calculate total correct cases
      acc = 100 * correct / total
  return losses, acc
  </code></pre>
  <p>Here is what i plug in and get back:</p>
  <pre><code>evaluate(model_1, dataloader=val_dl, calc_loss=True)
  </code></pre>
  <p>Results:</p>
  <blockquote>
  <pre><code>pass 1
  pass 2
  ---------------------------------------------------------------------------
  RuntimeError                              Traceback (most recent call last)
  &lt;ipython-input-22-881e9c4f2402&gt; in &lt;module&gt;
        1 os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
  ----&gt; 2 evaluate(model_1, dataloader=val_dl, calc_loss=True)
  
  &lt;ipython-input-15-edcb180f1931&gt; in evaluate(model, dataloader, calc_loss)
       29 
       30             # Count those we got correct
  ---&gt; 31             right = torch.sum(predicted==labels).item()
       32 
       33             print('pass 3', right)
  
  RuntimeError: CUDA error: device-side assert triggered
  </code></pre>
  </blockquote>
  <p>It seems to be getting this error where the predict==labels are at, but when I run that code in isolation (outside of the for loop / function) it runs everything perfectly. Any ideas?</p>