Thanks for your answer. in this way, I need to have the start and end index of the non padded values, isn’t there any other more straightforward way like Masking layer in keras?
one thing more, by slicing we feed the matrix with different shapes into RNN, is this acceptable in pytorch? (e.g. data[0].size() could be (timesteps=100, features=20) and  data[10].size() could be (timesteps=34, features=20))