I am trainning a batched seq2seq using the code in  https://github.com/spro/practical-pytorch/blob/master/seq2seq-translation/seq2seq-translation-batched.ipynb 9.
I found that decoder forward and backward speed is quite slow due to the for-loop as follow:
decoder_input = [SOS_token for _ in range(batch_size)]
for i in range(max_target_length)：
    decoder_output =  train_decoder(decoder_input )
    decoder_input  = target[i]
    loss+=loss_function(decoder_output )
loss.backward()

how to speed up in this case? or not use for-loop?