You should make something like:
input = Variable(torch.Tensor([[sos]*batch_size])
hidden, cell = RNN.init_hidden_cell(batch_size)
for di in range(MAX_LENGTH):
    output, (hidden,cell) = RNN(input, (hidden,cell))
    loss += criterion(output, targets[di,:])
    # for ex of a NLP output:
    # contains the probabilities for each word IDs.
    # The index of the probability is the word ID.
    _, topi = torch.topk(output,1)
    # topi = (batch*1)
    input = torch.transpose(topi,0,1)

And if you don’t use batchs, you can break the loop at the first “eos”.