so this is going to vary. The varying sequence length can’t be what’s causing the problem?

This is going to be a problem though. I.e., how do you concatenate vectors  or matrices of different dimensions? It’s an impossible task unless you do some padding or trimming.
E.g,. here are some ideas that may be helpful:

  
    
    
    DataLoader for various length of data 
  
  
    Felix, I think your code only pads correctly if dim=0.  This is because in the pad vector in the pad_tensor function has *vec.size()[1:] hardcoded into it.  I think you need to create a vector that is pad - vec.size(dim) in the dim dimension and not always in the zeroth dimension.  However, I could be wrong.  I adapted the code to work with python3 and added the ability to pad with different values, so I may have screwed something up in the process.