title: Chainer.grad() how to implement this function in Pytorch
body: <p>I am writing to migrate code from chainer framework to pytorch. I came across the below code:</p>
  <pre class="lang-py prettyprint-override"><code>chainer.grad(
      [loss_func(F.clipped_relu(X2, z=1.0), Yp)],
      [X2],
      set_grad=True,
      retain_grad=True,
  )
  </code></pre>
  <p>I tired looking at the pytorch documentation but was not able to find an equivalent function to implement the above code.</p>
  <p><a href="https://docs.chainer.org/en/stable/reference/generated/chainer.grad.html" rel="nofollow noreferrer">https://docs.chainer.org/en/stable/reference/generated/chainer.grad.html</a></p>
  <p>The above link explains what this function does in chainer framework. I would appreciate if someone could guide me on how to go about migrating the above chainer code to pytorch.</p>