title: Autograd.grad() for Tensor in pytorch
body: <p>I want to compute the gradient between two tensors in a net. The input X tensor (batch size x m) is sent through a set of convolutional layers which give me back and output Y tensor(batch size x n).</p>
  <p>I’m creating a new loss and I would like to know the gradient of Y w.r.t. X. Something that in tensorflow would be like:</p>
  <p><code>tf.gradients(ys=Y, xs=X)</code></p>
  <p>Unfortunately, I’ve been making tests with <code>torch.autograd.grad()</code>, but I could not figure out how to do it. I get errors like: <code>“RunTimeerror: grad can be implicitly created only for scalar outputs”</code>.</p>
  <p>What should be the inputs in <code>torch.autograd.grad()</code> if I want to know the gradient of Y w.r.t. X?</p>