Shortcuts

Class PackedSequence

Page Contents

Class Documentation

class torch::nn::utils::rnn::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 data abc and x the :class:PackedSequence would contain data axbc with batch_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 and unsorted_indices must be torch::kInt64 tensors on the same device as data.

However, batch_sizes should always be a CPU torch::kInt64 tensor.

This invariant is maintained throughout PackedSequence class, and all functions that construct a PackedSequence in libtorch (i.e., they only pass in tensors conforming to this constraint).

Public Functions

PackedSequence(Tensor data, Tensor batch_sizes, Tensor sorted_indices = {}, Tensor unsorted_indices = {})
const Tensor &data() const
const Tensor &batch_sizes() const
const Tensor &sorted_indices() const
const Tensor &unsorted_indices() const
PackedSequence pin_memory() const
PackedSequence to(TensorOptions options) const
PackedSequence cuda() const
PackedSequence cpu() const
bool is_cuda() const

Returns true if data_ stored on a gpu.

bool is_pinned() const

Returns true if data_ stored on in pinned memory.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources