title: one of the variables needed for gradient computation has been modified by an inplace operation : can't find inplace operation
body: <blockquote>
  <p>I have this code below and I can't find the inplace operation that prevents the gradient from computing.</p>
  </blockquote>
  <pre><code>for epoch in range(nepoch):
      model.train()
      scheduler.step()
  
      for batch1 in loader1:
          torch.ones(len(batch1[0]), dtype=torch.float)
          x, label = batch1
          x = x1.to('cuda', non_blocking=True)
          optimizer.zero_grad()
          pred = model(x)
          pred = pred.squeeze() if pred.ndimension() &gt; 1 else pred
          label = (label.float()).cuda(cuda0)
          weights = torch.ones(len(label))
          loss_fun = torch.nn.BCEWithLogitsLoss(weight=weights.cuda(cuda0))
          score = loss_fun(pred, label)
          label = np.array(np.round(label.cpu().detach())).astype(bool)
          pred = np.array(pred.cpu().detach()&gt;0).astype(bool)
          torch.autograd.set_detect_anomaly(True)
  
          score.backward()
          optimizer.step()
  </code></pre>
  <p>At the end I have this error that pops up:</p>
  <pre><code>Warning: Error detected in MulBackward0. Traceback of forward call        that caused the error:
  File &quot;train.py&quot;, line 98, in &lt;module&gt;
    pred = model(x)
  File &quot;/home/anatole2/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py&quot;, line 550, in __call__
    result = self.forward(*input, **kwargs)
  File &quot;/home/anatole2/miniconda3/lib/python3.7/site-packages/torch/nn/modules/container.py&quot;, line 100, in forward
    input = module(input)
  File &quot;/home/anatole2/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py&quot;, line 550, in __call__
    result = self.forward(*input, **kwargs)
  File &quot;/home/anatole2/best/PCEN_pytorch.py&quot;, line 30, in forward
    filtered[i] = filtered[i] + (1-exp(self.log_s)) * filtered[i-1]
  (print_stack at /pytorch/torch/csrc/autograd/python_anomaly_mode.cpp:60)
  Traceback (most recent call last):
  File &quot;train.py&quot;, line 116, in &lt;module&gt;
    score.backward()
  File &quot;/home/anatole2/miniconda3/lib/python3.7/site-packages/torch/tensor.py&quot;, line 198, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File &quot;/home/anatole2/miniconda3/lib/python3.7/site-packages/torch/autograd/__init__.py&quot;, line 100, in backward
    allow_unreachable=True)  # allow_unreachable flag
  RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [16, 1, 80]], which is output 0 of SelectBackward, is at version 378; expected version 377 instead. Hint: the backtrace further above shows the operation that failed to compute its gradient. The variable in question was changed in there or anywhere later. Good luck!
  </code></pre>
  <p>If you could help me that'd be great !</p>