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 2019/09/27 18:06:10 UTC

[GitHub] [incubator-mxnet] igolan opened a new issue #16301: mxnet.initializer.Constant with NDArray as input does not work with hybridize

igolan opened a new issue #16301: mxnet.initializer.Constant with NDArray as input does not work with hybridize
URL: https://github.com/apache/incubator-mxnet/issues/16301
 
 
   ## Description
   Hi,
   Using `mxnet.initializer.Constant` with NDArray as input does not work with hybridize, but according to the [mxnet.initializer.Constant documentation](https://beta.mxnet.io/api/gluon-related/_autogen/mxnet.initializer.Constant.html?highlight=initializer.constant#mxnet.initializer.Constant) it can get both float and NDArray.
   
   
   ## Environment info (Required)
   
   ```
   ----------Python Info----------
   Version      : 3.6.5
   Compiler     : GCC 7.2.0
   Build        : ('default', 'Apr 29 2018 16:14:56')
   Arch         : ('64bit', '')
   ------------Pip Info-----------
   Version      : 10.0.1
   Directory    : /home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/pip
   ----------MXNet Info-----------
   Version      : 1.4.1
   Directory    : /home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet
   Commit hash file "/home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/COMMIT_HASH" not found. Not installed from pre-built package or built from source.
   Library      : ['/home/ubuntu/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so']
   Build features:
   No runtime build feature info available
   ----------System Info----------
   Platform     : Linux-4.4.0-1092-aws-x86_64-with-debian-stretch-sid
   system       : Linux
   node         : ip-XXX-XX-X-XXX
   release      : 4.4.0-1092-aws
   version      : #103-Ubuntu SMP Tue Aug 27 10:21:48 UTC 2019
   ----------Hardware Info----------
   machine      : x86_64
   processor    : x86_64
   Architecture:          x86_64
   CPU op-mode(s):        32-bit, 64-bit
   Byte Order:            Little Endian
   CPU(s):                32
   On-line CPU(s) list:   0-31
   Thread(s) per core:    2
   Core(s) per socket:    16
   Socket(s):             1
   NUMA node(s):          1
   Vendor ID:             GenuineIntel
   CPU family:            6
   Model:                 79
   Model name:            Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz
   Stepping:              1
   CPU MHz:               2699.984
   CPU max MHz:           3000.0000
   CPU min MHz:           1200.0000
   BogoMIPS:              4600.08
   Hypervisor vendor:     Xen
   Virtualization type:   full
   L1d cache:             32K
   L1i cache:             32K
   L2 cache:              256K
   L3 cache:              46080K
   NUMA node0 CPU(s):     0-31
   Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx xsaveopt
   ----------Network Test----------
   Setting timeout: 10
   Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0018 sec, LOAD: 0.5233 sec.
   Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.1289 sec, LOAD: 0.4413 sec.
   Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.2271 sec, LOAD: 0.5561 sec.
   Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0098 sec, LOAD: 0.4055 sec.
   Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0145 sec, LOAD: 0.3227 sec.
   Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0135 sec, LOAD: 0.0799 sec.
   ----------Environment----------
   
   
   ```
   
   Package used Python with MXNET1.4.1
   
   ## Build info (Required if built from source)
   N/A
   
   ## Error Message:
   ```
   Traceback (most recent call last):
     File "/Users/XX/PycharmProjects/XX/playground.py", line 29, in <module>
       out = net(data)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/block.py", line 540, in __call__
       out = self.forward(*args)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/block.py", line 907, in forward
       return self._call_cached_op(x, *args)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/block.py", line 797, in _call_cached_op
       self._build_cache(*args)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/block.py", line 749, in _build_cache
       data, out = self._get_graph(*args)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/XX/gluon/block.py", line 739, in _get_graph
       params = {i: j.var() for i, j in self._reg_params.items()}
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/block.py", line 739, in <dictcomp>
       params = {i: j.var() for i, j in self._reg_params.items()}
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/gluon/parameter.py", line 555, in var
       init=self.init, stype=self._stype)
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/symbol/symbol.py", line 2543, in var
       init = init.dumps()
     File "/Users/XX/PycharmProjects/XX/venv/lib/python3.7/site-packages/mxnet/initializer.py", line 116, in dumps
       return json.dumps([self.__class__.__name__.lower(), self._kwargs])
     File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 231, in dumps
       return _default_encoder.encode(obj)
     File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
       chunks = self.iterencode(o, _one_shot=True)
     File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
       return _iterencode(o, 0)
     File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
       raise TypeError(f'Object of type {o.__class__.__name__} '
   TypeError: Object of type NDArray is not JSON serializable
   ```
   
   ## Minimum reproducible example
   ```
   import mxnet as mx
   from mxnet import nd, autograd, gluon
   
   
   class LYR(gluon.HybridBlock):
       def __init__(self, **kwargs):
           super(LYR, self).__init__(**kwargs)
           with self.name_scope():
               # Not working:
               self.w1 = self.params.get('w1', shape=(1),
                                                      init=mx.initializer.Constant(mx.ndarray.array([33])),
                                                      grad_req='null')
               # Working:
               # self.w1 = self.params.get('w1', shape=(1),
               #                                        init=mx.initializer.Constant(33),
               #                                        grad_req='null')
   
       def hybrid_forward(self, F, x, w1):
           out = F.broadcast_mul(w1, x)
           return out
   
   model_ctx = mx.cpu()
   net = LYR()
   
   net.collect_params().initialize(mx.init.Constant([1]), ctx=model_ctx)
   net.hybridize()
   
   data = nd.ones((128, 64, 16, 16)).as_in_context(model_ctx)
   out = net(data)
   ```
   
   ## Steps to reproduce
   Run the code above.
   
   ## What have you tried to solve it?
   N/A
   

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


With regards,
Apache Git Services