Incubator-mxnet: Type inference bug of negation

Created on 27 May 2020  路  2Comments  路  Source: apache/incubator-mxnet

import mxnet as mx
mx.npx.set_np()
a = mx.np.ones((10, 10), dtype=mx.np.int32)
b = -a
print(b.dtype)

Output:

float64
Bug Numpy WIP v2.0

Most helpful comment

@sxjscience

Thanks for your issue, I was able to reproduce this issue on my device, we discovered that the cause of this problem is https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/numpy/multiarray.py#L988, where the origin tensor would be multiplied by -1.0 when calling negation.

I believe this problem could be resolved by changing -1.0 to -1, as the backend is now able to perform type promotion for scalar-tensor binary ops, which should return a value of type int32.

I will create a fix for this issue.

All 2 comments

@sxjscience

Thanks for your issue, I was able to reproduce this issue on my device, we discovered that the cause of this problem is https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/numpy/multiarray.py#L988, where the origin tensor would be multiplied by -1.0 when calling negation.

I believe this problem could be resolved by changing -1.0 to -1, as the backend is now able to perform type promotion for scalar-tensor binary ops, which should return a value of type int32.

I will create a fix for this issue.

@CassiniXu thanks for finding the root cause. In terms of the solution, I'm not sure if multiply is the right way to go. After all, we don't want int8 number to be promoted to int32 when being negated. How about implementing a negation kernel?

Was this page helpful?
0 / 5 - 0 ratings