You can try and see if it works.
def init_hidden(self):
    if (train_on_gpu):
        hidden = (weight.new(self.n_layers, 1, self.hidden_dim).zero_().cuda(),
                         weight.new(self.n_layers, 1, self.hidden_dim).zero_().cuda())
    else:
        hidden = (weight.new(self.n_layers, 1, self.hidden_dim).zero_(),
                       weight.new(self.n_layers, 1, self.hidden_dim).zero_())
    return hidden

batch_size = inputs.size(0)
h = tuple([each.repeat(1, batch_size, 1).data for each in h])

batch_size = inputs.size(0)
val_h = tuple([each.repeat(1, batch_size, 1).data for each in val_h])

I think this is a method which can solve this problem.
Can you understand that?