# How can I create a many to many RNN with fix number of unrolling steps in decoder?

**URL:** <https://discuss.pytorch.org/t/how-can-i-create-a-many-to-many-rnn-with-fix-number-of-unrolling-steps-in-decoder/47808>\
**Category:** Uncategorized\
**Created:** [June 13, 2019, 2:47am UTC](https://discuss.pytorch.org/t/how-can-i-create-a-many-to-many-rnn-with-fix-number-of-unrolling-steps-in-decoder/47808 "2019-06-13T02:47:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![leolcling](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/leolcling/32/17880_2.png) [@leolcling](https://discuss.pytorch.org/u/leolcling)\
**Post date:** [June 13, 2019, 2:47am UTC](https://discuss.pytorch.org/t/how-can-i-create-a-many-to-many-rnn-with-fix-number-of-unrolling-steps-in-decoder/47808/1 "2019-06-13T02:47:01Z")

</div>

I suppose I should define a `RNNCell` (or `LSTMCell`/`GRUCell`) in my decoder and use a for loop in the forward method in decoder. Something like this:

> [@Different Between LSTM and LSTMCell Function](https://discuss.pytorch.org/t/different-between-lstm-and-lstmcell-function/5657/4):
>
> LSTMCell is more flexible and you need less code with LSTM . So with LSTMCell, def forward(self, x): h = self.get\_hidden() for input in x: h = self.rnn(input, h) # self.rnn = self.LSTMCell(input\_size, hidden\_size) while with LSTM it is def forward(self, x): h\_0 = self.get\_hidden() output, h = self.rnn(x, h\_0) # self.rnn = self.LSTM(input\_size, hidden\_size) output is the blue rectangles in your fig.

But when I look at the tutorial of [seq-seq translation](https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html). I got confused because the tutorial use nn.GRU as oppose to GRUCell, and a for loop was used in the training loop… Is is related to attention?

If I want to implement a many-to-many RNN with attention and control the output to be 5 steps, should I use `RNN` or `RNNCell`? Thanks.
