@Maghoumi thanks for your post! Someone also posted this here later in 2019 in case it might be useful to someone:
  

      suzyahyah.github.io
  

  
    

Pad pack sequences for Pytorch batch processing with DataLoader 11

  Pytorch setup for batch sentence/sequence processing - minimal working example. The pipeline consists of the following:


  

  
    
    
  

  


Also note that a boolean parameter enforce_sorted was added to  torch.nn.utils.rnn.pack_padded_sequence() in December 2018 (see this issue). So there is no need anymore to provide a sorted sequence, it is sorted internally when enforce_sorted=False.