Skip to content

feat(diffusion): periodic validation loss during training - #3579

Open
beccohov wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
beccohov:beccohov/feat/diffusion-val-loss
Open

feat(diffusion): periodic validation loss during training#3579
beccohov wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
beccohov:beccohov/feat/diffusion-val-loss

Conversation

@beccohov

@beccohov beccohov commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

Adds periodic validation loss to the diffusion training recipe, so checking eval loss no longer means saving a checkpoint and running the eval set through the model by hand.

Changelog

  • New optional data.validation_dataloader block, resolved by the same resolve_diffusion_dataloader as the training loader (_typed_config.py), so it takes the same four builders and the same field validation. One loader, matching the training side, rather than the dict of named loaders the LLM recipe has.
  • The recipe builds it in setup() with the same dp sharding and batch size as the training loader, and raises if it comes out empty. Half-configured setups get a warning instead of silence: a loader without val_every_steps validates on checkpoint steps only, val_every_steps without a loader is skipped.
  • _run_validation_epoch scores the held-out set with the training flow-matching objective in eval() under torch.no_grad(), restores train mode in a finally, and reduces [loss_sum, batch_count] in one all-reduce over the dp group, so the mean does not depend on how batches are spread across ranks. CP is excluded from that reduction since every peer computes the same full-sequence loss.
  • The pass runs inside ScopedRNG(seed=self.seed). Without it the sampled timesteps dominate the curve and validation would consume the training RNG stream, changing the run. FP8 autocast is deliberately not applied: delayed-scaling amax history is training state and should not be updated from held-out batches.
  • The loop calls it on step_scheduler.is_val_step, before the checkpoint branch, and logs val_loss to the console and to W&B.
  • Example config (wan2_2_t2v_flow.yaml) and the diffusion fine-tuning guide.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?

Additional Information

  • Closes Support periodic validation loss evaluation for diffusion training #3244
  • Unit tests cover the averaging in eval mode, train mode restored after a failing batch, repeatable sampling with the training RNG left untouched, the dp reduction, and that the loop validates only when a loader is configured.
  • Ran it for real on 2x H200 with FSDP2 (dp_size: 2) against a small Wan transformer: validation fired at the configured steps and the run finished clean. Also ran the same training twice, with and without validation enabled, and the training losses and final weights come out bit-identical, which is the property the fixed seed and RNG restore are there for.
  • Not exercised: cp_size > 1, tp_size > 1, multi-node, and the LoRA and FP8 paths.

Signed-off-by: Arkadii Be <beccohov@gmail.com>
@beccohov
beccohov requested review from a team and jgerh as code owners August 18, 2026 20:39
@copy-pr-bot

copy-pr-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@beccohov

Copy link
Copy Markdown
Contributor Author

Hey @HuiyingLi,
I created PR as we agreed in #3244

@HuiyingLi

Copy link
Copy Markdown
Contributor

Thank you! Taking a look

@HuiyingLi

Copy link
Copy Markdown
Contributor

/claude review

@claude

claude Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

LGTM

@jgerh jgerh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed tech pubs review of docs/guides/diffusion/finetune.mdx and provided a few copyedits and suggested text revisions.

Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
Comment thread docs/guides/diffusion/finetune.mdx Outdated
@HuiyingLi

Copy link
Copy Markdown
Contributor

/ok to test bdf62d5

@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

@beccohov

Copy link
Copy Markdown
Contributor Author

Thanks, @HuiyingLi
I'll wait till the tests finish and then probably I should update the docs according to what @jgerh suggested?

@HuiyingLi

Copy link
Copy Markdown
Contributor

@zyzhou5 could you please take a look too, thanks!

@akoumpa

akoumpa commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

/ok to test 01a0d3d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support periodic validation loss evaluation for diffusion training

5 participants