@SimonW thanks a lot for the response.
As I am not a pytorch expert I am trying to translate the following tensorflow code into pytorch:
def RNN(x, weight, bias):
       cell = rnn_cell.LSTMCell(n_hidden,state_is_tuple = True)
       cell = rnn_cell.MultiRNNCell([cell] * 2)
       output, state = tf.nn.dynamic_rnn(cell, x, dtype = tf.float32)
       output = tf.transpose(output, [1, 0, 2])
       last = tf.gather(output, int(output.get_shape()[0]) - 1)
       return tf.nn.softmax(tf.matmul(last, weight) + bias)

class RNN(nn.Module):
         def __init__(self, input, n_hidden, out):
               super(RNN, self).__init__()
               self.layer1 = nn.LSTMCell(input, n_hidden)
               self.layer2 = nn.RNNCell(n_hidden, n_hidden)
               self.layer3 = nn.RNN([n_hidden] * 2,  out)

         def forward(self, x, weight, bias):
               cell, h  = self.layer1(x)
               cell, h = self.layer2([cell] * 2)
               cell, h = self.layer3(cell)
              output = cell.transpose(1, 0)
              output = output.gather().shape[0]-1
              return nn.Softmax(torch.matmul(output, weight) + bias)

Am I translating this correctly?