nemo_automodel.recipes.diffusion.train
nemo_automodel.recipes.diffusion.train
Module Contents
Classes
Functions
Data
API
Bases: BaseRecipe
Training recipe for diffusion models.
Return the per-forward autocast context used when FSDP2 does not cast parameters.
Count samples processed across the data-parallel group.
Return the max elapsed wall-clock seconds across ranks since start_time.
Return a tensor device compatible with the active distributed backend.
Get data parallel world size, handling DDP mode where device_mesh is None.
Get data parallel rank, handling DDP mode where device_mesh is None.
Return PyTorch CUDA allocator memory counters, max-reduced across ranks.
Score the held-out set with the training flow-matching objective.
Seeding by data rank mirrors training: every evaluation draws the same timesteps, noise,
and CFG dropout, so val_loss tracks the model rather than the sampling, while
data-parallel ranks stay decorrelated and context-parallel peers of one rank draw
identical values for their shared batch. ScopedRNG restores the training RNG state
afterwards, leaving the training trajectory unchanged.
The forward runs under the same compute-dtype autocast as training, so a single-rank split-dtype config evaluates the way it trains. FP8 autocast is left out: delayed-scaling amax history is training state and must not be updated from held-out batches.
Parameters:
Current optimizer step, forwarded to the flow-matching pipeline for its periodic diagnostics.
Returns: float
Mean loss over the validation batches of the data-parallel group, comparable to the
Wait for queued CUDA work so timing reflects completed training work.
Return the per-forward Transformer Engine FP8 context.
Build the diffusion transformer’s sole parallelization input.
Build a Transformer Engine FP8 recipe from CLI-friendly config values.
Calculate directly measured training throughput metrics.
Count local samples processed by one optimizer step.
Return the number of samples in one local diffusion micro-batch.
Raise with old->new key mapping when a removed diffusion YAML key is present.
Parameters:
Raw recipe config (ConfigNode or RecipeConfig) as loaded from YAML.
Raises:
ValueError: If any key from_REMOVED_KEY_MIGRATIONSis present.
Resolve model storage and compute dtypes from the recipe config.
Resolve Transformer Engine’s quantization autocast context manager.
Reject split storage/compute dtypes on paths without FSDP param casting.
Build the sharded diffusion pipeline (model + parallel scheme).
The optimizer is built separately by the recipe via
OptimizerConfig.build(...) on the returned pipeline’s transformer, so
that parameters are collected after FSDP2 wrapping.
Parameters:
Pretrained model name or path.
Whether to load for finetuning (True) or pretraining (False).
Target device.
Model parameter storage dtype.
Forward/FSDP compute dtype. Defaults to dtype when unset.
Whether to enable CPU offload (FSDP only).
FSDP configuration dict. Mutually exclusive with ddp_cfg.
DDP configuration dict. Mutually exclusive with fsdp_cfg.
Optional attention backend override.
Whether to replace transformer torch.nn.Linear modules with Transformer Engine Linear.
Whether to skip TE conversion for known FP8-incompatible modules.
Whether to call Diffusers QKV projection fusion on the transformer before FSDP.
Whether to remove original projection modules after QKV fusion.
Pipeline specification for pretraining (from_config). Required when finetune_mode is False. Should contain:
- transformer_cls: str (e.g., “WanTransformer3DModel”, “FluxTransformer2DModel”)
- subfolder: str (e.g., “transformer”)
- Optional: pipeline_cls, load_full_pipeline
PeftConfig instance or None. When provided, only LoRA params are trained; base weights are frozen and sharded by FSDP2 for memory.
“flux” | “flux2” | “wan” | “hunyuan” | “ltx2”. Required when peft_cfg is provided.
For two-transformer pipelines (Wan2.2), select which
transformer to finetune. "transformer" (default for Wan2.2 = high-noise)
or "transformer_2" (low-noise). The unused transformer is dropped
before device placement so only one transformer lives on GPU.
BackendConfig for a transformer with a custom Automodel
implementation (for example MoE diffusion transformers that need expert parallelism).
Config attributes overridden before building a custom-model transformer.
Returns: NeMoAutoDiffusionPipeline
Tuple of (pipeline, resolved MeshContext). The mesh context carries both the
Raises:
ValueError: If both fsdp_cfg and ddp_cfg are provided.ValueError: If finetune_mode is False and pipeline_spec is not provided.