apache / mxnet

Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler; for Python, R, Julia, Scala, Go, Javascript and more
https://mxnet.apache.org
Apache License 2.0
20.78k stars 6.79k forks source link

mxnet.ndarray.from_numpy() throws error for float16 dtype #17218

Open OliverColeman opened 4 years ago

OliverColeman commented 4 years ago

Description

When trying to convert a numpy array with dtype float16 I get the error below. I looked through the code and it looks like it should be supported, but I've tried the latest production release (mxnet-cu101==1.5.1.post0) and the latest pre-release (mxnet-cu101==1.6.0b20191029) with no success.

Error Message

ValueError                                Traceback (most recent call last)
<ipython-input-3-699ed656d29b> in <module>
      3 
      4 a = np.zeros((1, 1), dtype=np.float16)
----> 5 b = mx.ndarray.from_numpy(a)

/opt/conda/lib/python3.7/site-packages/mxnet/ndarray/ndarray.py in from_numpy(ndarray, zero_copy)
   4268         raise ValueError("Only c-contiguous arrays are supported for zero-copy")
   4269     ndarray.flags['WRITEABLE'] = False
-> 4270     c_obj = _make_dl_managed_tensor(ndarray)
   4271     handle = NDArrayHandle()
   4272     check_call(_LIB.MXNDArrayFromDLPackEx(ctypes.byref(c_obj), True, ctypes.byref(handle)))

/opt/conda/lib/python3.7/site-packages/mxnet/ndarray/ndarray.py in _make_dl_managed_tensor(array)
   4257     def _make_dl_managed_tensor(array):
   4258         c_obj = DLManagedTensor()
-> 4259         c_obj.dl_tensor = _make_dl_tensor(array)
   4260         c_obj.manager_ctx = _make_manager_ctx(array)
   4261         c_obj.deleter = dl_managed_tensor_deleter

/opt/conda/lib/python3.7/site-packages/mxnet/ndarray/ndarray.py in _make_dl_tensor(array)
   4244     def _make_dl_tensor(array):
   4245         if str(array.dtype) not in DLDataType.TYPE_MAP:
-> 4246             raise ValueError(str(array.dtype) + " is not supported.")
   4247         dl_tensor = DLTensor()
   4248         dl_tensor.data = array.ctypes.data_as(ctypes.c_void_p)

ValueError: float16 is not supported.

To Reproduce

import numpy as np
import mxnet as mx
a = np.zeros((1, 1), dtype=np.float16)
b = mx.ndarray.from_numpy(a)

Environment

----------Python Info----------
Version      : 3.7.4
Compiler     : GCC 7.3.0
Build        : ('default', 'Aug 13 2019 20:35:49')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 19.2.3
Directory    : /opt/conda/lib/python3.7/site-packages/pip
----------MXNet Info-----------
Version      : 1.5.1
Directory    : /opt/conda/lib/python3.7/site-packages/mxnet
Num GPUs     : 2
Commit Hash   : c9818480680f84daa6e281a974ab263691302ba8
----------System Info----------
Platform     : Linux-4.15.0-55-generic-x86_64-with-debian-buster-sid
system       : Linux
node         : axl1
release      : 4.15.0-55-generic
version      : #60-Ubuntu SMP Tue Jul 2 18:22:20 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):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           AuthenticAMD
CPU family:          23
Model:               17
Model name:          AMD Ryzen 3 2200G with Radeon Vega Graphics
Stepping:            0
CPU MHz:             1439.174
CPU max MHz:         3500.0000
CPU min MHz:         1600.0000
BogoMIPS:            6986.88
Virtualization:      AMD-V
L1d cache:           32K
L1i cache:           64K
L2 cache:            512K
L3 cache:            4096K
NUMA node0 CPU(s):   0-3
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 mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx hw_pstate sme ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0203 sec, LOAD: 0.6295 sec.
Timing for GluonNLP GitHub: https://github.com/dmlc/gluon-nlp, DNS: 0.0064 sec, LOAD: 0.5858 sec.
Timing for GluonNLP: http://gluon-nlp.mxnet.io, DNS: 0.2835 sec, LOAD: 1.0021 sec.
Timing for D2L: http://d2l.ai, DNS: 0.3187 sec, LOAD: 0.2566 sec.
Timing for D2L (zh-cn): http://zh.d2l.ai, DNS: 0.0743 sec, LOAD: 0.3067 sec.
Timing for FashionMNIST: https://repo.mxnet.io/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.2324 sec, LOAD: 0.7845 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.1998 sec, LOAD: 1.2013 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0397 sec, LOAD: 0.3711 sec.
wkcn commented 4 years ago

Thank you for the report: ) I will check it.

wkcn commented 4 years ago

The bug has been fixed in the PR https://github.com/apache/incubator-mxnet/pull/16234 on Nov. 22, 2019. However, the version of the nightly-build mxnet-cu101mkl is 20191006, and the version of the nightly-build mxnet-cu101 is 20191122.

MXNet installed by pip install mxnet-cu101 --pre works.

Hi @yajiedesign , could you please help update these nightly-build packages? Thanks a lot : )

OliverColeman commented 4 years ago

That got it, thanks :)

yajiedesign commented 4 years ago

@wkcn hi.now the old windows build system has been borken.We will move the night release to S3, which is currently in progress and will take some time.

wkcn commented 4 years ago

@yajiedesign Thank you! It seems that the build system for Linux CUDA10.1 has been broken too. The version of nightly-built MXNet CUDA10.1 Linux is built on 20191122.