You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/10/03 16:36:47 UTC
[GitHub] altosaar commented on issue #8130: autograd.backward() segfaults: how to get gradients with respect to a subset of variables in mxnet?
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:
users@infra.apache.org
With regards,
Apache Git Services