Incubator-mxnet: [bug]mx.nd.stack couldn't stack scalars

Created on 2 Apr 2019  路  7Comments  路  Source: apache/incubator-mxnet

Description

Hi, there.
I found a bug about mx.nd.stack, which couldn't stack scalars whose shape is ().

Environment info (Required)

Package used (Python/R/Scala/Julia):
Python

Build info (Required if built from source)

Compiler (gcc/clang/mingw/visual studio):
gcc

MXNet commit hash:
5d2a4510c2c226c6921a8a213d04461f68ca7173

Build config:
make -j 5 USE_OPENCV=1 USE_BLAS=openblas USE_MKLDNN=0

Error Message:

I tried to fix the bug, however I do not why attach_grad calls the function infershape.

Traceback (most recent call last):                                                                                           
  File "test_stack.py", line 6, in <module>                                                                                  
    a.attach_grad()
  File "/home/wkcn/proj/incubator-mxnet/python/mxnet/ndarray/ndarray.py", line 2163, in attach_grad                          
    grad = op.zeros_like(self)  # pylint: disable=undefined-variable                                                         
  File "<string>", line 42, in zeros_like
  File "/home/wkcn/proj/incubator-mxnet/python/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke                     
    ctypes.byref(out_stypes)))
  File "/home/wkcn/proj/incubator-mxnet/python/mxnet/base.py", line 252, in check_call                                       
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [17:00:14] src/imperative/./imperative_utils.h:125: Check failed: infershape[attrs.op](attrs, &in_shape
s, &out_shapes)                                      

Stack trace returned 10 entries:                   
[bt] (0) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(dmlc::StackTrace[abi:cxx11]()+0x173) [0x7f5c78f31f
33]                                             
[bt] (1) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x39) [0
x7f5c78f32bb9]                                            
[bt] (2) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(mxnet::imperative::SetShapeType(mxnet::Context con
st&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray
*, std::allocator<mxnet::NDArray*> > const&, mxnet::DispatchMode*)+0x1a79) [0x7f5c7b5a1e69]
[bt] (3) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(mxnet::Imperative::Invoke(mxnet::Context const&, n
nvm::NodeAttrs const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray*, std
::allocator<mxnet::NDArray*> > const&)+0x674) [0x7f5c7b5a6d24]
[bt] (4) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(MXImperativeInvokeImpl(void*, int, void**, int*, v
oid***, int, char const**, char const**)+0x585) [0x7f5c7bc962f5]
[bt] (5) /home/wkcn/proj/incubator-mxnet/python/mxnet/../../lib/libmxnet.so(MXImperativeInvokeEx+0x67) [0x7f5c7bc98847]
[bt] (6) /usr/lib/libffi.so.6(ffi_call_unix64+0x4c) [0x7f5c87a676d0]
[bt] (7) /usr/lib/libffi.so.6(ffi_call+0x230) [0x7f5c87a670a0]
[bt] (8) /usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(_ctypes_callproc+0x2a5) [0x7f5c87acd625]
[bt] (9) /usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so(+0x12fb0) [0x7f5c87acdfb0]

Minimum reproducible example

Test case 1:

import mxnet as mx
import random

a = mx.nd.array(random.randint(1, 100))
b = mx.nd.array(random.randint(1, 100))
a.attach_grad()
b.attach_grad()
ograd = mx.nd.random.uniform(0, 100, (2,))
#with mx.autograd.record():
c = mx.nd.stack(a, b)
#    c.backward(ograd)
print(c)
print(a.grad)

Test case 2:

import mxnet as mx

a = mx.nd.array(3)
b = mx.nd.zeros_like(a)

Steps to reproduce

  1. Run the test case
Bug Operator

All 7 comments

Hey, this is the MXNet Label Bot.
Thank you for submitting the issue! I will try and suggest some labels so that the appropriate MXNet community members can help resolve it.
Here are my recommended labels: Bug

@wkcn looks like this is related to #14227 ?

scalars are not currently supported. this should probably be fixed by the zero size tensor support work.

@abhinavs95 @anirudh2290 Thank you! It is an issue about zero dimension tensor, which is similar to #14227

@mxnet-label-bot update [Bug, operator]

@anirudh2290
This is sam as supporting 0 shape -
https://github.com/apache/incubator-mxnet/issues/14227
Can we close either of them or both in favor of 0-shape support.

duplication of #14227 and should be fixed by #14253 . Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zy-huang picture zy-huang  路  3Comments

Zhaoyang-XU picture Zhaoyang-XU  路  3Comments

ranti-iitg picture ranti-iitg  路  3Comments

WangcsShuai picture WangcsShuai  路  3Comments

yuconglin picture yuconglin  路  3Comments