It’s unclear to me under what circumstances .grad will have a value


seems like it is ‘optimized out’ sometimes?


How to either request it not be ‘optimized out’ and / or obtain the value via some othre means?
In [36]: a = autograd.Variable(torch.rand(2), requires_grad=True)
In [37]: a.grad
In [38]: b = a * 2
In [39]: c = b * 2
In [40]: c.backward(torch.ones(2))
In [41]: c.grad
In [42]: b.grad
In [43]: a.grad
Out[43]:
Variable containing:
4
4
[torch.FloatTensor of size 2]
In [44]: b.requires_grad
Out[44]: True
In [45]: c.requires_grad
Out[45]: True