Directly getting gradients
Is there a way for me to directly compute the gradient of a variable w.r.t. another variable, like tf.gradients()?
yoonholee
<SCODE>import torch
from torch.autograd import Variable

x = Variable(torch.ones(10), requires_grad=True)
y = x * Variable(torch.linspace(1, 10, 10), requires_grad=False)
y.backward(torch.ones(10))
print(x.grad)
<ECODE> produces <SCODE>Variable containing:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
[torch.FloatTensor of size 10]<ECODE>
Tudor_Berariu
As far as I can tell, there’s no way of accomplishing this using y.backward(). That’s why I was wondering if there was a standalone function that differentiated.
yoonholee
alexis-jacq
we are working on enabling this. This will be in the next major pytorch release 2 months away. It wont be a full 2nd derivative but it will be the Hessian-vector product (whether it’s tf.gradients or in pytorch). We are tracking this feature as double-backprop / double backwards.
smth
vsahil
Dear PyTorch dev,
BruceShakeham
yf225
Yes it will. Hopefully this will be done in the next weeks !
albanD
Is this issue has be solved?
amitoz
albanD
Is it working? I tried that with v1.6. Same message with older versions.
rodsveiga
Hi,
albanD