You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/05/24 18:10:24 UTC

[GitHub] [incubator-mxnet] karan6181 opened a new issue #15062: Bug in BidirectionalCell for imperative mode when time_step is 1

karan6181 opened a new issue #15062: Bug in BidirectionalCell for imperative mode when time_step is 1
URL: https://github.com/apache/incubator-mxnet/issues/15062
 
 
   The `_reverse_sequences()` method in `~/mxnet/gluon/rnn/rnn_cell.py` gives unexpected output when the input is of single `time_step` with the imperative mode. Below is the example to demonstrate the issue:
   
   
   
   ```python
   import mxnet as mx
   from mxnet import gluon
   
   def test_bidirectional_unroll_valid_length():
       class BiLSTM(gluon.nn.HybridBlock):
           def __init__(self, rnn_size, time_step, **kwargs):
               super(BiLSTM, self).__init__(**kwargs)
               self.time_step = time_step
               with self.name_scope():
                   self.bi_lstm = gluon.rnn.BidirectionalCell(
                       gluon.rnn.LSTMCell(rnn_size, prefix='rnn_l0_'),
                       gluon.rnn.LSTMCell(rnn_size, prefix='rnn_r0_'),
                       output_prefix='lstm_bi_')
   
           def hybrid_forward(self, F, inputs, valid_len):
               outputs, states = self.bi_lstm.unroll(self.time_step, inputs, valid_length=valid_len, layout='NTC', merge_outputs=True)
               return outputs, states
   
       rnn_size, time_step = 100, 1
       net = BiLSTM(rnn_size, time_step)
       net.initialize()
       # net.hybridize()
       inputs_data = mx.nd.random.uniform(shape=(10, 1, 50))
       valid_len = mx.nd.array([1]*10)
       outputs, _ = net(inputs_data, valid_len)
       assert outputs.shape == (10, 1, 200)
   
   
   test_bidirectional_unroll_valid_length()
   ```
   
   Below is the debugged output from `_reverse_sequences()` method
   
   ```bash
   >>> len(sequences) # Before reversing the input
   1
   >>> sequences[0].shape # Before reversing the input
   (10, 50)
   >>> reversed_sequences.shape # After reversing the input
   (10, 50)
   >>> len(reversed_sequences) # After reversing the input
   10
   
   # The correct output should be
   >>> len(reversed_sequences)
   1
   reversed_sequences[0].shape
   (10, 50)
   ```
   
   The issue is not reproducible in symbolic mode(Please uncomment the `net.hybridize()` if you want to run it in symbolic mode). Also, the failure can only be seen in the nightly pip release due to the change made in this PR [#13575](<https://github.com/apache/incubator-mxnet/pull/13575>).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services