zheng-da opened a new issue #10609: Gluon code fails in the normal mode but 
succeeds in the hybrid mode.
URL: https://github.com/apache/incubator-mxnet/issues/10609
 
 
   ## Description
   ```python
   from mxnet import gluon
   import mxnet as mx
   gru = gluon.rnn.GRUCell(5)
   gru.initialize(ctx=mx.cpu(0))
   data =  mx.nd.random.uniform(shape=(2, 3))
   state = mx.nd.random.uniform(shape=(2, 5))
   out = gru(data, state)
   ```
   the code above fails with the following error:
   ```
   MXNetError                                Traceback (most recent call last)
   <ipython-input-1-47be0261e99b> in <module>()
         5 data =  mx.nd.random.uniform(shape=(2, 3))
         6 state = mx.nd.random.uniform(shape=(2, 5))
   ----> 7 out = gru(data, state)
   
   /home/ubuntu/incubator-mxnet/python/mxnet/gluon/block.pyc in __call__(self, 
*args)
       411     def __call__(self, *args):
       412         """Calls forward. Only accepts positional arguments."""
   --> 413         return self.forward(*args)
       414 
       415     def forward(self, *args):
   
   /home/ubuntu/incubator-mxnet/python/mxnet/gluon/rnn/rnn_cell.pyc in 
forward(self, inputs, states)
       287         # pylint: disable= arguments-differ
       288         self._counter += 1
   --> 289         return super(RecurrentCell, self).forward(inputs, states)
       290 
       291 
   
   /home/ubuntu/incubator-mxnet/python/mxnet/gluon/block.pyc in forward(self, 
x, *args)
       627                     return self._call_cached_op(x, *args)
       628                 params = {i: j.data(ctx) for i, j in 
self._reg_params.items()}
   --> 629                 return self.hybrid_forward(ndarray, x, *args, 
**params)
       630 
       631         assert isinstance(x, Symbol), \
   
   /home/ubuntu/incubator-mxnet/python/mxnet/gluon/rnn/rnn_cell.pyc in 
hybrid_forward(self, F, inputs, states, i2h_weight, h2h_weight, i2h_bias, 
h2h_bias)
       610                                bias=h2h_bias,
       611                                num_hidden=self._hidden_size * 3,
   --> 612                                name=prefix+'h2h')
       613 
       614         i2h_r, i2h_z, i2h = F.SliceChannel(i2h, num_outputs=3,
   
   /home/ubuntu/incubator-mxnet/python/mxnet/ndarray/register.pyc in 
FullyConnected(data, weight, bias, num_hidden, no_bias, flatten, out, name, 
**kwargs)
   
   /home/ubuntu/incubator-mxnet/python/mxnet/_ctypes/ndarray.pyc in 
_imperative_invoke(handle, ndargs, keys, vals, out)
        90         c_str_array(keys),
        91         c_str_array([str(s) for s in vals]),
   ---> 92         ctypes.byref(out_stypes)))
        93 
        94     if original_output is not None:
   
   /home/ubuntu/incubator-mxnet/python/mxnet/base.pyc in check_call(ret)
       147     """
       148     if ret != 0:
   --> 149         raise MXNetError(py_str(_LIB.MXGetLastError()))
       150 
       151 
   
   MXNetError: Shape inconsistent, Provided = [15,5], inferred shape=(15,1)
   ```
   
   If I call hybridize the block and pass the data again to the block. It works.
   
   ```python
   gru.hybridize()
   out = gru(data, state)
   ```
   
   Is this a bug?
   

----------------------------------------------------------------
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

Reply via email to