nemo_automodel.components.datasets.packing
nemo_automodel.components.datasets.packing
Dataset-owned packed-sequence construction contracts and helpers.
Module Contents
Classes
Functions
Data
DEFAULT_PACKED_SEQUENCE_CONTRACT
_LEGACY_FLASH_ATTENTION_IMPLEMENTATIONS
API
Structural model contract consumed while collating packed data.
Packed attention-mask representation required by the model.
Whether the model consumes flat token indices and cumulative lengths.
Bases: typing.TypedDict
Batch-major metadata that remains valid after microbatch splitting.
Block-causal packing defaults for callers without model requirements.
Build batch-major metadata for a padded indexed packing mask.
Parameters:
Integer tensor of shape [batch, sequence] containing 1-based document IDs and zero-valued padding.
Returns: PackedSequenceMetadata
Metadata containing row-local packed_token_indices of shape
Extract document lengths from an indexed packed-sequence mask.
Parameters:
Integer tensor of shape [batch, sequence]. Each nonzero value is a 1-based document index local to its batch row; zero marks padding.
Returns: torch.Tensor
Tensor of shape [documents] containing nonzero document lengths in
Build varlen metadata for an indexed or binary attention mask.
Indexed masks treat every distinct positive document index in each batch row as a separate sequence. Binary masks treat every nonempty batch row as one sequence. Padding tokens are omitted from the flattened token stream.
Parameters:
Integer or boolean tensor of shape [batch, sequence]. Positive values identify valid tokens and zero marks padding.
Returns: torch.Tensor
A tuple containing indices of shape [tokens] into the flattened
Raises:
ValueError: If the mask is not rank two or contains no valid tokens.
Translate the deprecated attention keyword to a packing contract.
Parameters:
Explicit structural packing contract. It takes precedence when both migration surfaces are supplied.
Deprecated attention-backend name, or None.
Returns: PackedSequenceContract
The explicit contract, or a compatibility contract matching the legacy