How to transform a 2D and index tensors for torch.nn.utils.rnn.pack_sequence

I have a sequences collection in the following form:

sequences = torch.tensor([[2,1],[5,6],[3,0])
indexes = torch.tensor([1,0,1])

that is, the sequence 0 is made of just [5,6], and the sequence 1 is made of [2,1] , [3,0]. Mathematically sequence[i] = { sequences[j] such that i = indexes[j] }

I need to feed these sequences into an LSTM. Since these are variable-length sequences, pytorch documentation states to use something like torch.nn.utils.rnn.pack_sequence.

Sadly, this method and its like want, as input, a list of tensors where each of them is a L x *, with L being the length of the single sequence.

How can build something that can be fed into a pytorch LSTM?

P.s. throughout the code I work with these tensors using scatter and gather functionalities but I can’t find a way to use them to achieve this goal.

p.p.s I posted this question also on stackoverflow