My input is also a batch of variable-length input. I also padded them and pack them using pack_padded_sequence.
using ht[-1] return the same result as your solution.
I think you are expecting ht[-1] will return zeros for short inputs that were padded, right? But, that’s not the case when I tested it. Would you mind to double-check that? Or am I missing something here?