kpot commented on issue #8337: mx.autograd.grad works or fails depending on use 
of slices
URL: 
https://github.com/apache/incubator-mxnet/issues/8337#issuecomment-337796013
 
 
   @ZiyueHuang Yes, I think the empty line is indeed the argument `''`.
   But when I replace `mx.nd.ones_like(b)` with `mx.nd.ones((1,))` I still get 
the same error. Are you sure that when it worked for you, you actually did use 
slicing?
   
   Just to be on the same page, here's the full code that fails, even though I 
believe it shouldn't:
   ```
   import mxnet as mx
   from mxnet import nd, autograd
   
   ctx = mx.cpu()
   
   a = mx.nd.array([1, 2, 3, 4], ctx=ctx)
   a.attach_grad()
   
   with autograd.record():
       b = nd.sum(2 * (a[0:4] ** 2))   # works without slicing
   
   grads = autograd.grad(b, [a], create_graph=True, retain_graph=True)
   da_sym = autograd.get_symbol(grads[0])
   executor = da_sym.bind(ctx=ctx, args=[nd.ones_like(b), a])
   executor.forward()
   print(executor.outputs[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

Reply via email to