altosaar commented on issue #8130: autograd.backward() segfaults: how to get gradients with respect to a subset of variables in mxnet? URL: https://github.com/apache/incubator-mxnet/issues/8130#issuecomment-333903906 Thanks @piiswrong ! I installed the newest mxnet (`pip install --pre mxnet`). Here is a reproducible example based on what you suggested: ``` In [49]: from mxnet import nd, autograd In [50]: x = nd.array([1.]) In [51]: z = nd.array([1.]) In [52]: x.attach_grad() In [53]: z.attach_grad() In [54]: with autograd.record(): ...: first = nd.square(x) ...: second = nd.square(z) ...: y = first + second ...: autograd.grad(y, [x], retain_graph=True) ...: autograd.grad(y, [z]) ...: In [56]: x.grad Out[56]: [ 0.] <NDArray 1 @cpu(0)> In [57]: z.grad Out[57]: [ 0.] <NDArray 1 @cpu(0)> ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org
With regards, Apache Git Services