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 vision
  
  
    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 11. 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.