You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/06/02 15:59:02 UTC

[GitHub] [incubator-mxnet] matteosal edited a comment on issue #18078: [Numpy] Gradient of np.prod is wrong when there are zeros in the array

matteosal edited a comment on issue #18078:
URL: https://github.com/apache/incubator-mxnet/issues/18078#issuecomment-637637711


   @yzhliu 
   Me and @zleyk22 spent some time investigating this and tracking it down. We managed to track it down to [this line](https://github.com/apache/incubator-mxnet/blob/master/src/operator/tensor/broadcast_reduce_op.h#L966).
   `OP::Map(data[i], DType(out[out_idx]))` computes `DType(out[out_idx]) / data[i]`, which returns nan when `data[i]` is zero (our input is `mx.nd.array([[4, 0]])`).
   
   The logic behind this computation is that (unless zeros are involved) dividing `x*y*z` by e.g. `x` gives you `y*z` which is the desired gradient. But this trick doesn't work when zeros are involved. In this case, the code should just recompute the entire product, leaving `x` out.
   
   But it seems that this infrastructure is quite rigid and only allows to re-use the previously-computed output and one single input element at a time. So it seems that fixing this bug would require some changes to this system, which is shared by more than one operator. Due to our low familiarity with the codebase, we don't think we are able to proceed further without a bit of guidance and help.
   
   Can you suggest a way forward? Thanks!


----------------------------------------------------------------
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:
users@infra.apache.org