nemo_automodel.components.training.domain_mixture
nemo_automodel.components.training.domain_mixture
Objective weighting for named pretraining data mixtures.
Module Contents
Classes
Data
API
Runtime importance weights and metrics for a named data mixture.
loss_multipliers[i] = objective_weights[i] / sampling_weights[i].
Applying that multiplier to every supervised token sampled from domain
i makes the expected training objective match objective_weights
without changing the sampler or creating separate optimizers.
Validate and flatten per-sample dataset IDs to shape [batch].
Parameters:
Integer tensor of per-sample domain IDs.
Bounds-check the IDs. This costs two blocking
device-to-host syncs, so callers on the per-microbatch critical
path pass False once a step-level pass has already validated
the very same batches.
Return the multiplier vector on device, building it at most once.
loss_multipliers is immutable after DomainMixtureConfig.build,
so rebuilding it per microbatch only adds a pageable host-to-device copy
on the critical path.
Count supervised tokens per domain.
Parameters:
Integer tensor with one domain ID per label row.
Target token IDs of shape [batch, ...] or a flat
single-sample tensor.
Label value excluded from the count.
Returns: torch.Tensor
Int64 tensor of shape [num_domains].
Expand per-sample importance weights to the label layout.
Parameters:
Integer tensor of shape [batch] (or a scalar for a
single sample). IDs follow the domain order in the config.
Target token IDs of shape [batch, sequence] or
[sequence] for a single flattened sample.
Bounds-check dataset_ids. Costs two device syncs;
see _domain_ids.
Returns: torch.Tensor
Float32 tensor matching labels.shape. Every row is constant
Combine named per-domain validation losses using objective weights.
Configuration for importance-weighted multi-domain pretraining.
Build the immutable runtime domain-mixture objective.
Parameters:
Parsed training corpus prefixes and explicit sampling weights, in dataset ID order. When provided, construction validates the declared domain bindings against this blend. Omit for standalone objective calculations.
Returns: 'DomainMixture'
The domain-mixture objective with validated bindings when supplied.
Declarative sampling and objective weights for one data domain.
Domain name. The position in DomainMixtureConfig.domains must
match the dataset_id assigned by the blended dataset.
Relative contribution of the domain to the training and validation objectives.
Explicit Megatron corpus prefix for this domain. Required by the training recipe to verify blend order; optional for standalone objective calculations. Names are never inferred from this path.
Relative probability used to sample the domain.