modeste2015 opened a new issue #18539:
URL: https://github.com/apache/incubator-mxnet/issues/18539


   `mxnet.executor.backward` gives false values of gradient. the gradient of 
`a` must be equal to `[2 2]` and the gradient of `b` must equal to  `[1 1]`. 
mxnet.executor.backward gives instead `[8 14]` and `[4 7]`. It seems the error 
do not come from python 
[file](https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/executor.py).
 The issue comes from c++ 
[file](https://github.com/apache/incubator-mxnet/blob/master/src/executor/graph_executor.cc)
  because result is the same in Julia. `mx.executor.backward` calls in fact 
`GraphExecutor::Backward`.
   ```python
   import mxnet as mx
   
   a = mx.sym.Variable('a')
   b = mx.sym.Variable('b')
   # c is not a loss function symbol
   c = 2 * a + b
   args = {'a': mx.nd.array([1,2]), 'b':mx.nd.array([2,3])}
   args_grad = {'a': mx.nd.zeros((2)), 'b': mx.nd.zeros((2))}
   texec = c.bind(ctx=mx.cpu(), args=args, args_grad=args_grad)
   out = texec.forward(is_train=True)[0].copy()
   print(out.asnumpy())
   # answer [ 4.  7.]
   # out_grads is the head gradient in backward pass.
   # Here we define 'c' as loss function.
   # Then 'out' is passed as head gradient of backward pass.
   texec.backward(out)
   print(texec.grad_arrays[0].asnumpy())
   # answer[ 8.  14.]
   print(texec.grad_arrays[1].asnumpy())
   # answer [ 4.  7.]
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to