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

broadcast_like requires inputs to have same dtype #16851

Open
leezu opened this issue Nov 19, 2019 · 4 comments
Open

broadcast_like requires inputs to have same dtype #16851

leezu opened this issue Nov 19, 2019 · 4 comments
Assignees
Labels
Bug v1.x Targeting v1.x branch

Comments

@leezu
Copy link
Contributor

leezu commented Nov 19, 2019

Description

broadcast_like "Broadcasts lhs to have the same shape as rhs."
Thus only the shape information of lhs and rhs array should matter.
However, it also asserts that the dtypes are equal.

Error Message

[08:58:11] /home/ANT.AMAZON.COM/lausen/src/mxnet-master/src/io/../operator/elemwise_op_common.h:135: Check failed: assign(&dattr, vec.at(i)): Incompatible attr in node  at 1-th input: expected float32, got int64
Stack trace:
  [bt] (0) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x43) [0x7f8b58c46d63]
  [bt] (1) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(mxnet::op::ElemwiseAttr<int, &mxnet::op::type_is_none, &mxnet::op::type_assign, true, &mxnet::op::type_string[abi:cxx11], -1, -1>(nnvm::NodeAttrs const&, std::vector<int, std::allocator<int> >*, std::vector<int, std::allocator<int> >*, int const&)::{lambda(std::vector<int, std::allocator<int> > const&, unsigned long, char const*)#1}::operator()(std::vector<int, std::allocator<int> > const&, unsigned long, char const*) const+0x275) [0x7f8b58e26e75]
  [bt] (2) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(bool mxnet::op::ElemwiseAttr<int, &mxnet::op::type_is_none, &mxnet::op::type_assign, true, &mxnet::op::type_string[abi:cxx11], -1, -1>(nnvm::NodeAttrs const&, std::vector<int, std::allocator<int> >*, std::vector<int, std::allocator<int> >*, int const&)+0x1b3) [0x7f8b58fd7783]
  [bt] (3) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(bool mxnet::op::ElemwiseType<2, 1>(nnvm::NodeAttrs const&, std::vector<int, std::allocator<int> >*, std::vector<int, std::allocator<int> >*)+0x23f) [0x7f8b59021c6f]
  [bt] (4) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(mxnet::imperative::SetShapeType(mxnet::Context const&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, mxnet::DispatchMode*)+0x57e) [0x7f8b58df513e]
  [bt] (5) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(mxnet::Imperative::Invoke(mxnet::Context const&, nnvm::NodeAttrs const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&, std::vector<mxnet::NDArray*, std::allocator<mxnet::NDArray*> > const&)+0xeb) [0x7f8b58de6a4b]
  [bt] (6) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(MXImperativeInvokeImpl(void*, int, void**, int*, void***, int, char const**, char const**)+0x538) [0x7f8b58c82388]
  [bt] (7) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/../../build/libmxnet.so(MXImperativeInvokeEx+0x8b) [0x7f8b58c833cb]
  [bt] (8) /home/ANT.AMAZON.COM/lausen/src/mxnet-master/python/mxnet/_cy3/ndarray.cpython-37m-x86_64-linux-gnu.so(+0x13be8) [0x7f8b2f1f0be8]

To Reproduce

mx.nd.broadcast_like(mx.nd.ones((1,)), mx.nd.arange(10, dtype=int))

@leezu
Copy link
Contributor Author

leezu commented Nov 19, 2019

mx.np.broadcast_arrays(mx.np.ones((1,)), mx.np.arange(10, dtype=int)) works correctly.

@leezu
Copy link
Contributor Author

leezu commented Nov 19, 2019

The reason that this bug is important: When writing a HybridBlock, the dtype of some input array depends on the user. But some other internally used array may have a fixed dtype that could be unequal of the input dtype.
Workaround is to add an extra cast prior to broadcast_like.

leezu added a commit to leezu/gluon-nlp that referenced this issue Nov 19, 2019
leezu added a commit to dmlc/gluon-nlp that referenced this issue Nov 20, 2019
* Make GPT2Model a HybridBlock

* Enable gpt2 test for sequence_sampling.py

* Fix

* Hybridize

* Workaround apache/mxnet#16851

* Fix #1015

* Enable test

* Ignore warning about package resolution using __spec__ or __package__
@samskalicky
Copy link
Contributor

Since this issue has 2 parts:

  • Should not assert, should throw an error/exception instead
  • broadcast_like should be enhanced [Feature request] to support different types
    Assigning to Mu for the first part, fixing error messages
    @zachgk assign [@mli ]

@szha szha added v1.x Targeting v1.x branch and removed good first issue labels Jul 12, 2020
@szha
Copy link
Member

szha commented Jul 12, 2020

this issue is related to an op that is deprecated in 2.0, so I'm marking this as 1.x.
this issue is probably not a good first issue without pointers on where to look to address it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug v1.x Targeting v1.x branch
Projects
None yet
Development

No branches or pull requests

4 participants