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/04/29 16:00:33 UTC

[GitHub] [incubator-mxnet] sxjscience opened a new issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken after https://github.com/apache/incubator-mxnet/pull/17283

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


   ```python
   import mxnet as mx
   mx.npx.set_np()
   from mxnet.gluon import nn
   net = nn.Dense(16, in_units=16)
   net.initialize()
   out = net(mx.np.ones((32, 16)))
   out.asnumpy()
   ```
   
   
   ~/mxnet/python/mxnet/numpy/random.py in uniform(low, high, size, dtype, ctx, out)
       135     inequality condition.
       136     """
   --> 137     return _mx_nd_np.random.uniform(low, high, size=size, ctx=ctx, dtype=dtype, out=out)
       138 
       139 
   
   ~/mxnet/python/mxnet/ndarray/numpy/random.py in uniform(low, high, size, dtype, ctx, out)
       135     if size == ():
       136         size = None
   --> 137     return _api_internal.uniform(low, high, size, ctx, dtype, out)
       138 
       139 
   
   ~/mxnet/python/mxnet/_ffi/_ctypes/function.py in __call__(self, *args)
       113                 self.handle, values, tcodes, ctypes.c_int(num_args),
       114                 ctypes.byref(ret_val), ctypes.byref(ret_tcode)) != 0:
   --> 115             raise get_last_ffi_error()
       116         _ = temp_args
       117         _ = args
   
   Error:
   ```
   MXNetError: Traceback (most recent call last):
     File "../src/imperative/./imperative_utils.h", line 251
   MXNetError: Check failed: outputs[i]->dtype() == out_types[i] (0 vs. 1) : 0-th output has invalid dtype. Expecting 1 got 0 in operator _npi_uniform
   ```
   


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



[GitHub] [incubator-mxnet] JiangZhaoh commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
JiangZhaoh commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621577944


   I have found the reason. It because `set_np()` only change the mxnet.numpy functions to default dtype as float64, but doesn't effect mxnet.ndarray functions which still default float32.
   The issue mentioned above just like this code:
   ```
   >>> import mxnet
   >>> from mxnet import numpy as np
   >>> from mxnet import ndarray as nd
   >>> from mxnet import npx
   >>> npx.set_np()
   >>> a = nd.zeros(5)
   >>> a.dtype
   <class 'numpy.float32'>
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/home/ubuntu/mxnet/python/mxnet/numpy/random.py", line 137, in uniform
       return _mx_nd_np.random.uniform(low, high, size=size, ctx=ctx, dtype=dtype, out=out)
     File "/home/ubuntu/mxnet/python/mxnet/ndarray/numpy/random.py", line 145, in uniform
       return _api_internal.uniform(low, high, size, ctx, dtype, out)
     File "mxnet/_ffi/_cython/./function.pxi", line 188, in mxnet._ffi._cy3.core.FunctionBase.__call__
     File "mxnet/_ffi/_cython/./function.pxi", line 133, in mxnet._ffi._cy3.core.FuncCall
     File "mxnet/_ffi/_cython/./base.pxi", line 90, in mxnet._ffi._cy3.core.CALL
   mxnet.base.MXNetError: Traceback (most recent call last):
     File "../src/imperative/./imperative_utils.h", line 251
   MXNetError: Check failed: outputs[i]->dtype() == out_types[i] (0 vs. 1) : 0-th output has invalid dtype. Expecting 1 got 0 in operator _npi_uniform
   >>> npx.set_np(dtype = False)
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   [0.09762704 0.18568921 0.43037868 0.6885315  0.20552671]
   <NDArray 5 @cpu(0)>
   ```
   So, I think I'd better not to set `dtype=True` flag in `npx.set_np()`, seperate this flag along in a single function `npx.set_numpy_default_dtype()` instead. Or if there any other better solutions, please tell me. 


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



[GitHub] [incubator-mxnet] sxjscience commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621306354


   @yzhliu @JiangZhaoh @szha 


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



[GitHub] [incubator-mxnet] sxjscience edited a comment on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
sxjscience edited a comment on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621534184


   @szha For example, https://github.com/apache/incubator-mxnet/blob/73d1b055d04a0f0f511a9cc2dd46ae2eb03a8628/tests/python/unittest/test_numpy_gluon.py#L382-L411 I think there are tests in `test_numpy_gluon.py` that will capture this.


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



[GitHub] [incubator-mxnet] sxjscience commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621548153


   OK, so this is not related to CI.


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



[GitHub] [incubator-mxnet] yzhliu commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
yzhliu commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621501382


   Assignee: @JiangZhaoh 


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



[GitHub] [incubator-mxnet] szha commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
szha commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621533240


   which tests were supposed to catch this issue?


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



[GitHub] [incubator-mxnet] sxjscience commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621588139


   I think one of the root cause is that gluon optimizer and initializer are still using the legacy NDArray. We should fix that.
   
   Get Outlook for iOS<https://aka.ms/o0ukef>
   ________________________________
   From: JiangZhaoh <no...@github.com>
   Sent: Wednesday, April 29, 2020 7:37:14 PM
   To: apache/incubator-mxnet <in...@noreply.github.com>
   Cc: Xingjian SHI <xs...@connect.ust.hk>; Author <au...@noreply.github.com>
   Subject: Re: [apache/incubator-mxnet] [Bug][Numpy] Very basic functionality of Gluon is broken (#18193)
   
   
   I have found the reason. It because set_np() only change the mxnet.numpy functions to default dtype as float64, but doesn't effect mxnet.ndarray functions which still default float32.
   The issue mentioned above just like this code:
   
   >>> import mxnet
   >>> from mxnet import numpy as np
   >>> from mxnet import ndarray as nd
   >>> from mxnet import npx
   >>> npx.set_np()
   >>> a = nd.zeros(5)
   >>> a.dtype
   <class 'numpy.float32'>
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/home/ubuntu/mxnet/python/mxnet/numpy/random.py", line 137, in uniform
       return _mx_nd_np.random.uniform(low, high, size=size, ctx=ctx, dtype=dtype, out=out)
     File "/home/ubuntu/mxnet/python/mxnet/ndarray/numpy/random.py", line 145, in uniform
       return _api_internal.uniform(low, high, size, ctx, dtype, out)
     File "mxnet/_ffi/_cython/./function.pxi", line 188, in mxnet._ffi._cy3.core.FunctionBase.__call__
     File "mxnet/_ffi/_cython/./function.pxi", line 133, in mxnet._ffi._cy3.core.FuncCall
     File "mxnet/_ffi/_cython/./base.pxi", line 90, in mxnet._ffi._cy3.core.CALL
   mxnet.base.MXNetError: Traceback (most recent call last):
     File "../src/imperative/./imperative_utils.h", line 251
   MXNetError: Check failed: outputs[i]->dtype() == out_types[i] (0 vs. 1) : 0-th output has invalid dtype. Expecting 1 got 0 in operator _npi_uniform
   >>> npx.set_np(dtype = False)
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   [0.09762704 0.18568921 0.43037868 0.6885315  0.20552671]
   <NDArray 5 @cpu(0)>
   
   
   So, I think I'd better not to set dtype=True flag in npx.set_np(), seperate this flag along in a single function npx.set_numpy_default_dtype() instead. Or if there any other better solutions, please tell me.
   
   —
   You are receiving this because you authored the thread.
   Reply to this email directly, view it on GitHub<https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621577944>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABHQH3R5XJLVP76L7A6LBD3RPDP5VANCNFSM4MT3GKPQ>.
   


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



[GitHub] [incubator-mxnet] JiangZhaoh commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
JiangZhaoh commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621547683


   That's my issue. In order to not effect original tests, I didn't change the decorator "use_np", which still use `return use_np_shape(use_np_array(func))`. But in npx.set_np() I default flag `dtype` as `True` and then `set_np_default_dtype(dtype)`.
   Details in /mxnet/python/mxnet/util.py
   


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



[GitHub] [incubator-mxnet] sxjscience commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
sxjscience commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621534184


   @szha For example, https://github.com/apache/incubator-mxnet/blob/73d1b055d04a0f0f511a9cc2dd46ae2eb03a8628/tests/python/unittest/test_numpy_gluon.py#L382-L411 I think there are tests in `test_numpy_gluon.py` that will capture this. Let me confirm.


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



[GitHub] [incubator-mxnet] yzhliu closed issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
yzhliu closed issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193


   


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



[GitHub] [incubator-mxnet] JiangZhaoh commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
JiangZhaoh commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621530470


   Sorry for that. I'll fix it as soon as possible.


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



[GitHub] [incubator-mxnet] JiangZhaoh edited a comment on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
JiangZhaoh edited a comment on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-621577944


   I have found the reason. It because `set_np()` only change the mxnet.numpy functions to default dtype as float64, but doesn't effect mxnet.ndarray functions which still default float32.
   The issue mentioned above just like this code:
   ```
   >>> import mxnet
   >>> from mxnet import numpy as np
   >>> from mxnet import ndarray as nd
   >>> from mxnet import npx
   >>> npx.set_np()
   >>> a = nd.zeros(5)
   >>> a.dtype
   <class 'numpy.float32'>
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/home/ubuntu/mxnet/python/mxnet/numpy/random.py", line 137, in uniform
       return _mx_nd_np.random.uniform(low, high, size=size, ctx=ctx, dtype=dtype, out=out)
     File "/home/ubuntu/mxnet/python/mxnet/ndarray/numpy/random.py", line 145, in uniform
       return _api_internal.uniform(low, high, size, ctx, dtype, out)
     File "mxnet/_ffi/_cython/./function.pxi", line 188, in mxnet._ffi._cy3.core.FunctionBase.__call__
     File "mxnet/_ffi/_cython/./function.pxi", line 133, in mxnet._ffi._cy3.core.FuncCall
     File "mxnet/_ffi/_cython/./base.pxi", line 90, in mxnet._ffi._cy3.core.CALL
   mxnet.base.MXNetError: Traceback (most recent call last):
     File "../src/imperative/./imperative_utils.h", line 251
   MXNetError: Check failed: outputs[i]->dtype() == out_types[i] (0 vs. 1) : 0-th output has invalid dtype. Expecting 1 got 0 in operator _npi_uniform
   >>> npx.set_np(dtype = False)
   >>> np.random.uniform(low = -1, high = 1, size = (5), out = a)
   [0.09762704 0.18568921 0.43037868 0.6885315  0.20552671]
   <NDArray 5 @cpu(0)>
   ```
   So, I think I'd better **not** to set `dtype=True` flag in `npx.set_np()`, seperate this flag along in a single function `npx.set_numpy_default_dtype()` instead. Or if there any other better solutions, please tell me. 


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



[GitHub] [incubator-mxnet] yzhliu commented on issue #18193: [Bug][Numpy] Very basic functionality of Gluon is broken

Posted by GitBox <gi...@apache.org>.
yzhliu commented on issue #18193:
URL: https://github.com/apache/incubator-mxnet/issues/18193#issuecomment-631749885


   should be resolved by #18200 


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