Class PackedSequence¶
Defined in File rnn.h
Page Contents
Class Documentation¶
-
class PackedSequence¶
Holds the data and list of
batch_sizes
of 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 dataabc
andx
the :class:PackedSequence
would contain dataaxbc
withbatch_sizes=[2,1,1]
.Attributes: data (Tensor): Tensor containing packed sequence batch_sizes (Tensor): Tensor of integers holding information about the batch size at each sequence step sorted_indices (Tensor, optional): Tensor of integers holding how this :class:
PackedSequence
is constructed from sequences. unsorted_indices (Tensor, optional): Tensor of integers holding how this to recover the original sequences with correct order... note::
data
can be on arbitrary device and of arbitrary dtype.sorted_indices
andunsorted_indices
must betorch::kInt64
tensors on the same device asdata
.However,
batch_sizes
should always be a CPUtorch::kInt64
tensor.This invariant is maintained throughout
PackedSequence
class, and all functions that construct aPackedSequence
in libtorch (i.e., they only pass in tensors conforming to this constraint).Public Functions
-
inline explicit PackedSequence(Tensor data, Tensor batch_sizes, Tensor sorted_indices = {}, Tensor unsorted_indices = {})¶
-
inline const Tensor &data() const¶
-
inline const Tensor &batch_sizes() const¶
-
inline const Tensor &sorted_indices() const¶
-
inline const Tensor &unsorted_indices() const¶
-
inline PackedSequence pin_memory() const¶
-
inline PackedSequence to(TensorOptions options) const¶
-
inline PackedSequence cuda() const¶
-
inline PackedSequence cpu() const¶
-
inline bool is_cuda() const¶
Returns true if
data_
stored on a gpu.
-
inline bool is_pinned() const¶
Returns true if
data_
stored on in pinned memory.
-
inline explicit PackedSequence(Tensor data, Tensor batch_sizes, Tensor sorted_indices = {}, Tensor unsorted_indices = {})¶