title: Why by changing tensor using detach method make backpropagation not always unable to work in pytorch?
body: <p>After constructing a graph, when using the <code>detach</code> method to change some tensor value, it is expected that an error pops up when computing the back propagation. However, this is not always the case. In the following two blocks of code: the first one raises an error, while the second one does not. Why does this happen?</p>
  <pre><code>x = torch.tensor(3.0, requires_grad=True)
  y = x + 1
  z = y**2
  c = y.detach()
  c.zero_()
  z.backward(retain_graph=True)
  print(x.grad) # errors pop up
  </code></pre>
  <pre><code>x = torch.tensor(3.0, requires_grad=True)
  y1 = x+1
  y2 = x**2
  z = 3*y1 + 4*y2
  c = y2.detach()
  c.zero_()
  z.backward(retain_graph=True)
  print(x.grad) # no errors. The printed value is 27
  </code></pre>