import torch
import torch.nn as nn
from torch.autograd import Variable

rnn = nn.Sequential(nn.LSTM(10, 10, 2, bidirectional=True))
rnn = rnn.cuda()
rnn.eval()

i = torch.Tensor(2, 1, 10).cuda()
i = Variable(i, requires_grad=True)

o, _ = rnn(i)
o = o.mean()
o.backward(torch.ones(1).cuda())