matteosal commented on issue #20471:
URL: 
https://github.com/apache/incubator-mxnet/issues/20471#issuecomment-887596932


   I see the same sign flip with this other symbol (which can be fed to the 
same above script)
   [sym2.zip](https://github.com/apache/incubator-mxnet/files/6886594/sym2.zip)
   
   And with this one
   [sym3.zip](https://github.com/apache/incubator-mxnet/files/6886596/sym3.zip)
   Which goes with this script:
   ```
   import numpy as np
   import mxnet as mx
   
   json_path = 'sym3.json'
   sym = mx.sym.load(json_path)
   
   input_1 = np.random.rand(1, 2, 3, 4).tolist()
   input_2 = np.random.rand(1, 2, 4).tolist()
   input_3 = np.random.rand(1, 2).tolist()
   
   def run_example(ctx, reqs):
        ex = sym._bind(
                ctx,
                {
                        '.Inputs.Input1': mx.ndarray.array(input_1, ctx=ctx),
                        '.Inputs.Input2': mx.ndarray.array(input_2, ctx=ctx),
                        '.Inputs.Input3': mx.ndarray.array(input_3, ctx=ctx)
                },
                args_grad={
                        '.Inputs.Input1': mx.ndarray.zeros([1, 2, 3, 4], 
ctx=ctx),
                        '.Inputs.Input2': mx.ndarray.zeros([1, 2, 4], ctx=ctx),
                        '.Inputs.Input3': mx.ndarray.zeros([1, 2], ctx=ctx)
                },
                grad_req=dict(zip(['.Inputs.Input1', '.Inputs.Input2', 
'.Inputs.Input3'], reqs))
        )
   
        ex.forward()
        ex.backward(out_grads=[mx.ndarray.ones([1, 2, 3, 4], ctx=ctx)])
   
        print(ex.grad_dict['.Inputs.Input2'])
   
   print('Input1 + Input2 gradient, CPU (OK):')
   run_example(mx.cpu(), ['write', 'write', 'null'])
   print('\n')
   print('Input1 + Input2 gradient, GPU (OK):')
   run_example(mx.gpu(), ['write', 'write', 'null'])
   print('\n')
   print('Input2 gradient only, CPU (OK):')
   run_example(mx.cpu(), ['null', 'write', 'null'])
   print('\n')
   print('Input2 gradient only, GPU (WRONG):')
   run_example(mx.gpu(), ['null', 'write', 'null'])
   ```
   Output is
   ```
   Input1 + Input2 gradient, CPU (OK):
   
   [[[-3. -2. -3. -2.]
     [ 0. -2. -2. -3.]]]
   <NDArray 1x2x4 @cpu(0)>
   
   
   Input1 + Input2 gradient, GPU (OK):
   
   [[[-3. -2. -3. -2.]
     [ 0. -2. -2. -3.]]]
   <NDArray 1x2x4 @gpu(0)>
   
   
   Input2 gradient only, CPU (OK):
   
   [[[-3. -2. -3. -2.]
     [ 0. -2. -2. -3.]]]
   <NDArray 1x2x4 @cpu(0)>
   
   
   Input2 gradient only, GPU (WRONG):
   
   [[[3. 2. 3. 2.]
     [0. 2. 2. 3.]]]
   <NDArray 1x2x4 @gpu(0)>
   ```
   


-- 
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.

To unsubscribe, e-mail: [email protected]

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to