The error is most likely thrown, since you are passing single “words” to the model in these lines:
for ei in range(input_length):
    encoder_output, encoder_hidden = encoder(
        input_tensor[ei], encoder_hidden)
    encoder_outputs[ei] = encoder_output[0, 0]

Since encoder is now a nn.DataParallel module, it expects a batch size > 1, which is not the case.
You would need to change the code to work with batched input.