Rate this Page

PackedSequence#

classtorch.nn.utils.rnn.PackedSequence(data,batch_sizes=None,sorted_indices=None,unsorted_indices=None)[source]#

Holds the data and list ofbatch_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 meantto be instantiated by functions likepack_padded_sequence().

Batch sizes represent the number elements at each sequence step inthe batch, not the varying sequence lengths passed topack_padded_sequence(). For instance, given dataabc andxthePackedSequence would contain dataaxbc withbatch_sizes=[2,1,1].

Variables
  • data (Tensor) – Tensor containing packed sequence

  • batch_sizes (Tensor) – Tensor of integers holdinginformation about the batch size at each sequence step

  • sorted_indices (Tensor,optional) – Tensor of integers holding how thisPackedSequence is constructed from sequences.

  • unsorted_indices (Tensor,optional) – Tensor of integers holding how thisto recover the original sequences with correct order.

Return type

Self

Note

data can be on arbitrary device and of arbitrary dtype.sorted_indices andunsorted_indices must betorch.int64tensors on the same device asdata.

However,batch_sizes should always be a CPUtorch.int64 tensor.

This invariant is maintained throughoutPackedSequence class,and all functions that construct aPackedSequence in PyTorch(i.e., they only pass in tensors conforming to this constraint).

batch_sizes:Tensor#

Alias for field number 1

count(value,/)#

Return number of occurrences of value.

data:Tensor#

Alias for field number 0

index(value,start=0,stop=9223372036854775807,/)#

Return first index of value.

Raises ValueError if the value is not present.

propertyis_cuda:bool#

Return true ifself.data stored on a gpu.

is_pinned()[source]#

Return true ifself.data stored on in pinned memory.

Return type

bool

sorted_indices:Optional[Tensor]#

Alias for field number 2

to(dtype:dtype,non_blocking:bool=...,copy:bool=...)Self[source]#
to(device:Optional[Union[str,device,int]]=...,dtype:Optional[dtype]=...,non_blocking:bool=...,copy:bool=...)Self
to(other:Tensor,non_blocking:bool=...,copy:bool=...)Self

Perform dtype and/or device conversion onself.data.

It has similar signature astorch.Tensor.to(), except optionalarguments likenon_blocking andcopy should be passed as kwargs,not args, or they will not apply to the index tensors.

Note

If theself.data Tensor already has the correcttorch.dtypeandtorch.device, thenself is returned.Otherwise, returns a copy with the desired configuration.

unsorted_indices:Optional[Tensor]#

Alias for field number 3