Batch variable length input then return to original length for forward pass

I’m dealing with audio data where the length of each sequence can vary by orders of magnitude at sample level and need a way of allowing the model to process the original sequences.

I have written a simple collate_fn which pads the audio sequences for the purposes of creating the batches, however, I then want to undo the padding so the forward() function of my model operates on the original sequences. The simple reason for this is that training on audio where some examples may contain more zero padding than original data will have ramifications to the learning process.

Is there a way of doing this without resorting to having a pretty inefficient for loop within my forward function where I’m forced to process a single example at a time.