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

[bug]mx.nd.stack couldn't stack scalars #14594

Closed
wkcn opened this issue Apr 2, 2019 · 7 comments
Closed

[bug]mx.nd.stack couldn't stack scalars #14594

wkcn opened this issue Apr 2, 2019 · 7 comments

Comments

@wkcn
Copy link
Member

wkcn commented Apr 2, 2019

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:
5d2a451

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
@mxnet-label-bot
Copy link
Contributor

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 wkcn added the Bug label Apr 2, 2019
@abhinavs95
Copy link
Contributor

@wkcn looks like this is related to #14227 ?

@anirudh2290
Copy link
Member

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

@wkcn
Copy link
Member Author

wkcn commented Apr 2, 2019

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

@abhinavs95
Copy link
Contributor

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

@Vikas-kum
Copy link
Contributor

@anirudh2290
This is sam as supporting 0 shape -
#14227
Can we close either of them or both in favor of 0-shape support.

@anirudh2290
Copy link
Member

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

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

6 participants