oneflow.nn.utils.rnn.PackedSequence¶
-
class
oneflow.nn.utils.rnn.PackedSequence(data: oneflow.Tensor, batch_sizes: Optional[oneflow.Tensor] = None, sorted_indices: Optional[oneflow.Tensor] = None, unsorted_indices: Optional[oneflow.Tensor] = None)¶ The interface is consistent with PyTorch. The documentation is referenced from: https://pytorch.org/docs/1.10/generated/torch.nn.utils.rnn.PackedSequence.html.
Holds the data and list of
batch_sizesof a packed sequence.All RNN modules accept packed sequences as inputs.
Note
Instances of this class should never be created manually. They are meant to be instantiated by functions like
pack_padded_sequence().Batch sizes represent the number elements at each sequence step in the batch, not the varying sequence lengths passed to
pack_padded_sequence(). For instance, given dataabcandxthePackedSequencewould contain dataaxbcwithbatch_sizes=[2,1,1].-
batch_sizes¶ Tensor of integers holding information about the batch size at each sequence step
- Type
-
sorted_indices¶ Tensor of integers holding how this
PackedSequenceis constructed from sequences.- Type
Tensor, optional
-
unsorted_indices¶ Tensor of integers holding how this to recover the original sequences with correct order.
- Type
Tensor, optional
Note
datacan be on arbitrary device and of arbitrary dtype.sorted_indicesandunsorted_indicesmust beoneflow.int64tensors on the same device asdata.However,
batch_sizesshould always be a CPUoneflow.int64tensor.This invariant is maintained throughout
PackedSequenceclass, and all functions that construct a :class:PackedSequence in PyTorch (i.e., they only pass in tensors conforming to this constraint).-