Thanks for the replying.
Perhaps I have not described my problem correctly.
Let me try again.
I have a list of indices, like A = [[1,2,3], [2,3,4,5,7],…],  each of indices has different length.
Now I want to use this 2-D indices to index Embeddings.
For example, Embedding(A[0]) means I want three embeddings at position 1,2,3; Embedding(A[1]) means I want four embeddings at position 2,3,4,5,7.
But, I can not Embedding(A) directly, because each A[i] has different length.
If we use padding, padding(A)=B=[[1,2,3, 0,0], [2,3,4,5,7]], then we can use Embedding(B) to index all the embedding I need (0 is the padding index).
However, the max length of A[i] can be huge, i.e. 1000000.
If we still use padding, it would waste most of the memory.
And in my model, len(A) = 20000 and I need to compute Embedding(A) in every batch.
When I use small dataset, padding is totally fine.
But when I use large dataset, most of the cuda memory is wasted.
My model does not use LSTM or RNN. I do not need bptt here …
Hope I explained clearly.