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

TypeError: Block's inputs must be of type mxnet.numpy.ndarray ... #20442

Closed
EnricoMi opened this issue Jul 11, 2021 · 5 comments
Closed

TypeError: Block's inputs must be of type mxnet.numpy.ndarray ... #20442

EnricoMi opened this issue Jul 11, 2021 · 5 comments

Comments

@EnricoMi
Copy link

EnricoMi commented Jul 11, 2021

Description

One of our MXNet tests in Horovod started to fail on the nightly packages after 2021-06-20. Can you please point me to any breaking changes around that time that might cause this error and need some adoption on our side?

TypeError: Block's inputs must be of type `mxnet.numpy.ndarray`, while got output type <class 'mxnet.ndarray.ndarray.NDArray'>

Error Message

    def test_horovod_broadcast_deferred_init_parameters(self):
        """Test that the deferred initialized parameters are broadcasted."""
        hvd.init()
        root_rank = 0
        rank = hvd.rank()
    
        # This test does not apply if there is only one worker.
        if hvd.size() == 1:
            self.skipTest("Only one worker available")
    
        mx.random.seed(rank)
        layer = mx.gluon.nn.Conv2D(10, 2)
        layer.initialize()
        hvd.broadcast_parameters(layer.collect_params(), root_rank=root_rank)
    
        x = mx.nd.ones((5, 4, 10, 10))
>       layer(x)

test_mxnet.py:737: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.8/dist-packages/mxnet/util.py:299: in _with_np_shape
    return func(*args, **kwargs)
/usr/local/lib/python3.8/dist-packages/mxnet/util.py:481: in _with_np_array
    return func(*args, **kwargs)
/usr/local/lib/python3.8/dist-packages/mxnet/gluon/block.py:1578: in __call__
    _check_block_input_np_ndarrays([x, *args])
/usr/local/lib/python3.8/dist-packages/mxnet/gluon/utils.py:505: in _check_block_input_np_ndarrays
    _check_block_input_np_ndarrays(i)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

inputs = 
[[[[1. 1. 1. ... 1. 1. 1.]
   [1. 1. 1. ... 1. 1. 1.]
   [1. 1. 1. ... 1. 1. 1.]
   ...
   [1. 1. 1. ... 1. 1. 1.]
  ...
   ...
   [1. 1. 1. ... 1. 1. 1.]
   [1. 1. 1. ... 1. 1. 1.]
   [1. 1. 1. ... 1. 1. 1.]]]]
<NDArray 5x4x10x10 @cpu(0)>

    def _check_block_input_np_ndarrays(inputs):
        """Check if block's inputs are numpy ndarrays."""
        from ..numpy import ndarray as np_ndarray
        from ..symbol import Symbol as nd_symbol
        from ..ndarray import NDArray as nd_ndarray
    
        # pylint: disable=no-else-raise
        if isinstance(inputs, (nd_ndarray, nd_symbol)) and not isinstance(inputs, (np_ndarray)):
>           raise TypeError("Block's inputs must be of type `mxnet.numpy.ndarray`, "
                            "while got output type {}"
E                           TypeError: Block's inputs must be of type `mxnet.numpy.ndarray`, while got output type <class 'mxnet.ndarray.ndarray.NDArray'>

Environment

Environment Information
----------Python Info----------
Version      : 3.8.0
Compiler     : GCC 8.4.0
Build        : ('default', 'Feb 25 2021 22:10:10')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 21.1.3
Directory    : /usr/local/lib/python3.8/dist-packages/pip
----------MXNet Info-----------
Version      : 2.0.0
Directory    : /usr/local/lib/python3.8/dist-packages/mxnet
Commit hash file "/usr/local/lib/python3.8/dist-packages/mxnet/COMMIT_HASH" not found. Not installed from pre-built package or built from source.
Library      : ['/usr/local/lib/python3.8/dist-packages/mxnet/libmxnet.so']
Build features:
✖ CUDA
✖ CUDNN
✖ NCCL
✖ TENSORRT
✖ CUTENSOR
✔ CPU_SSE
✔ CPU_SSE2
✔ CPU_SSE3
✖ CPU_SSE4_1
✖ CPU_SSE4_2
✖ CPU_SSE4A
✖ CPU_AVX
✖ CPU_AVX2
✔ OPENMP
✖ SSE
✖ F16C
✖ JEMALLOC
✔ BLAS_OPEN
✖ BLAS_ATLAS
✖ BLAS_MKL
✖ BLAS_APPLE
✔ LAPACK
✔ ONEDNN
✔ OPENCV
✔ DIST_KVSTORE
✔ INT64_TENSOR_SIZE
✔ SIGNAL_HANDLER
✖ DEBUG
✖ TVM_OP
----------System Info----------
Platform     : Linux-5.4.0-67-generic-x86_64-with-glibc2.27
system       : Linux
node         : 9a4e11949b22
release      : 5.4.0-67-generic
version      : #75-Ubuntu SMP Fri Feb 19 18:03:38 UTC 2021
----------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):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               158
Model name:          Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Stepping:            9
CPU MHz:             3536.135
CPU max MHz:         3800.0000
CPU min MHz:         800.0000
BogoMIPS:            5599.85
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0288 sec, LOAD: 0.5301 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.0899 sec, LOAD: 0.6390 sec.
Error open Gluon Tutorial(cn): https://zh.gluon.ai, <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1108)>, DNS finished in 5.028506517410278 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.0254 sec, LOAD: 0.8350 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0328 sec, LOAD: 0.8642 sec.
Error open Conda: https://repo.continuum.io/pkgs/free/, HTTP Error 403: Forbidden, DNS finished in 0.04214024543762207 sec.
----------Environment----------
@Zha0q1
Copy link
Contributor

Zha0q1 commented Jul 11, 2021

#20262

@barry-jin is the author of the commit

@barry-jin
Copy link
Contributor

Hi @EnricoMi , after #20262 being merged, MXNet2.0 will switch to use Gluon2.0 API and deprecate all the use of legacy NDArrays and ndarray/symbol operators in Gluon Blocks/Layers. In your case, you can just change x = mx.nd.ones((5, 4, 10, 10)) to x = mx.np.ones((5, 4, 10, 10)) because in current Gluon2.0, only mxnet.numpy arrays are allowed.
For more detailed information, you can follow the migration guide here.

@EnricoMi
Copy link
Author

Hi @barry-jin, thanks for the quick and precise reply. Is that fix backward compatible with MXNet 1.x?

@barry-jin
Copy link
Contributor

Yes, using x = mx.np.ones((5, 4, 10, 10)) is still compatible with MXNet 1.x.

@EnricoMi
Copy link
Author

Thanks a lot for the input.

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

No branches or pull requests

3 participants