Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Type inference bug of negation #18414

Closed
sxjscience opened this issue May 27, 2020 · 2 comments · Fixed by #18467
Closed

Type inference bug of negation #18414

sxjscience opened this issue May 27, 2020 · 2 comments · Fixed by #18467

Comments

@sxjscience
Copy link
Member

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
@ryanwentaoxu
Copy link
Contributor

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

@szha
Copy link
Member

szha commented May 27, 2020

@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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants