# PackedSequence Source: https://www.tensorplay.cn/docs/generated/tensorplay.nn.utils.rnn.PackedSequence.html ```python class tensorplay.nn.utils.rnn.PackedSequence(data, batch_sizes=None, sorted_indices=None, unsorted_indices=None) ``` Holds the data and list of [batch_sizes](#tensorplay.nn.utils.rnn.PackedSequence.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 PackedSequence would contain data axbc with batch_sizes=[2,1,1]. Variables: - data ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – Tensor containing packed sequence - batch_sizes ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – Tensor of integers holding information about the batch size at each sequence step - sorted_indices ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – Tensor of integers holding how this [PackedSequence](#tensorplay.nn.utils.rnn.PackedSequence) is constructed from sequences. - unsorted_indices ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.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 int64 tensors on the same device as data. However, batch_sizes should always be a CPU int64 tensor. This invariant is maintained throughout PackedSequence class, and all functions that construct a PackedSequence in TensorPlay (i.e. they only pass in tensors conforming to this constraint). ```python batch_sizes: Tensor ``` Alias for field number 1 ```python count(value, /) ``` Return number of occurrences of value. ```python data: Tensor ``` Alias for field number 0 ```python index(value, start=0, stop=9223372036854775807, /) ``` Return first index of value. Raises ValueError if the value is not present. ```python property is_cuda: bool ``` Return true if self.data stored on a gpu. ```python is_pinned() → bool ``` Return true if self.data stored on in pinned memory. ```python sorted_indices: Tensor | None ``` Alias for field number 2 ```python to(*args: Any, **kwargs: Any) ``` Perform dtype and/or device conversion on self.data. It has similar signature as tensorplay.Tensor.to() > **Note** > > If the self.data Tensor already has the correct tensorplay.DType and tensorplay.Device, then self is returned. Otherwise, returns a copy with the desired configuration. ```python unsorted_indices: Tensor | None ``` Alias for field number 3