zheng-da opened a new issue #12154: the cond operator doesn't support a function that doesn't require inputs. URL: https://github.com/apache/incubator-mxnet/issues/12154 The python functions of the cond operator has to access some variables outside the function. ```python def test_no_inputs(): class TestBlock(gluon.HybridBlock): def __init__(self, prefix=None, params=None): super(TestBlock, self).__init__(prefix=prefix, params=params) def hybrid_forward(self, F, data): def then_func(): return F.ones((1)).expand_dims(0) def else_func(): return data return F.contrib.cond(data == 0, then_func, else_func) block = TestBlock() block.initialize(ctx=default_context()) block.hybridize() data = mx.nd.ones((1)).expand_dims(0) print(data) block(data) ``` The following code will run into an error as follows: ``` ====================================================================== ERROR: __main__.test_no_inputs ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "tests/python/unittest/test_contrib_control_flow.py", line 47, in test_no_inputs block(data) File "/Users/dzzhen/Workspace/incubator-mxnet/python/mxnet/gluon/block.py", line 541, in __call__ out = self.forward(*args) File "/Users/dzzhen/Workspace/incubator-mxnet/python/mxnet/gluon/block.py", line 908, in forward return self._call_cached_op(x, *args) File "/Users/dzzhen/Workspace/incubator-mxnet/python/mxnet/gluon/block.py", line 814, in _call_cached_op out = self._cached_op(*cargs) File "/Users/dzzhen/Workspace/incubator-mxnet/python/mxnet/_ctypes/ndarray.py", line 150, in __call__ ctypes.byref(out_stypes))) File "/Users/dzzhen/Workspace/incubator-mxnet/python/mxnet/base.py", line 255, in check_call raise MXNetError(py_str(_LIB.MXGetLastError())) MXNetError: [16:00:03] src/imperative/cached_op.cc:127: Check failed: idx.input_nodes().size() >= 1 (0 vs. 1) CachedOp requires at least 1 input Stack trace returned 10 entries: [bt] (0) 0 libmxnet.so 0x00000001053cfe50 dmlc::StackTrace() + 272 [bt] (1) 1 libmxnet.so 0x00000001053cfbff dmlc::LogMessageFatal::~LogMessageFatal() + 47 [bt] (2) 2 libmxnet.so 0x000000010673209c mxnet::CachedOp::CachedOp(nnvm::Symbol const&, std::__1::vector<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&) + 3164 [bt] (3) 3 libmxnet.so 0x00000001068d6865 mxnet::op::LoopState::MakeSharedOp(nnvm::Symbol const&) + 453 [bt] (4) 4 libmxnet.so 0x0000000106cbdb74 mxnet::op::LoopState::LoopState(nnvm::Symbol const&) + 164 [bt] (5) 5 libmxnet.so 0x00000001068da510 mxnet::op::CondState::CondState(mxnet::op::CondParam const&, nnvm::Symbol const&, nnvm::Symbol const&, nnvm::Symbol const&) + 64 [bt] (6) 6 libmxnet.so 0x00000001068da41b mxnet::OpStatePtr mxnet::OpStatePtr::Create<mxnet::op::CondState, mxnet::op::CondParam const&, nnvm::Symbol&, nnvm::Symbol&, nnvm::Symbol&>(mxnet::op::CondParam const&&&, nnvm::Symbol&&&, nnvm::Symbol&&&, nnvm::Symbol&&&) + 75 [bt] (7) 7 libmxnet.so 0x00000001068d1731 mxnet::op::CreateCondState(nnvm::NodeAttrs const&, mxnet::Context, std::__1::vector<nnvm::TShape, std::__1::allocator<nnvm::TShape> > const&, std::__1::vector<int, std::__1::allocator<int> > const&) + 49 [bt] (8) 8 libmxnet.so 0x0000000105550b4e std::__1::__function::__func<mxnet::OpStatePtr (*)(nnvm::NodeAttrs const&, mxnet::Context, std::__1::vector<nnvm::TShape, std::__1::allocator<nnvm::TShape> > const&, std::__1::vector<int, std::__1::allocator<int> > const&), std::__1::allocator<mxnet::OpStatePtr (*)(nnvm::NodeAttrs const&, mxnet::Context, std::__1::vector<nnvm::TShape, std::__1::allocator<nnvm::TShape> > const&, std::__1::vector<int, std::__1::allocator<int> > const&)>, mxnet::OpStatePtr (nnvm::NodeAttrs const&, mxnet::Context, std::__1::vector<nnvm::TShape, std::__1::allocator<nnvm::TShape> > const&, std::__1::vector<int, std::__1::allocator<int> > const&)>::operator()(nnvm::NodeAttrs const&, mxnet::Context&&, std::__1::vector<nnvm::TShape, std::__1::allocator<nnvm::TShape> > const&, std::__1::vector<int, std::__1::allocator<int> > const&) + 30 [bt] (9) 9 libmxnet.so 0x000000010676ca6e mxnet::imperative::RunGraph(bool, nnvm::IndexedGraph const&, std::__1::vector<mxnet::NDArray*, std::__1::allocator<mxnet::NDArray*> >, unsigned long, unsigned long, std::__1::vector<mxnet::OpReqType, std::__1::allocator<mxnet::OpReqType> >&&, std::__1::vector<unsigned int, std::__1::allocator<unsigned int> >&&, std::__1::vector<mxnet::OpStatePtr, std::__1::allocator<mxnet::OpStatePtr> >*, std::__1::vector<mxnet::DispatchMode, std::__1::allocator<mxnet::DispatchMode> > const&, bool) + 2462 ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services