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
Sort sequences internally in pack_padded_sequence #3584
Comments
I am working on 1128. I can add this to my code as well |
This will make it impossible to do the batched filling we do now |
@apaszke, you can sort and then do the batched filling |
but how do you sort a tensor? with a series of selects and cat? it's expensive |
A single call to index_select
…On Thu, Nov 9, 2017 at 2:23 PM Adam Paszke ***@***.***> wrote:
but how do you sort a tensor? with a series of selects and cat? it's
expensive
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3584 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAoB-hCFQG8UvJVnuJfTVdP1LmS3LTnvks5s01FJgaJpZM4QXUD4>
.
|
Would really love to have this feature! Has this been implemented yet? |
But you'd still have to manually sort all other tensors in a batch, no? |
Well, I was hoping for a method that would first sort the inputs, then compute the results and then restore the original order before returning the results. This way everything would happen under-the-hood and the user need not worry about sorting anything else in their code. |
If we manually do the sort before RNN and unsort after the RNN, would it influence the backpropagation? For example,
|
@zhoujunpei if not, the backprop will fit into garbage (random labels) maybe your method also works. the point is the ouput and label index is same |
second this proposal |
For efficiency, is it possible to check whether the sequence is sorted inside the function "pack_padded_sequence"? |
… in RNNs Fixes pytorch#3584. Motivation: manually sorting sequences, packing them, and then unsorting them is something a lot of users have complained about doing, especially when we can offer library support for them. Overview: we internally sort sequences before packing them and store a list of `unsorted_indices` that represent how to unsort the sequences inside PackedSequence. The packing helper functions return PackedSequence with the `permutation` field and the unpacking helper functions use it to unsort. To implement this, the following changes were made: - PackedSequence now keeps `sorted_indices` and `unsorted_indices`. These two can be thought of as permutations and are inverses of each other. `sorted_indices` is how the sequences were sorted; `unsorted_indices` is how to unsort the sequences. - Added an `enforce_sorted` argument to pack_sequence and pack_padded_sequence that maintains the legacy behavior of error-ing out on unsorted-sequences. When `enforce_sorted=True`, these functions maintain their ONNX exportability. - pack_sequence(sequences, enforce_sorted) takes in unsorted sequences. - pack_padded_sequence can take in a padded tensor that represents padded, unsorted sequences. - pad_packed_sequence unsorts the PackedSequence such that it is still the inverse operation of packed_padded_sequence. - RNNs apply `sort_indices` to their input hidden state and apply `unsort_indices` to their output hidden state. This is to ensure that the hidden state batches correspond to the user's ordering of input sequences. NOT BC-Breaking - The default for pack_sequence and pack_padded_sequence is `enforce_sorted=True` to avoid breaking ONNX export. To use the new functionality, pass in `enforce_sorted=False` Testing Plan - Modified TestNN.test_pack_sequence, TestNN.test_packed_padded_sequence, and TestNN.test_variable_sequence (RNN test) to check the behavior of unsorted sequences, sorted sequences, and sorted sequences with enforce_sorted=True
Excellent! |
Currently,
pack_padded_sequence
requires the caller to sortinputs
by the length (descending). We should sort and reorder the input internally if it's not already sorted. We can then restore the original order inpad_packed_sequence
.cc @kyunghyuncho
The text was updated successfully, but these errors were encountered: