title: How to set gradients to Zero without optimizer?
body: <p>Between mutliple <code>.backward()</code> passes I'd like to set the gradients to zero. Right now I have to do this for every component seperately  (here these are <code>x</code> and <code>t</code>), is there a way to do this "globally" for all affected variables? (I imagine something like <code>z.set_all_gradients_to_zero()</code>.) </p>
  
  <p>I know there is <code>optimizer.zero_grad()</code> if you use an optimizer, but is there also a direct way without using an optimizer?</p>
  
  <pre><code>import torch
  
  x = torch.randn(3, requires_grad = True)
  t = torch.randn(3, requires_grad = True)
  y = x + t
  z = y + y.flip(0)
  
  z.backward(torch.tensor([1., 0., 0.]), retain_graph = True)
  print(x.grad)
  print(t.grad)
  x.grad.data.zero_()  # both gradients need to be set to zero 
  t.grad.data.zero_()
  z.backward(torch.tensor([0., 1., 0.]), retain_graph = True)
  print(x.grad)
  print(t.grad)
  </code></pre>