Just use for-loop to iterate on you variant length sequences. But in the sense of efficiency, I would recommend you to use padded sequences for mini-batch.
You can use the output of RNN to calculate loss and do backward.