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 <notificati...@github.com>
   Sent: Wednesday, April 29, 2020 7:37:14 PM
   To: apache/incubator-mxnet <incubator-mx...@noreply.github.com>
   Cc: Xingjian SHI <xsh...@connect.ust.hk>; Author <aut...@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:
us...@infra.apache.org


Reply via email to