Hi, thank you for your response, sure :
Here is my collate function which retrieves the length of one-hot-encoded sequences lengths, and then returns padded sequence, and lengths. (tag corresponds to the y, this is a regression problem).
def collate(batch):

    ## Get sequence lengths 
    lengths = torch.IntTensor([np.array(t['seq']).shape[0] for t in batch  ])
    ## padd
    batch_ = [torch.Tensor(t['seq']).to(device) for t in batch]
    batch_ = torch.nn.utils.rnn.pad_sequence(batch_, batch_first=True)
    #batch_ = torch.nn.utils.rnn.pack_padded_sequence(batch_, batch_first=True)
    
    # Get tags
    tags = [t['tag'] for t in batch]
    tags = torch.FloatTensor(tags)
    
    return batch_, lengths, tags

Here is a snippet of my forward function in my CNN :
    def forward(self, x, length):
        
        # Would like to resize x based on the length here :
        # Something like x = x[:length,:]

        
        x = self.conv1(x)
        x = F.relu(x)
        x = self.batch1(x)

And this is my training loop :
    for i_batch, item in enumerate(train_loader):
              
        seqs = item[0]
        tags = item[2]
        lengths = item[1]
        # (1) :
        outputs = custom_model(seqs, lengths)  

the line after #(1): raises an error because lengths is a vector. But I would like to apply the resize function to each of my sequences based on the corresponding value in the length vector.
If you would have more questions, don’t hesitate !
Mat