Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why sort instances by sequence length in descending order step is needed? #7

Open
mrgloom opened this issue Aug 5, 2019 · 1 comment

Comments

@mrgloom
Copy link

mrgloom commented Aug 5, 2019

Why sort instances by sequence length in descending order step is needed?

@rayryeng
Copy link

rayryeng commented Nov 24, 2020

This was required in earlier versions of PyTorch and that was so that the examples in a batch can be interleaved properly when performing forward + backprop. Knowing the size of each example before you pad with zeroes and sorting the sequences was crucial for the interleave to work. However, this is no longer needed as of PyTorch 1.1.0 as you can specify enforce_sorted=False so it can do the sorting internally. Also with newer versions of PyTorch, you can just use pack_sequence instead of pack_padded_sequence where you no longer need to pad the sequences. You would just provide a list of tensors, with each tensor being a sequence in the batch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants