nemo_automodel.components.datasets.loader
nemo_automodel.components.datasets.loader
Typed, data-parallel-aware dataloader construction.
ParallelAwareDataloaderis a stateful, data-parallel-awareDataLoader: it shards anIterableDataset(or attaches a distributed / length-grouped sampler to a map-style dataset) for(dp_rank, dp_world_size)and inheritsStatefulDataLoaderfor per-rank checkpoint resume.DataloaderConfigowns dataset, sampler, packing, and dataloader construction. Runtime-only objects such as tokenizers and the rank-ordering context are explicitDataloaderConfig.buildarguments.
Module Contents
Classes
Functions
Data
API
Dataset config whose build implementation performs collectives across all ranks.
Typed construction contract for a dataset-specific batch sampler.
Build a per-rank batch sampler for a materialized dataset.
Construction-time configuration for a tokenizer-aware collator class.
Instantiate the collator once with its runtime tokenizer or processor.
Parameters:
Runtime tokenizer or multimodal processor used by the collator.
Returns: CollateFn
Callable collator passed to the dataloader.
A typed dataset config and settings for native or delegated stream construction.
dataset_config is a typed per-dataset config (for example ChatDatasetConfig or
GLUE_MRPCConfig); the dataset’s declarative arguments live there. Runtime dependencies are explicit
build arguments, while native DataLoader settings are named fields on this config.
A StreamDatasetConfig owns its complete loader. Its compatible dataloader config subclass
supplies the stream metadata; the shared build path rejects native-only settings.
Whether dataset construction must bypass rank-zero-first ordering.
Deprecated boolean spelling; use output_format instead.
Whether the loader emits packed inputs, including prepacked THD data.
Selected native packing/collator format; stream subclasses supply their own.
Configured packed input length, or zero for ordinary examples.
Require a stream-specific metadata adapter for complete stream datasets.
Materialize only the dataset inside the caller-provided ordering context.
Adapt a typed dataset for this loader at the recipe config boundary.
Native loaders retain the supplied dataset. Specialized loaders may translate supported dataset descriptions into their own typed configs. No data is loaded or tokenized during adaptation.
Build the configured dataset, packing, sampler, collator, and stateful dataloader.
Parameters:
Rank within the data-parallel group.
Size of the data-parallel group.
Whether pipeline parallelism requires dropping incomplete batches.
Runtime tokenizer or multimodal processor for tokenizer-aware datasets and collators.
Optional caller-owned rank-ordering context used only while materializing the
dataset. Collective dataset builders should pass None.
Whether the model forward contract accepts THD seq_lens metadata.
Actual context-parallel world size, including model-owned CP.
Optional native packing alignment degree when a model owns CP dispatch. Stream builders always receive the actual cp_size.
Runtime optimizer schedule for stream validation.
Optional runtime loss reweighting policy.
Whether this is the training loader rather than validation.
Deprecated attention-backend name retained for Python-call compatibility during the packing-contract migration.
Structural model contract used by NEAT packing. Native mask/Flash collation requires a model-derived contract supplying the attention conversion; recipes provide it automatically.
Stream-backend label exclusion value. Native collators retain their own configured supervision policy and do not consume this value.
Returns: Iterable[object]
Stateful, data-parallel-aware dataloader.
Training schedule values required while materializing schedule-aware datasets.
Bases: PackingConfig
NEAT (bin-packed) packing paired with neat_packed_collater.
Pack with NEAT and configure the collator for the selected attention implementation.
Base config for sequence packing; None (no config) means no packing.
Subclasses (ThdPackingConfig / NeatPackingConfig) pick the packing strategy and the
matching collater. build returns (dataset, collate_fn) — the packed dataset and the
packing-specific collater. Construction-time knobs are the fields; runtime / model-derived values
(split / seed / supports_seq_lens / pad_token_id / cp_size / packing_contract)
are build args.
Number of processes used to pre-tokenize an indexable dataset before packing.
Whether the dataset already contains packed samples and must not be repacked.
Materialize lazy tokenization in parallel when packing can consume the full dataset.
Pack dataset and return (dataset, collate_fn).
Bases: StatefulDataLoader
Stateful, data-parallel-aware DataLoader.
Routes a dataset to (dp_rank, dp_world_size): an IterableDataset is sharded (and optionally
buffer-shuffled); a map-style dataset gets the default distributed (or length-grouped) sampler with
batch_size and drop_last under PP. Inherits StatefulDataLoader for per-rank checkpoint resume.
Dataset config whose build contract has no runtime dependencies.
Build the configured dataset.
Bases: TokenizerDatasetConfig
Dataset config that additionally consumes the recipe training schedule.
Build the configured dataset with tokenizer and schedule dependencies.
Runtime values shared by complete text and image stream builders.
The explicit seed is identical on TP/PP peers. It is independent of the rank-adjusted ScopedRNG protecting incidental construction randomness.
Bases: Generic[_StreamContext, _StreamResult]
Dataset config constructing a complete loader instead of individual samples.
Common loader configs delegate before native sampling, packing or collation. Capabilities are available before construction so recipes can prepare models. Text and image contexts describe their distinct runtime dependencies.
Compatible loader config when YAML omits dataloader._target_.
None retains the recipe’s native default. A stream that requires a
specialized loader config can declare it without coupling recipes to
its implementation.
Explicit packed input limit, or zero when no limit is configured.
Construct a complete stream from declarative fields and runtime inputs.
Bases: StreamBuildContext
Resolved tokenizer for a text stream; never stored on its config.
Bases: PackingConfig
THD (flattened, seq_lens-based) packing; pairs with packed_sequence_thd_collater.
Requires a model whose forward accepts seq_lens; unsupported inputs are rejected.
Align each document’s physical span, counting padding within the pack budget.
Pack with THD, rejecting models that cannot consume sequence lengths.
Dataset config whose build contract accepts a runtime tokenizer or processor.
Build the configured dataset with a runtime tokenizer or processor.
Bases: typing.TypedDict
Options assembled for the stateful PyTorch dataloader constructor.
Fallback shim for a dataset _target_ that has no typed <Name>Config.
make_dataset_config maps known datasets onto their typed config; the few
targets with no config yet (a handful of VLM make_* factories) land here instead. Wraps the target so
it satisfies the typed dataset build contract. Config resolution records whether the external target accepts
a tokenizer, and build forwards only that explicit runtime dependency.
Call the wrapped dataset target with its declared YAML arguments.
Parameters:
Runtime tokenizer or processor. It is forwarded only when the target explicitly declares
a tokenizer parameter; that compatibility decision is recorded once at config resolution.
Returns: object
Dataset object returned by the configured target.
Build the default map-style sampler (distributed, or length-grouped).
Resolve target via registry, a dotted import path, or pass it through unchanged.
target may be a key in registry (whose value is the object itself or a dotted path to it), a
dotted import path ("pkg.mod.attr"), or an already-resolved object (returned as-is). This backs the
make_* resolvers below so packing configs, collate fns and sampler factories share one lookup.
Set the multiprocessing start method to spawn if not already set.
Shard an IterableDataset across data-parallel ranks for unique samples.
Calls the dataset’s own shard or HuggingFace split_dataset_by_node.
Release resources through a loader’s public close method, when provided.
Native PyTorch loaders retain their existing iterator-owned worker lifecycle. Stateful stream loaders can release resources without changing checkpoint routing.
Resolve a collate target into a batch callable or tokenizer-aware config.
target is a built-in collator key (for example "default"), a dotted import path, or an already
resolved callable. Collator classes become CollatorConfig so DataloaderConfig.build
instantiates them once with the runtime tokenizer. Function kwargs remain partial-bound per batch.
Resolve a dataset _target_ to an object exposing a typed build method.
Exact legacy registrations map a pre-config dataset class or make_* factory onto its typed
<Name>Config without class-name dispatch. Misses fall back to the _target_ itself, so a target that
already names a config imports directly. Typed config fields are validated before construction; external
factories use _LegacyDatasetConfig.
Resolve a packing-config target and construct it from kwargs (target=None → no packing).
target is either a built-in strategy key ("thd" / "neat") or a dotted import path to
a PackingConfig subclass (e.g. "my_pkg.MyPackingConfig"). Strategy-specific fields from the
union-shaped packed_sequence YAML block are accepted and filtered for the selected strategy; unknown
fields are rejected instead of silently disappearing.