fn
pad_packed_sequence
→Tensorpad_packed_sequence(sequence: PackedSequence, batch_first: bool = False, padding_value: float = 0.0, total_length: int | None = None)Inverse of pack_padded_sequence — produce a padded tensor.
Re-inflates a PackedSequence into a dense
(or )
tensor with the original batch order restored. The freshly created
cells beyond each sequence's true length are filled with
padding_value.
Parameters
sequencePackedSequencePacked batch to unpack.
batch_firstbool= FalseOutput layout.
False (default) yields (T, B, *),
True yields (B, T, *).padding_valuefloat= 0.0Fill value for padded entries. Default
0.0.total_lengthint= NoneIf given, pad up to this length instead of the longest packed
sequence. Useful when downstream code expects a fixed
T_max (e.g. fully-static export graphs). Must be >= the
longest sequence.Returns
TensorPadded batch tensor.
Notes
Output time dimension is (or total_length
if larger). The function honours unsorted_indices on the
packed sequence so the rows of the returned tensor match the order
the caller used at pack time.
Examples
>>> from lucid.nn.utils.rnn import pad_packed_sequence
>>> padded, lens = pad_packed_sequence(packed, batch_first=True)